Skip to content

Commit a7bd760

Browse files
authored
Support transtype for DualLayout{ApplyLayout{typeof(*)}} (#335)
* Support transtype for DualLayout{ApplyLayout{typeof(*)}} * Deal with bugs introduced by DualLayout{LazyLayout} * Update mul.jl * go back to DualLayout not being <: LazyLayouts * Padded' * Banded * fix tests * increase coverage * increase cov * Update addtests.jl * Avoid breaking QuasiArrays.jl * Update addtests.jl
1 parent 343c13d commit a7bd760

File tree

11 files changed

+182
-29
lines changed

11 files changed

+182
-29
lines changed

.github/workflows/downstream.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
- {repo: InfiniteArrays.jl, group: JuliaArrays}
3636
- {repo: QuasiArrays.jl, group: JuliaApproximation}
3737
- {repo: ContinuumArrays.jl, group: JuliaApproximation}
38+
- {repo: ClassicalOrthogonalPolynomials.jl, group: JuliaApproximation}
3839

3940
steps:
4041
- uses: actions/checkout@v4

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "LazyArrays"
22
uuid = "5078a376-72f3-5289-bfd5-ec5146d43c02"
3-
version = "2.1.4"
3+
version = "2.1.5"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

ext/LazyArraysBandedMatricesExt.jl

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using BandedMatrices, LazyArrays, LinearAlgebra
44
using LazyArrays.ArrayLayouts, LazyArrays.FillArrays, LazyArrays.LazyArrays
55
import ArrayLayouts: colsupport, rowsupport, materialize!, MatMulVecAdd, MatMulMatAdd, DenseColumnMajor,
66
OnesLayout, AbstractFillLayout, mulreduce, inv_layout, _fill_lmul!, copyto!_layout, _copy_oftype,
7-
layout_getindex
7+
layout_getindex, transtype
88
import LazyArrays: sublayout, symmetriclayout, hermitianlayout, applylayout, cachedlayout, transposelayout,
99
LazyArrayStyle, ApplyArrayBroadcastStyle, AbstractInvLayout, AbstractLazyLayout, LazyLayouts,
1010
AbstractPaddedLayout, PaddedLayout, PaddedRows, PaddedColumns, CachedArray, CachedMatrix, LazyLayout, BroadcastLayout, ApplyLayout,
@@ -132,22 +132,30 @@ end
132132
# Vcat(Zeros{T}(max(0,j-u-1)), view(data, (kr .- j .+ (u+1)) ∩ axes(data,1), j))
133133
# end
134134

135-
function similar(M::MulAdd{<:BandedLayouts,<:AbstractPaddedLayout}, ::Type{T}, axes::Tuple{Any}) where T
135+
function similar(M::MulAdd{<:BandedLayouts,<:Union{PaddedColumns,PaddedLayout}}, ::Type{T}, axes::Tuple{Any}) where T
136136
A,x = M.A,M.B
137137
xf = paddeddata(x)
138138
n = max(0,min(length(xf) + bandwidth(A,1),length(M)))
139139
Vcat(Vector{T}(undef, n), Zeros{T}(size(A,1)-n))
140140
end
141141

142-
function similar(M::MulAdd{<:BandedLayouts,<:AbstractPaddedLayout}, ::Type{T}, axes::Tuple{Any,Any}) where T
142+
function similar(M::MulAdd{<:BandedLayouts,<:Union{PaddedColumns,PaddedLayout}}, ::Type{T}, axes::Tuple{Any,Any}) where T
143143
A,x = M.A,M.B
144144
xf = paddeddata(x)
145145
m = max(0,min(size(xf,1) + bandwidth(A,1),size(M,1)))
146146
n = size(xf,2)
147147
PaddedArray(Matrix{T}(undef, m, n), size(A,1), size(x,2))
148148
end
149149

150-
function materialize!(M::MatMulVecAdd{<:BandedLayouts,<:AbstractPaddedLayout,<:AbstractPaddedLayout})
150+
function similar(M::MulAdd{<:DualLayout{<:PaddedRows}, <:BandedLayouts}, ::Type{T}, axes::Tuple{Any,Any}) where T
151+
xt,A = M.A,M.B
152+
trans = transtype(xt)
153+
xf = paddeddata(trans(xt))
154+
n = max(0,min(length(xf) + bandwidth(A,2),size(M,2)))
155+
trans(Vcat(Vector{T}(undef, n), Zeros{T}(size(A,1)-n)))
156+
end
157+
158+
function materialize!(M::MatMulVecAdd{<:BandedLayouts,<:Union{PaddedColumns,PaddedLayout},<:Union{PaddedColumns,PaddedLayout}})
151159
α,A,x,β,y = M.α,M.A,M.B,M.β,M.C
152160
length(y) == size(A,1) || throw(DimensionMismatch())
153161
length(x) == size(A,2) || throw(DimensionMismatch())
@@ -160,7 +168,7 @@ function materialize!(M::MatMulVecAdd{<:BandedLayouts,<:AbstractPaddedLayout,<:A
160168
y
161169
end
162170

163-
function materialize!(M::MatMulMatAdd{<:BandedLayouts,<:AbstractPaddedLayout,<:AbstractPaddedLayout})
171+
function materialize!(M::MatMulMatAdd{<:BandedLayouts,<:Union{PaddedColumns,PaddedLayout},<:Union{PaddedColumns,PaddedLayout}})
164172
α,A,x,β,y = M.α,M.A,M.B,M.β,M.C
165173
size(y) == (size(A,1),size(x,2)) || throw(DimensionMismatch())
166174
size(x,1) == size(A,2) || throw(DimensionMismatch())
@@ -293,7 +301,7 @@ broadcasted(::LazyArrayStyle, ::typeof(\), c::Number, A::BandedMatrix) = _Banded
293301
broadcasted(::LazyArrayStyle, ::typeof(/), A::BandedMatrix, c::Number) = _BandedMatrix(A.data ./ c, A.raxis, A.l, A.u)
294302

295303

296-
copy(M::Mul{BroadcastBandedLayout{typeof(*)}, <:AbstractPaddedLayout}) = _broadcast_banded_padded_mul(arguments(BroadcastBandedLayout{typeof(*)}(), M.A), M.B)
304+
copy(M::Mul{BroadcastBandedLayout{typeof(*)}, <:Union{PaddedColumns,PaddedLayout}}) = _broadcast_banded_padded_mul(arguments(BroadcastBandedLayout{typeof(*)}(), M.A), M.B)
297305

298306

299307
###
@@ -585,6 +593,7 @@ simplifiable(::Mul{<:AbstractInvLayout, <:BandedLazyLayouts}) = Val(false)
585593
copy(M::Mul{<:AbstractInvLayout, <:BandedLazyLayouts}) = simplify(M)
586594

587595

596+
588597
copy(L::Ldiv{<:BandedLazyLayouts}) = lazymaterialize(\, L.A, L.B)
589598
copy(L::Ldiv{<:BandedLazyLayouts,<:AbstractLazyLayout}) = lazymaterialize(\, L.A, L.B)
590599
copy(L::Ldiv{<:BandedLazyLayouts, Blay}) where Blay<:Union{AbstractStridedLayout,PaddedColumns} = copy(Ldiv{UnknownLayout,Blay}(L.A, L.B))
@@ -619,18 +628,24 @@ copy(M::Mul{ApplyLayout{typeof(\)}, <:BroadcastBandedLayout}) = lazymaterialize(
619628
copy(M::Mul{BroadcastLayout{typeof(*)}, <:BroadcastBandedLayout}) = lazymaterialize(*, M.A, M.B)
620629

621630
## padded copy
622-
mulreduce(M::Mul{<:BroadcastBandedLayout, <:Union{AbstractPaddedLayout,AbstractStridedLayout}}) = MulAdd(M)
623-
mulreduce(M::Mul{ApplyBandedLayout{F}, D}) where {F,D<:Union{AbstractPaddedLayout,AbstractStridedLayout}} = Mul{ApplyLayout{F},D}(M.A, M.B)
631+
mulreduce(M::Mul{<:BroadcastBandedLayout, <:Union{PaddedColumns,PaddedLayout,AbstractStridedLayout}}) = MulAdd(M)
632+
mulreduce(M::Mul{ApplyBandedLayout{F}, D}) where {F,D<:Union{PaddedColumns,PaddedLayout,AbstractStridedLayout}} = Mul{ApplyLayout{F},D}(M.A, M.B)
624633
# need to overload copy due to above
625-
copy(M::Mul{<:BroadcastBandedLayout, <:Union{AbstractPaddedLayout,AbstractStridedLayout}}) = copy(mulreduce(M))
626-
copy(M::Mul{<:AbstractInvLayout{<:BandedLazyLayouts}, <:Union{AbstractPaddedLayout,AbstractStridedLayout}}) = ArrayLayouts.ldiv(pinv(M.A), M.B)
627-
copy(M::Mul{<:BandedLazyLayouts, <:Union{AbstractPaddedLayout,AbstractStridedLayout}}) = copy(mulreduce(M))
628-
copy(M::Mul{<:Union{AbstractPaddedLayout,AbstractStridedLayout,DualLayout{<:PaddedRows}}, <:BandedLazyLayouts}) = copy(mulreduce(M))
629-
630-
simplifiable(M::Mul{<:AbstractInvLayout{<:BandedLazyLayouts}, <:Union{AbstractPaddedLayout,AbstractStridedLayout}}) = Val(true)
631-
simplifiable(M::Mul{<:Union{AbstractPaddedLayout,AbstractStridedLayout}, <:BandedLazyLayouts}) = Val(true)
632-
simplifiable(M::Mul{<:BandedLazyLayouts, <:Union{AbstractPaddedLayout,AbstractStridedLayout}}) = Val(true)
633-
simplifiable(::Mul{<:BroadcastBandedLayout, <:Union{AbstractPaddedLayout,AbstractStridedLayout}}) = Val(true)
634+
copy(M::Mul{<:BroadcastBandedLayout, <:Union{PaddedColumns,PaddedLayout}}) = copy(mulreduce(M))
635+
copy(M::Mul{<:BroadcastBandedLayout, <:AbstractStridedLayout}) = copy(mulreduce(M))
636+
copy(M::Mul{<:AbstractInvLayout{<:BandedLazyLayouts}, <:Union{PaddedColumns,PaddedLayout,AbstractStridedLayout}}) = ArrayLayouts.ldiv(pinv(M.A), M.B)
637+
copy(M::Mul{<:BandedLayouts, <:Union{PaddedColumns,PaddedLayout}}) = copy(mulreduce(M))
638+
copy(M::Mul{<:BandedLazyLayouts, <:Union{PaddedColumns,PaddedLayout}}) = copy(mulreduce(M))
639+
copy(M::Mul{<:BandedLazyLayouts, <:AbstractStridedLayout}) = copy(mulreduce(M))
640+
copy(M::Mul{<:Union{PaddedRows,PaddedLayout,DualLayout{<:PaddedRows}}, <:BandedLayouts}) = copy(mulreduce(M))
641+
copy(M::Mul{<:Union{PaddedRows,PaddedLayout,DualLayout{<:PaddedRows}}, <:BandedLazyLayouts}) = copy(mulreduce(M))
642+
copy(M::Mul{<:Union{AbstractStridedLayout,DualLayout{<:AbstractStridedLayout}}, <:BandedLazyLayouts}) = copy(mulreduce(M))
643+
644+
simplifiable(M::Mul{<:AbstractInvLayout{<:BandedLayouts}, <:Union{PaddedColumns,PaddedLayout,AbstractStridedLayout}}) = Val(true)
645+
simplifiable(M::Mul{<:Union{PaddedRows,PaddedLayout,DualLayout{<:PaddedRows}}, <:BandedLayouts}) = Val(true)
646+
simplifiable(M::Mul{<:BandedLayouts, <:Union{PaddedColumns,PaddedLayout}}) = Val(true)
647+
simplifiable(M::Mul{<:Union{AbstractStridedLayout,DualLayout{<:AbstractStridedLayout}}, <:BandedLazyLayouts}) = Val(true)
648+
simplifiable(M::Mul{<:BandedLazyLayouts, <:AbstractStridedLayout}) = Val(true)
634649

635650
copy(L::Ldiv{ApplyBandedLayout{typeof(*)}, Lay}) where Lay = copy(Ldiv{ApplyLayout{typeof(*)},Lay}(L.A, L.B))
636651
copy(L::Ldiv{ApplyBandedLayout{typeof(*)}, Lay}) where {Lay<:AbstractLazyLayout} = copy(Ldiv{ApplyLayout{typeof(*)},Lay}(L.A, L.B))

src/LazyArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import ArrayLayouts: AbstractQLayout, Dot, Dotu, Ldiv, Lmul, MatMulMatAdd, MatMu
3838
hermitianlayout, layout_getindex, layout_replace_in_print_matrix, ldivaxes, materialize,
3939
materialize!, mulreduce, reshapedlayout, rowsupport, scalarone, scalarzero, sub_materialize,
4040
sublayout, symmetriclayout, symtridiagonallayout, transposelayout, triangulardata,
41-
triangularlayout, tridiagonallayout, zero!
41+
triangularlayout, tridiagonallayout, zero!, transtype
4242

4343
import FillArrays: AbstractFill, getindex_value
4444

src/linalg/add.jl

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,24 @@ _broadcasted_mul(A::AbstractMatrix, B::Tuple{AbstractMatrix,Vararg{Any}}) = (siz
102102

103103
for op in (:+, :-)
104104
@eval begin
105-
simplify(M::Mul{Lay}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(arguments(Lay(), M.A), M.B)...)
106-
simplify(M::Mul{<:Any,Lay}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(M.A, arguments(Lay(), M.B))...)
107-
simplify(M::Mul{Lay,Lay}) where Lay<:BroadcastLayout{typeof($op)} = simplify(Mul{Lay,UnknownLayout}(M.A, M.B))
105+
simplifiable(M::Mul{<:BroadcastLayout{typeof($op)}}) = Val(true)
106+
simplifiable(M::Mul{<:Any,<:BroadcastLayout{typeof($op)}}) = Val(true)
107+
simplifiable(M::Mul{<:BroadcastLayout{typeof($op)},<:BroadcastLayout{typeof($op)}}) = simplifiable(Mul{BroadcastLayout{typeof($op)},UnknownLayout}(M.A, M.B))
108+
copy(M::Mul{Lay}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(arguments(Lay(), M.A), M.B)...)
109+
copy(M::Mul{Lay,<:LazyLayouts}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(arguments(Lay(), M.A), M.B)...)
110+
copy(M::Mul{<:Any,Lay}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(M.A, arguments(Lay(), M.B))...)
111+
copy(M::Mul{<:LazyLayouts,Lay}) where Lay<:BroadcastLayout{typeof($op)} = broadcast($op, _broadcasted_mul(M.A, arguments(Lay(), M.B))...)
112+
copy(M::Mul{Lay,Lay}) where Lay<:BroadcastLayout{typeof($op)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B))
113+
simplify(M::Mul{Lay}) where Lay<:BroadcastLayout{typeof($op)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B)) # TODO: remove, here for back-compat with QuasiArrays.jl
114+
simplify(M::Mul{<:Any,Lay}) where Lay<:BroadcastLayout{typeof($op)} = copy(Mul{UnknownLayout,Lay}(M.A, M.B)) # TODO: remove, here for back-compat with QuasiArrays.jl
115+
simplify(M::Mul{Lay,Lay}) where Lay<:BroadcastLayout{typeof($op)} = copy(M) # TODO: remove, here for back-compat with QuasiArrays.jl
108116
end
109117
end
110118

111-
simplify(M::Mul{Lay,BroadcastLayout{typeof(-)}}) where Lay<:BroadcastLayout{typeof(+)} = simplify(Mul{Lay,UnknownLayout}(M.A, M.B))
112-
simplify(M::Mul{Lay,BroadcastLayout{typeof(+)}}) where Lay<:BroadcastLayout{typeof(-)} = simplify(Mul{Lay,UnknownLayout}(M.A, M.B))
119+
simplifiable(M::Mul{Lay,BroadcastLayout{typeof(-)}}) where Lay<:BroadcastLayout{typeof(+)} = simplifiable(Mul{Lay,UnknownLayout}(M.A, M.B))
120+
simplifiable(M::Mul{Lay,BroadcastLayout{typeof(+)}}) where Lay<:BroadcastLayout{typeof(-)} = simplifiable(Mul{Lay,UnknownLayout}(M.A, M.B))
121+
122+
copy(M::Mul{Lay,BroadcastLayout{typeof(-)}}) where Lay<:BroadcastLayout{typeof(+)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B))
123+
copy(M::Mul{Lay,BroadcastLayout{typeof(+)}}) where Lay<:BroadcastLayout{typeof(-)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B))
124+
simplify(M::Mul{Lay,BroadcastLayout{typeof(-)}}) where Lay<:BroadcastLayout{typeof(+)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B)) # TODO: remove, here for back-compat with QuasiArrays.jl
125+
simplify(M::Mul{Lay,BroadcastLayout{typeof(+)}}) where Lay<:BroadcastLayout{typeof(-)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B)) # TODO: remove, here for back-compat with QuasiArrays.jl

