Skip to content

Missing methods for reshape? #947

@mcabbott

Description

@mcabbott

I thought this would work, and produce a SizedArray:

julia> using StaticArrays

julia> reshape(hcat([1,2,3]), axes(SA[1,2,3]))
ERROR: MethodError: no method matching reshape(::Matrix{Int64}, ::Tuple{SOneTo{3}})

julia> SizedArray{Tuple{3}}([1,2,3])  # what I expected:
3-element SizedVector{3, Int64, Vector{Int64}} with indices SOneTo(3):
 1
 2
 3

Context is FluxML/Zygote.jl#1044, trying to make AD more careful about restoring the types of its inputs. Reshaping like this works for OffsetArrays, which in fact (piratically) resolves the above error:

julia> using OffsetArrays

julia> reshape(hcat([1,2,3]), axes(SA[1,2,3]))  # this works...
3-element OffsetArray(::Vector{Int64}, 1:3) with eltype Int64 with indices 1:3:
 1
 2
 3

julia> reshape(hcat([1,2,3]), axes(OffsetArray([1,2,3],3)))  # as a size-effect of this ...
3-element OffsetArray(::Vector{Int64}, 4:6) with eltype Int64 with indices 4:6:
 1
 2
 3

julia> reshape(hcat([1,2,3]), (4:6,))  # ... because it's piratically broad.
3-element OffsetArray(::Vector{Int64}, 4:6) with eltype Int64 with indices 4:6:
 1
 2
 3

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