Skip to content

Commit 85debaa

Browse files
authored
Improvements to blockedunitrange (#74)
* Improvements to blockedunitrange * v0.5.5 * add tests
1 parent 4734173 commit 85debaa

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "InfiniteLinearAlgebra"
22
uuid = "cde9dba0-b1de-11e9-2c62-0bab9446c55c"
3-
version = "0.5.4"
3+
version = "0.5.5"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ 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
378+
sub_materialize(::AbstractBlockLayout, V, ::Tuple{<:BlockedUnitRange{<:InfRanges}}) = V
377379

378380
##
379381
# 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: 25 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)
@@ -134,12 +134,24 @@ end
134134
n = Fill.(oneto(∞),oneto(∞))
135135
@test broadcast(length,k) map(length,k) OneToInf()
136136
@test broadcast(length,n) map(length,n) OneToInf()
137+
137138
b = mortar(Fill([1,2],∞))
138139
@test blockaxes(b,1) Block.(OneToInf())
139140
@test b[Block(5)] == [1,2]
141+
@test b[Block.(2:∞)][Block.(2:10)] == b[Block.(3:11)]
142+
@test exp.(b)[Block.(2:∞)][Block.(2:10)] == exp.(b[Block.(3:11)])
143+
144+
c = PseudoBlockArray(1:∞,Vcat(2,Fill(3,∞)))
145+
@test c[Block.(2:∞)][Block.(2:10)] == c[Block.(3:11)]
146+
140147
@test length(axes(b,1)) ℵ₀
141-
@test last(axes(b,1))
148+
@test last(axes(b,1)) RealInfinity()
142149
@test Base.BroadcastStyle(typeof(b)) isa LazyArrayStyle{1}
150+
151+
@test unitblocks(oneto(∞)) blockedrange(Ones{Int}(∞))
152+
@test unitblocks(2:∞) == 2:
153+
154+
@test unitblocks(oneto(∞))[Block.(2:∞)] == 2:
143155
end
144156

145157
@testset "1:∞ blocks" begin
@@ -193,8 +205,8 @@ end
193205

194206
@testset "triangle recurrences" begin
195207
@testset "n and k" begin
196-
n = mortar(Fill.(oneto(∞),oneto(∞)))
197-
k = mortar(Base.OneTo.(oneto(∞)))
208+
n = mortar(Fill.(oneto(∞),oneto(∞)));
209+
k = mortar(Base.OneTo.(oneto(∞)));
198210

199211
@test n[Block(5)] layout_getindex(n, Block(5)) view(n,Block(5)) Fill(5,5)
200212
@test k[Block(5)] layout_getindex(k, Block(5)) view(k,Block(5)) Base.OneTo(5)
@@ -217,6 +229,11 @@ end
217229
@test @allocated(axes(v)) 40
218230
@test copyto!(dest, v) == v
219231

232+
@testset "stack overflow" begin
233+
i = Base.to_indices(k, (Block.(2:∞),))[1].indices;
234+
last(i)
235+
end
236+
220237
v = view(k,Block.(2:∞))
221238
@test Base.BroadcastStyle(typeof(v)) isa LazyArrayStyle{1}
222239
@test v[Block(1)] == 1:2
@@ -254,7 +271,7 @@ end
254271
n = mortar(Fill.(oneto(∞),oneto(∞)))
255272
k = mortar(Base.OneTo.(oneto(∞)))
256273
Dy = BlockBandedMatrices._BandedBlockBandedMatrix((k .+ (b+c))', axes(k,1), (-1,1), (-1,1))
257-
N = 100;
274+
N = 100;
258275
@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))
259276
end
260277
end

0 commit comments

Comments
 (0)