@@ -149,17 +149,23 @@ for (fname, elty) in ((:cblas_zdotu_sub,:Complex128),
149
149
end
150
150
function dot {T<:BlasReal} (DX:: Union(DenseArray{T},StridedVector{T}) , DY:: Union(DenseArray{T},StridedVector{T}) )
151
151
n = length (DX)
152
- n == length (DY) || throw (DimensionMismatch (" dot product arguments have lengths $(length (DX)) and $(length (DY)) " ))
152
+ if n != length (DY)
153
+ throw (DimensionMismatch (" dot product arguments have lengths $(length (DX)) and $(length (DY)) " ))
154
+ end
153
155
dot (n, pointer (DX), stride (DX, 1 ), pointer (DY), stride (DY, 1 ))
154
156
end
155
157
function dotc {T<:BlasComplex} (DX:: Union(DenseArray{T},StridedVector{T}) , DY:: Union(DenseArray{T},StridedVector{T}) )
156
158
n = length (DX)
157
- n == length (DY) || throw (DimensionMismatch (" dot product arguments have lengths $(length (DX)) and $(length (DY)) " ))
159
+ if n != length (DY)
160
+ throw (DimensionMismatch (" dot product arguments have lengths $(length (DX)) and $(length (DY)) " ))
161
+ end
158
162
dotc (n, pointer (DX), stride (DX, 1 ), pointer (DY), stride (DY, 1 ))
159
163
end
160
164
function dotu {T<:BlasComplex} (DX:: Union(DenseArray{T},StridedVector{T}) , DY:: Union(DenseArray{T},StridedVector{T}) )
161
165
n = length (DX)
162
- n == length (DY) || throw (DimensionMismatch (" dot product arguments have lengths $(length (DX)) and $(length (DY)) " ))
166
+ if n != length (DY)
167
+ throw (DimensionMismatch (" dot product arguments have lengths $(length (DX)) and $(length (DY)) " ))
168
+ end
163
169
dotu (n, pointer (DX), stride (DX, 1 ), pointer (DY), stride (DY, 1 ))
164
170
end
165
171
@@ -219,18 +225,24 @@ for (fname, elty) in ((:daxpy_,:Float64),
219
225
end
220
226
end
221
227
function axpy! {T<:BlasFloat,Ta<:Number} (alpha:: Ta , x:: Union(DenseArray{T},StridedVector{T}) , y:: Union(DenseArray{T},StridedVector{T}) )
222
- length (x) == length (y) || throw (DimensionMismatch (" x has length $(length (x)) , but y has length $(length (y)) " ))
228
+ if length (x) != length (y)
229
+ throw (DimensionMismatch (" x has length $(length (x)) , but y has length $(length (y)) " ))
230
+ end
223
231
axpy! (length (x), convert (T,alpha), pointer (x), stride (x, 1 ), pointer (y), stride (y, 1 ))
224
232
y
225
233
end
226
234
227
235
function axpy! {T<:BlasFloat,Ta<:Number,Ti<:Integer} (alpha:: Ta , x:: Array{T} , rx:: Union(UnitRange{Ti},Range{Ti}) ,
228
236
y:: Array{T} , ry:: Union(UnitRange{Ti},Range{Ti}) )
229
237
230
- length (rx)== length (ry) || throw (DimensionMismatch ())
231
-
232
- if minimum (rx) < 1 || maximum (rx) > length (x) || minimum (ry) < 1 || maximum (ry) > length (y)
233
- throw (BoundsError ())
238
+ if length (rx) != length (ry)
239
+ throw (DimensionMismatch (" Ranges of differing lengths" ))
240
+ end
241
+ if minimum (rx) < 1 || maximum (rx) > length (x)
242
+ throw (BoundsError (" Range out of bounds for x, of length $(length (x)) " ))
243
+ end
244
+ if minimum (ry) < 1 || maximum (ry) > length (y)
245
+ throw (BoundsError (" Range out of bounds for y, of length $(length (y)) " ))
234
246
end
235
247
axpy! (length (rx), convert (T, alpha), pointer (x)+ (first (rx)- 1 )* sizeof (T), step (rx), pointer (y)+ (first (ry)- 1 )* sizeof (T), step (ry))
236
248
y
@@ -269,7 +281,13 @@ for (fname, elty) in ((:dgemv_,:Float64),
269
281
# DOUBLE PRECISION A(LDA,*),X(*),Y(*)
270
282
function gemv! (trans:: Char , alpha:: ($elty) , A:: StridedVecOrMat{$elty} , X:: StridedVector{$elty} , beta:: ($elty) , Y:: StridedVector{$elty} )
271
283
m,n = size (A,1 ),size (A,2 )
272
- length (X) == (trans == ' N' ? n : m) && length (Y) == (trans == ' N' ? m : n) || throw (DimensionMismatch ())
284
+ if trans == ' N' && (length (X) != n || length (Y) != m)
285
+ throw (DimensionMismatch (" A has dimensions $(size (A)) , X has length $(length (X)) and Y has length $(length (Y)) " ))
286
+ elseif trans == ' C' && (length (X) != m || length (Y) != n)
287
+ throw (DimensionMismatch (" A' has dimensions $n , $m , X has length $(length (X)) and Y has length $(length (Y)) " ))
288
+ elseif trans == ' T' && (length (X) != m || length (Y) != n)
289
+ throw (DimensionMismatch (" A.' has dimensions $n , $m , X has length $(length (X)) and Y has length $(length (Y)) " ))
290
+ end
273
291
ccall (($ (blasfunc (fname)), libblas), Void,
274
292
(Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt}, Ref{$ elty},
275
293
Ptr{$ elty}, Ref{BlasInt}, Ptr{$ elty}, Ref{BlasInt},
@@ -340,7 +358,9 @@ for (fname, elty) in ((:dsymv_,:Float64),
340
358
function symv! (uplo:: Char , alpha:: ($elty) , A:: StridedMatrix{$elty} , x:: StridedVector{$elty} ,beta:: ($elty) , y:: StridedVector{$elty} )
341
359
m, n = size (A)
342
360
if m != n throw (DimensionMismatch (" Matrix A is $m by $n but must be square" )) end
343
- if m != length (x) || m != length (y) throw (DimensionMismatch ()) end
361
+ if m != length (x) || m != length (y)
362
+ throw (DimensionMismatch (" A has size ($m ,$n ), x has length $(length (x)) , y has length $(length (y)) " ))
363
+ end
344
364
ccall (($ (blasfunc (fname)), libblas), Void,
345
365
(Ref{UInt8}, Ref{BlasInt}, Ref{$ elty}, Ptr{$ elty},
346
366
Ref{BlasInt}, Ptr{$ elty}, Ref{BlasInt}, Ref{$ elty},
@@ -365,8 +385,12 @@ for (fname, elty) in ((:zhemv_,:Complex128),
365
385
@eval begin
366
386
function hemv! (uplo:: Char , α:: $elty , A:: StridedMatrix{$elty} , x:: StridedVector{$elty} , β:: $elty , y:: StridedVector{$elty} )
367
387
n = size (A, 2 )
368
- n == length (x) || throw (DimensionMismatch ())
369
- size (A, 1 ) == length (y) || throw (DimensionMismatch ())
388
+ if n != length (x)
389
+ throw (DimensionMismatch (" A has size $(size (A)) , and x has length $(length (x)) " ))
390
+ end
391
+ if size (A, 1 ) != length (y)
392
+ throw (DimensionMismatch (" A has size $(size (A)) , and y has length $(length (x)) " ))
393
+ end
370
394
lda = max (1 , stride (A, 2 ))
371
395
incx = stride (x, 1 )
372
396
incy = stride (y, 1 )
@@ -464,7 +488,9 @@ for (fname, elty) in ((:dtrsv_,:Float64),
464
488
# DOUBLE PRECISION A(LDA,*),X(*)
465
489
function trsv! (uplo:: Char , trans:: Char , diag:: Char , A:: StridedMatrix{$elty} , x:: StridedVector{$elty} )
466
490
n = chksquare (A)
467
- n== length (x) || throw (DimensionMismatch (" size of A is $n != length(x) = $(length (x)) " ))
491
+ if n != length (x)
492
+ throw (DimensionMismatch (" size of A is $n != length(x) = $(length (x)) " ))
493
+ end
468
494
ccall (($ (blasfunc (fname)), libblas), Void,
469
495
(Ref{UInt8}, Ref{UInt8}, Ref{UInt8}, Ref{BlasInt},
470
496
Ptr{$ elty}, Ref{BlasInt}, Ptr{$ elty}, Ref{BlasInt}),
@@ -486,8 +512,9 @@ for (fname, elty) in ((:dger_,:Float64),
486
512
@eval begin
487
513
function ger! (α:: $elty , x:: StridedVector{$elty} , y:: StridedVector{$elty} , A:: StridedMatrix{$elty} )
488
514
m, n = size (A)
489
- m == length (x) || throw (DimensionMismatch ())
490
- n == length (y) || throw (DimensionMismatch ())
515
+ if m != length (x) || n != length (y)
516
+ throw (DimensionMismatch (" A has size ($m ,$n ), x has length $(length (x)) , y has length $(length (y)) " ))
517
+ end
491
518
ccall (($ (blasfunc (fname)), libblas), Void,
492
519
(Ref{BlasInt}, Ref{BlasInt}, Ref{$ elty}, Ptr{$ elty},
493
520
Ref{BlasInt}, Ptr{$ elty}, Ref{BlasInt}, Ptr{$ elty},
@@ -508,7 +535,9 @@ for (fname, elty) in ((:dsyr_,:Float64),
508
535
@eval begin
509
536
function syr! (uplo:: Char , α:: $elty , x:: StridedVector{$elty} , A:: StridedMatrix{$elty} )
510
537
n = chksquare (A)
511
- length (x) == n || throw (DimensionMismatch (" Length of vector must be the same as the matrix dimensions" ))
538
+ if length (x) != n
539
+ throw (DimensionMismatch (" A has size ($n ,$n ), x has length $(length (x)) " ))
540
+ end
512
541
ccall (($ (blasfunc (fname)), libblas), Void,
513
542
(Ref{UInt8}, Ref{BlasInt}, Ref{$ elty}, Ptr{$ elty},
514
543
Ref{BlasInt}, Ptr{$ elty}, Ref{BlasInt}),
@@ -525,7 +554,9 @@ for (fname, elty) in ((:zher_,:Complex128),
525
554
@eval begin
526
555
function her! (uplo:: Char , α:: $elty , x:: StridedVector{$elty} , A:: StridedMatrix{$elty} )
527
556
n = chksquare (A)
528
- length (x) == A || throw (DimensionMismatch (" Length of vector must be the same as the matrix dimensions" ))
557
+ if length (x) != A
558
+ throw (DimensionMismatch (" A has size ($n ,$n ), x has length $(length (x)) " ))
559
+ end
529
560
ccall (($ (blasfunc (fname)), libblas), Void,
530
561
(Ref{UInt8}, Ref{BlasInt}, Ref{$ elty}, Ptr{$ elty},
531
562
Ref{BlasInt}, Ptr{$ elty}, Ref{BlasInt}),
@@ -559,7 +590,7 @@ for (gemm, elty) in
559
590
k = size (A, transA == ' N' ? 2 : 1 )
560
591
n = size (B, transB == ' N' ? 2 : 1 )
561
592
if m != size (C,1 ) || n != size (C,2 )
562
- throw (DimensionMismatch ())
593
+ throw (DimensionMismatch (" A has size ( $m , $k ), B has size ( $k , $n ), C has size $( size (C)) " ))
563
594
end
564
595
ccall (($ (blasfunc (gemm)), libblas), Void,
565
596
(Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt},
@@ -667,7 +698,7 @@ for (fname, elty) in ((:dsyrk_,:Float64),
667
698
beta:: ($elty) , C:: StridedMatrix{$elty} )
668
699
n = chksquare (C)
669
700
nn = size (A, trans == ' N' ? 1 : 2 )
670
- if nn != n throw (DimensionMismatch (" syrk! " )) end
701
+ if nn != n throw (DimensionMismatch (" C has size ( $n , $n ), corresponding dimension of A is $nn " )) end
671
702
k = size (A, trans == ' N' ? 2 : 1 )
672
703
ccall (($ (blasfunc (fname)), libblas), Void,
673
704
(Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt},
@@ -701,7 +732,10 @@ for (fname, elty, relty) in ((:zherk_, :Complex128, :Float64),
701
732
function herk! (uplo:: Char , trans:: Char , α:: $relty , A:: StridedVecOrMat{$elty} ,
702
733
β:: $relty , C:: StridedMatrix{$elty} )
703
734
n = chksquare (C)
704
- n == size (A, trans == ' N' ? 1 : 2 ) || throw (DimensionMismatch (" the matrix to update has dimension $n but the implied dimension of the update is $(size (A, trans == ' N' ? 1 : 2 )) " ))
735
+ nn = size (A, trans == ' N' ? 1 : 2 )
736
+ if nn != n
737
+ throw (DimensionMismatch (" the matrix to update has dimension $n but the implied dimension of the update is $(size (A, trans == ' N' ? 1 : 2 )) " ))
738
+ end
705
739
k = size (A, trans == ' N' ? 2 : 1 )
706
740
ccall (($ (blasfunc (fname)), libblas), Void,
707
741
(Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt},
@@ -740,7 +774,7 @@ for (fname, elty) in ((:dsyr2k_,:Float64),
740
774
beta:: ($elty) , C:: StridedMatrix{$elty} )
741
775
n = chksquare (C)
742
776
nn = size (A, trans == ' N' ? 1 : 2 )
743
- if nn != n throw (DimensionMismatch (" syr2k! " )) end
777
+ if nn != n throw (DimensionMismatch (" C has size ( $n , $n ), corresponding dimension of A is $nn " )) end
744
778
k = size (A, trans == ' N' ? 2 : 1 )
745
779
ccall (($ (blasfunc (fname)), libblas), Void,
746
780
(Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt},
@@ -776,7 +810,8 @@ for (fname, elty1, elty2) in ((:zher2k_,:Complex128,:Float64), (:cher2k_,:Comple
776
810
A:: StridedVecOrMat{$elty1} , B:: StridedVecOrMat{$elty1} ,
777
811
beta:: ($elty2) , C:: StridedMatrix{$elty1} )
778
812
n = chksquare (C)
779
- n == size (A, trans == ' N' ? 1 : 2 ) || throw (DimensionMismatch (" her2k!" ))
813
+ nn = size (A, trans == ' N' ? 1 : 2 )
814
+ if nn != n throw (DimensionMismatch (" C has size ($n ,$n ), corresponding dimension of A is $nn " )) end
780
815
k = size (A, trans == ' N' ? 2 : 1 )
781
816
ccall (($ (blasfunc (fname)), libblas), Void,
782
817
(Ref{UInt8}, Ref{UInt8}, Ref{BlasInt}, Ref{BlasInt},
@@ -836,7 +871,9 @@ for (mmname, smname, elty) in
836
871
alpha:: $elty , A:: StridedMatrix{$elty} , B:: StridedMatrix{$elty} )
837
872
m, n = size (B)
838
873
k = chksquare (A)
839
- k== (side == ' L' ? m : n) || throw (DimensionMismatch (" size of A is $n , size(B)=($m ,$n ) and transa='$transa '" ))
874
+ if k != (side == ' L' ? m : n)
875
+ throw (DimensionMismatch (" size of A is $n , size(B)=($m ,$n ) and transa='$transa '" ))
876
+ end
840
877
ccall (($ (blasfunc (smname)), libblas), Void,
841
878
(Ref{UInt8}, Ref{UInt8}, Ref{UInt8}, Ref{UInt8},
842
879
Ref{BlasInt}, Ref{BlasInt}, Ref{$ elty}, Ptr{$ elty},
@@ -856,10 +893,15 @@ end # module
856
893
857
894
function copy! {T<:BlasFloat,Ti<:Integer} (dest:: Array{T} , rdest:: Union(UnitRange{Ti},Range{Ti}) ,
858
895
src:: Array{T} , rsrc:: Union(UnitRange{Ti},Range{Ti}) )
859
- if minimum (rdest) < 1 || maximum (rdest) > length (dest) || minimum (rsrc) < 1 || maximum (rsrc) > length (src)
860
- throw (BoundsError ())
896
+ if minimum (rdest) < 1 || maximum (rdest) > length (dest)
897
+ throw (BoundsError (" Range out of bounds for dest, of length $(length (dest)) " ))
898
+ end
899
+ if minimum (rsrc) < 1 || maximum (rsrc) > length (src)
900
+ throw (BoundsError (" Range out of bounds for src, of length $(length (src)) " ))
901
+ end
902
+ if length (rdest) != length (rsrc)
903
+ throw (DimensionMismatch (" Ranges must be of the same length" ))
861
904
end
862
- length (rdest)== length (rsrc) || throw (DimensionMismatch (" Ranges must be of the same length" ))
863
905
BLAS. blascopy! (length (rsrc), pointer (src)+ (first (rsrc)- 1 )* sizeof (T), step (rsrc),
864
906
pointer (dest)+ (first (rdest)- 1 )* sizeof (T), step (rdest))
865
907
dest
0 commit comments