1 // Code generated by "go generate gonum.org/v1/gonum/blas/gonum”; DO NOT EDIT.
3 // Copyright ©2015 The Gonum Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
10 math "gonum.org/v1/gonum/internal/math32"
12 "gonum.org/v1/gonum/blas"
13 "gonum.org/v1/gonum/internal/asm/f32"
16 var _ blas.Float32Level1 = Implementation{}
18 // Snrm2 computes the Euclidean norm of a vector,
19 // sqrt(\sum_i x[i] * x[i]).
20 // This function returns 0 if incX is negative.
22 // Float32 implementations are autogenerated and not directly tested.
23 func (Implementation) Snrm2(n int, x []float32, incX int) float32 {
30 if incX > 0 && (n-1)*incX >= len(x) {
46 sumSquares float32 = 1
55 if math.IsNaN(absxi) {
59 sumSquares = 1 + sumSquares*(scale/absxi)*(scale/absxi)
62 sumSquares = sumSquares + (absxi/scale)*(absxi/scale)
65 if math.IsInf(scale, 1) {
68 return scale * math.Sqrt(sumSquares)
70 for ix := 0; ix < n*incX; ix += incX {
75 absxi := math.Abs(val)
76 if math.IsNaN(absxi) {
80 sumSquares = 1 + sumSquares*(scale/absxi)*(scale/absxi)
83 sumSquares = sumSquares + (absxi/scale)*(absxi/scale)
86 if math.IsInf(scale, 1) {
89 return scale * math.Sqrt(sumSquares)
92 // Sasum computes the sum of the absolute values of the elements of x.
94 // Sasum returns 0 if incX is negative.
96 // Float32 implementations are autogenerated and not directly tested.
97 func (Implementation) Sasum(n int, x []float32, incX int) float32 {
108 if incX > 0 && (n-1)*incX >= len(x) {
113 for _, v := range x {
118 for i := 0; i < n; i++ {
119 sum += math.Abs(x[i*incX])
124 // Isamax returns the index of an element of x with the largest absolute value.
125 // If there are multiple such indices the earliest is returned.
126 // Isamax returns -1 if n == 0.
128 // Float32 implementations are autogenerated and not directly tested.
129 func (Implementation) Isamax(n int, x []float32, incX int) int {
136 if incX > 0 && (n-1)*incX >= len(x) {
144 return -1 // Netlib returns invalid index when n == 0
151 max := math.Abs(x[0])
153 for i, v := range x[:n] {
163 for i := 1; i < n; i++ {
175 // Sswap exchanges the elements of two vectors.
176 // x[i], y[i] = y[i], x[i] for all i
178 // Float32 implementations are autogenerated and not directly tested.
179 func (Implementation) Sswap(n int, x []float32, incX int, y []float32, incY int) {
192 if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
195 if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
198 if incX == 1 && incY == 1 {
200 for i, v := range x {
212 for i := 0; i < n; i++ {
213 x[ix], y[iy] = y[iy], x[ix]
219 // Scopy copies the elements of x into the elements of y.
220 // y[i] = x[i] for all i
222 // Float32 implementations are autogenerated and not directly tested.
223 func (Implementation) Scopy(n int, x []float32, incX int, y []float32, incY int) {
236 if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
239 if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
242 if incX == 1 && incY == 1 {
253 for i := 0; i < n; i++ {
260 // Saxpy adds alpha times x to y
261 // y[i] += alpha * x[i] for all i
263 // Float32 implementations are autogenerated and not directly tested.
264 func (Implementation) Saxpy(n int, alpha float32, x []float32, incX int, y []float32, incY int) {
277 if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
280 if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
286 if incX == 1 && incY == 1 {
287 f32.AxpyUnitary(alpha, x[:n], y[:n])
297 f32.AxpyInc(alpha, x, y, uintptr(n), uintptr(incX), uintptr(incY), uintptr(ix), uintptr(iy))
300 // Srotg computes the plane rotation
302 // | c s | | a | | r |
303 // | -s c | * | b | = | 0 |
307 // c = a/r, the cosine of the plane rotation
308 // s = b/r, the sine of the plane rotation
310 // NOTE: There is a discrepancy between the refence implementation and the BLAS
311 // technical manual regarding the sign for r when a or b are zero.
312 // Srotg agrees with the definition in the manual and other
313 // common BLAS implementations.
315 // Float32 implementations are autogenerated and not directly tested.
316 func (Implementation) Srotg(a, b float32) (c, s, r, z float32) {
317 if b == 0 && a == 0 {
325 r = math.Copysign(r, a)
327 r = math.Copysign(r, b)
333 } else if c != 0 { // r == 0 case handled above
341 // Srotmg computes the modified Givens rotation. See
342 // http://www.netlib.org/lapack/explore-html/df/deb/drotmg_8f.html
345 // Float32 implementations are autogenerated and not directly tested.
346 func (Implementation) Srotmg(d1, d2, x1, y1 float32) (p blas.SrotmParams, rd1, rd2, rx1 float32) {
347 var p1, p2, q1, q2, u float32
352 rgamsq = 5.9604645e-8
356 p.Flag = blas.Rescaling
362 p.Flag = blas.Identity
372 absQ1 := math.Abs(q1)
373 absQ2 := math.Abs(q2)
375 if absQ1 < absQ2 && q2 < 0 {
376 p.Flag = blas.Rescaling
381 p.Flag = blas.Diagonal
384 u = 1 + p.H[0]*p.H[3]
385 rd1, rd2 = d2/u, d1/u
390 // Now we know that d1 != 0, and d2 != 0. If d2 == 0, it would be caught
391 // when p2 == 0, and if d1 == 0, then it is caught above
396 u = 1 - p.H[2]*p.H[1]
400 p.Flag = blas.OffDiagonal
401 // u must be greater than zero because |q1| > |q2|, so check from netlib
403 // This is left in for ease of comparison with complex routines
410 p.Flag = blas.Diagonal
413 u = 1 + p.H[0]*p.H[3]
419 for rd1 <= rgamsq || rd1 >= gamsq {
420 if p.Flag == blas.OffDiagonal {
423 p.Flag = blas.Rescaling
424 } else if p.Flag == blas.Diagonal {
427 p.Flag = blas.Rescaling
442 for math.Abs(rd2) <= rgamsq || math.Abs(rd2) >= gamsq {
443 if p.Flag == blas.OffDiagonal {
446 p.Flag = blas.Rescaling
447 } else if p.Flag == blas.Diagonal {
450 p.Flag = blas.Rescaling
452 if math.Abs(rd2) <= rgamsq {
465 // Srot applies a plane transformation.
466 // x[i] = c * x[i] + s * y[i]
467 // y[i] = c * y[i] - s * x[i]
469 // Float32 implementations are autogenerated and not directly tested.
470 func (Implementation) Srot(n int, x []float32, incX int, y []float32, incY int, c float32, s float32) {
483 if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
486 if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
489 if incX == 1 && incY == 1 {
491 for i, vx := range x {
493 x[i], y[i] = c*vx+s*vy, c*vy-s*vx
504 for i := 0; i < n; i++ {
507 x[ix], y[iy] = c*vx+s*vy, c*vy-s*vx
513 // Srotm applies the modified Givens rotation to the 2×n matrix.
515 // Float32 implementations are autogenerated and not directly tested.
516 func (Implementation) Srotm(n int, x []float32, incX int, y []float32, incY int, p blas.SrotmParams) {
529 if (incX > 0 && (n-1)*incX >= len(x)) || (incX < 0 && (1-n)*incX >= len(x)) {
532 if (incY > 0 && (n-1)*incY >= len(y)) || (incY < 0 && (1-n)*incY >= len(y)) {
536 var h11, h12, h21, h22 float32
546 case blas.OffDiagonal:
563 if incX == 1 && incY == 1 {
565 for i, vx := range x {
567 x[i], y[i] = vx*h11+vy*h12, vx*h21+vy*h22
571 for i := 0; i < n; i++ {
574 x[ix], y[iy] = vx*h11+vy*h12, vx*h21+vy*h22
580 // Sscal scales x by alpha.
582 // Sscal has no effect if incX < 0.
584 // Float32 implementations are autogenerated and not directly tested.
585 func (Implementation) Sscal(n int, alpha float32, x []float32, incX int) {
592 if (n-1)*incX >= len(x) {
609 for ix := 0; ix < n*incX; ix += incX {
615 f32.ScalUnitary(alpha, x[:n])
618 f32.ScalInc(alpha, x, uintptr(n), uintptr(incX))