github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/vector/define/axpy.go (about)

     1  package define
     2  
     3  import . "github.com/egonelbre/exp/vector/vector"
     4  
     5  // AxpyUnitary calculates y[i] = y[i] + alpha * x[i].
     6  func AxpyUnitary[T float32 | float64 | complex64 | complex128](alpha T, xs, ys []T) {
     7  	Apply2(
     8  		Vector[T]{Values: ys, Offset: 0, Inc: 1},
     9  		Vector[T]{Values: xs, Offset: 0, Inc: 1},
    10  		uintptr(len(ys)), func(y, x T) T {
    11  			return y + alpha*x
    12  		})
    13  }
    14  
    15  // AxpyUnitaryTo calculates dst[i] = y[i] + alpha * x[i].
    16  func AxpyUnitaryTo[T float32 | float64 | complex64 | complex128](dst []T, alpha T, xs, ys []T) {
    17  	Apply2To(
    18  		Vector[T]{Values: dst, Offset: 0, Inc: 1},
    19  		Vector[T]{Values: ys, Offset: 0, Inc: 1},
    20  		Vector[T]{Values: xs, Offset: 0, Inc: 1},
    21  		uintptr(len(ys)), func(y, x T) T {
    22  			return y + x*alpha
    23  		})
    24  }