Skip to content

Commit a202b30

Browse files
authored
No reshape piracy (#194)
* No reshape piracy. Fixes #193, reverts #123 * Actually let's just delete the `reshape` method.
1 parent ed42033 commit a202b30

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ComponentArrays"
22
uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
33
authors = ["Jonnie Diegelman <[email protected]>"]
4-
version = "0.13.8"
4+
version = "0.13.9"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/array_interface.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ Base.axes(x::ComponentArray) = CombinedAxis.(getaxes(x), axes(getdata(x)))
1010

1111
Base.reinterpret(::Type{T}, x::ComponentArray, args...) where T = ComponentArray(reinterpret(T, getdata(x), args...), getaxes(x))
1212

13-
Base.reshape(A::AbstractArray, axs::NTuple{N,<:CombinedAxis}) where {N} = reshape(A, _array_axis.(axs))
14-
1513
ArrayInterface.indices_do_not_alias(::Type{ComponentArray{T,N,A,Axes}}) where {T,N,A,Axes} = ArrayInterface.indices_do_not_alias(A)
1614
ArrayInterface.instances_do_not_alias(::Type{ComponentArray{T,N,A,Axes}}) where {T,N,A,Axes} = ArrayInterface.instances_do_not_alias(A)
1715

src/componentarray.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ function make_idx(data, nt::Union{NamedTuple, AbstractDict}, last_val)
162162
end
163163
function make_idx(data, pair::Pair, last_val)
164164
data, ax = make_idx(data, pair.second, last_val)
165+
len = recursive_length(data)
165166
return (data, ViewAxis(last_val:(last_val+len-1), Axis(pair.second)))
166167
end
167168
make_idx(data, x, last_val) = (

test/runtests.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ end
263263
@test ca[Not(2:3)] == getdata(ca)[Not(2:3)]
264264

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

269272
@testset "Set" begin
@@ -621,6 +624,10 @@ end
621624
# Issue #140
622625
@test ComponentArrays.ArrayInterface.indices_do_not_alias(typeof(ca)) == true
623626
@test ComponentArrays.ArrayInterface.instances_do_not_alias(typeof(ca)) == false
627+
628+
# Issue #193
629+
# Make sure we aren't doing type piracy on `reshape`
630+
@test ndims(dropdims(ones(1,1), dims=(1,2))) == 0
624631
end
625632

626633
@testset "Autodiff" begin

0 commit comments

Comments
 (0)