1// Copyright ©2015 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// +build !noasm,!appengine,!safe 6 7package f64 8 9// L1Norm is 10// for _, v := range x { 11// sum += math.Abs(v) 12// } 13// return sum 14func L1Norm(x []float64) (sum float64) 15 16// L1NormInc is 17// for i := 0; i < n*incX; i += incX { 18// sum += math.Abs(x[i]) 19// } 20// return sum 21func L1NormInc(x []float64, n, incX int) (sum float64) 22 23// AddConst is 24// for i := range x { 25// x[i] += alpha 26// } 27func AddConst(alpha float64, x []float64) 28 29// Add is 30// for i, v := range s { 31// dst[i] += v 32// } 33func Add(dst, s []float64) 34 35// AxpyUnitary is 36// for i, v := range x { 37// y[i] += alpha * v 38// } 39func AxpyUnitary(alpha float64, x, y []float64) 40 41// AxpyUnitaryTo is 42// for i, v := range x { 43// dst[i] = alpha*v + y[i] 44// } 45func AxpyUnitaryTo(dst []float64, alpha float64, x, y []float64) 46 47// AxpyInc is 48// for i := 0; i < int(n); i++ { 49// y[iy] += alpha * x[ix] 50// ix += incX 51// iy += incY 52// } 53func AxpyInc(alpha float64, x, y []float64, n, incX, incY, ix, iy uintptr) 54 55// AxpyIncTo is 56// for i := 0; i < int(n); i++ { 57// dst[idst] = alpha*x[ix] + y[iy] 58// ix += incX 59// iy += incY 60// idst += incDst 61// } 62func AxpyIncTo(dst []float64, incDst, idst uintptr, alpha float64, x, y []float64, n, incX, incY, ix, iy uintptr) 63 64// CumSum is 65// if len(s) == 0 { 66// return dst 67// } 68// dst[0] = s[0] 69// for i, v := range s[1:] { 70// dst[i+1] = dst[i] + v 71// } 72// return dst 73func CumSum(dst, s []float64) []float64 74 75// CumProd is 76// if len(s) == 0 { 77// return dst 78// } 79// dst[0] = s[0] 80// for i, v := range s[1:] { 81// dst[i+1] = dst[i] * v 82// } 83// return dst 84func CumProd(dst, s []float64) []float64 85 86// Div is 87// for i, v := range s { 88// dst[i] /= v 89// } 90func Div(dst, s []float64) 91 92// DivTo is 93// for i, v := range s { 94// dst[i] = v / t[i] 95// } 96// return dst 97func DivTo(dst, x, y []float64) []float64 98 99// DotUnitary is 100// for i, v := range x { 101// sum += y[i] * v 102// } 103// return sum 104func DotUnitary(x, y []float64) (sum float64) 105 106// DotInc is 107// for i := 0; i < int(n); i++ { 108// sum += y[iy] * x[ix] 109// ix += incX 110// iy += incY 111// } 112// return sum 113func DotInc(x, y []float64, n, incX, incY, ix, iy uintptr) (sum float64) 114 115// L1Dist is 116// var norm float64 117// for i, v := range s { 118// norm += math.Abs(t[i] - v) 119// } 120// return norm 121func L1Dist(s, t []float64) float64 122 123// LinfDist is 124// var norm float64 125// if len(s) == 0 { 126// return 0 127// } 128// norm = math.Abs(t[0] - s[0]) 129// for i, v := range s[1:] { 130// absDiff := math.Abs(t[i+1] - v) 131// if absDiff > norm || math.IsNaN(norm) { 132// norm = absDiff 133// } 134// } 135// return norm 136func LinfDist(s, t []float64) float64 137 138// ScalUnitary is 139// for i := range x { 140// x[i] *= alpha 141// } 142func ScalUnitary(alpha float64, x []float64) 143 144// ScalUnitaryTo is 145// for i, v := range x { 146// dst[i] = alpha * v 147// } 148func ScalUnitaryTo(dst []float64, alpha float64, x []float64) 149 150// ScalInc is 151// var ix uintptr 152// for i := 0; i < int(n); i++ { 153// x[ix] *= alpha 154// ix += incX 155// } 156func ScalInc(alpha float64, x []float64, n, incX uintptr) 157 158// ScalIncTo is 159// var idst, ix uintptr 160// for i := 0; i < int(n); i++ { 161// dst[idst] = alpha * x[ix] 162// ix += incX 163// idst += incDst 164// } 165func ScalIncTo(dst []float64, incDst uintptr, alpha float64, x []float64, n, incX uintptr) 166 167// Sum is 168// var sum float64 169// for i := range x { 170// sum += x[i] 171// } 172func Sum(x []float64) float64 173