-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmatmul_test.go
49 lines (43 loc) · 1.03 KB
/
matmul_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package numgo
import (
"math"
"testing"
)
func TestDotProd(t *testing.T) {
a, b := Arange(11), Arange(11).AddC(1)
//fmaSet := fmaSupt
for i, v := range []struct {
a *Array64
b *Array64
c float64
e error
}{
{a, b, 440, nil},
{a.C().Resize(2, 5), b.C().Resize(2, 4), math.NaN(), ShapeError},
{a.C().Resize(10), b.C().Resize(10), 330, nil},
{a.C().Resize(2, 5), b.C().Resize(2, 5), 0, nil},
} {
if c := v.a.DotProd(v.b); c.At(0) != v.c && math.IsNaN(c.At(0)) != math.IsNaN(v.c) {
t.Log("Test", i, "Expected", v.c, "Got", c.At(0))
t.Fail()
}
/*fmaSupt = false
if c := v.a.DotProd(v.b); c.At(0) != v.c && math.IsNaN(c.At(0)) != math.IsNaN(v.c) {
t.Log("Test", i, "No FMA expected", v.c, "Got", c.At(0))
t.Fail()
}
fmaSupt = fmaSet*/
if c := v.a.GetErr(); c != v.e {
t.Log("Error test", i, "Expected", v.e, "Got", c)
t.Fail()
}
}
}
func BenchmarkDotProd(t *testing.B) {
a, b := Arange(1000000), Arange(1000000)
t.ReportAllocs()
t.ResetTimer()
for i := 0; i < t.N; i++ {
_ = a.DotProd(b)
}
}