diff --git a/cgo/blas.go b/cgo/blas.go index e5cadf5..d92e551 100644 --- a/cgo/blas.go +++ b/cgo/blas.go @@ -83,6 +83,9 @@ func (Implementation) Srotm(n int, x []float32, incX int, y []float32, incY int, if p.Flag < blas.Identity || p.Flag > blas.Diagonal { panic("blas: illegal blas.Flag value") } + if n == 0 { + return + } pi := srotmParams{ flag: float32(p.Flag), h: p.H, @@ -117,6 +120,9 @@ func (Implementation) Drotm(n int, x []float64, incX int, y []float64, incY int, if p.Flag < blas.Identity || p.Flag > blas.Diagonal { panic("blas: illegal blas.Flag value") } + if n == 0 { + return + } pi := drotmParams{ flag: float64(p.Flag), h: p.H, @@ -139,6 +145,9 @@ func (Implementation) Cdotu(n int, x []complex64, incX int, y []complex64, incY if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return 0 + } C.cblas_cdotu_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotu)) return dotu } @@ -158,6 +167,9 @@ func (Implementation) Cdotc(n int, x []complex64, incX int, y []complex64, incY if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return 0 + } C.cblas_cdotc_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotc)) return dotc } @@ -177,6 +189,9 @@ func (Implementation) Zdotu(n int, x []complex128, incX int, y []complex128, inc if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return 0 + } C.cblas_zdotu_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotu)) return dotu } @@ -196,10 +211,15 @@ func (Implementation) Zdotc(n int, x []complex128, incX int, y []complex128, inc if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return 0 + } C.cblas_zdotc_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotc)) return dotc } +// Generated cases ... + func (Implementation) Sdsdot(n int, alpha float32, x []float32, incX int, y []float32, incY int) float32 { if n < 0 { panic("blas: n < 0") @@ -216,6 +236,9 @@ func (Implementation) Sdsdot(n int, alpha float32, x []float32, incX int, y []fl if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return 0 + } return float32(C.cblas_sdsdot(C.int(n), C.float(alpha), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY))) } func (Implementation) Dsdot(n int, x []float32, incX int, y []float32, incY int) float64 { @@ -234,6 +257,9 @@ func (Implementation) Dsdot(n int, x []float32, incX int, y []float32, incY int) if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return 0 + } return float64(C.cblas_dsdot(C.int(n), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY))) } func (Implementation) Sdot(n int, x []float32, incX int, y []float32, incY int) float32 { @@ -252,6 +278,9 @@ func (Implementation) Sdot(n int, x []float32, incX int, y []float32, incY int) if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return 0 + } return float32(C.cblas_sdot(C.int(n), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY))) } func (Implementation) Ddot(n int, x []float64, incX int, y []float64, incY int) float64 { @@ -270,6 +299,9 @@ func (Implementation) Ddot(n int, x []float64, incX int, y []float64, incY int) if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return 0 + } return float64(C.cblas_ddot(C.int(n), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY))) } func (Implementation) Snrm2(n int, x []float32, incX int) float32 { @@ -285,6 +317,9 @@ func (Implementation) Snrm2(n int, x []float32, incX int) float32 { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return 0 + } return float32(C.cblas_snrm2(C.int(n), (*C.float)(&x[0]), C.int(incX))) } func (Implementation) Sasum(n int, x []float32, incX int) float32 { @@ -300,6 +335,9 @@ func (Implementation) Sasum(n int, x []float32, incX int) float32 { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return 0 + } return float32(C.cblas_sasum(C.int(n), (*C.float)(&x[0]), C.int(incX))) } func (Implementation) Dnrm2(n int, x []float64, incX int) float64 { @@ -315,6 +353,9 @@ func (Implementation) Dnrm2(n int, x []float64, incX int) float64 { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return 0 + } return float64(C.cblas_dnrm2(C.int(n), (*C.double)(&x[0]), C.int(incX))) } func (Implementation) Dasum(n int, x []float64, incX int) float64 { @@ -330,6 +371,9 @@ func (Implementation) Dasum(n int, x []float64, incX int) float64 { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return 0 + } return float64(C.cblas_dasum(C.int(n), (*C.double)(&x[0]), C.int(incX))) } func (Implementation) Scnrm2(n int, x []complex64, incX int) float32 { @@ -345,6 +389,9 @@ func (Implementation) Scnrm2(n int, x []complex64, incX int) float32 { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return 0 + } return float32(C.cblas_scnrm2(C.int(n), unsafe.Pointer(&x[0]), C.int(incX))) } func (Implementation) Scasum(n int, x []complex64, incX int) float32 { @@ -360,6 +407,9 @@ func (Implementation) Scasum(n int, x []complex64, incX int) float32 { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return 0 + } return float32(C.cblas_scasum(C.int(n), unsafe.Pointer(&x[0]), C.int(incX))) } func (Implementation) Dznrm2(n int, x []complex128, incX int) float64 { @@ -375,6 +425,9 @@ func (Implementation) Dznrm2(n int, x []complex128, incX int) float64 { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return 0 + } return float64(C.cblas_dznrm2(C.int(n), unsafe.Pointer(&x[0]), C.int(incX))) } func (Implementation) Dzasum(n int, x []complex128, incX int) float64 { @@ -390,6 +443,9 @@ func (Implementation) Dzasum(n int, x []complex128, incX int) float64 { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return 0 + } return float64(C.cblas_dzasum(C.int(n), unsafe.Pointer(&x[0]), C.int(incX))) } func (Implementation) Isamax(n int, x []float32, incX int) int { @@ -405,6 +461,9 @@ func (Implementation) Isamax(n int, x []float32, incX int) int { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return -1 + } return int(C.cblas_isamax(C.int(n), (*C.float)(&x[0]), C.int(incX))) } func (Implementation) Idamax(n int, x []float64, incX int) int { @@ -420,6 +479,9 @@ func (Implementation) Idamax(n int, x []float64, incX int) int { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return -1 + } return int(C.cblas_idamax(C.int(n), (*C.double)(&x[0]), C.int(incX))) } func (Implementation) Icamax(n int, x []complex64, incX int) int { @@ -435,6 +497,9 @@ func (Implementation) Icamax(n int, x []complex64, incX int) int { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return -1 + } return int(C.cblas_icamax(C.int(n), unsafe.Pointer(&x[0]), C.int(incX))) } func (Implementation) Izamax(n int, x []complex128, incX int) int { @@ -450,6 +515,9 @@ func (Implementation) Izamax(n int, x []complex128, incX int) int { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return -1 + } return int(C.cblas_izamax(C.int(n), unsafe.Pointer(&x[0]), C.int(incX))) } func (Implementation) Sswap(n int, x []float32, incX int, y []float32, incY int) { @@ -468,6 +536,9 @@ func (Implementation) Sswap(n int, x []float32, incX int, y []float32, incY int) if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_sswap(C.int(n), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY)) } func (Implementation) Scopy(n int, x []float32, incX int, y []float32, incY int) { @@ -486,6 +557,9 @@ func (Implementation) Scopy(n int, x []float32, incX int, y []float32, incY int) if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_scopy(C.int(n), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY)) } func (Implementation) Saxpy(n int, alpha float32, x []float32, incX int, y []float32, incY int) { @@ -504,6 +578,9 @@ func (Implementation) Saxpy(n int, alpha float32, x []float32, incX int, y []flo if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_saxpy(C.int(n), C.float(alpha), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY)) } func (Implementation) Dswap(n int, x []float64, incX int, y []float64, incY int) { @@ -522,6 +599,9 @@ func (Implementation) Dswap(n int, x []float64, incX int, y []float64, incY int) if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_dswap(C.int(n), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY)) } func (Implementation) Dcopy(n int, x []float64, incX int, y []float64, incY int) { @@ -540,6 +620,9 @@ func (Implementation) Dcopy(n int, x []float64, incX int, y []float64, incY int) if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_dcopy(C.int(n), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY)) } func (Implementation) Daxpy(n int, alpha float64, x []float64, incX int, y []float64, incY int) { @@ -558,6 +641,9 @@ func (Implementation) Daxpy(n int, alpha float64, x []float64, incX int, y []flo if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_daxpy(C.int(n), C.double(alpha), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY)) } func (Implementation) Cswap(n int, x []complex64, incX int, y []complex64, incY int) { @@ -576,6 +662,9 @@ func (Implementation) Cswap(n int, x []complex64, incX int, y []complex64, incY if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_cswap(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY)) } func (Implementation) Ccopy(n int, x []complex64, incX int, y []complex64, incY int) { @@ -594,6 +683,9 @@ func (Implementation) Ccopy(n int, x []complex64, incX int, y []complex64, incY if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_ccopy(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY)) } func (Implementation) Caxpy(n int, alpha complex64, x []complex64, incX int, y []complex64, incY int) { @@ -612,6 +704,9 @@ func (Implementation) Caxpy(n int, alpha complex64, x []complex64, incX int, y [ if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_caxpy(C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY)) } func (Implementation) Zswap(n int, x []complex128, incX int, y []complex128, incY int) { @@ -630,6 +725,9 @@ func (Implementation) Zswap(n int, x []complex128, incX int, y []complex128, inc if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_zswap(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY)) } func (Implementation) Zcopy(n int, x []complex128, incX int, y []complex128, incY int) { @@ -648,6 +746,9 @@ func (Implementation) Zcopy(n int, x []complex128, incX int, y []complex128, inc if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_zcopy(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY)) } func (Implementation) Zaxpy(n int, alpha complex128, x []complex128, incX int, y []complex128, incY int) { @@ -666,6 +767,9 @@ func (Implementation) Zaxpy(n int, alpha complex128, x []complex128, incX int, y if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_zaxpy(C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY)) } func (Implementation) Srot(n int, x []float32, incX int, y []float32, incY int, c float32, s float32) { @@ -684,6 +788,9 @@ func (Implementation) Srot(n int, x []float32, incX int, y []float32, incY int, if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_srot(C.int(n), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY), C.float(c), C.float(s)) } func (Implementation) Drot(n int, x []float64, incX int, y []float64, incY int, c float64, s float64) { @@ -702,6 +809,9 @@ func (Implementation) Drot(n int, x []float64, incX int, y []float64, incY int, if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_drot(C.int(n), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY), C.double(c), C.double(s)) } func (Implementation) Sscal(n int, alpha float32, x []float32, incX int) { @@ -717,6 +827,9 @@ func (Implementation) Sscal(n int, alpha float32, x []float32, incX int) { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_sscal(C.int(n), C.float(alpha), (*C.float)(&x[0]), C.int(incX)) } func (Implementation) Dscal(n int, alpha float64, x []float64, incX int) { @@ -732,6 +845,9 @@ func (Implementation) Dscal(n int, alpha float64, x []float64, incX int) { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_dscal(C.int(n), C.double(alpha), (*C.double)(&x[0]), C.int(incX)) } func (Implementation) Cscal(n int, alpha complex64, x []complex64, incX int) { @@ -747,6 +863,9 @@ func (Implementation) Cscal(n int, alpha complex64, x []complex64, incX int) { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_cscal(C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX)) } func (Implementation) Zscal(n int, alpha complex128, x []complex128, incX int) { @@ -762,6 +881,9 @@ func (Implementation) Zscal(n int, alpha complex128, x []complex128, incX int) { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_zscal(C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX)) } func (Implementation) Csscal(n int, alpha float32, x []complex64, incX int) { @@ -777,6 +899,9 @@ func (Implementation) Csscal(n int, alpha float32, x []complex64, incX int) { if incX > 0 && (n-1)*incX >= len(x) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_csscal(C.int(n), C.float(alpha), unsafe.Pointer(&x[0]), C.int(incX)) } func (Implementation) Zdscal(n int, alpha float64, x []complex128, incX int) { @@ -789,6 +914,9 @@ func (Implementation) Zdscal(n int, alpha float64, x []complex128, incX int) { if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_zdscal(C.int(n), C.double(alpha), unsafe.Pointer(&x[0]), C.int(incX)) } func (Implementation) Sgemv(tA blas.Transpose, m int, n int, alpha float32, a []float32, lda int, x []float32, incX int, beta float32, y []float32, incY int) { @@ -936,6 +1064,9 @@ func (Implementation) Stpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_stpmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), (*C.float)(&ap[0]), (*C.float)(&x[0]), C.int(incX)) } func (Implementation) Strsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float32, lda int, x []float32, incX int) { @@ -1011,6 +1142,9 @@ func (Implementation) Stpsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_stpsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), (*C.float)(&ap[0]), (*C.float)(&x[0]), C.int(incX)) } func (Implementation) Dgemv(tA blas.Transpose, m int, n int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) { @@ -1158,6 +1292,9 @@ func (Implementation) Dtpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_dtpmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), (*C.double)(&ap[0]), (*C.double)(&x[0]), C.int(incX)) } func (Implementation) Dtrsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []float64, lda int, x []float64, incX int) { @@ -1233,6 +1370,9 @@ func (Implementation) Dtpsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_dtpsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), (*C.double)(&ap[0]), (*C.double)(&x[0]), C.int(incX)) } func (Implementation) Cgemv(tA blas.Transpose, m int, n int, alpha complex64, a []complex64, lda int, x []complex64, incX int, beta complex64, y []complex64, incY int) { @@ -1380,6 +1520,9 @@ func (Implementation) Ctpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_ctpmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), unsafe.Pointer(&ap[0]), unsafe.Pointer(&x[0]), C.int(incX)) } func (Implementation) Ctrsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []complex64, lda int, x []complex64, incX int) { @@ -1455,6 +1598,9 @@ func (Implementation) Ctpsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_ctpsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), unsafe.Pointer(&ap[0]), unsafe.Pointer(&x[0]), C.int(incX)) } func (Implementation) Zgemv(tA blas.Transpose, m int, n int, alpha complex128, a []complex128, lda int, x []complex128, incX int, beta complex128, y []complex128, incY int) { @@ -1602,6 +1748,9 @@ func (Implementation) Ztpmv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_ztpmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), unsafe.Pointer(&ap[0]), unsafe.Pointer(&x[0]), C.int(incX)) } func (Implementation) Ztrsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, a []complex128, lda int, x []complex128, incX int) { @@ -1677,6 +1826,9 @@ func (Implementation) Ztpsv(ul blas.Uplo, tA blas.Transpose, d blas.Diag, n int, if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_ztpsv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.enum_CBLAS_TRANSPOSE(tA), C.enum_CBLAS_DIAG(d), C.int(n), unsafe.Pointer(&ap[0]), unsafe.Pointer(&x[0]), C.int(incX)) } func (Implementation) Ssymv(ul blas.Uplo, n int, alpha float32, a []float32, lda int, x []float32, incX int, beta float32, y []float32, incY int) { @@ -1752,6 +1904,9 @@ func (Implementation) Sspmv(ul blas.Uplo, n int, alpha float32, ap []float32, x if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_sspmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.float(alpha), (*C.float)(&ap[0]), (*C.float)(&x[0]), C.int(incX), C.float(beta), (*C.float)(&y[0]), C.int(incY)) } func (Implementation) Sger(m int, n int, alpha float32, x []float32, incX int, y []float32, incY int, a []float32, lda int) { @@ -1812,6 +1967,9 @@ func (Implementation) Sspr(ul blas.Uplo, n int, alpha float32, x []float32, incX if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_sspr(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.float(alpha), (*C.float)(&x[0]), C.int(incX), (*C.float)(&ap[0])) } func (Implementation) Ssyr2(ul blas.Uplo, n int, alpha float32, x []float32, incX int, y []float32, incY int, a []float32, lda int) { @@ -1860,6 +2018,9 @@ func (Implementation) Sspr2(ul blas.Uplo, n int, alpha float32, x []float32, inc if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_sspr2(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.float(alpha), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY), (*C.float)(&ap[0])) } func (Implementation) Dsymv(ul blas.Uplo, n int, alpha float64, a []float64, lda int, x []float64, incX int, beta float64, y []float64, incY int) { @@ -1935,6 +2096,9 @@ func (Implementation) Dspmv(ul blas.Uplo, n int, alpha float64, ap []float64, x if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_dspmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.double(alpha), (*C.double)(&ap[0]), (*C.double)(&x[0]), C.int(incX), C.double(beta), (*C.double)(&y[0]), C.int(incY)) } func (Implementation) Dger(m int, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) { @@ -1995,6 +2159,9 @@ func (Implementation) Dspr(ul blas.Uplo, n int, alpha float64, x []float64, incX if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_dspr(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.double(alpha), (*C.double)(&x[0]), C.int(incX), (*C.double)(&ap[0])) } func (Implementation) Dsyr2(ul blas.Uplo, n int, alpha float64, x []float64, incX int, y []float64, incY int, a []float64, lda int) { @@ -2043,6 +2210,9 @@ func (Implementation) Dspr2(ul blas.Uplo, n int, alpha float64, x []float64, inc if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_dspr2(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.double(alpha), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY), (*C.double)(&ap[0])) } func (Implementation) Chemv(ul blas.Uplo, n int, alpha complex64, a []complex64, lda int, x []complex64, incX int, beta complex64, y []complex64, incY int) { @@ -2118,6 +2288,9 @@ func (Implementation) Chpmv(ul blas.Uplo, n int, alpha complex64, ap []complex64 if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_chpmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&ap[0]), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&beta), unsafe.Pointer(&y[0]), C.int(incY)) } func (Implementation) Cgeru(m int, n int, alpha complex64, x []complex64, incX int, y []complex64, incY int, a []complex64, lda int) { @@ -2202,6 +2375,9 @@ func (Implementation) Chpr(ul blas.Uplo, n int, alpha float32, x []complex64, in if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_chpr(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.float(alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&ap[0])) } func (Implementation) Cher2(ul blas.Uplo, n int, alpha complex64, x []complex64, incX int, y []complex64, incY int, a []complex64, lda int) { @@ -2250,6 +2426,9 @@ func (Implementation) Chpr2(ul blas.Uplo, n int, alpha complex64, x []complex64, if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_chpr2(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&ap[0])) } func (Implementation) Zhemv(ul blas.Uplo, n int, alpha complex128, a []complex128, lda int, x []complex128, incX int, beta complex128, y []complex128, incY int) { @@ -2325,6 +2504,9 @@ func (Implementation) Zhpmv(ul blas.Uplo, n int, alpha complex128, ap []complex1 if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_zhpmv(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&ap[0]), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&beta), unsafe.Pointer(&y[0]), C.int(incY)) } func (Implementation) Zgeru(m int, n int, alpha complex128, x []complex128, incX int, y []complex128, incY int, a []complex128, lda int) { @@ -2409,6 +2591,9 @@ func (Implementation) Zhpr(ul blas.Uplo, n int, alpha float64, x []complex128, i if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) { panic("blas: x index out of range") } + if n == 0 { + return + } C.cblas_zhpr(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), C.double(alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&ap[0])) } func (Implementation) Zher2(ul blas.Uplo, n int, alpha complex128, x []complex128, incX int, y []complex128, incY int, a []complex128, lda int) { @@ -2457,6 +2642,9 @@ func (Implementation) Zhpr2(ul blas.Uplo, n int, alpha complex128, x []complex12 if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return + } C.cblas_zhpr2(C.enum_CBLAS_ORDER(rowMajor), C.enum_CBLAS_UPLO(ul), C.int(n), unsafe.Pointer(&alpha), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&ap[0])) } func (Implementation) Sgemm(tA blas.Transpose, tB blas.Transpose, m int, n int, k int, alpha float32, a []float32, lda int, b []float32, ldb int, beta float32, c []float32, ldc int) { diff --git a/cgo/genBlas.pl b/cgo/genBlas.pl index 31c0192..6084586 100755 --- a/cgo/genBlas.pl +++ b/cgo/genBlas.pl @@ -119,6 +119,9 @@ package cgo if p.Flag < blas.Identity || p.Flag > blas.Diagonal { panic("blas: illegal blas.Flag value") } + if n == 0 { + return + } pi := srotmParams{ flag: float32(p.Flag), h: p.H, @@ -153,6 +156,9 @@ package cgo if p.Flag < blas.Identity || p.Flag > blas.Diagonal { panic("blas: illegal blas.Flag value") } + if n == 0 { + return + } pi := drotmParams{ flag: float64(p.Flag), h: p.H, @@ -175,6 +181,9 @@ package cgo if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return 0 + } C.cblas_cdotu_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotu)) return dotu } @@ -194,6 +203,9 @@ package cgo if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return 0 + } C.cblas_cdotc_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotc)) return dotc } @@ -213,6 +225,9 @@ package cgo if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return 0 + } C.cblas_zdotu_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotu)) return dotu } @@ -232,9 +247,14 @@ package cgo if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) { panic("blas: y index out of range") } + if n == 0 { + return 0 + } C.cblas_zdotc_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotc)) return dotc } + +// Generated cases ... EOH printf $goblas < 0; return $checks diff --git a/testblas/level1double.go b/testblas/level1double.go index 28417c6..5a14a29 100644 --- a/testblas/level1double.go +++ b/testblas/level1double.go @@ -382,6 +382,26 @@ var DoubleOneVectorCases = []DoubleOneVectorCase{ }, }, }, + { + Name: "Empty", + X: []float64{}, + Incx: 1, + N: 0, + Panic: false, + Dasum: 0, + Dnrm2: 0, + Idamax: -1, + DscalCases: []DScalCase{ + { + Alpha: -2, + Ans: []float64{}, + }, + { + Alpha: 0, + Ans: []float64{}, + }, + }, + }, } type DoubleTwoVectorCase struct {