src/linalg/mul.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ simplify(M::Applied{<:Any,typeof(*)}) = simplify(*, arguments(M)...)
368368
@inline copy(M::Mul{<:DualLayout,<:LazyLayouts,<:AbstractMatrix,<:AbstractVector}) = copy(Dot(M))
369369

370370
applylayout(::Type{typeof(*)}, ::DualLayout{Lay}, args...) where Lay = DualLayout{typeof(applylayout(typeof(*), Lay(), args...))}()
371+
transtype(A::MulMatrix) = transtype(first(A.args))
371372

372373
#TODO: Why not all DiagonalLayout?
373374
@inline simplifiable(M::Mul{<:DiagonalLayout{<:AbstractFillLayout}}) = Val(true)

src/padded.jl

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,33 @@ function layout_replace_in_print_matrix(::AbstractPaddedLayout{Lay}, f::Abstract
505505
end
506506

507507
# avoid ambiguity in LazyBandedMatrices
508-
copy(M::Mul{<:DiagonalLayout,<:AbstractPaddedLayout}) = copy(Lmul(M))
509-
copy(M::Mul{<:Union{TriangularLayout{'U', 'N', <:AbstractLazyLayout}, TriangularLayout{'U', 'U', <:AbstractLazyLayout}}, <:AbstractPaddedLayout}) = copy(Lmul(M))
510-
simplifiable(::Mul{<:Union{TriangularLayout{'U', 'N', <:AbstractLazyLayout}, TriangularLayout{'U', 'U', <:AbstractLazyLayout}}, <:AbstractPaddedLayout}) = Val(true)
508+
copy(M::Mul{<:DiagonalLayout,<:Union{PaddedColumns,PaddedLayout}}) = copy(Lmul(M))
509+
copy(M::Mul{<:Union{TriangularLayout{'U', 'N', <:AbstractLazyLayout}, TriangularLayout{'U', 'U', <:AbstractLazyLayout}}, <:Union{PaddedColumns,PaddedLayout}}) = copy(Lmul(M))
510+
simplifiable(::Mul{<:Union{TriangularLayout{'U', 'N', <:AbstractLazyLayout}, TriangularLayout{'U', 'U', <:AbstractLazyLayout}}, <:Union{PaddedColumns,PaddedLayout}}) = Val(true)
511511

512512

513+
simplifiable(::Mul{<:DualLayout{<:AbstractLazyLayout}, <:Union{PaddedColumns,PaddedLayout}}) = Val(true)
514+
copy(M::Mul{<:DualLayout{<:AbstractLazyLayout}, <:Union{PaddedColumns,PaddedLayout}}) = copy(mulreduce(M))
515+
simplifiable(::Mul{<:DiagonalLayout{<:AbstractFillLayout}, <:Union{PaddedColumns,PaddedLayout}}) = Val(true)
516+
517+
function simplifiable(M::Mul{<:DualLayout{<:PaddedRows}, <:LazyLayouts})
518+
trans = transtype(M.A)
519+
simplifiable(*, trans(M.B), trans(M.A))
520+
end
521+
function copy(M::Mul{<:DualLayout{<:PaddedRows}, <:LazyLayouts})
522+
trans = transtype(M.A)
523+
trans(trans(M.B) * trans(M.A))
524+
end
525+
526+
for op in (:+, :-)
527+
@eval begin
528+
simplifiable(M::Mul{<:BroadcastLayout{typeof($op)},<:Union{PaddedColumns,PaddedLayout}}) = Val(true)
529+
simplifiable(M::Mul{<:DualLayout{<:PaddedRows},<:BroadcastLayout{typeof($op)}}) = Val(true)
530+
copy(M::Mul{Lay,<:Union{PaddedColumns,PaddedLayout}}) where Lay<:BroadcastLayout{typeof($op)} = copy(Mul{Lay,UnknownLayout}(M.A, M.B))
531+
copy(M::Mul{<:DualLayout{<:PaddedRows},Lay}) where Lay<:BroadcastLayout{typeof($op)} = copy(Mul{UnknownLayout,Lay}(M.A, M.B))
532+
end
533+
end
534+
513535

514536
# Triangular columns
515537

test/addtests.jl

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module AddTests
22

33
using LazyArrays, Test
44
using LinearAlgebra
5-
import LazyArrays: Add, AddArray, MulAdd, materialize!, MemoryLayout, ApplyLayout
5+
import LazyArrays: Add, AddArray, MulAdd, materialize!, MemoryLayout, ApplyLayout, simplifiable, simplify
66

77
@testset "Add/Subtract" begin
88
@testset "Add" begin
@@ -302,6 +302,34 @@ import LazyArrays: Add, AddArray, MulAdd, materialize!, MemoryLayout, ApplyLayou
302302
@test B*C 3A * (-A)
303303
@test C*B (-A) * 3A
304304
end
305+
306+
@testset "simplifiable" begin
307+
A = randn(5,5)
308+
B = BroadcastArray(+, A, 2A)
309+
C = BroadcastArray(-, A, 2A)
310+
D = ApplyArray(exp, A)
311+
@test simplifiable(*, A, B) == Val(true)
312+
@test simplifiable(*, B, A) == Val(true)
313+
@test simplifiable(*, A, C) == Val(true)
314+
@test simplifiable(*, C, A) == Val(true)
315+
@test simplifiable(*, B, C) == Val(true)
316+
@test simplifiable(*, C, B) == Val(true)
317+
@test simplifiable(*, B, B) == Val(true)
318+
@test simplifiable(*, C, C) == Val(true)
319+
@test simplifiable(*, B, D) == Val(true)
320+
@test simplifiable(*, D, B) == Val(true)
321+
322+
@test A*B simplify(Mul(A,B)) A * Matrix(B)
323+
@test B*A simplify(Mul(B,A)) Matrix(B)A
324+
@test A*C simplify(Mul(A,C)) A * Matrix(C)
325+
@test C*A simplify(Mul(C,A)) Matrix(C)A
326+
@test B*C simplify(Mul(B,C)) B * Matrix(C)
327+
@test C*B simplify(Mul(C,B)) Matrix(C)B
328+
@test B*B simplify(Mul(B,B)) Matrix(B)B
329+
@test C*C simplify(Mul(C,C)) Matrix(C)C
330+
@test B*D simplify(Mul(B,D)) Matrix(B)*D
331+
@test D*B simplify(Mul(D,B)) D*Matrix(B)
332+
end
305333
end
306334
end # testset
307335

test/bandedtests.jl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,50 @@ LinearAlgebra.lmul!(β::Number, A::PseudoBandedMatrix) = (lmul!(β, A.data); A)
888888
@test A[band(1)] == [A[i, i+1] for i in 1:7]
889889
@test A[band(-1)] == [A[i+1, i] for i in 1:8]
890890
end
891+
892+
@testset "Banded * Padded" begin
893+
n = 10
894+
A = _BandedMatrix(MyLazyArray(randn(3,n)),n,1,1)
895+
B = brand(n,n,1,1)
896+
C = BroadcastArray(+, B)
897+
x = Vcat([1,2,3], Zeros(n-3))
898+
y = randn(n)
899+
@test A*x isa Vcat
900+
@test B*x isa Vcat
901+
@test C*x isa Vcat
902+
@test simplifiable(*, A, x) == Val(true)
903+
@test simplifiable(*, B, x) == Val(true)
904+
@test simplifiable(*, C, x) == Val(true)
905+
906+
@test A*y isa Vector
907+
@test C*y isa Vector
908+
@test simplifiable(*, A, y) == Val(true)
909+
@test simplifiable(*, C, y) == Val(true)
910+
911+
@test x'A isa Adjoint{<:Any,<:Vcat}
912+
@test x'B isa Adjoint{<:Any,<:Vcat}
913+
@test x'C isa Adjoint{<:Any,<:Vcat}
914+
@test transpose(x)A isa Transpose{<:Any,<:Vcat}
915+
@test transpose(x)B isa Transpose{<:Any,<:Vcat}
916+
@test transpose(x)C isa Transpose{<:Any,<:Vcat}
917+
@test simplifiable(*, x', A) == Val(true)
918+
@test simplifiable(*, x', B) == Val(true)
919+
@test simplifiable(*, x', C) == Val(true)
920+
@test simplifiable(*, transpose(x), A) == Val(true)
921+
@test simplifiable(*, transpose(x), B) == Val(true)
922+
@test simplifiable(*, transpose(x), C) == Val(true)
923+
@test x'A x'Matrix(A)
924+
@test x'B x'Matrix(B)
925+
@test x'C x'Matrix(C)
926+
927+
@test y'A isa Adjoint{<:Any,<:Vector}
928+
@test y'C isa Adjoint{<:Any,<:Vector}
929+
@test simplifiable(*, y', A) == Val(true)
930+
@test simplifiable(*, y', B) == Val(true)
931+
@test simplifiable(*, y', C) == Val(true)
932+
@test y'A y'Matrix(A)
933+
@test y'C y'Matrix(C)
934+
end
891935
end
892936

893937
end # module

test/lazymultests.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ LinearAlgebra.factorize(A::MyLazyArray) = factorize(A.data)
369369
@test (UpperTriangular(A)UpperTriangular(A)) * b isa Vector
370370
@test (UpperTriangular(A)UpperTriangular(A)) * b UpperTriangular(A.A)^2 * b
371371
end
372+
373+
@testset "DualLayout{ApplyLayout{typeof(*)}} translayout" begin
374+
@test ApplyArray(*, (1:2)', [1 2; 3 4]) * [1 2; 3 4] [37,54]'
375+
@test ApplyArray(*, (1:2)', [1 2; 3 4]) * [1 2; 3 4] isa Adjoint
376+
end
372377
end
373378

374379
end # module

0 commit comments

Comments
 (0)