Fixed minor bug

This commit is contained in:
btracey
2013-08-16 12:56:33 -07:00
parent 80c75ed891
commit c445087eb0
2 changed files with 17 additions and 0 deletions

View File

@@ -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

View File

@@ -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)