Skip to content

Improvements to blockedunitrange #74

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 3 commits into from
Mar 17, 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
4 changes: 2 additions & 2 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.5.4"
version = "0.5.5"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand All @@ -21,7 +21,7 @@ BandedMatrices = "0.16"
BlockArrays = "0.14.5, 0.15"
BlockBandedMatrices = "0.10"
FillArrays = "0.11"
InfiniteArrays = "0.10"
InfiniteArrays = "0.10.6"
LazyArrays = "0.20.2, 0.21"
LazyBandedMatrices = "0.5"
MatrixFactorizations = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion src/InfiniteLinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module InfiniteLinearAlgebra
using BlockArrays, BlockBandedMatrices, BandedMatrices, LazyArrays, LazyBandedMatrices, SemiseparableMatrices,
FillArrays, InfiniteArrays, MatrixFactorizations, ArrayLayouts, LinearAlgebra

import Base: +, -, *, /, \, ^, OneTo, getindex, promote_op, _unsafe_getindex, size, axes,
import Base: +, -, *, /, \, ^, OneTo, getindex, promote_op, _unsafe_getindex, size, axes, length,
AbstractMatrix, AbstractArray, Matrix, Array, Vector, AbstractVector, Slice,
show, getproperty, copy, copyto!, map, require_one_based_indexing, similar, inv
import Base.Broadcast: BroadcastStyle, Broadcasted, broadcasted
Expand Down
2 changes: 2 additions & 0 deletions src/banded/infbanded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ sub_materialize(::AbstractBandedLayout, V, ::Tuple{InfAxes,OneTo{Int}}) = V
@inline sub_materialize(::BroadcastBandedLayout, V, ::Tuple{InfAxes,InfAxes}) = V
@inline sub_materialize(::BandedColumns, V, ::Tuple{InfAxes,InfAxes}) = BandedMatrix(V)

sub_materialize(_, V, ::Tuple{<:BlockedUnitRange{<:InfRanges}}) = V
sub_materialize(::AbstractBlockLayout, V, ::Tuple{<:BlockedUnitRange{<:InfRanges}}) = V

