-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall_test.go
90 lines (72 loc) · 1.97 KB
/
all_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"testing"
"time"
ng "ndgo/ndgo"
)
func TestApply(t *testing.T) {
a := ng.Random([]int{2, 4, 2})
_ = ng.Exp(a)
}
func TestReshape(t *testing.T) {
_ = ng.Arange(1, 17, 1).Reshape([]int{2, 2, 4})
}
func TestIndices(t *testing.T) {
a := ng.Arange(1, 17, 1).Reshape([]int{2, 4, 2})
t.Log("Testing n-dimensional indices...")
t.Log(a.Idxs.Indices)
t.Log("Testing 1-dimensional indices...")
t.Log(a.Lidxs.Indices)
if a.Data[a.Totalsize-1] != a.Data[a.Lidxs.Indices[a.Totalsize-1]] {
panic("bad linear indices")
}
}
func TestTranspose(t *testing.T) {
t.Log("Testing 1D transpose...")
a := ng.Arange(1, 17, 1)
b := a.Transpose(nil)
t.Log(b.Shape, b.Strides, b.C_ORDER, b.F_ORDER)
t.Log(b.Idxs, b.Lidxs)
t.Log("Testing nD transpose...")
a = ng.Arange(1, 17, 1).Reshape([]int{2, 4, 2})
b = a.Transpose(nil)
t.Log(b.Shape, b.Strides, b.C_ORDER, b.F_ORDER)
t.Log(b.Idxs, b.Lidxs)
ng.PrettyPrint(b)
t.Log("Testing nD transpose with axes...")
a = ng.Arange(1, 17, 1).Reshape([]int{2, 4, 2})
b = a.Transpose([]int{2, 1, 0})
t.Log(b.Shape, b.Strides, b.C_ORDER, b.F_ORDER)
t.Log(b.Idxs, b.Lidxs)
ng.PrettyPrint(b)
}
func TestNormalTransposeOps(t *testing.T) {
a := ng.Arange(1, 17, 1).Reshape([]int{2, 4, 2})
b := a.Transpose(nil)
c := ng.Add(a, b)
t.Log(c.Shape, c.Strides, c.C_ORDER, c.F_ORDER)
t.Log(c.Idxs, c.Lidxs)
ng.PrettyPrint(c)
}
func TestMatmul(t *testing.T) {
a := ng.Arange(1, 17, 1).Reshape([]int{2, 4, 2})
b := ng.Arange(1, 17, 1).Reshape([]int{2, 2, 4})
c := ng.Matmul(a, b)
t.Log(a.Shape, b.Shape, c.Shape)
ng.PrettyPrint(c)
}
func TestParallelAdd(t *testing.T) {
a := ng.Random([]int{100, 100})
b := ng.Random([]int{100, 100})
start := time.Now()
_ = ng.Add(a, b)
duration := time.Since(start)
t.Log("Time taken for add: ", duration)
}
func TestSub(t *testing.T) {
a := ng.Arange(1, 17, 1).Reshape([]int{2, 4, 2})
b := ng.Arange(11, 27, 1).Reshape([]int{2, 4, 2})
// subtract operation
c := ng.Sub(a, b)
ng.PrettyPrint(c)
}