Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

overload simplifiable for special cases of Mul #188

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 = "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