Skip to content

Integer instead of Int for Size function #37

@rchomjak

Description

@rchomjak

Hello,

Motivation:

I was trying to create stack based on some types:

julia> TYPE_VAR_STACK = UInt8
UInt8

julia> LEN_STACK = UInt8
UInt8

julia> SizedArray{Tuple{typemax(LEN_STACK),}}(zeros(eltype(TYPE_VAR_STACK), typemax(LEN_STACK)))

typemax returns max value of the input type, so I cannot use typemax for Uints

Directly operations with StaticArray:

julia> SizedVector{Int(2), Int64, Vector{Int64}}(undef)
2-element SizedVector{2, Int64, Vector{Int64}} with indices SOneTo(2):
 140635748783968
 140635617105504

julia> SizedVector{UInt(2), Int64, Vector{Int64}}(undef)
Error showing value of type SizedVector{2, Int64, Vector{Int64}}:

SYSTEM (REPL): showing an error caused an error
ERROR: 1-element ExceptionStack:
TypeError: in typeassert, expected Tuple{Vararg{Union{StaticArraysCore.Dynamic, Int64}}}, got a value of type Tuple{UInt64}
Stacktrace:
  [1] Size{(2,)}()
    @ StaticArraysCore ~/devel/julia/StaticArraysCore.jl/src/StaticArraysCore.jl:510
  [2] Size(::Type{Tuple{2}})
    @ StaticArraysCore ~/devel/julia/StaticArraysCore.jl/src/StaticArraysCore.jl:517
  [3] Size(::Type{SizedVector{2, Int64, Vector{Int64}}})
    @ StaticArraysCore ~/devel/julia/StaticArraysCore.jl/src/StaticArraysCore.jl:539
  [4] Size(a::SizedVector{2, Int64, Vector{Int64}})
...

Not sure, if it is the intention, but same behavior is in the builtin Array:

julia> Array{Float64, Int(1)}(undef,1)
1-element Vector{Float64}:
 0.0

julia> Array{Float64, UInt(1)}(undef,1)
ERROR: MethodError: no method matching Array{Float64, 1}(::UndefInitializer, ::Int64)
The type `Array{Float64, 1}` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  Array{T, N}(::Missing, ::Any...) where {T, N}
   @ Base baseext.jl:43
  Array{T, N}(::Nothing, ::Any...) where {T, N}

I think, it has to support the UInt, because it is kind of Integer:

julia> supertype(Int)
Signed

julia> supertype(UInt)
Unsigned

julia> supertype(Signed)
Integer

julia> supertype(Unsigned)
Integer

Moreover, UIntS have bigger range.

Here is the PR #36

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions