Skip to content

Commit 0b99065

Browse files
committed
Improvements to blockedunitrange
1 parent 4734173 commit 0b99065

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ BandedMatrices = "0.16"
2121
BlockArrays = "0.14.5, 0.15"
2222
BlockBandedMatrices = "0.10"
2323
FillArrays = "0.11"
24-
InfiniteArrays = "0.10"
24+
InfiniteArrays = "0.10.6"
2525
LazyArrays = "0.20.2, 0.21"
2626
LazyBandedMatrices = "0.5"
2727
MatrixFactorizations = "0.8"

src/InfiniteLinearAlgebra.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module InfiniteLinearAlgebra
22
using BlockArrays, BlockBandedMatrices, BandedMatrices, LazyArrays, LazyBandedMatrices, SemiseparableMatrices,
33
FillArrays, InfiniteArrays, MatrixFactorizations, ArrayLayouts, LinearAlgebra
44

5-
import Base: +, -, *, /, \, ^, OneTo, getindex, promote_op, _unsafe_getindex, size, axes,
5+
import Base: +, -, *, /, \, ^, OneTo, getindex, promote_op, _unsafe_getindex, size, axes, length,
66
AbstractMatrix, AbstractArray, Matrix, Array, Vector, AbstractVector, Slice,
77
show, getproperty, copy, copyto!, map, require_one_based_indexing, similar, inv
88
import Base.Broadcast: BroadcastStyle, Broadcasted, broadcasted

src/banded/infbanded.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ sub_materialize(::AbstractBandedLayout, V, ::Tuple{InfAxes,OneTo{Int}}) = V
374374
@inline sub_materialize(::BroadcastBandedLayout, V, ::Tuple{InfAxes,InfAxes}) = V
375375
@inline sub_materialize(::BandedColumns, V, ::Tuple{InfAxes,InfAxes}) = BandedMatrix(V)
376376

377+
sub_materialize(_, V, ::Tuple{<:BlockedUnitRange{<:InfRanges}}) = V
377378

378379
##
379380
# UniformScaling

src/blockbanded/blockbanded.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ function BlockArrays.sortedunion(a::Vcat{Int,1,<:Tuple{<:AbstractVector{Int},Inf
2626
end
2727

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

3031
const OneToInfBlocks = BlockedUnitRange{OneToInfCumsum}
3132
const OneToBlocks = BlockedUnitRange{OneToCumsum}
3233

3334
axes(a::OneToInfBlocks) = (a,)
3435
axes(a::OneToBlocks) = (a,)
3536

37+
LazyBandedMatrices.unitblocks(a::OneToInf) = blockedrange(Ones{Int}(length(a)))
38+
3639
BlockArrays.dimlength(start, ::Infinity) = ℵ₀
3740

3841
function copy(bc::Broadcasted{<:BroadcastStyle,<:Any,typeof(*),<:Tuple{Ones{T,1,Tuple{OneToInfBlocks}},AbstractArray{V,N}}}) where {N,T,V}
@@ -71,9 +74,6 @@ BroadcastStyle(::Type{<:BlockArray{T,N,<:AbstractArray{<:AbstractArray{T,N},N},<
7174
BroadcastStyle(::Type{<:PseudoBlockArray{T,N,<:AbstractArray{T,N},<:NTuple{N,BlockedUnitRange{<:RangeCumsum{Int,<:InfRanges}}}}}) where {T,N} = LazyArrayStyle{N}()
7275

7376

74-
BlockArrays._length(::BlockedUnitRange, ::OneToInf) = ℵ₀
75-
BlockArrays._last(::BlockedUnitRange, ::OneToInf) =
76-
7777
###
7878
# KronTrav
7979
###

test/runtests.jl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ using InfiniteLinearAlgebra, BlockBandedMatrices, BlockArrays, BandedMatrices, I
22
MatrixFactorizations, ArrayLayouts, LinearAlgebra, Random, LazyBandedMatrices, StaticArrays
33
import InfiniteLinearAlgebra: qltail, toeptail, tailiterate , tailiterate!, tail_de, ql_X!,
44
InfToeplitz, PertToeplitz, TriToeplitz, InfBandedMatrix, InfBandCartesianIndices,
5-
rightasymptotics, QLHessenberg, ConstRows, PertConstRows,
5+
rightasymptotics, QLHessenberg, ConstRows, PertConstRows,
66
BandedToeplitzLayout, PertToeplitzLayout, TridiagonalToeplitzLayout, BidiagonalToeplitzLayout
77
import Base: BroadcastStyle
88
import BlockArrays: _BlockArray
99
import BlockBandedMatrices: isblockbanded, _BlockBandedMatrix
1010
import MatrixFactorizations: QLPackedQ
1111
import BandedMatrices: bandeddata, _BandedMatrix, BandedStyle
1212
import LazyArrays: colsupport, ApplyStyle, MemoryLayout, ApplyLayout, LazyArrayStyle, arguments
13-
import InfiniteArrays: OneToInf, oneto
13+
import InfiniteArrays: OneToInf, oneto, RealInfinity
1414
import LazyBandedMatrices: BroadcastBandedBlockBandedLayout, BroadcastBandedLayout, LazyBandedLayout
1515

1616

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

42-
@test _BandedMatrix((1:∞)', ∞, -1, 1) isa BandedMatrix
42+
@test _BandedMatrix((1:∞)', ∞, -1, 1) isa BandedMatrix
4343
end
4444

4545
@testset "∞-Toeplitz" begin
@@ -103,7 +103,7 @@ import LazyBandedMatrices: BroadcastBandedBlockBandedLayout, BroadcastBandedLayo
103103
@test (A + 2I)[1:10,1:10] == (2I + A)[1:10,1:10] == A[1:10,1:10] + 2I
104104
@test (Adjoint(A) + 2I)[1:10,1:10] == (2I + Adjoint(A))[1:10,1:10] == Adjoint(A)[1:10,1:10] + 2I
105105
end
106-
106+
107107

108108
@testset "InfBanded" begin
109109
A = _BandedMatrix(Fill(2,4,∞),ℵ₀,2,1)
@@ -138,7 +138,7 @@ end
138138
@test blockaxes(b,1) Block.(OneToInf())
139139
@test b[Block(5)] == [1,2]
140140
@test length(axes(b,1)) ℵ₀
141-
@test last(axes(b,1))
141+
@test last(axes(b,1)) RealInfinity()
142142
@test Base.BroadcastStyle(typeof(b)) isa LazyArrayStyle{1}
143143
end
144144

@@ -193,8 +193,8 @@ end
193193

194194
@testset "triangle recurrences" begin
195195
@testset "n and k" begin
196-
n = mortar(Fill.(oneto(∞),oneto(∞)))
197-
k = mortar(Base.OneTo.(oneto(∞)))
196+
n = mortar(Fill.(oneto(∞),oneto(∞)));
197+
k = mortar(Base.OneTo.(oneto(∞)));
198198

199199
@test n[Block(5)] layout_getindex(n, Block(5)) view(n,Block(5)) Fill(5,5)
200200
@test k[Block(5)] layout_getindex(k, Block(5)) view(k,Block(5)) Base.OneTo(5)
@@ -217,6 +217,11 @@ end
217217
@test @allocated(axes(v)) 40
218218
@test copyto!(dest, v) == v
219219

220+
@testset "stack overflow" begin
221+
i = Base.to_indices(k, (Block.(2:∞),))[1].indices;
222+
last(i)
223+
end
224+
220225
v = view(k,Block.(2:∞))
221226
@test Base.BroadcastStyle(typeof(v)) isa LazyArrayStyle{1}
222227
@test v[Block(1)] == 1:2
@@ -254,7 +259,7 @@ end
254259
n = mortar(Fill.(oneto(∞),oneto(∞)))
255260
k = mortar(Base.OneTo.(oneto(∞)))
256261
Dy = BlockBandedMatrices._BandedBlockBandedMatrix((k .+ (b+c))', axes(k,1), (-1,1), (-1,1))
257-
N = 100;
262+
N = 100;
258263
@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))
259264
end
260265
end

0 commit comments

Comments
 (0)