Example #1
0
// ScaleVec scales the vector a by alpha, placing the result in the receiver.
func (v *Vector) ScaleVec(alpha float64, a *Vector) {
	n := a.Len()
	if v != a {
		v.reuseAs(n)
		if v.mat.Inc == 1 && a.mat.Inc == 1 {
			asm.DscalUnitaryTo(v.mat.Data, alpha, a.mat.Data)
			return
		}
		asm.DscalIncTo(v.mat.Data, uintptr(v.mat.Inc),
			alpha, a.mat.Data, uintptr(n), uintptr(a.mat.Inc))
		return
	}
	if v.mat.Inc == 1 {
		asm.DscalUnitary(alpha, v.mat.Data)
		return
	}
	asm.DscalInc(alpha, v.mat.Data, uintptr(n), uintptr(v.mat.Inc))
}
Example #2
0
// Dscal scales x by alpha.
//  x[i] *= alpha
// Dscal has no effect if incX < 0.
func (Implementation) Dscal(n int, alpha float64, x []float64, incX int) {
	if incX < 1 {
		if incX == 0 {
			panic(zeroIncX)
		}
		return
	}
	if (n-1)*incX >= len(x) {
		panic(badX)
	}
	if n < 1 {
		if n == 0 {
			return
		}
		panic(negativeN)
	}
	if alpha == 0 {
		if incX == 1 {
			x = x[:n]
			for i := range x {
				x[i] = 0
			}
			return
		}
		for ix := 0; ix < n*incX; ix += incX {
			x[ix] = 0
		}
		return
	}
	if incX == 1 {
		asm.DscalUnitary(alpha, x[:n])
		return
	}
	for ix := 0; ix < n*incX; ix += incX {
		x[ix] *= alpha
	}
}
Example #3
0
// Scale multiplies every element in dst by the scalar c.
func Scale(c float64, dst []float64) {
	if len(dst) > 0 {
		asm.DscalUnitary(c, dst)
	}
}