Skip to content

Commit 4757c63

Browse files
authored
Fix ∞-dimensional setindex!(::DiagTrav, ...) (#143)
* Fix ∞-dimensional setindex!(::DiagTrav, ...) * Update blockkron.jl
1 parent 9ed8340 commit 4757c63

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LazyBandedMatrices"
22
uuid = "d7e5e226-e90b-4449-9968-0f923699bf6f"
33
authors = ["Sheehan Olver <[email protected]>"]
4-
version = "0.11.3"
4+
version = "0.11.4"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/blockkron.jl

+29-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,32 @@ function colsupport(A::DiagTrav{<:Any,2}, _)
9898
end
9999

100100

101-
function getindex(A::DiagTrav, K::Block{1})
101+
Base.@propagate_inbounds function getindex(A::DiagTrav, Kk::BlockIndex{1})
102+
@boundscheck checkbounds(A, Kk)
103+
_diagtravgetindex(MemoryLayout(A.array), A.array, Kk)
104+
end
105+
106+
function _diagtravgetindex(_, A::AbstractMatrix, Kk::BlockIndex{1})
107+
K,j = Int(block(Kk)), blockindex(Kk)
108+
m,n = size(A)
109+
j = max(0,K-m)+j
110+
A[K-j+1,j]
111+
end
112+
113+
Base.@propagate_inbounds function setindex!(A::DiagTrav, v, Kk::BlockIndex{1})
114+
@boundscheck checkbounds(A, Kk)
115+
_diagtravsetindex!(MemoryLayout(A.array), A.array, v, Kk)
116+
A
117+
end
118+
119+
function _diagtravsetindex!(_, A, v, Kk::BlockIndex{1})
120+
K,j = Int(block(Kk)), blockindex(Kk)
121+
m,n = size(A)
122+
j = max(0,K-m)+j
123+
A[K-j+1,j] = v
124+
end
125+
126+
Base.@propagate_inbounds function getindex(A::DiagTrav, K::Block{1})
102127
@boundscheck checkbounds(A, K)
103128
_diagtravgetindex(MemoryLayout(A.array), A.array, K)
104129
end
@@ -157,6 +182,9 @@ function _diagtravgetindex(::AbstractStridedLayout, A::AbstractArray{T,3}, K::Bl
157182
ret
158183
end
159184

185+
# TODO: don't build the block
186+
_diagtravgetindex(lay, A::AbstractArray{T,3}, Kk::BlockIndex{1}) where T = _diagtravgetindex(lay, A, block(Kk))[blockindex(Kk)]
187+
160188
getindex(A::DiagTrav, k::Int) = A[findblockindex(axes(A,1), k)]
161189
setindex!(A::DiagTrav, v, k::Int) = A[findblockindex(axes(A,1), k)] = v
162190

test/test_lazybandedinf.jl

+7
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ const InfKronTravBandedBlockBandedLayout = LazyBandedMatricesInfiniteArraysExt.I
7676
@test blockcolsupport(A) == Block.(1:6)
7777
@test A[Block.(1:7)] == [1; 5; 2; 9; 6; 3; 0; 10; 7; 4; 0; 0; 11; 8; 0; 0; 0; 0; 12; zeros(9)]
7878

79+
C = zeros(∞,∞);
80+
A = DiagTrav(C);
81+
A[1] = 1
82+
@test A[1] == 1
83+
A[1:9] = 1:9
84+
@test A[1:10] == [1:9; 0]
85+
7986
C = zeros(∞,4);
8087
C[1:3,1:4] .= [1 2 3 4; 5 6 7 8; 9 10 11 12]
8188
A = DiagTrav(C)

0 commit comments

Comments
 (0)