Skip to content

Commit 0ce2b6a

Browse files
authored
Make RaggedMatrix immutable (#435)
* Avoid setfield for RaggedMatrix in resizedata * Make RaggedMatrix immutable * householder RaggedMatrix in dispatch in resizedata
1 parent ad4f0c0 commit 0ce2b6a

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.8.10"
3+
version = "0.8.11"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Caching/blockbanded.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ QROperator(R::CachedOperator{T,BlockBandedMatrix{T}}) where {T} =
201201
resizedata!(QR::QROperator{<:CachedOperator{T,BlockBandedMatrix{T}}}, ::Colon, col::Int) where {T} =
202202
resizedata!(QR, :, block(domainspace(QR.R_cache),col))
203203

204-
function resizedata!(QR::QROperator{<:CachedOperator{T,BlockBandedMatrix{T}}}, ::Colon, COL::Block) where {T<:BlasFloat}
204+
function resizedata!(QR::QROperator{<:CachedOperator{T,BlockBandedMatrix{T}}, <:RaggedMatrix}, ::Colon, COL::Block) where {T}
205205
MO = QR.R_cache
206206
W = QR.H
207207
R = MO.data
@@ -235,13 +235,16 @@ function resizedata!(QR::QROperator{<:CachedOperator{T,BlockBandedMatrix{T}}}, :
235235
m = size(W,2)
236236
resize!(W.cols, 2col+1)
237237

238+
Wm = W.m
238239
for j=m+1:2col
239240
cs = blockstop(rangespace(MO), blockcolstop(MO, block(domainspace(MO),j)))
240241
W.cols[j+1]=W.cols[j] + cs-j+1
241-
W.m=max(W.m,cs-j+1)
242+
Wm=max(Wm,cs-j+1)
242243
end
243244

244245
resize!(W.data, W.cols[end]-1)
246+
W = RaggedMatrix(W.data, W.cols, Wm)
247+
QR.H = W
245248
end
246249

247250
ri = firstindex(R.data)

src/Caching/ragged.jl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function resizedata!(B::CachedOperator{T,RaggedMatrix{T}},::Colon,n::Integer) wh
3737
end
3838

3939
pad!(B.data.data,B.data.cols[n+1]-1)
40-
B.data.m = K
40+
B.data = RaggedMatrix(B.data.data, B.data.cols, K)
4141

4242
jr=B.datasize[2]+1:n
4343
kr=1:K
@@ -52,8 +52,8 @@ end
5252

5353
function resizedata!(B::CachedOperator{T,RaggedMatrix{T}},n::Integer,m::Integer) where T<:Number
5454
resizedata!(B,:,m)
55-
B.data.m = max(B.data.m,n) # make sure we have at least n rows
56-
55+
data = B.data
56+
B.data = RaggedMatrix(data.data, data.cols, max(data.m,n)) # make sure we have at least n rows
5757
B
5858
end
5959

@@ -63,7 +63,7 @@ end
6363
QROperator(R::CachedOperator{T,RaggedMatrix{T}}) where {T} =
6464
QROperator(R,RaggedMatrix{T}(undef,0,Int[]),0)
6565

66-
function resizedata!(QR::QROperator{<:CachedOperator{T,RaggedMatrix{T}}}, ::Colon, col) where {T}
66+
function resizedata!(QR::QROperator{<:CachedOperator{T,RaggedMatrix{T}}, <:RaggedMatrix}, ::Colon, col) where {T}
6767
if col QR.ncols
6868
return QR
6969
end
@@ -79,7 +79,7 @@ function resizedata!(QR::QROperator{<:CachedOperator{T,RaggedMatrix{T}}}, ::Colo
7979
for J=1:QR.ncols
8080
wp=view(W,1:colstop(W,J),J)
8181
for j = m+1:MO.datasize[2]
82-
kr = J:J+length(wp)-1
82+
kr = range(J, length=length(wp))
8383
v = view(MO.data,kr,j)
8484
dt = dot(wp,v)
8585
axpy!(-2dt, wp, v)
@@ -92,19 +92,24 @@ function resizedata!(QR::QROperator{<:CachedOperator{T,RaggedMatrix{T}}}, ::Colo
9292
m = size(W,2)
9393
resize!(W.cols,col+101)
9494

95+
Wm = W.m
9596
for j=m+1:col+100
9697
cs = colstop(MO.data,j)
9798
W.cols[j+1] = W.cols[j] + cs-j+1
98-
W.m = max(W.m,cs-j+1)
99+
Wm = max(Wm,cs-j+1)
99100
end
100101

101102
resize!(W.data,W.cols[end]-1)
103+
W = RaggedMatrix(W.data, W.cols, Wm)
104+
QR.H = W
102105
end
103106

104107
for k=QR.ncols+1:col
105108
cs = colstop(MO.data,k)
106-
W[1:cs-k+1,k] = view(MO.data,k:cs,k) # diagonal and below
107-
wp = view(W,1:cs-k+1,k)
109+
indsk = k:cs
110+
indskax = eachindex(indsk)
111+
W[indskax,k] = view(MO.data,indsk,k) # diagonal and below
112+
wp = view(W,indskax,k)
108113
W[1,k] += flipsign(norm(wp),W[1,k])
109114
normalize!(wp)
110115

src/LinearAlgebra/RaggedMatrix.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ getindex(A::AbstractMatrix,k::Integer,::Type{FiniteRange}) = A[k,1:rowstop(A,k)]
66

77
const = FiniteRange
88

9-
mutable struct RaggedMatrix{T} <: AbstractMatrix{T}
9+
struct RaggedMatrix{T} <: AbstractMatrix{T}
1010
data::Vector{T} # a Vector of non-zero entries
1111
cols::Vector{Int} # a Vector specifying the first index of each column
1212
m::Int #Number of rows

0 commit comments

Comments
 (0)