Skip to content

Commit 8ee4b11

Browse files
committed
Don't pirate Base methods for WrappedArray queries.
1 parent f298353 commit 8ee4b11

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Adapt"
22
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
3-
version = "2.4.0"
3+
version = "3.0.0"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/wrappers.jl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@ permutation(::PermutedDimsArray{T,N,perm}) where {T,N,perm} = perm
88
export WrappedArray
99

1010
adapt_structure(to, A::SubArray) =
11-
SubArray(adapt(to, parent(A)), adapt(to, parentindices(A)))
11+
SubArray(adapt(to, Base.parent(A)), adapt(to, parentindices(A)))
1212
adapt_structure(to, A::Base.LogicalIndex) =
1313
Base.LogicalIndex(adapt(to, A.mask))
1414
adapt_structure(to, A::PermutedDimsArray) =
15-
PermutedDimsArray(adapt(to, parent(A)), permutation(A))
15+
PermutedDimsArray(adapt(to, Base.parent(A)), permutation(A))
1616
adapt_structure(to, A::Base.ReshapedArray) =
17-
Base.reshape(adapt(to, parent(A)), size(A))
17+
Base.reshape(adapt(to, Base.parent(A)), size(A))
1818
adapt_structure(to, A::Base.ReinterpretArray) =
19-
Base.reinterpret(eltype(A), adapt(to, parent(A)))
19+
Base.reinterpret(Base.eltype(A), adapt(to, Base.parent(A)))
2020

2121
adapt_structure(to, A::LinearAlgebra.Adjoint) =
22-
LinearAlgebra.adjoint(adapt(to, parent(A)))
22+
LinearAlgebra.adjoint(adapt(to, Base.parent(A)))
2323
adapt_structure(to, A::LinearAlgebra.Transpose) =
24-
LinearAlgebra.transpose(adapt(to, parent(A)))
24+
LinearAlgebra.transpose(adapt(to, Base.parent(A)))
2525
adapt_structure(to, A::LinearAlgebra.LowerTriangular) =
26-
LinearAlgebra.LowerTriangular(adapt(to, parent(A)))
26+
LinearAlgebra.LowerTriangular(adapt(to, Base.parent(A)))
2727
adapt_structure(to, A::LinearAlgebra.UnitLowerTriangular) =
28-
LinearAlgebra.UnitLowerTriangular(adapt(to, parent(A)))
28+
LinearAlgebra.UnitLowerTriangular(adapt(to, Base.parent(A)))
2929
adapt_structure(to, A::LinearAlgebra.UpperTriangular) =
30-
LinearAlgebra.UpperTriangular(adapt(to, parent(A)))
30+
LinearAlgebra.UpperTriangular(adapt(to, Base.parent(A)))
3131
adapt_structure(to, A::LinearAlgebra.UnitUpperTriangular) =
32-
LinearAlgebra.UnitUpperTriangular(adapt(to, parent(A)))
32+
LinearAlgebra.UnitUpperTriangular(adapt(to, Base.parent(A)))
3333
adapt_structure(to, A::LinearAlgebra.Diagonal) =
34-
LinearAlgebra.Diagonal(adapt(to, parent(A)))
34+
LinearAlgebra.Diagonal(adapt(to, Base.parent(A)))
3535
adapt_structure(to, A::LinearAlgebra.Tridiagonal) =
3636
LinearAlgebra.Tridiagonal(adapt(to, A.dl), adapt(to, A.d), adapt(to, A.du))
3737

