Skip to content

Commit 90a3300

Browse files
musmandreasnoack
authored andcommitted
Use refs instead of Vector in Lapack (#23419)
* Use refs instead of Vector in Lapack * Use uninitialized refs * Manual constructors * Simply
1 parent 9944d3d commit 90a3300

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

base/linalg/blas.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ function check()
143143
(_, info) = LinAlg.LAPACK.potrf!('U', [1.0 0.0; 0.0 -1.0])
144144
if info != 2 # mangled info code
145145
if info == 2^33
146-
error("""BLAS and LAPACK are compiled with 32-bit integer support, but Julia expects 64-bit integers. Please build Julia with USE_BLAS64=0.""")
146+
error("BLAS and LAPACK are compiled with 32-bit integer support, but Julia expects 64-bit integers. Please build Julia with USE_BLAS64=0.")
147147
elseif info == 0
148-
error("""BLAS and LAPACK are compiled with 64-bit integer support but Julia expects 32-bit integers. Please build Julia with USE_BLAS64=1.""")
148+
error("BLAS and LAPACK are compiled with 64-bit integer support but Julia expects 32-bit integers. Please build Julia with USE_BLAS64=1.")
149149
else
150-
error("""The LAPACK library produced an undefined error code. Please verify the installation of BLAS and LAPACK.""")
150+
error("The LAPACK library produced an undefined error code. Please verify the installation of BLAS and LAPACK.")
151151
end
152152
end
153153

base/linalg/lapack.jl

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ for (gbtrf, gbtrs, elty) in
148148
end
149149
ccall((@blasfunc($gbtrs), liblapack), Void,
150150
(Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt},
151-
Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
151+
Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
152152
Ptr{BlasInt}),
153153
&trans, &n, &kl, &ku, &size(B,2), AB, &max(1,stride(AB,2)), ipiv,
154154
B, &max(1,stride(B,2)), info)
@@ -1040,7 +1040,7 @@ for (gesvx, elty) in
10401040
ldaf = stride(AF,2)
10411041
nrhs = size(B,2)
10421042
ldb = stride(B,2)
1043-
rcond = Vector{$elty}(1)
1043+
rcond = Ref{$elty}()
10441044
ferr = similar(A, $elty, nrhs)
10451045
berr = similar(A, $elty, nrhs)
10461046
work = Vector{$elty}(4n)
@@ -1062,7 +1062,7 @@ for (gesvx, elty) in
10621062
chknonsingular(info[])
10631063
end
10641064
#WORK(1) contains the reciprocal pivot growth factor norm(A)/norm(U)
1065-
X, equed, R, C, B, rcond[1], ferr, berr, work[1]
1065+
X, equed, R, C, B, rcond[], ferr, berr, work[1]
10661066
end
10671067

10681068
function gesvx!(A::StridedMatrix{$elty}, B::StridedVecOrMat{$elty})
@@ -1109,7 +1109,7 @@ for (gesvx, elty, relty) in
11091109
ldaf = stride(AF,2)
11101110
nrhs = size(B,2)
11111111
ldb = stride(B,2)
1112-
rcond = Vector{$relty}(1)
1112+
rcond = Ref{$relty}()
11131113
ferr = similar(A, $relty, nrhs)
11141114
berr = similar(A, $relty, nrhs)
11151115
work = Vector{$elty}(2n)
@@ -1131,7 +1131,7 @@ for (gesvx, elty, relty) in
11311131
chknonsingular(info[])
11321132
end
11331133
#RWORK(1) contains the reciprocal pivot growth factor norm(A)/norm(U)
1134-
X, equed, R, C, B, rcond[1], ferr, berr, rwork[1]
1134+
X, equed, R, C, B, rcond[], ferr, berr, rwork[1]
11351135
end
11361136

11371137
#Wrapper for the no-equilibration, no-transpose calculation
@@ -1205,8 +1205,7 @@ for (gelsd, gelsy, elty) in
12051205
end
12061206
newB = [B; zeros($elty, max(0, n - size(B, 1)), size(B, 2))]
12071207
s = similar(A, $elty, min(m, n))
1208-
rcond = convert($elty, rcond)
1209-
rnk = Vector{BlasInt}(1)
1208+
rnk = Ref{BlasInt}()
12101209
info = Ref{BlasInt}()
12111210
work = Vector{$elty}(1)
12121211
lwork = BlasInt(-1)
@@ -1215,18 +1214,20 @@ for (gelsd, gelsy, elty) in
12151214
ccall((@blasfunc($gelsd), liblapack), Void,
12161215
(Ptr{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt},
12171216
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
1218-
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
1217+
Ptr{$elty}, Ref{$elty}, Ref{BlasInt}, Ptr{$elty},
12191218
Ptr{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}),
1220-
&m, &n, &size(B,2), A, &max(1,stride(A,2)),
1221-
newB, &max(1,stride(B,2),n), s, &rcond, rnk, work, &lwork, iwork, info)
1219+
&m, &n, &size(B,2),
1220+
A, &max(1,stride(A,2)), newB, &max(1,stride(B,2),n),
1221+
s, $elty(rcond), rnk, work,
1222+
&lwork, iwork, info)
12221223
chklapackerror(info[])
12231224
if i == 1
12241225
lwork = BlasInt(real(work[1]))
12251226
resize!(work, lwork)
12261227
resize!(iwork, iwork[1])
12271228
end
12281229
end
1229-
subsetrows(B, newB, n), rnk[1]
1230+
subsetrows(B, newB, n), rnk[]
12301231
end
12311232

