blas/blas32: add length field to Vector
MODIFY
blas/blas32/blas32.go
blas/blas32/blas32.go
@@ -28,6 +28,7 @@ func Implementation() blas.Float32 {
// Vector represents a vector with an associated element increment.
type Vector struct {
+ N int
Inc int
Data []float32
}
@@ -102,42 +103,42 @@ const negInc = "blas32: negative vector increment"
// Dot computes the dot product of the two vectors:
// \sum_i x[i]*y[i].
-func Dot(n int, x, y Vector) float32 {
- return blas32.Sdot(n, x.Data, x.Inc, y.Data, y.Inc)
+func Dot(x, y Vector) float32 {
+ return blas32.Sdot(x.N, x.Data, x.Inc, y.Data, y.Inc)
}
// DDot computes the dot product of the two vectors:
// \sum_i x[i]*y[i].
-func DDot(n int, x, y Vector) float64 {
- return blas32.Dsdot(n, x.Data, x.Inc, y.Data, y.Inc)
+func DDot(x, y Vector) float64 {
+ return blas32.Dsdot(x.N, x.Data, x.Inc, y.Data, y.Inc)
}
// SDDot computes the dot product of the two vectors adding a constant:
// alpha + \sum_i x[i]*y[i].
-func SDDot(n int, alpha float32, x, y Vector) float32 {
- return blas32.Sdsdot(n, alpha, x.Data, x.Inc, y.Data, y.Inc)
+func SDDot(alpha float32, x, y Vector) float32 {
+ return blas32.Sdsdot(x.N, alpha, x.Data, x.Inc, y.Data, y.Inc)
}
// Nrm2 computes the Euclidean norm of the vector x:
// sqrt(\sum_i x[i]*x[i]).
//
// Nrm2 will panic if the vector increment is negative.
-func Nrm2(n int, x Vector) float32 {
+func Nrm2(x Vector) float32 {
if x.Inc < 0 {
panic(negInc)
}
- return blas32.Snrm2(n, x.Data, x.Inc)
+ return blas32.Snrm2(x.N, x.Data, x.Inc)
}
// Asum computes the sum of the absolute values of the elements of x:
// \sum_i |x[i]|.
//
// Asum will panic if the vector increment is negative.
-func Asum(n int, x Vector) float32 {
+func Asum(x Vector) float32 {
if x.Inc < 0 {
panic(negInc)
}
- return blas32.Sasum(n, x.Data, x.Inc)
+ return blas32.Sasum(x.N, x.Data, x.Inc)
}
// Iamax returns the index of an element of x with the largest absolute value.
@@ -145,29 +146,29 @@ func Asum(n int, x Vector) float32 {
// Iamax returns -1 if n == 0.
//
// Iamax will panic if the vector increment is negative.
-func Iamax(n int, x Vector) int {
+func Iamax(x Vector) int {
if x.Inc < 0 {
panic(negInc)
}
- return blas32.Isamax(n, x.Data, x.Inc)
+ return blas32.Isamax(x.N, x.Data, x.Inc)
}
// Swap exchanges the elements of the two vectors:
// x[i], y[i] = y[i], x[i] for all i.
-func Swap(n int, x, y Vector) {
- blas32.Sswap(n, x.Data, x.Inc, y.Data, y.Inc)
+func Swap(x, y Vector) {
+ blas32.Sswap(x.N, x.Data, x.Inc, y.Data, y.Inc)
}
// Copy copies the elements of x into the elements of y:
// y[i] = x[i] for all i.
-func Copy(n int, x, y Vector) {
- blas32.Scopy(n, x.Data, x.Inc, y.Data, y.Inc)
+func Copy(x, y Vector) {
+ blas32.Scopy(x.N, x.Data, x.Inc, y.Data, y.Inc)
}
// Axpy adds x scaled by alpha to y:
// y[i] += alpha*x[i] for all i.
-func Axpy(n int, alpha float32, x, y Vector) {
- blas32.Saxpy(n, alpha, x.Data, x.Inc, y.Data, y.Inc)
+func Axpy(alpha float32, x, y Vector) {
+ blas32.Saxpy(x.N, alpha, x.Data, x.Inc, y.Data, y.Inc)
}
// Rotg computes the parameters of a Givens plane rotation so that
@@ -211,11 +212,11 @@ func Rotm(n int, x, y Vector, p blas.SrotmParams) {
// x[i] *= alpha for all i.
//
// Scal will panic if the vector increment is negative.
-func Scal(n int, alpha float32, x Vector) {
+func Scal(alpha float32, x Vector) {
if x.Inc < 0 {
panic(negInc)
}
- blas32.Sscal(n, alpha, x.Data, x.Inc)
+ blas32.Sscal(x.N, alpha, x.Data, x.Inc)
}
// Level 2

blas/blas32: add length field to Vector