@@ -103,26 +103,26 @@ WrappedArray{T,N,Src,Dst} = Union{
103103
# https://github.com/JuliaLang/julia/pull/31563
104104

105105
# accessors for extracting information about the wrapper type
106-
Base.ndims(::Type{<:Base.LogicalIndex}) = 1
107-
Base.ndims(::Type{<:LinearAlgebra.Adjoint}) = 2
108-
Base.ndims(::Type{<:LinearAlgebra.Transpose}) = 2
109-
Base.ndims(::Type{<:LinearAlgebra.LowerTriangular}) = 2
110-
Base.ndims(::Type{<:LinearAlgebra.UnitLowerTriangular}) = 2
111-
Base.ndims(::Type{<:LinearAlgebra.UpperTriangular}) = 2
112-
Base.ndims(::Type{<:LinearAlgebra.UnitUpperTriangular}) = 2
113-
Base.ndims(::Type{<:LinearAlgebra.Diagonal}) = 2
114-
Base.ndims(::Type{<:LinearAlgebra.Tridiagonal}) = 2
115-
Base.ndims(::Type{<:WrappedArray{<:Any,N}}) where {N} = N
116-
117-
Base.eltype(::Type{<:WrappedArray{T}}) where {T} = T # every wrapper has a T typevar
106+
ndims(::Type{<:Base.LogicalIndex}) = 1
107+
ndims(::Type{<:LinearAlgebra.Adjoint}) = 2
108+
ndims(::Type{<:LinearAlgebra.Transpose}) = 2
109+
ndims(::Type{<:LinearAlgebra.LowerTriangular}) = 2
110+
ndims(::Type{<:LinearAlgebra.UnitLowerTriangular}) = 2
111+
ndims(::Type{<:LinearAlgebra.UpperTriangular}) = 2
112+
ndims(::Type{<:LinearAlgebra.UnitUpperTriangular}) = 2
113+
ndims(::Type{<:LinearAlgebra.Diagonal}) = 2
114+
ndims(::Type{<:LinearAlgebra.Tridiagonal}) = 2
115+
ndims(::Type{<:WrappedArray{<:Any,N}}) where {N} = N
116+
117+
eltype(::Type{<:WrappedArray{T}}) where {T} = T # every wrapper has a T typevar
118118

119119
for T in [:(Base.LogicalIndex{<:Any,<:Src}),
120120
:(PermutedDimsArray{<:Any,<:Any,<:Any,<:Any,<:Src}),
121121
:(WrappedReinterpretArray{<:Any,<:Any,<:Src}),
122122
:(WrappedReshapedArray{<:Any,<:Any,<:Src}),
123123
:(WrappedSubArray{<:Any,<:Any,<:Src})]
124124
@eval begin
125-
Base.parent(::Type{<:$T}) where {Src} = Src.name.wrapper
125+
parent(::Type{<:$T}) where {Src} = Src.name.wrapper
126126
end
127127
end
128-
Base.parent(::Type{<:WrappedArray{<:Any,<:Any,<:Any,Dst}}) where {Dst} = Dst.name.wrapper
128+
parent(::Type{<:WrappedArray{<:Any,<:Any,<:Any,Dst}}) where {Dst} = Dst.name.wrapper

test/runtests.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ const d = CustomArray{Float64,1}(rand(3))
108108
@test_adapt CustomArray Tridiagonal(dl.arr, d.arr, du.arr) Tridiagonal(dl, d, du) AnyCustomArray
109109

110110
@testset "Extracting type information" begin
111-
@test ndims(LinearAlgebra.Transpose{Float64,Array{Float64,1}}) == 2
112-
@test ndims(Adapt.WrappedSubArray{Float64,3,Array{Float64,3}}) == 3
111+
@test Adapt.ndims(LinearAlgebra.Transpose{Float64,Array{Float64,1}}) == 2
112+
@test Adapt.ndims(Adapt.WrappedSubArray{Float64,3,Array{Float64,3}}) == 3
113113

114-
@test parent(LinearAlgebra.Transpose{Float64,Array{Float64,1}}) == Array
115-
@test parent(Adapt.WrappedSubArray{Float64,3,Array{Float64,3}}) == Array
114+
@test Adapt.parent(LinearAlgebra.Transpose{Float64,Array{Float64,1}}) == Array
115+
@test Adapt.parent(Adapt.WrappedSubArray{Float64,3,Array{Float64,3}}) == Array
116116
end

0 commit comments

Comments
 (0)