From ad4af83ec549f78098ef770b611eb6961245367f Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Wed, 27 Nov 2024 15:23:20 +0000 Subject: [PATCH] overload simplifiable for special cases of Mul (#188) * overload simplifiable for special cases of Mul * increase codecov --- Project.toml | 2 +- src/banded/infbanded.jl | 3 +++ test/test_infbanded.jl | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 7d88418..6f939df 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "InfiniteLinearAlgebra" uuid = "cde9dba0-b1de-11e9-2c62-0bab9446c55c" -version = "0.8.4" +version = "0.8.5" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/banded/infbanded.jl b/src/banded/infbanded.jl index 215104a..67121ce 100644 --- a/src/banded/infbanded.jl +++ b/src/banded/infbanded.jl @@ -428,6 +428,7 @@ similar(M::MulAdd{<:AbstractBandedLayout,<:AbstractBandedLayout}, ::Type{T}, axe # BandedFill * BandedFill ### +simplifiable(::Mul{<:BandedColumns{<:AbstractFillLayout},<:BandedColumns{<:AbstractFillLayout}}) = Val(true) copy(M::MulAdd{<:BandedColumns{<:AbstractFillLayout},<:BandedColumns{<:AbstractFillLayout},ZerosLayout}) = _bandedfill_mul(M, axes(M.A), axes(M.B)) @@ -456,6 +457,8 @@ mulreduce(M::Mul{<:InfToeplitzLayouts}) = ApplyArray(M) mulreduce(M::Mul{<:InfToeplitzLayouts,<:PaddedColumns}) = MulAdd(M) mulreduce(M::Mul{<:Any, <:InfToeplitzLayouts}) = ApplyArray(M) mulreduce(M::Mul{<:AbstractQLayout, <:InfToeplitzLayouts}) = ApplyArray(M) +simplifiable(::Mul{<:DiagonalLayout, <:InfToeplitzLayouts}) = Val(true) +simplifiable(::Mul{<:InfToeplitzLayouts, <:DiagonalLayout}) = Val(true) mulreduce(M::Mul{<:DiagonalLayout, <:InfToeplitzLayouts}) = Lmul(M) mulreduce(M::Mul{<:InfToeplitzLayouts, <:DiagonalLayout}) = Rmul(M) diff --git a/test/test_infbanded.jl b/test/test_infbanded.jl index 804e17e..5a383e0 100644 --- a/test/test_infbanded.jl +++ b/test/test_infbanded.jl @@ -2,6 +2,7 @@ using InfiniteLinearAlgebra, ArrayLayouts, InfiniteArrays, BandedMatrices, FillA import BandedMatrices: _BandedMatrix, bandeddata using InfiniteLinearAlgebra: InfToeplitz, ConstRows, BandedToeplitzLayout, TridiagonalToeplitzLayout, BidiagonalToeplitzLayout, PertToeplitz, PertToeplitzLayout using Base: oneto +using LazyArrays: simplifiable @testset "∞-banded" begin @testset "Diagonal and BandedMatrix" begin @@ -55,6 +56,9 @@ using Base: oneto @test A * [1; 2; Zeros(∞)] isa Vcat @test A * [1; 2; Zeros(∞)] == [A[1:5,1:2] * [1,2]; Zeros(∞)] + @test A * Vcat([1 2; 3 4], Zeros(∞,2)) isa ApplyMatrix{ComplexF64,typeof(Base.setindex)} + @test simplifiable(*, A, Vcat([1 2; 3 4], Zeros(∞,2))) == Val(true) + @test MemoryLayout(Tridiagonal(Fill(1,∞), Fill(2,∞), Fill(3,∞))) isa TridiagonalToeplitzLayout @test MemoryLayout(Bidiagonal(Fill(1,∞), Fill(2,∞), :U)) isa BidiagonalToeplitzLayout @test MemoryLayout(SymTridiagonal(Fill(1,∞), Fill(2,∞))) isa TridiagonalToeplitzLayout @@ -87,6 +91,18 @@ using Base: oneto @test (B*B)[1:10,1:10] ≈ B[1:10,1:14]B[1:14,1:10] @test (A*B)[1:10,1:10] ≈ A[1:10,1:14]B[1:14,1:10] @test (B*A)[1:10,1:10] ≈ B[1:10,1:14]A[1:14,1:10] + @test simplifiable(*, B, B) == Val(true) + @test length((A*B*B).args) == 2 + @test length((B*B*A).args) == 2 + end + + @testset "Toep * Diag" begin + A = BandedMatrix(1 => Fill(2im,∞), 2 => Fill(-1,∞), 3 => Fill(2,∞), -2 => Fill(-4,∞), -3 => Fill(-2im,∞)) + D = Diagonal(1:∞) + @test D*A isa BroadcastMatrix + @test A*D isa BroadcastMatrix + @test simplifiable(*, D, A) == Val(true) + @test simplifiable(*, A, D) == Val(true) end end