Skip to content

Commit 51b7289

Browse files
authored
Maintain Transpose/Adjoint types and unroll subarrays when materialis… (#136)
* Maintain Transpose/Adjoint types and unroll subarrays when materialising DualLayout * add tests * Update ci.yml * Increase coverage
1 parent 35a135b commit 51b7289

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ jobs:
1414
version:
1515
- '1.6'
1616
- '1'
17-
- '^1.9.0-0'
1817
os:
1918
- ubuntu-latest
2019
- macOS-latest

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ArrayLayouts"
22
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "1.0.4"
4+
version = "1.0.5"
55

66
[deps]
77
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"

src/memorylayout.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,14 @@ adjointlayout(::Type{T}, ::DualLayout{ML}) where {T,ML} = adjointlayout(T, ML())
298298
adjointlayout(::Type{T}, M::MemoryLayout) where T = transposelayout(conjlayout(T, M))
299299
sublayout(::DualLayout{ML}, ::Type{<:Tuple{KR,JR}}) where {ML,KR<:Slice,JR} = DualLayout{typeof(sublayout(ML(),Tuple{KR,JR}))}()
300300
sublayout(::DualLayout{ML}, INDS::Type) where ML = sublayout(ML(), INDS)
301-
sub_materialize(::DualLayout{ML}, A) where ML = sub_materialize(adjointlayout(eltype(A), ML()), A')'
301+
302+
# try to maintain "type" of parent ie adjoint/transpose when materialising, even though layouts are equivalent
303+
# to preserve special overloads
304+
_dual_adjoint(a::SubArray{<:Any, 2, <:Any, <:Tuple{Slice,Any}}) = view(parent(a)', parentindices(a)[2])
305+
_dual_transpose(a::SubArray{<:Any, 2, <:Any, <:Tuple{Slice,Any}}) = view(transpose(parent(a)), parentindices(a)[2])
306+
sub_materialize(::DualLayout{ML}, A::AbstractMatrix{<:Real}) where ML = sub_materialize(adjointlayout(eltype(A), ML()), _dual_adjoint(A))'
307+
sub_materialize(::DualLayout{ML}, A::AbstractMatrix) where ML<:ConjLayout = sub_materialize(adjointlayout(eltype(A), ML()), _dual_adjoint(A))'
308+
sub_materialize(::DualLayout{ML}, A::AbstractMatrix) where ML = transpose(sub_materialize(transposelayout(ML()), _dual_transpose(A)))
302309

303310
_copyto!(dlay, ::DualLayout{ML}, dest::AbstractArray{T,N}, src::AbstractArray{V,N}) where {T,V,N,ML} =
304311
_copyto!(dlay, ML(), dest, src)

test/test_layouts.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,14 @@ struct FooNumber <: Number end
8989
@test (a')[:,1:3] == layout_getindex(a',:,1:3)
9090
@test (a')[1:1,1:3] == layout_getindex(a',1:1,1:3)
9191
@test layout_getindex(a',:,1:3) isa Adjoint
92+
@test layout_getindex(transpose(a),:,1:3) isa Adjoint
93+
@test layout_getindex((a .+ im)',:,1:3) isa Adjoint
94+
@test layout_getindex(transpose(a .+ im),:,1:3) isa Transpose
9295
@test layout_getindex(a',1:1,1:3) isa Array
9396

97+
@test layout_getindex((a .+ im)',:,1:3) == (a .+ im)[1:3]'
98+
@test layout_getindex(transpose(a .+ im),:,1:3) == transpose((a .+ im)[1:3])
99+
94100
@test ArrayLayouts._copyto!(similar(a'), a') == a'
95101
end
96102
end
@@ -181,7 +187,9 @@ struct FooNumber <: Number end
181187
@test colsupport(Symmetric(A),2) colsupport(Symmetric(A),1:2)
182188
rowsupport(Symmetric(A),2) rowsupport(Symmetric(A),1:2) 1:2
183189
@test colsupport(Hermitian(A),2) colsupport(Hermitian(A),1:2)
184-
rowsupport(Hermitian(A),2) rowsupport(Hermitian(A),1:2) 1:2
190+
rowsupport(Hermitian(A),2) rowsupport(Hermitian(A),1:2)
191+
colsupport(Symmetric(A,:L),2) colsupport(Hermitian(A,:L),2)
192+
rowsupport(Symmetric(A,:L),2) rowsupport(Hermitian(A,:L),2) 1:2
185193

186194
B = [1.0+im 2; 3 4]
187195
@test MemoryLayout(Symmetric(B)) == SymmetricLayout{DenseColumnMajor}()
@@ -299,6 +307,9 @@ struct FooNumber <: Number end
299307
@test layout_getindex(Ones{Int}(1,10), 1, 1:3) Ones{Int}(3)
300308
@test layout_getindex(Zeros{Int}(5,10,12), 1, 1:3,4:6) Zeros{Int}(3,3)
301309

310+
@test isempty(colsupport(Zeros(5,10), 2))
311+
@test isempty(rowsupport(Zeros(5,10), 2))
312+
302313
# views of Fill no longer create Sub Arrays, but are supported
303314
# as there was no strong need to delete their support
304315
v = SubArray(Fill(1,10),(1:3,))

0 commit comments

Comments
 (0)