github.com/gopherd/gonum@v0.0.4/internal/asm/f32/stubs_noasm.go (about)

     1  // Copyright ©2016 The Gonum Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build !amd64 || noasm || gccgo || safe
     6  // +build !amd64 noasm gccgo safe
     7  
     8  package f32
     9  
    10  // AxpyUnitary is
    11  //  for i, v := range x {
    12  //  	y[i] += alpha * v
    13  //  }
    14  func AxpyUnitary(alpha float32, x, y []float32) {
    15  	for i, v := range x {
    16  		y[i] += alpha * v
    17  	}
    18  }
    19  
    20  // AxpyUnitaryTo is
    21  //  for i, v := range x {
    22  //  	dst[i] = alpha*v + y[i]
    23  //  }
    24  func AxpyUnitaryTo(dst []float32, alpha float32, x, y []float32) {
    25  	for i, v := range x {
    26  		dst[i] = alpha*v + y[i]
    27  	}
    28  }
    29  
    30  // AxpyInc is
    31  //  for i := 0; i < int(n); i++ {
    32  //  	y[iy] += alpha * x[ix]
    33  //  	ix += incX
    34  //  	iy += incY
    35  //  }
    36  func AxpyInc(alpha float32, x, y []float32, n, incX, incY, ix, iy uintptr) {
    37  	for i := 0; i < int(n); i++ {
    38  		y[iy] += alpha * x[ix]
    39  		ix += incX
    40  		iy += incY
    41  	}
    42  }
    43  
    44  // AxpyIncTo is
    45  //  for i := 0; i < int(n); i++ {
    46  //  	dst[idst] = alpha*x[ix] + y[iy]
    47  //  	ix += incX
    48  //  	iy += incY
    49  //  	idst += incDst
    50  //  }
    51  func AxpyIncTo(dst []float32, incDst, idst uintptr, alpha float32, x, y []float32, n, incX, incY, ix, iy uintptr) {
    52  	for i := 0; i < int(n); i++ {
    53  		dst[idst] = alpha*x[ix] + y[iy]
    54  		ix += incX
    55  		iy += incY
    56  		idst += incDst
    57  	}
    58  }
    59  
    60  // DotUnitary is
    61  //  for i, v := range x {
    62  //  	sum += y[i] * v
    63  //  }
    64  //  return sum
    65  func DotUnitary(x, y []float32) (sum float32) {
    66  	for i, v := range x {
    67  		sum += y[i] * v
    68  	}
    69  	return sum
    70  }
    71  
    72  // DotInc is
    73  //  for i := 0; i < int(n); i++ {
    74  //  	sum += y[iy] * x[ix]
    75  //  	ix += incX
    76  //  	iy += incY
    77  //  }
    78  //  return sum
    79  func DotInc(x, y []float32, n, incX, incY, ix, iy uintptr) (sum float32) {
    80  	for i := 0; i < int(n); i++ {
    81  		sum += y[iy] * x[ix]
    82  		ix += incX
    83  		iy += incY
    84  	}
    85  	return sum
    86  }
    87  
    88  // DdotUnitary is
    89  //  for i, v := range x {
    90  //  	sum += float64(y[i]) * float64(v)
    91  //  }
    92  //  return
    93  func DdotUnitary(x, y []float32) (sum float64) {
    94  	for i, v := range x {
    95  		sum += float64(y[i]) * float64(v)
    96  	}
    97  	return
    98  }
    99  
   100  // DdotInc is
   101  //  for i := 0; i < int(n); i++ {
   102  //  	sum += float64(y[iy]) * float64(x[ix])
   103  //  	ix += incX
   104  //  	iy += incY
   105  //  }
   106  //  return
   107  func DdotInc(x, y []float32, n, incX, incY, ix, iy uintptr) (sum float64) {
   108  	for i := 0; i < int(n); i++ {
   109  		sum += float64(y[iy]) * float64(x[ix])
   110  		ix += incX
   111  		iy += incY
   112  	}
   113  	return
   114  }
   115  
   116  // Sum is
   117  //  var sum float32
   118  //  for _, v := range x {
   119  //  	sum += v
   120  //  }
   121  //  return sum
   122  func Sum(x []float32) float32 {
   123  	var sum float32
   124  	for _, v := range x {
   125  		sum += v
   126  	}
   127  	return sum
   128  }