Skip to content

ConstRows and PertConstRows should be lazy #184

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

Merged
merged 2 commits into from
Jun 17, 2024
Merged
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.3"
version = "0.8.4"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
2 changes: 1 addition & 1 deletion src/InfiniteLinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import LazyArrays: AbstractCachedMatrix, AbstractCachedVector, AbstractLazyLayou
CachedArray, CachedLayout, CachedMatrix, CachedVector, LazyArrayStyle, LazyLayout,
LazyLayouts, LazyMatrix, AbstractPaddedLayout, PaddedColumns, _broadcast_sub_arguments,
applybroadcaststyle, applylayout, arguments, cacheddata, paddeddata, resizedata!, simplifiable,
simplify
simplify, islazy, islazy_layout

import LazyBandedMatrices: AbstractLazyBandedBlockBandedLayout, AbstractLazyBandedLayout, ApplyBandedLayout, BlockVec,
BroadcastBandedLayout, KronTravBandedBlockBandedLayout, LazyBandedLayout,
Expand Down
9 changes: 7 additions & 2 deletions src/banded/infbanded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ ConstRowMatrix(A::AbstractMatrix{T}) where T = ApplyMatrix(*, A[:,1], Ones{T}(1,
PertConstRowMatrix(A::AbstractMatrix{T}) where T =
Hcat(_pertdata(A), ApplyMatrix(*, _constrows(A), Ones{T}(1,size(A,2))))

struct ConstRows <: MemoryLayout end
struct PertConstRows <: MemoryLayout end
struct ConstRows <: AbstractLazyLayout end
struct PertConstRows <: AbstractLazyLayout end
MemoryLayout(::Type{<:ConstRowMatrix}) = ConstRows()
MemoryLayout(::Type{<:PertConstRowMatrix}) = PertConstRows()
bandedcolumns(::ConstRows) = BandedToeplitzLayout()
Expand Down Expand Up @@ -361,6 +361,11 @@ diagonalconstant(A) = getindex_value(diagonaldata(A))
supdiagonalconstant(A) = getindex_value(supdiagonaldata(A))


islazy_layout(::InfToeplitzLayouts) = Val(true)
islazy(::BandedMatrix{<:Any,<:Any,OneToInf{Int}}) = Val(true)



_BandedMatrix(::BandedToeplitzLayout, A::AbstractMatrix) =
_BandedMatrix(ConstRowMatrix(bandeddata(A)), size(A,1), bandwidths(A)...)
_BandedMatrix(::PertToeplitzLayout, A::AbstractMatrix) =
Expand Down
7 changes: 5 additions & 2 deletions test/test_infbanded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ using Base: oneto
@testset "∞-Toeplitz" begin
A = BandedMatrix(1 => Fill(2im,∞), 2 => Fill(-1,∞), 3 => Fill(2,∞), -2 => Fill(-4,∞), -3 => Fill(-2im,∞))
@test A isa InfToeplitz
@test MemoryLayout(typeof(A.data)) == ConstRows()
@test MemoryLayout(typeof(A)) == BandedToeplitzLayout()
@test MemoryLayout(A.data) == ConstRows()
@test MemoryLayout(A) == BandedToeplitzLayout()
@test LazyArrays.islazy(A) == Val(true)

V = view(A,:,3:∞)
@test MemoryLayout(typeof(bandeddata(V))) == ConstRows()
@test MemoryLayout(typeof(V)) == BandedToeplitzLayout()
Expand Down Expand Up @@ -166,6 +168,7 @@ using Base: oneto

@testset "Banded * PaddedMatrix" begin
A = Eye(∞)[2:∞,:]
@test LazyArrays.islazy(A) == Val(true)
B = PaddedArray(randn(3,3),ℵ₀,ℵ₀)
@test (A*B)[1:10,1:10] ≈ A[1:10,1:10] * B[1:10,1:10]
end
Expand Down