From 80c75ed891cb52bbbbc2e8284fc70e476624d438 Mon Sep 17 00:00:00 2001 From: btracey Date: Fri, 16 Aug 2013 12:15:28 -0700 Subject: [PATCH] Added Mul function --- floats.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/floats.go b/floats.go index 116f7f61..7fc56a96 100644 --- a/floats.go +++ b/floats.go @@ -233,6 +233,18 @@ func Min(s []float64) (min float64, ind int) { return min, ind } +// Mul performs element-wise multiplication between s +// and t and stores the value in s. Panics if the +// lengths of s and t are not equal +func Mul(s []float64, t []float64) { + if len(s) != len(t) { + panic("floats: slice lengths do not match") + } + for i, val := range t { + s[i] *= val + } +} + // 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