Closed
Description
Right now a reshape of a OneHotArray that preserves the first dimension doesn't return a OneHotArray:
julia> oh = onehotbatch(rand('a':'b', (3, 2)), 'a':'b')
2×3×2 OneHotArray(::Matrix{UInt32}) with eltype Bool:
[:, :, 1] =
0 0 0
1 1 1
[:, :, 2] =
0 0 0
1 1 1
julia> x = reshape(oh, 2, :)
2×6 reshape(OneHotArray(::Matrix{UInt32}), 2, 6) with eltype Bool:
⋅ ⋅ ⋅ ⋅ ⋅ ⋅
1 1 1 1 1 1
julia> x isa Base.ReshapedArray
true
It would be convenient to return onehotarrays in that case, for convenience and in order to avoid downstream such as
FluxML/Flux.jl#2160.
If we want to do this we have two options:
- give up type instability, and return a onehotarray only if the first dimension is preserved, and a reshaped array otherwise
- error out on any reshape that doesn't preserve the first dimension.
I remember we already had a discussion on reshape
somewhere, but maybe worth revisiting.
Metadata
Metadata
Assignees
Labels
No labels