I was surprised to find out that using UInt16
s is not a valid way to reshape an Array
. I get the following behavior on Julia 0.6.4 as well as Julia 1.0.2
julia> a = collect(1:6)
6-element Array{Int64,1}:
1
2
3
4
5
6
julia> b = reshape(a, 3, 2)
3×2 Array{Int64,2}:
1 4
2 5
3 6
julia> c = reshape(a, UInt16(3), UInt16(2))
ERROR: MethodError: no method matching reshape(::Array{Int64,1}, ::UInt16, ::UInt16)
Closest candidates are:
reshape(::Array{T,N}, ::Tuple{Vararg{Int64,N}}) where {N, T} at array.jl:303
reshape(::Array{T,N} where N, ::Tuple{Vararg{Int64,N}}) where {N, T} at array.jl:314
reshape(::AbstractArray, ::Int64...) at reshapedarray.jl:99
...
Stacktrace:
[1] top-level scope at none:0
julia>
Is this intended? I’m reading a UInt16
from a network stream as information to reshape incoming data and I now have to cast to explicitly convert my UInt16
’s to Int32
’s.
As an aside, I do enjoy the irony that reshaping with negative numbers seems invalid, but Int32
allows for that