##
# UniformScaling
Expand Down
6 changes: 3 additions & 3 deletions src/blockbanded/blockbanded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ function BlockArrays.sortedunion(a::Vcat{Int,1,<:Tuple{<:AbstractVector{Int},Inf
end

sizes_from_blocks(A::AbstractVector, ::Tuple{OneToInf{Int}}) = (map(length,A),)
length(::BlockedUnitRange{<:InfRanges}) = ℵ₀

const OneToInfBlocks = BlockedUnitRange{OneToInfCumsum}
const OneToBlocks = BlockedUnitRange{OneToCumsum}

axes(a::OneToInfBlocks) = (a,)
axes(a::OneToBlocks) = (a,)

LazyBandedMatrices.unitblocks(a::OneToInf) = blockedrange(Ones{Int}(length(a)))

BlockArrays.dimlength(start, ::Infinity) = ℵ₀

function copy(bc::Broadcasted{<:BroadcastStyle,<:Any,typeof(*),<:Tuple{Ones{T,1,Tuple{OneToInfBlocks}},AbstractArray{V,N}}}) where {N,T,V}
Expand Down Expand Up @@ -71,9 +74,6 @@ BroadcastStyle(::Type{<:BlockArray{T,N,<:AbstractArray{<:AbstractArray{T,N},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) = ∞

###
# KronTrav
###
Expand Down
33 changes: 25 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ using InfiniteLinearAlgebra, BlockBandedMatrices, BlockArrays, BandedMatrices, I
MatrixFactorizations, ArrayLayouts, LinearAlgebra, Random, LazyBandedMatrices, StaticArrays
import InfiniteLinearAlgebra: qltail, toeptail, tailiterate , tailiterate!, tail_de, ql_X!,
InfToeplitz, PertToeplitz, TriToeplitz, InfBandedMatrix, InfBandCartesianIndices,
rightasymptotics, QLHessenberg, ConstRows, PertConstRows,
rightasymptotics, QLHessenberg, ConstRows, PertConstRows,
BandedToeplitzLayout, PertToeplitzLayout, TridiagonalToeplitzLayout, BidiagonalToeplitzLayout
import Base: BroadcastStyle
import BlockArrays: _BlockArray
import BlockBandedMatrices: isblockbanded, _BlockBandedMatrix
import MatrixFactorizations: QLPackedQ
import BandedMatrices: bandeddata, _BandedMatrix, BandedStyle
import LazyArrays: colsupport, ApplyStyle, MemoryLayout, ApplyLayout, LazyArrayStyle, arguments
import InfiniteArrays: OneToInf, oneto
import InfiniteArrays: OneToInf, oneto, RealInfinity
import LazyBandedMatrices: BroadcastBandedBlockBandedLayout, BroadcastBandedLayout, LazyBandedLayout


Expand Down Expand Up @@ -39,7 +39,7 @@ import LazyBandedMatrices: BroadcastBandedBlockBandedLayout, BroadcastBandedLayo
@test B*A*x isa Vcat
@test (B*A*x)[1:10] == [0; 10; 14; 12; zeros(6)]

@test _BandedMatrix((1:∞)', ∞, -1, 1) isa BandedMatrix
@test _BandedMatrix((1:∞)', ∞, -1, 1) isa BandedMatrix
end

@testset "∞-Toeplitz" begin
Expand Down Expand Up @@ -103,7 +103,7 @@ import LazyBandedMatrices: BroadcastBandedBlockBandedLayout, BroadcastBandedLayo
@test (A + 2I)[1:10,1:10] == (2I + A)[1:10,1:10] == A[1:10,1:10] + 2I
@test (Adjoint(A) + 2I)[1:10,1:10] == (2I + Adjoint(A))[1:10,1:10] == Adjoint(A)[1:10,1:10] + 2I
end


@testset "InfBanded" begin
A = _BandedMatrix(Fill(2,4,∞),ℵ₀,2,1)
Expand Down Expand Up @@ -134,12 +134,24 @@ end
n = Fill.(oneto(∞),oneto(∞))
@test broadcast(length,k) ≡ map(length,k) ≡ OneToInf()
@test broadcast(length,n) ≡ map(length,n) ≡ OneToInf()

b = mortar(Fill([1,2],∞))
@test blockaxes(b,1) ≡ Block.(OneToInf())
@test b[Block(5)] == [1,2]
@test b[Block.(2:∞)][Block.(2:10)] == b[Block.(3:11)]
@test exp.(b)[Block.(2:∞)][Block.(2:10)] == exp.(b[Block.(3:11)])

c = PseudoBlockArray(1:∞,Vcat(2,Fill(3,∞)))
@test c[Block.(2:∞)][Block.(2:10)] == c[Block.(3:11)]

@test length(axes(b,1)) ≡ ℵ₀
@test last(axes(b,1)) ≡
@test last(axes(b,1)) ≡ RealInfinity()
@test Base.BroadcastStyle(typeof(b)) isa LazyArrayStyle{1}

@test unitblocks(oneto(∞)) ≡ blockedrange(Ones{Int}(∞))
@test unitblocks(2:∞) == 2:∞

@test unitblocks(oneto(∞))[Block.(2:∞)] == 2:∞
end

@testset "1:∞ blocks" begin
Expand Down Expand Up @@ -193,8 +205,8 @@ end

@testset "triangle recurrences" begin
@testset "n and k" begin
n = mortar(Fill.(oneto(∞),oneto(∞)))
k = mortar(Base.OneTo.(oneto(∞)))
n = mortar(Fill.(oneto(∞),oneto(∞)));
k = mortar(Base.OneTo.(oneto(∞)));

@test n[Block(5)] ≡ layout_getindex(n, Block(5)) ≡ view(n,Block(5)) ≡ Fill(5,5)
@test k[Block(5)] ≡ layout_getindex(k, Block(5)) ≡ view(k,Block(5)) ≡ Base.OneTo(5)
Expand All @@ -217,6 +229,11 @@ end
@test @allocated(axes(v)) ≤ 40
@test copyto!(dest, v) == v

@testset "stack overflow" begin
i = Base.to_indices(k, (Block.(2:∞),))[1].indices;
last(i)
end

v = view(k,Block.(2:∞))
@test Base.BroadcastStyle(typeof(v)) isa LazyArrayStyle{1}
@test v[Block(1)] == 1:2
Expand Down Expand Up @@ -254,7 +271,7 @@ end
n = mortar(Fill.(oneto(∞),oneto(∞)))
k = mortar(Base.OneTo.(oneto(∞)))
Dy = BlockBandedMatrices._BandedBlockBandedMatrix((k .+ (b+c))', axes(k,1), (-1,1), (-1,1))
N = 100;
N = 100;
@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
Expand Down