Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ArrayLayouts"
uuid = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
version = "1.16"
version = "1.16.1"
authors = ["Sheehan Olver <solver@mac.com>"]

[deps]
Expand Down
8 changes: 6 additions & 2 deletions src/memorylayout.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,12 @@ sublayout(::DualLayout{ML}, INDS::Type) where ML = sublayout(ML(), INDS)

# try to maintain "type" of parent ie adjoint/transpose when materialising, even though layouts are equivalent
# to preserve special overloads
_dual_adjoint(a::SubArray{<:Any, 2, <:Any, <:Tuple{Slice,Any}}) = view(parent(a)', parentindices(a)[2])
_dual_transpose(a::SubArray{<:Any, 2, <:Any, <:Tuple{Slice,Any}}) = view(transpose(parent(a)), parentindices(a)[2])
# parent may be a 1×n matrix with DualLayout (e.g. a wrapper around an adjoint vector), in which case
# we take a column view of its adjoint rather than linear indexing (which would reshape)
_dual_view(v::AbstractVector, jr) = view(v, jr)
_dual_view(A::AbstractMatrix, jr) = view(A, jr, only(axes(A,2)))
_dual_adjoint(a::SubArray{<:Any, 2, <:Any, <:Tuple{Slice,Any}}) = _dual_view(parent(a)', parentindices(a)[2])
_dual_transpose(a::SubArray{<:Any, 2, <:Any, <:Tuple{Slice,Any}}) = _dual_view(transpose(parent(a)), parentindices(a)[2])
sub_materialize(::DualLayout{ML}, A::AbstractMatrix{<:Real}) where ML = sub_materialize(adjointlayout(eltype(A), ML()), _dual_adjoint(A))'
sub_materialize(::DualLayout{ML}, A::AbstractMatrix) where ML<:ConjLayout = sub_materialize(adjointlayout(eltype(A), ML()), _dual_adjoint(A))'
sub_materialize(::DualLayout{ML}, A::AbstractMatrix) where ML = transpose(sub_materialize(transposelayout(ML()), _dual_transpose(A)))
Expand Down
18 changes: 18 additions & 0 deletions test/test_layoutarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -910,4 +910,22 @@ end
@test transpose(lv) * F == transpose(v) * F
end

@testset "DualLayout matrix parent" begin
# a 1×n matrix with DualLayout that is not itself an adjoint vector
a = randn(5)
for (M, f) in ((MyMatrix(a'), adjoint), (MyMatrix(transpose(a)), transpose),
(MyMatrix((a .+ im)'), adjoint), (MyMatrix(transpose(a .+ im)), transpose))
@test MemoryLayout(M) isa DualLayout
V = view(M, :, 1:3)
@test MemoryLayout(V) isa DualLayout
@test M[:,1:3] == f(f(M)[1:3])
# avoid linear indexing into a matrix, which reshapes
@test !(parent(ArrayLayouts._dual_adjoint(V)) isa Base.ReshapedArray)
@test !(parent(ArrayLayouts._dual_transpose(V)) isa Base.ReshapedArray)
end
# linear indexing into an infinite matrix is not supported, so must avoid reshape
M = MyMatrix(InfiniteArrays.InfVec()')
@test M[:,1:3] == M.A[:,1:3]
end

end
Loading