Skip to content

Commit ad4af83

Browse files
authored
overload simplifiable for special cases of Mul (#188)
* overload simplifiable for special cases of Mul * increase codecov
1 parent bb5a874 commit ad4af83

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "InfiniteLinearAlgebra"
22
uuid = "cde9dba0-b1de-11e9-2c62-0bab9446c55c"
3-
version = "0.8.4"
3+
version = "0.8.5"
44

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

src/banded/infbanded.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ similar(M::MulAdd{<:AbstractBandedLayout,<:AbstractBandedLayout}, ::Type{T}, axe
428428
# BandedFill * BandedFill
429429
###
430430

431+
simplifiable(::Mul{<:BandedColumns{<:AbstractFillLayout},<:BandedColumns{<:AbstractFillLayout}}) = Val(true)
431432
copy(M::MulAdd{<:BandedColumns{<:AbstractFillLayout},<:BandedColumns{<:AbstractFillLayout},ZerosLayout}) =
432433
_bandedfill_mul(M, axes(M.A), axes(M.B))
433434

@@ -456,6 +457,8 @@ mulreduce(M::Mul{<:InfToeplitzLayouts}) = ApplyArray(M)
456457
mulreduce(M::Mul{<:InfToeplitzLayouts,<:PaddedColumns}) = MulAdd(M)
457458
mulreduce(M::Mul{<:Any, <:InfToeplitzLayouts}) = ApplyArray(M)
458459
mulreduce(M::Mul{<:AbstractQLayout, <:InfToeplitzLayouts}) = ApplyArray(M)
460+
simplifiable(::Mul{<:DiagonalLayout, <:InfToeplitzLayouts}) = Val(true)
461+
simplifiable(::Mul{<:InfToeplitzLayouts, <:DiagonalLayout}) = Val(true)
459462
mulreduce(M::Mul{<:DiagonalLayout, <:InfToeplitzLayouts}) = Lmul(M)
460463
mulreduce(M::Mul{<:InfToeplitzLayouts, <:DiagonalLayout}) = Rmul(M)
461464

test/test_infbanded.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ using InfiniteLinearAlgebra, ArrayLayouts, InfiniteArrays, BandedMatrices, FillA
22
import BandedMatrices: _BandedMatrix, bandeddata
33
using InfiniteLinearAlgebra: InfToeplitz, ConstRows, BandedToeplitzLayout, TridiagonalToeplitzLayout, BidiagonalToeplitzLayout, PertToeplitz, PertToeplitzLayout
44
using Base: oneto
5+
using LazyArrays: simplifiable
56

67
@testset "∞-banded" begin
78
@testset "Diagonal and BandedMatrix" begin
@@ -55,6 +56,9 @@ using Base: oneto
5556
@test A * [1; 2; Zeros(∞)] isa Vcat
5657
@test A * [1; 2; Zeros(∞)] == [A[1:5,1:2] * [1,2]; Zeros(∞)]
5758

59+
@test A * Vcat([1 2; 3 4], Zeros(∞,2)) isa ApplyMatrix{ComplexF64,typeof(Base.setindex)}
60+
@test simplifiable(*, A, Vcat([1 2; 3 4], Zeros(∞,2))) == Val(true)
61+
5862
@test MemoryLayout(Tridiagonal(Fill(1,∞), Fill(2,∞), Fill(3,∞))) isa TridiagonalToeplitzLayout
5963
@test MemoryLayout(Bidiagonal(Fill(1,∞), Fill(2,∞), :U)) isa BidiagonalToeplitzLayout
6064
@test MemoryLayout(SymTridiagonal(Fill(1,∞), Fill(2,∞))) isa TridiagonalToeplitzLayout
@@ -87,6 +91,18 @@ using Base: oneto
8791
@test (B*B)[1:10,1:10] B[1:10,1:14]B[1:14,1:10]
8892
@test (A*B)[1:10,1:10] A[1:10,1:14]B[1:14,1:10]
8993
@test (B*A)[1:10,1:10] B[1:10,1:14]A[1:14,1:10]
94+
@test simplifiable(*, B, B) == Val(true)
95+
@test length((A*B*B).args) == 2
96+
@test length((B*B*A).args) == 2
97+
end
98+
99+
@testset "Toep * Diag" begin
100+
A = BandedMatrix(1 => Fill(2im,∞), 2 => Fill(-1,∞), 3 => Fill(2,∞), -2 => Fill(-4,∞), -3 => Fill(-2im,∞))
101+
D = Diagonal(1:∞)
102+
@test D*A isa BroadcastMatrix
103+
@test A*D isa BroadcastMatrix
104+
@test simplifiable(*, D, A) == Val(true)
105+
@test simplifiable(*, A, D) == Val(true)
90106
end
91107
end
92108

0 commit comments

Comments
 (0)