Skip to content

Commit 8ba543c

Browse files
authored
remove pointer-based mulpars implementations (#427)
1 parent 887acf9 commit 8ba543c

File tree

4 files changed

+16
-126
lines changed

4 files changed

+16
-126
lines changed

src/Caching/blockbanded.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function resizedata!(QR::QROperator{<:CachedOperator{T,BlockBandedMatrix{T}}}, :
254254
κ, ξ = blockindex.(bi)
255255

256256
st = bs.block_strides[J1] # the stride of the matrix
257-
shft = bs.block_starts[K1,J1]-1 + st*-1) + κ-1 # the index of the pointer to the j, j entry
257+
shft = bs.block_starts[K1,J1]-1 + st*-1) + κ-1 # the linear index of the j, j entry
258258

259259

260260
K_CS = Int(blockcolstop(R, Block(J1))) # last row in J-th blockcolumn
@@ -286,7 +286,7 @@ function resizedata!(QR::QROperator{<:CachedOperator{T,BlockBandedMatrix{T}}}, :
286286

287287
for J = J1+1:min(K1+u,J_end)
288288
st = bs.block_strides[J]
289-
shft = bs.block_starts[K1,J] + κ-2 # the index of the pointer to the j, j entry
289+
shft = bs.block_starts[K1,J] + κ-2 # the linear index of the j, j entry
290290
for ξ_2 = axes(bs.axes[2][Block(J)],1)
291291
# we now apply I-2v*v' in place
292292
RM = view(R.data, shft + st*(ξ_2-1) .+ (1:M))

src/Caching/matrix.jl

Lines changed: 13 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ end
4242

4343
function mulpars(Ac::Adjoint{T,<:QROperatorQ{QROperator{RR,Matrix{T},T},T}},
4444
B::AbstractVector{T},tolerance,maxlength, inplace::Val = Val(false)) where {RR,T}
45+
46+
Base.require_one_based_indexing(B)
47+
4548
A = parent(Ac)
4649
if length(B) > A.QR.ncols
4750
# upper triangularize extra columns to prepare for \
@@ -50,97 +53,40 @@ function mulpars(Ac::Adjoint{T,<:QROperatorQ{QROperator{RR,Matrix{T},T},T}},
5053

5154
H=A.QR.H
5255
M=size(H,1)
53-
m=length(B)
54-
Y=_pad!!(inplace)(B,m+M+10)
55-
56-
k=1
57-
yp=view(Y,1:M)
58-
while (k m+M || norm(yp) > tolerance )
59-
if k > maxlength
60-
@warn "Maximum length $maxlength reached."
61-
break
62-
end
63-
64-
if k+M-1>length(Y)
65-
pad!(Y,2*(k+M))
66-
end
67-
if k > A.QR.ncols
68-
# upper triangularize extra columns to prepare for \
69-
resizedata!(A.QR,:,k+M+50)
70-
H=A.QR.H
71-
end
72-
73-
wp=view(H,:,k)
74-
yp=view(Y,k:k+M-1)
75-
76-
dt=dot(wp,yp)
77-
axpy!(-2*dt,wp,yp)
78-
k+=1
79-
end
80-
nz = findlast(!iszero, Y)
81-
resize!(Y,nz === nothing ? k : min(k, nz)) # chop off zeros
82-
end
83-
84-
85-
# BLAS apply Q
86-
87-
function mulpars(Ac::Adjoint{T,<:QROperatorQ{QROperator{RR,Matrix{T},T},T}},
88-
B::AbstractVector{T},
89-
tolerance,maxlength, inplace::Val = Val(false)) where {RR,T<:BlasFloat}
90-
91-
A = parent(Ac)
92-
93-
A_dim = size(A,1)
94-
95-
if length(B) > A.QR.ncols
96-
# upper triangularize extra columns to prepare for \
97-
resizedata!(A.QR,:,length(B)+size(A.QR.H,1)+10)
98-
end
9956

100-
if size(A.QR.H,1) == 1 # diagonal scaling, avoid growing
101-
diagv=view(A.QR.H,1,1:length(B))
57+
if M == 1 # diagonal scaling, avoid growing
10258
ret = inplace isa Val{true} ? B : similar(B)
103-
@simd for k=1:length(ret)
104-
@inbounds ret[k]=(1-2A.QR.H[1,k]^2)*B[k]
59+
@simd for k in eachindex(ret)
60+
@inbounds ret[k]=(1-2H[1,k]^2)*B[k]
10561
end
10662
return ret
10763
end
10864

109-
H=A.QR.H
110-
h=pointer(H)
111-
M=size(H,1)
112-
st=stride(H,2)
113-
114-
sz=sizeof(T)
115-
11665
m=length(B)
117-
Y=_pad!!(inplace)(B,m+M+10)
118-
y=pointer(Y)
66+
Y = _pad!!(inplace)(B,m+M+10)
11967

12068
k=1
121-
yp=y
122-
while (k min(m+M,A_dim) || BLAS.nrm2(M,yp,1) > tolerance )
69+
yp=view(Y,1:M)
70+
while (k m+M || norm(yp) > tolerance )
12371
if k > maxlength
12472
@warn "Maximum length $maxlength reached."
12573
break
12674
end
12775

12876
if k+M-1>length(Y)
12977
pad!(Y,2*(k+M))
130-
y=pointer(Y)
13178
end
13279
if k > A.QR.ncols
13380
# upper triangularize extra columns to prepare for \
13481
resizedata!(A.QR,:,2*(k+M))
13582
H=A.QR.H
136-
h=pointer(H)
13783
end
13884

139-
wp=h+sz*st*(k-1)
140-
yp=y+sz*(k-1)
85+
wp=view(H,:,k)
86+
yp=view(Y, range(k, length=M))
14187

142-
dt = dot(M,wp,1,yp,1)
143-
BLAS.axpy!(M,-2*dt,wp,1,yp,1)
88+
dt=dot(wp,yp)
89+
axpy!(-2dt,wp,yp)
14490
k+=1
14591
end
14692
nz = findlast(!iszero, Y)

src/Caching/ragged.jl

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -193,60 +193,3 @@ function mulpars(Ac::Adjoint{T,<:QROperatorQ{QROperator{RR,RaggedMatrix{T},T},T}
193193
nz = findlast(!iszero, Y)
194194
resize!(Y,nz === nothing ? k : min(k, nz)) # chop off zeros
195195
end
196-
197-
198-
199-
# BLAS apply Q
200-
201-
function mulpars(Ac::Adjoint{T,<:QROperatorQ{QROperator{RR,RaggedMatrix{T},T},T}},
202-
B::AbstractVector{T},tolerance,maxlength) where {RR,T<:BlasFloat}
203-
A = parent(Ac)
204-
if length(B) > A.QR.ncols
205-
# upper triangularize extra columns to prepare for \
206-
resizedata!(A.QR,:,length(B)+size(A.QR.H,1)+10)
207-
end
208-
209-
H=A.QR.H
210-
h=pointer(H.data)
211-
212-
M=size(H,1)
213-
m=length(B)
214-
Y=pad(B,m+M+10)
215-
216-
sz=sizeof(T)
217-
218-
k=1
219-
y=pointer(Y)
220-
221-
yp=y
222-
while (k m || BLAS.nrm2(M,yp,1) > tolerance )
223-
if k > maxlength
224-
@warn "Maximum length $maxlength reached."
225-
break
226-
end
227-
if k > A.QR.ncols
228-
# upper triangularize extra columns to prepare for \
229-
resizedata!(A.QR,:,k+M+50)
230-
H=A.QR.H
231-
h=pointer(H.data)
232-
end
233-
234-
235-
M=colstop(H,k)
236-
237-
if k+M-1>length(Y)
238-
pad!(Y,2*(k+M))
239-
y=pointer(Y)
240-
end
241-
242-
243-
wp=h + sz*(H.cols[k]-1)
244-
yp=y+sz*(k-1)
245-
246-
dt = dot(M,wp,1,yp,1)
247-
BLAS.axpy!(M,-2dt,wp,1,yp,1)
248-
k+=1
249-
end
250-
nz = findlast(!iszero, Y)
251-
resize!(Y, nz === nothing ? k : min(k, nz)) # chop off zeros
252-
end

src/LinearAlgebra/helper.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ function pad(v::AbstractVector,n::Integer,m::Integer)
237237
end
238238

239239
function pad(A::AbstractMatrix,n::Integer,m::Integer)
240+
Base.require_one_based_indexing(A)
240241
T=eltype(A)
241242
if n <= size(A,1) && m <= size(A,2)
242243
A[1:n,1:m]

0 commit comments

Comments
 (0)