diff --git a/floats.go b/floats.go index 7fc56a96..76af12e6 100644 --- a/floats.go +++ b/floats.go @@ -245,6 +245,19 @@ func Mul(s []float64, t []float64) { } } +// MulTo performs element-wise multiplication between s +// and t and stores the value in dst. Panics if the +// lengths of s, t, and dst are not equal +func MulTo(dst []float64, s []float64, t []float64) []float64 { + if len(s) != len(t) || len(dst) != len(t) { + panic("floats: slice lengths do not match") + } + for i, val := range t { + dst[i] = val * s[i] + } + return dst +} + // Nearest returns the index of the element in s // whose value is nearest to v. If several such // elements exist, the lowest index is returned diff --git a/floats_test.go b/floats_test.go index ede37121..eb33f46b 100644 --- a/floats_test.go +++ b/floats_test.go @@ -282,6 +282,10 @@ func TestMin(t *testing.T) { } } +func TestMul(t *testing.T) { + +} + func TestNearest(t *testing.T) { s := []float64{6.2, 3, 5, 6.2, 8} ind := Nearest(s, 2.0)