Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reshape back #298

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/componentarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ function maybe_reshape(data, axs::AbstractAxis...)
return reshape(data, shapes)
end

function Base.reshape(parent::AbstractArray, dims::ComponentArrays.CombinedAxis...)
reshape(parent, getfield.(dims, :array_axis))
function Base.reshape(A::AbstractArray, axs::Tuple{CombinedAxis, Vararg{CombinedAxis}})
reshape(A, _array_axis.(axs))
end

# Recurse through nested ViewAxis types to find the last index
Expand Down
10 changes: 3 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,6 @@ end
@test ca[Not(3)] == getdata(ca)[Not(3)]
@test ca[Not(2:3)] == getdata(ca)[Not(2:3)]

# Issue #123
# We had to revert this because there is no way to work around
# OffsetArrays' type piracy without introducing type piracy
# ourselves because `() isa Tuple{N, <:CombinedAxis} where {N}`
# @test reshape(a, axes(ca)...) isa Vector{Float64}

# Issue #248: Indexing ComponentMatrix with FlatAxis components
@test cmat3[:a, :a] == cmat3check[1, 1]
@test cmat3[:a, :b] == cmat3check[1, 2:5]
Expand All @@ -308,7 +302,8 @@ end

# https://discourse.julialang.org/t/no-method-error-reshape-when-solving-ode-with-componentarrays-jl/126342
x = ComponentVector(x=1.0, y=0.0, z=0.0)
@test reshape(x, axes(x)...) isa ComponentVector
@test reshape(x, axes(x)...) === x
@test reshape(x, axes(x)) === x
@test reshape(a, axes(ca)...) isa Vector{Float64}

# Issue #265: Multi-symbol indexing with matrix components
Expand Down Expand Up @@ -727,6 +722,7 @@ end
# Issue #193
# Make sure we aren't doing type piracy on `reshape`
@test ndims(dropdims(ones(1,1), dims=(1,2))) == 0
@test reshape([1]) == fill(1, ())

if VERSION >= v"1.9"
# `stack` was introduced in Julia 1.9
Expand Down