Skip to content

Commit a965580

Browse files
authored
Use parent for similar(::PermutedDimsArray) (#35304)
1 parent e25b357 commit a965580

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

base/permuteddimsarray.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ function PermutedDimsArray(data::AbstractArray{T,N}, perm) where {T,N}
4646
end
4747

4848
Base.parent(A::PermutedDimsArray) = A.parent
49-
Base.size(A::PermutedDimsArray{T,N,perm}) where {T,N,perm} = genperm(size(parent(A)), perm)
49+
Base.size(A::PermutedDimsArray{T,N,perm}) where {T,N,perm} = genperm(size(parent(A)), perm)
5050
Base.axes(A::PermutedDimsArray{T,N,perm}) where {T,N,perm} = genperm(axes(parent(A)), perm)
5151

52+
Base.similar(A::PermutedDimsArray, T::Type, dims::Base.Dims) = similar(parent(A), T, dims)
53+
5254
Base.unsafe_convert(::Type{Ptr{T}}, A::PermutedDimsArray{T}) where {T} = Base.unsafe_convert(Ptr{T}, parent(A))
5355

5456
# It's OK to return a pointer to the first element, and indeed quite

test/arrayops.jl

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# Array test
44
isdefined(Main, :OffsetArrays) || @eval Main include("testhelpers/OffsetArrays.jl")
55
using .Main.OffsetArrays
6+
7+
isdefined(@__MODULE__, :T24Linear) || include("testhelpers/arrayindexingtypes.jl")
8+
69
using SparseArrays
710

811
using Random, LinearAlgebra
@@ -683,6 +686,13 @@ end
683686
y = [0, 0, 0, 0]
684687
copyto!(y, x)
685688
@test y == [1, 2, 3, 4]
689+
690+
# similar, https://github.com/JuliaLang/julia/pull/35304
691+
x = PermutedDimsArray([1 2; 3 4], (2, 1))
692+
@test similar(x, 3,3) isa Array
693+
z = TSlow([1 2; 3 4])
694+
x_slow = PermutedDimsArray(z, (2, 1))
695+
@test similar(x_slow, 3,3) isa TSlow
686696
end
687697

688698
@testset "circshift" begin

0 commit comments

Comments
 (0)