forked from gorgonia/gorgonia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dual_test.go
53 lines (44 loc) · 1.14 KB
/
dual_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
package gorgonia
import (
"testing"
"github.com/chewxy/gorgonia/tensor"
"github.com/chewxy/hm"
"github.com/stretchr/testify/assert"
)
func Test_dvBind0(t *testing.T) {
var x, y, z Value
var xT, yT, zT hm.Type
x, xT = anyToScalar(2.0)
y, yT = anyToScalar(3.0)
z, zT = anyToScalar(0.0)
op := newEBOByType(addOpType, xT, yT)
xdv := constantDV(x)
ydv := constantDV(y)
zdv := constantDV(z)
dvBind0(op, zdv, []*dualValue{xdv, ydv})
t.Logf("%v %v", zdv, zT)
}
func TestDVBindVar(t *testing.T) {
var x, y Value
var xT, yT hm.Type
x, xT = anyToScalar(2.0)
y, yT = anyToScalar(3.0)
op := newEBOByType(addOpType, xT, yT)
xdv := constantDV(x)
ydv := constantDV(y)
retVal, err := dvBindVar(op, []*dualValue{xdv, ydv})
if err != nil {
t.Error(err)
}
assert.Equal(t, 1.0, retVal.d.Data())
x = tensor.New(tensor.WithBacking([]float64{1, 2, 3, 4}))
x = tensor.New(tensor.WithBacking([]float64{4, 3, 2, 1}))
op = newEBOByType(addOpType, TypeOf(x), TypeOf(y))
xdv = constantDV(x)
ydv = constantDV(y)
retVal, err = dvBindVar(op, []*dualValue{xdv, ydv})
if err != nil {
t.Error(err)
}
assert.Equal(t, []float64{1, 1, 1, 1}, retVal.d.Data())
}