Skip to content

Suppport Diagonal block times padded #66

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 8 commits into from
Feb 4, 2021
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
8 changes: 4 additions & 4 deletions 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.4.6"
version = "0.4.7"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand All @@ -18,12 +18,12 @@ SemiseparableMatrices = "f8ebbe35-cbfb-4060-bf7f-b10e4670cf57"
[compat]
ArrayLayouts = "0.5.1"
BandedMatrices = "0.16"
BlockArrays = "0.14"
BlockArrays = "0.14.2"
BlockBandedMatrices = "0.10"
FillArrays = "0.11"
InfiniteArrays = "0.9"
InfiniteArrays = "0.9.3"
LazyArrays = "0.20.2"
LazyBandedMatrices = "0.4.2"
LazyBandedMatrices = "0.4.5"
MatrixFactorizations = "0.7.1, 0.8"
SemiseparableMatrices = "0.2.2"
julia = "1.5"
Expand Down
26 changes: 20 additions & 6 deletions src/blockbanded/blockbanded.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
const OneToInfCumsum = InfiniteArrays.RangeCumsum{Int,OneToInf{Int}}
const OneToCumsum = InfiniteArrays.RangeCumsum{Int,OneTo{Int}}

BlockArrays.sortedunion(::AbstractVector{Infinity}, ::AbstractVector{Infinity}) = [∞]
function BlockArrays.sortedunion(::AbstractVector{Infinity}, b)
@assert isinf(length(b))
b
end

function BlockArrays.sortedunion(b, ::AbstractVector{Infinity})
@assert isinf(length(b))
b
end
BlockArrays.sortedunion(a::OneToInfCumsum, ::OneToInfCumsum) = a
BlockArrays.sortedunion(a::OneToCumsum, ::OneToCumsum) = a
function BlockArrays.sortedunion(a::RangeCumsum{<:Any,<:InfStepRange}, b::RangeCumsum{<:Any,<:InfStepRange})
@assert a == b
a
end


function BlockArrays.sortedunion(a::Vcat{Int,1,<:Tuple{<:AbstractVector{Int},InfStepRange{Int,Int}}},
b::Vcat{Int,1,<:Tuple{<:AbstractVector{Int},InfStepRange{Int,Int}}})
Expand Down Expand Up @@ -49,12 +64,11 @@ BroadcastStyle(::Type{<:SubArray{T,N,Arr,<:NTuple{N,BlockSlice{BlockRange{1,Tupl
LazyArrayStyle{N}()

# TODO: generalise following
for Ax in (:(RangeCumsum{Int,OneToInf{Int}}), :(OneToInf{Int}))
@eval begin
BroadcastStyle(::Type{BlockArray{T,N,Arr,NTuple{N,BlockedUnitRange{$Ax}}}}) where {T,N,Arr} = LazyArrayStyle{N}()
BroadcastStyle(::Type{PseudoBlockArray{T,N,Arr,NTuple{N,BlockedUnitRange{$Ax}}}}) where {T,N,Arr} = LazyArrayStyle{N}()
end
end
BroadcastStyle(::Type{<:BlockArray{T,N,<:AbstractArray{<:AbstractArray{T,N},N},<:NTuple{N,BlockedUnitRange{<:InfRanges}}}}) where {T,N} = LazyArrayStyle{N}()
BroadcastStyle(::Type{<:PseudoBlockArray{T,N,<:AbstractArray{T,N},<:NTuple{N,BlockedUnitRange{<:InfRanges}}}}) where {T,N} = LazyArrayStyle{N}()
BroadcastStyle(::Type{<:BlockArray{T,N,<:AbstractArray{<:AbstractArray{T,N},N},<:NTuple{N,BlockedUnitRange{<:RangeCumsum{Int,<:InfRanges}}}}}) where {T,N} = LazyArrayStyle{N}()
BroadcastStyle(::Type{<:PseudoBlockArray{T,N,<:AbstractArray{T,N},<:NTuple{N,BlockedUnitRange{<:RangeCumsum{Int,<:InfRanges}}}}}) where {T,N} = LazyArrayStyle{N}()


BlockArrays._length(::BlockedUnitRange, ::OneToInf) = ∞
BlockArrays._last(::BlockedUnitRange, ::OneToInf) = ∞
Expand Down
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ end
@test blockaxes(b,1) ≡ Block.(OneToInf())
@test b[Block(5)] == [1,2]
@test length(axes(b,1)) ≡ last(axes(b,1)) ≡ ∞
@test Base.BroadcastStyle(typeof(b)) isa LazyArrayStyle{1}
end

@testset "1:∞ blocks" begin
Expand Down Expand Up @@ -166,6 +167,20 @@ end
@test Dy[Block.(1:N), Block.(1:N)] == BlockBandedMatrices._BandedBlockBandedMatrix((k .+ (b+c))[Block.(1:N)]', axes(k,1)[Block.(1:N)], (-1,1), (-1,1))
end
end

@testset "blockdiag" begin
D = Diagonal(mortar(Fill.((-(0:∞)-(0:∞).^2), 1:2:∞)))
x = [randn(5); zeros(∞)]
x̃ = PseudoBlockArray(x, (axes(D,1),))
@test (D * x)[1:10] == (D * x̃)[1:10]
end

@testset "sortedunion" begin
a = cumsum(1:2:∞)
@test BlockArrays.sortedunion(a,a) ≡ a
@test BlockArrays.sortedunion([∞],a) ≡ BlockArrays.sortedunion(a,[∞]) ≡ a
@test BlockArrays.sortedunion([∞],[∞]) == [∞]
end
end

@testset "∞-Toeplitz and Pert-Toeplitz" begin
Expand Down