Skip to content

return OneHotArray on proper reshape? #30

Closed
@CarloLucibello

Description

@CarloLucibello

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:

  1. give up type instability, and return a onehotarray only if the first dimension is preserved, and a reshaped array otherwise
  2. 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

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