Skip to content

Commit

Permalink
SymTriPertToeplitz MemoryLayout (#204)
Browse files Browse the repository at this point in the history
* SymTriPertToeplitz MemoryLayout

* Update InfiniteArraysBandedMatricesExt.jl

* increase coverage
  • Loading branch information
dlfivefifty authored Dec 2, 2024
1 parent 66441ec commit 4381348
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "InfiniteArrays"
uuid = "4858937d-0d70-526a-a4dd-2d5cb5dd786c"
version = "0.15.0-dev"
version = "0.15.0"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
15 changes: 2 additions & 13 deletions ext/InfiniteArraysBandedMatricesExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ using InfiniteArrays.LazyArrays, InfiniteArrays.ArrayLayouts, InfiniteArrays.Fil

import Base: BroadcastStyle, size, getindex, similar, copy, *, +, -, /, \, materialize!, copyto!, OneTo
import Base.Broadcast: Broadcasted
import InfiniteArrays: InfIndexRanges, Infinity, PosInfinity, OneToInf, InfAxes, AbstractInfUnitRange, InfRanges, InfBaseToeplitzLayouts, ConstRowMatrix, PertConstRowMatrix, SymTriPertToeplitz, TriPertToeplitz, ConstRows, PertConstRows
import InfiniteArrays: InfIndexRanges, Infinity, PosInfinity, OneToInf, InfAxes, AbstractInfUnitRange, InfRanges, InfBaseToeplitzLayouts, ConstRowMatrix, PertConstRowMatrix, SymTriPertToeplitz, TriPertToeplitz, ConstRows, PertConstRows, PertTridiagonalToeplitzLayout
import ArrayLayouts: sub_materialize, MemoryLayout, sublayout, mulreduce, triangularlayout, MatLdivVec, subdiagonaldata, diagonaldata, supdiagonaldata
import LazyArrays: applybroadcaststyle, applylayout, islazy, islazy_layout, simplifiable, AbstractLazyLayout, PaddedColumns, LazyArrayStyle, ApplyLayout, AbstractLazyBandedLayout, ApplyBandedLayout, BroadcastBandedLayout
import BandedMatrices: _BandedMatrix, AbstractBandedMatrix, banded_similar, BandedMatrix, bandedcolumns, BandedColumns, bandeddata
import BandedMatrices: _BandedMatrix, AbstractBandedMatrix, banded_similar, BandedMatrix, bandedcolumns, BandedColumns, bandeddata, _default_banded_broadcast
import FillArrays: AbstractFillMatrix, AbstractFill, getindex_value

BroadcastStyle(::Type{<:SubArray{<:Any,2,<:AbstractBandedMatrix,<:Tuple{<:InfIndexRanges,<:InfIndexRanges}}})= LazyArrayStyle{2}()
Expand Down Expand Up @@ -416,15 +416,4 @@ copy(A::Transpose{T,<:BandedMatrix{T,<:Any,OneToInf{Int}}}) where T = transpose(
Base.typed_hcat(::Type{T}, A::BandedMatrix{<:Any,<:Any,OneToInf{Int}}, B::AbstractVecOrMat...) where T = Hcat{T}(A, B...)



###
# SymTriPertToeplitz
###

MemoryLayout(::Type{<:SymTriPertToeplitz}) = PertTridiagonalToeplitzLayout()


sublayout(::ApplyBandedLayout, ::Type{<:Tuple{KR,Integer}}) where {KR<:InfAxes} =
sublayout(PaddedColumns{UnknownLayout}(), Tuple{KR})

end # module
9 changes: 8 additions & 1 deletion src/inftoeplitz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,11 @@ for op in (:-, :+)
Vcat(convert.(AbstractVector{TV}, broadcast($op, A.dl.args))...))
end
end
end
end

MemoryLayout(::Type{<:SymTriPertToeplitz}) = PertTridiagonalToeplitzLayout()

sublayout(::ApplyBandedLayout, ::Type{<:Tuple{KR,Integer}}) where {KR<:InfAxes} =
sublayout(PaddedColumns{UnknownLayout}(), Tuple{KR})
sublayout(::ApplyBandedLayout, ::Type{<:Tuple{Integer,JR}}) where {JR<:InfAxes} =
sublayout(PaddedColumns{UnknownLayout}(), Tuple{JR})
23 changes: 22 additions & 1 deletion test/test_infbanded.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using ArrayLayouts, InfiniteArrays, BandedMatrices, FillArrays, LazyArrays, Test
import BandedMatrices: _BandedMatrix, bandeddata
import InfiniteArrays: TridiagonalToeplitzLayout, BidiagonalToeplitzLayout, TriPertToeplitz, SymTriPertToeplitz, TriToeplitz, ConstRows, SymTriPertToeplitz, AdjTriPertToeplitz, subdiagonalconstant, diagonalconstant, supdiagonalconstant
import InfiniteArrays: TridiagonalToeplitzLayout, BidiagonalToeplitzLayout, TriPertToeplitz, SymTriPertToeplitz,
TriToeplitz, ConstRows, SymTriPertToeplitz, AdjTriPertToeplitz, subdiagonalconstant,
diagonalconstant, supdiagonalconstant, PertTridiagonalToeplitzLayout
using Base: oneto
using LazyArrays: simplifiable, ApplyLayout, BroadcastBandedLayout, islazy

Expand Down Expand Up @@ -138,6 +140,7 @@ const InfBandCartesianIndices = InfiniteArraysBandedMatricesExt.InfBandCartesian
@testset "TriPert" begin
A = SymTridiagonal(Vcat([1,2.], Fill(2.,∞)), Vcat([3.,4.], Fill.(0.5,∞)))
@test A isa SymTriPertToeplitz
@test MemoryLayout(A) isa PertTridiagonalToeplitzLayout
@test (A + 2I)[1:10,1:10] == (2I + A)[1:10,1:10] == A[1:10,1:10] + 2I
@test BandedMatrix(A, (2,3))[1:10,1:10] == A[1:10,1:10]

Expand Down Expand Up @@ -350,4 +353,22 @@ const InfBandCartesianIndices = InfiniteArraysBandedMatricesExt.InfBandCartesian
U = UpperTriangular(Tridiagonal(Fill(1,∞), Fill(2,∞), Fill(3,∞)))
@test MemoryLayout(U) isa BidiagonalToeplitzLayout
end

@testset "padded column" begin
A = BandedMatrix(1 => Fill(2im,∞), 2 => Fill(-1,∞), 3 => Fill(2,∞), -2 => Fill(-4,∞), -3 => Fill(-2im,∞))
@test MemoryLayout(A[:,5]) isa LazyArrays.PaddedColumns
@test MemoryLayout(A[5,:]) isa LazyArrays.PaddedColumns

@test MemoryLayout((A*A)[:,5]) isa LazyArrays.PaddedColumns
@test MemoryLayout((A*A)[5,:]) isa LazyArrays.PaddedColumns

V = Vcat(Zeros(1,∞), A)
@test MemoryLayout(V[:,5]) isa LazyArrays.PaddedColumns
@test MemoryLayout(V[5,:]) isa LazyArrays.PaddedColumns
end

@testset "Default broadcasted" begin
A = BandedMatrix(1 => Fill(2im,∞), 2 => Fill(-1,∞), 3 => Fill(2,∞), -2 => Fill(-4,∞), -3 => Fill(-2im,∞))
@test copy(Base.broadcasted(BandedMatrices.BandedStyle(), exp,A))[1:10,1:10] == exp.(A[1:10,1:10])
end
end

2 comments on commit 4381348

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/120563

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.15.0 -m "<description of version>" 43813480a8332e5cee622acb4bfc7d120c507e26
git push origin v0.15.0

Please sign in to comment.