Skip to content

Commit 2bf20c1

Browse files
committed
Add xggsvd3 wrappers. The subroutines replace xggsvd in LAPACK 3.6.0 so calls are made conditionally
on the existence of the symbols by defining a constant with the LAPACK version number. Make blasfunc a macro such that it can be called without @eval $name.
1 parent e83b755 commit 2bf20c1

File tree

6 files changed

+323
-152
lines changed

6 files changed

+323
-152
lines changed

base/linalg/blas.jl

+30-30
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module BLAS
44

5-
import Base: copy!, blasfunc
5+
import Base: copy!, @blasfunc
66
import Base.LinAlg: axpy!, dot
77

88
export
@@ -67,7 +67,7 @@ for (fname, elty) in ((:dcopy_,:Float64),
6767
@eval begin
6868
# SUBROUTINE DCOPY(N,DX,INCX,DY,INCY)
6969
function blascopy!(n::Integer, DX::Union{Ptr{$elty},StridedArray{$elty}}, incx::Integer, DY::Union{Ptr{$elty},StridedArray{$elty}}, incy::Integer)
70-
ccall(($(blasfunc(fname)), libblas), Void,
70+
ccall((@blasfunc($fname), libblas), Void,
7171
(Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
7272
&n, DX, &incx, DY, &incy)
7373
DY
@@ -83,7 +83,7 @@ for (fname, elty) in ((:dscal_,:Float64),
8383
@eval begin
8484
# SUBROUTINE DSCAL(N,DA,DX,INCX)
8585
function scal!(n::Integer, DA::$elty, DX::Union{Ptr{$elty},DenseArray{$elty}}, incx::Integer)
86-
ccall(($(blasfunc(fname)), libblas), Void,
86+
ccall((@blasfunc($fname), libblas), Void,
8787
(Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}),
8888
&n, &DA, DX, &incx)
8989
DX
@@ -103,7 +103,7 @@ for (fname, elty) in ((:ddot_,:Float64),
103103
# * .. Array Arguments ..
104104
# DOUBLE PRECISION DX(*),DY(*)
105105
function dot(n::Integer, DX::Union{Ptr{$elty},DenseArray{$elty}}, incx::Integer, DY::Union{Ptr{$elty},DenseArray{$elty}}, incy::Integer)
106-
ccall(($(blasfunc(fname)), libblas), $elty,
106+
ccall((@blasfunc($fname), libblas), $elty,
107107
(Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
108108
&n, DX, &incx, DY, &incy)
109109
end
@@ -120,7 +120,7 @@ for (fname, elty) in ((:cblas_zdotc_sub,:Complex128),
120120
# DOUBLE PRECISION DX(*),DY(*)
121121
function dotc(n::Integer, DX::Union{Ptr{$elty},DenseArray{$elty}}, incx::Integer, DY::Union{Ptr{$elty},DenseArray{$elty}}, incy::Integer)
122122
result = Array($elty, 1)
123-
ccall(($(blasfunc(fname)), libblas), Void,
123+
ccall((@blasfunc($fname), libblas), Void,
124124
(BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}),
125125
n, DX, incx, DY, incy, result)
126126
result[1]
@@ -138,7 +138,7 @@ for (fname, elty) in ((:cblas_zdotu_sub,:Complex128),
138138
# DOUBLE PRECISION DX(*),DY(*)
139139
function dotu(n::Integer, DX::Union{Ptr{$elty},DenseArray{$elty}}, incx::Integer, DY::Union{Ptr{$elty},DenseArray{$elty}}, incy::Integer)
140140
result = Array($elty, 1)
141-
ccall(($(blasfunc(fname)), libblas), Void,
141+
ccall((@blasfunc($fname), libblas), Void,
142142
(BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}, BlasInt, Ptr{$elty}),
143143
n, DX, incx, DY, incy, result)
144144
result[1]
@@ -175,7 +175,7 @@ for (fname, elty, ret_type) in ((:dnrm2_,:Float64,:Float64),
175175
@eval begin
176176
# SUBROUTINE DNRM2(N,X,INCX)
177177
function nrm2(n::Integer, X::Union{Ptr{$elty},DenseArray{$elty}}, incx::Integer)
178-
ccall(($(blasfunc(fname)), libblas), $ret_type,
178+
ccall((@blasfunc($fname), libblas), $ret_type,
179179
(Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
180180
&n, X, &incx)
181181
end
@@ -192,7 +192,7 @@ for (fname, elty, ret_type) in ((:dasum_,:Float64,:Float64),
192192
@eval begin
193193
# SUBROUTINE ASUM(N, X, INCX)
194194
function asum(n::Integer, X::Union{Ptr{$elty},DenseArray{$elty}}, incx::Integer)
195-
ccall(($(blasfunc(fname)), libblas), $ret_type,
195+
ccall((@blasfunc($fname), libblas), $ret_type,
196196
(Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
197197
&n, X, &incx)
198198
end
@@ -215,7 +215,7 @@ for (fname, elty) in ((:daxpy_,:Float64),
215215
#* .. Array Arguments ..
216216
# DOUBLE PRECISION DX(*),DY(*)
217217
function axpy!(n::Integer, alpha::($elty), dx::Union{Ptr{$elty}, DenseArray{$elty}}, incx::Integer, dy::Union{Ptr{$elty}, DenseArray{$elty}}, incy::Integer)
218-
ccall(($(blasfunc(fname)), libblas), Void,
218+
ccall((@blasfunc($fname), libblas), Void,
219219
(Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
220220
&n, &alpha, dx, &incx, dy, &incy)
221221
dy
@@ -253,7 +253,7 @@ for (fname, elty) in ((:idamax_,:Float64),
253253
(:icamax_,:Complex64))
254254
@eval begin
255255
function iamax(n::Integer, dx::Union{Ptr{$elty}, DenseArray{$elty}}, incx::Integer)
256-
ccall(($(blasfunc(fname)), libblas),BlasInt,
256+
ccall((@blasfunc($fname), libblas),BlasInt,
257257
(Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
258258
&n, dx, &incx)
259259
end
@@ -286,7 +286,7 @@ for (fname, elty) in ((:dgemv_,:Float64),
286286
elseif trans == 'T' && (length(X) != m || length(Y) != n)
287287
throw(DimensionMismatch("A.' has dimensions $n, $m, X has length $(length(X)) and Y has length $(length(Y))"))
288288
end
289-
ccall(($(blasfunc(fname)), libblas), Void,
289+
ccall((@blasfunc($fname), libblas), Void,
290290
(Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty},
291291
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
292292
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}),
@@ -318,7 +318,7 @@ for (fname, elty) in ((:dgbmv_,:Float64),
318318
# * .. Array Arguments ..
319319
# DOUBLE PRECISION A(LDA,*),X(*),Y(*)
320320
function gbmv!(trans::Char, m::Integer, kl::Integer, ku::Integer, alpha::($elty), A::StridedMatrix{$elty}, x::StridedVector{$elty}, beta::($elty), y::StridedVector{$elty})
321-
ccall(($(blasfunc(fname)), libblas), Void,
321+
ccall((@blasfunc($fname), libblas), Void,
322322
(Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt},
323323
Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt},
324324
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
@@ -364,7 +364,7 @@ for (fname, elty) in ((:dsymv_,:Float64),
364364
if m != length(y)
365365
throw(DimensionMismatch("A has size $(size(A)), and y has length $(length(y))"))
366366
end
367-
ccall(($(blasfunc(fname)), libblas), Void,
367+
ccall((@blasfunc($fname), libblas), Void,
368368
(Ptr{UInt8}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
369369
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
370370
Ptr{$elty}, Ptr{BlasInt}),
@@ -400,7 +400,7 @@ for (fname, elty) in ((:zhemv_,:Complex128),
400400
lda = max(1, stride(A, 2))
401401
incx = stride(x, 1)
402402
incy = stride(y, 1)
403-
ccall(($(blasfunc(fname)), libblas), Void,
403+
ccall((@blasfunc($fname), libblas), Void,
404404
(Ptr{UInt8}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
405405
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
406406
Ptr{$elty}, Ptr{BlasInt}),
@@ -430,7 +430,7 @@ for (fname, elty) in ((:dsbmv_,:Float64),
430430
# * .. Array Arguments ..
431431
# DOUBLE PRECISION A(LDA,*),X(*),Y(*)
432432
function sbmv!(uplo::Char, k::Integer, alpha::($elty), A::StridedMatrix{$elty}, x::StridedVector{$elty}, beta::($elty), y::StridedVector{$elty})
433-
ccall(($(blasfunc(fname)), libblas), Void,
433+
ccall((@blasfunc($fname), libblas), Void,
434434
(Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty},
435435
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
436436
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}),
@@ -461,7 +461,7 @@ for (fname, elty) in ((:zhbmv_,:Complex128),
461461
# * .. Array Arguments ..
462462
# DOUBLE PRECISION A(LDA,*),X(*),Y(*)
463463
function hbmv!(uplo::Char, k::Integer, alpha::($elty), A::StridedMatrix{$elty}, x::StridedVector{$elty}, beta::($elty), y::StridedVector{$elty})
464-
ccall(($(blasfunc(fname)), libblas), Void,
464+
ccall((@blasfunc($fname), libblas), Void,
465465
(Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty},
466466
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
467467
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}),
@@ -497,7 +497,7 @@ for (fname, elty) in ((:dtrmv_,:Float64),
497497
if n != length(x)
498498
throw(DimensionMismatch("A has size ($n,$n), x has length $(length(x))"))
499499
end
500-
ccall(($(blasfunc(fname)), libblas), Void,
500+
ccall((@blasfunc($fname), libblas), Void,
501501
(Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}, Ptr{BlasInt},
502502
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
503503
&uplo, &trans, &diag, &n,
@@ -526,7 +526,7 @@ for (fname, elty) in ((:dtrsv_,:Float64),
526526
if n != length(x)
527527
throw(DimensionMismatch("size of A is $n != length(x) = $(length(x))"))
528528
end
529-
ccall(($(blasfunc(fname)), libblas), Void,
529+
ccall((@blasfunc($fname), libblas), Void,
530530
(Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}, Ptr{BlasInt},
531531
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
532532
&uplo, &trans, &diag, &n,
@@ -550,7 +550,7 @@ for (fname, elty) in ((:dger_,:Float64),
550550
if m != length(x) || n != length(y)
551551
throw(DimensionMismatch("A has size ($m,$n), x has length $(length(x)), y has length $(length(y))"))
552552
end
553-
ccall(($(blasfunc(fname)), libblas), Void,
553+
ccall((@blasfunc($fname), libblas), Void,
554554
(Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
555555
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
556556
Ptr{BlasInt}),
@@ -573,7 +573,7 @@ for (fname, elty) in ((:dsyr_,:Float64),
573573
if length(x) != n
574574
throw(DimensionMismatch("A has size ($n,$n), x has length $(length(x))"))
575575
end
576-
ccall(($(blasfunc(fname)), libblas), Void,
576+
ccall((@blasfunc($fname), libblas), Void,
577577
(Ptr{UInt8}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
578578
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
579579
&uplo, &n, &α, x,
@@ -592,7 +592,7 @@ for (fname, elty, relty) in ((:zher_,:Complex128, :Float64),
592592
if length(x) != n
593593
throw(DimensionMismatch("A has size ($n,$n), x has length $(length(x))"))
594594
end
595-
ccall(($(blasfunc(fname)), libblas), Void,
595+
ccall((@blasfunc($fname), libblas), Void,
596596
(Ptr{UInt8}, Ptr{BlasInt}, Ptr{$relty}, Ptr{$elty},
597597
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
598598
&uplo, &n, &α, x,
@@ -627,7 +627,7 @@ for (gemm, elty) in
627627
if m != size(C,1) || n != size(C,2)
628628
throw(DimensionMismatch("A has size ($m,$k), B has size ($k,$n), C has size $(size(C))"))
629629
end
630-
ccall(($(blasfunc(gemm)), libblas), Void,
630+
ccall((@blasfunc($gemm), libblas), Void,
631631
(Ptr{UInt8}, Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt},
632632
Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt},
633633
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
@@ -669,7 +669,7 @@ for (mfname, elty) in ((:dsymm_,:Float64),
669669
if size(B,2) != n
670670
throw(DimensionMismatch("B has second dimension $(size(B,2)) but needs to match second dimension of C, $n"))
671671
end
672-
ccall(($(blasfunc(mfname)), libblas), Void,
672+
ccall((@blasfunc($mfname), libblas), Void,
673673
(Ptr{UInt8}, Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt},
674674
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
675675
Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}),
@@ -707,7 +707,7 @@ for (mfname, elty) in ((:zhemm_,:Complex128),
707707
if size(B,2) != n
708708
throw(DimensionMismatch("B has second dimension $(size(B,2)) but needs to match second dimension of C, $n"))
709709
end
710-
ccall(($(blasfunc(mfname)), libblas), Void,
710+
ccall((@blasfunc($mfname), libblas), Void,
711711
(Ptr{UInt8}, Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt},
712712
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
713713
Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}),
@@ -745,7 +745,7 @@ for (fname, elty) in ((:dsyrk_,:Float64),
745745
nn = size(A, trans == 'N' ? 1 : 2)
746746
if nn != n throw(DimensionMismatch("C has size ($n,$n), corresponding dimension of A is $nn")) end
747747
k = size(A, trans == 'N' ? 2 : 1)
748-
ccall(($(blasfunc(fname)), libblas), Void,
748+
ccall((@blasfunc($fname), libblas), Void,
749749
(Ptr{UInt8}, Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt},
750750
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
751751
Ptr{$elty}, Ptr{BlasInt}),
@@ -782,7 +782,7 @@ for (fname, elty, relty) in ((:zherk_, :Complex128, :Float64),
782782
throw(DimensionMismatch("the matrix to update has dimension $n but the implied dimension of the update is $(size(A, trans == 'N' ? 1 : 2))"))
783783
end
784784
k = size(A, trans == 'N' ? 2 : 1)
785-
ccall(($(blasfunc(fname)), libblas), Void,
785+
ccall((@blasfunc($fname), libblas), Void,
786786
(Ptr{UInt8}, Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt},
787787
Ptr{$relty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$relty},
788788
Ptr{$elty}, Ptr{BlasInt}),
@@ -821,7 +821,7 @@ for (fname, elty) in ((:dsyr2k_,:Float64),
821821
nn = size(A, trans == 'N' ? 1 : 2)
822822
if nn != n throw(DimensionMismatch("C has size ($n,$n), corresponding dimension of A is $nn")) end
823823
k = size(A, trans == 'N' ? 2 : 1)
824-
ccall(($(blasfunc(fname)), libblas), Void,
824+
ccall((@blasfunc($fname), libblas), Void,
825825
(Ptr{UInt8}, Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt},
826826
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty},
827827
Ptr{$elty}, Ptr{BlasInt}),
@@ -858,7 +858,7 @@ for (fname, elty1, elty2) in ((:zher2k_,:Complex128,:Float64), (:cher2k_,:Comple
858858
nn = size(A, trans == 'N' ? 1 : 2)
859859
if nn != n throw(DimensionMismatch("C has size ($n,$n), corresponding dimension of A is $nn")) end
860860
k = size(A, trans == 'N' ? 2 : 1)
861-
ccall(($(blasfunc(fname)), libblas), Void,
861+
ccall((@blasfunc($fname), libblas), Void,
862862
(Ptr{UInt8}, Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt},
863863
Ptr{$elty1}, Ptr{$elty1}, Ptr{BlasInt}, Ptr{$elty1}, Ptr{BlasInt},
864864
Ptr{$elty2}, Ptr{$elty1}, Ptr{BlasInt}),
@@ -896,7 +896,7 @@ for (mmname, smname, elty) in
896896
if nA != (side == 'L' ? m : n)
897897
throw(DimensionMismatch("size of A, $(size(A)), doesn't match $side size of B with dims, $(size(B))"))
898898
end
899-
ccall(($(blasfunc(mmname)), libblas), Void,
899+
ccall((@blasfunc($mmname), libblas), Void,
900900
(Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt},
901901
Ptr{$elty}, Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),
902902
&side, &uplo, &transa, &diag, &m, &n,
@@ -921,7 +921,7 @@ for (mmname, smname, elty) in
921921
if k != (side == 'L' ? m : n)
922922
throw(DimensionMismatch("size of A is $n, size(B)=($m,$n) and transa='$transa'"))
923923
end
924-
ccall(($(blasfunc(smname)), libblas), Void,
924+
ccall((@blasfunc($smname), libblas), Void,
925925
(Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8},
926926
Ptr{BlasInt}, Ptr{BlasInt}, Ptr{$elty}, Ptr{$elty},
927927
Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt}),

0 commit comments

Comments
 (0)