Skip to content

Commit

Permalink
overload simplifiable for special cases of Mul (#188)
Browse files Browse the repository at this point in the history
* overload simplifiable for special cases of Mul

* increase codecov
  • Loading branch information
dlfivefifty authored Nov 27, 2024
1 parent bb5a874 commit ad4af83
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/banded/infbanded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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)

Expand Down
16 changes: 16 additions & 0 deletions test/test_infbanded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit ad4af83

Please sign in to comment.