12321233
# SUBROUTINE DGELSY( M, N, NRHS, A, LDA, B, LDB, JPVT, RCOND, RANK,
@@ -1250,28 +1251,27 @@ for (gelsd, gelsy, elty) in
12501251
lda = max(1, m)
12511252
ldb = max(1, m, n)
12521253
jpvt = zeros(BlasInt, n)
1253-
rcond = convert($elty, rcond)
1254-
rnk = Vector{BlasInt}(1)
1254+
rnk = Ref{BlasInt}()
12551255
work = Vector{$elty}(1)
12561256
lwork = BlasInt(-1)
12571257
info = Ref{BlasInt}()
12581258
for i = 1:2 # first call returns lwork as work[1]
12591259
ccall((@blasfunc($gelsy), liblapack), Void,
12601260
(Ptr{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty},
12611261
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt},
1262-
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
1262+
Ref{$elty}, Ref{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
12631263
Ptr{BlasInt}),
12641264
&m, &n, &nrhs, A,
12651265
&lda, newB, &ldb, jpvt,
1266-
&rcond, rnk, work, &lwork,
1266+
$elty(rcond), rnk, work, &lwork,
12671267
info)
12681268
chklapackerror(info[])
12691269
if i == 1
12701270
lwork = BlasInt(work[1])
12711271
resize!(work, lwork)
12721272
end
12731273
end
1274-
subsetrows(B, newB, n), rnk[1]
1274+
subsetrows(B, newB, n), rnk[]
12751275
end
12761276
end
12771277
end
@@ -1298,8 +1298,7 @@ for (gelsd, gelsy, elty, relty) in
12981298
end
12991299
newB = [B; zeros($elty, max(0, n - size(B, 1)), size(B, 2))]
13001300
s = similar(A, $relty, min(m, n))
1301-
rcond = convert($relty, rcond)
1302-
rnk = Vector{BlasInt}(1)
1301+
rnk = Ref{BlasInt}()
13031302
info = Ref{BlasInt}()
13041303
work = Vector{$elty}(1)
13051304
lwork = BlasInt(-1)
@@ -1309,10 +1308,12 @@ for (gelsd, gelsy, elty, relty) in
13091308
ccall((@blasfunc($gelsd), liblapack), Void,
13101309
(Ptr{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty},
13111310
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$relty},
1312-
Ptr{$relty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
1313-
Ptr{$relty}, Ptr{BlasInt}, Ptr{BlasInt}),
1314-
&m, &n, &size(B,2), A, &max(1,stride(A,2)),
1315-
newB, &max(1,stride(B,2),n), s, &rcond, rnk, work, &lwork, rwork, iwork, info)
1311+
Ref{$relty}, Ref{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
1312+
Ptr{$relty}, Ref{BlasInt}, Ref{BlasInt}),
1313+
&m, &n, &size(B,2), A,
1314+
&max(1,stride(A,2)), newB, &max(1,stride(B,2),n), s,
1315+
$relty(rcond), rnk, work, &lwork,
1316+
rwork, iwork, info)
13161317
chklapackerror(info[])
13171318
if i == 1
13181319
lwork = BlasInt(real(work[1]))
@@ -1321,7 +1322,7 @@ for (gelsd, gelsy, elty, relty) in
13211322
resize!(iwork, iwork[1])
13221323
end
13231324
end
1324-
subsetrows(B, newB, n), rnk[1]
1325+
subsetrows(B, newB, n), rnk[]
13251326
end
13261327

13271328
# SUBROUTINE ZGELSY( M, N, NRHS, A, LDA, B, LDB, JPVT, RCOND, RANK,
@@ -1345,8 +1346,7 @@ for (gelsd, gelsy, elty, relty) in
13451346
lda = max(1, m)
13461347
ldb = max(1, m, n)
13471348
jpvt = zeros(BlasInt, n)
1348-
rcond = convert($relty, rcond)
1349-
rnk = Vector{BlasInt}(1)
1349+
rnk = Ref{BlasInt}(1)
13501350
work = Vector{$elty}(1)
13511351
lwork = BlasInt(-1)
13521352
rwork = Vector{$relty}(2n)
@@ -1355,19 +1355,19 @@ for (gelsd, gelsy, elty, relty) in
13551355
ccall((@blasfunc($gelsy), liblapack), Void,
13561356
(Ptr{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty},
13571357
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt},
1358-
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
1358+
Ref{$relty}, Ref{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
13591359
Ptr{$relty}, Ptr{BlasInt}),
13601360
&m, &n, &nrhs, A,
13611361
&lda, newB, &ldb, jpvt,
1362-
&rcond, rnk, work, &lwork,
1362+
$relty(rcond), rnk, work, &lwork,
13631363
rwork, info)
13641364
chklapackerror(info[])
13651365
if i == 1
13661366
lwork = BlasInt(real(work[1]))
13671367
resize!(work, lwork)
13681368
end
13691369
end
1370-
subsetrows(B, newB, n), rnk[1]
1370+
subsetrows(B, newB, n), rnk[]
13711371
end
13721372
end
13731373
end
@@ -3334,17 +3334,17 @@ for (trcon, trevc, trrfs, elty) in
33343334
chkdiag(diag)
33353335
n = checksquare(A)
33363336
chkuplo(uplo)
3337-
rcond = Vector{$elty}(1)
3337+
rcond = Ref{$elty}()
33383338
work = Vector{$elty}(3n)
33393339
iwork = Vector{BlasInt}(n)
33403340
info = Ref{BlasInt}()
33413341
ccall((@blasfunc($trcon), liblapack), Void,
33423342
(Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}, Ptr{BlasInt},
3343-
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt}),
3343+
Ptr{$elty}, Ptr{BlasInt}, Ref{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt}),
33443344
&norm, &uplo, &diag, &n,
33453345
A, &max(1,stride(A,2)), rcond, work, iwork, info)
33463346
chklapackerror(info[])
3347-
rcond[1]
3347+
rcond[]
33483348
end
33493349

33503350
# SUBROUTINE DTREVC( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL, VR,
@@ -3462,17 +3462,17 @@ for (trcon, trevc, trrfs, elty, relty) in
34623462
n = checksquare(A)
34633463
chkuplo(uplo)
34643464
chkdiag(diag)
3465-
rcond = Vector{$relty}(1)
3465+
rcond = Ref{$relty}(1)
34663466
work = Vector{$elty}(2n)
34673467
rwork = Vector{$relty}(n)
34683468
info = Ref{BlasInt}()
34693469
ccall((@blasfunc($trcon), liblapack), Void,
34703470
(Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}, Ptr{BlasInt},
3471-
Ptr{$elty}, Ptr{BlasInt}, Ptr{$relty}, Ptr{$elty}, Ptr{$relty}, Ptr{BlasInt}),
3471+
Ptr{$elty}, Ptr{BlasInt}, Ref{$relty}, Ptr{$elty}, Ptr{$relty}, Ptr{BlasInt}),
34723472
&norm, &uplo, &diag, &n,
34733473
A, &max(1,stride(A,2)), rcond, work, rwork, info)
34743474
chklapackerror(info[])
3475-
rcond[1]
3475+
rcond[]
34763476
end
34773477

34783478
# SUBROUTINE ZTREVC( SIDE, HOWMNY, SELECT, N, T, LDT, VL, LDVL, VR,
@@ -5337,18 +5337,18 @@ for (gecon, elty) in
53375337
chkstride1(A)
53385338
n = checksquare(A)
53395339
lda = max(1, stride(A, 2))
5340-
rcond = Vector{$elty}(1)
5340+
rcond = Ref{$elty}()
53415341
work = Vector{$elty}(4n)
53425342
iwork = Vector{BlasInt}(n)
53435343
info = Ref{BlasInt}()
53445344
ccall((@blasfunc($gecon), liblapack), Void,
53455345
(Ptr{UInt8}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
5346-
Ptr{$elty}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt},
5346+
Ptr{$elty}, Ref{$elty}, Ptr{$elty}, Ptr{BlasInt},
53475347
Ptr{BlasInt}),
53485348
&normtype, &n, A, &lda, &anorm, rcond, work, iwork,
53495349
info)
53505350
chklapackerror(info[])
5351-
rcond[1]
5351+
rcond[]
53525352
end
53535353
end
53545354
end
@@ -5371,18 +5371,18 @@ for (gecon, elty, relty) in
53715371
chkstride1(A)
53725372
n = checksquare(A)
53735373
lda = max(1, stride(A, 2))
5374-
rcond = Vector{$relty}(1)
5374+
rcond = Ref{$relty}()
53755375
work = Vector{$elty}(2n)
53765376
rwork = Vector{$relty}(2n)
53775377
info = Ref{BlasInt}()
53785378
ccall((@blasfunc($gecon), liblapack), Void,
53795379
(Ptr{UInt8}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
5380-
Ptr{$relty}, Ptr{$relty}, Ptr{$elty}, Ptr{$relty},
5380+
Ptr{$relty}, Ref{$relty}, Ptr{$elty}, Ptr{$relty},
53815381
Ptr{BlasInt}),
53825382
&normtype, &n, A, &lda, &anorm, rcond, work, rwork,
53835383
info)
53845384
chklapackerror(info[])
5385-
rcond[1]
5385+
rcond[]
53865386
end
53875387
end
53885388
end

0 commit comments

Comments
 (0)