|
@@ -23,13 +23,14 @@ func TestInput(t *testing.T) {
|
|
a := assert.A(t)
|
|
a := assert.A(t)
|
|
f := flow.New()
|
|
f := flow.New()
|
|
|
|
|
|
- opIn, err := f.In(0)
|
|
|
|
- a.Eq(err, nil, "input err should be nil")
|
|
|
|
|
|
+ opIn := f.In(0)
|
|
|
|
+ a.NotEq(opIn, nil, "input err should not be nil")
|
|
|
|
|
|
d, err := opIn.Process([]float32{2, 2, 2})
|
|
d, err := opIn.Process([]float32{2, 2, 2})
|
|
a.Eq(d, []float32{2, 2, 2}, "array should be equal")
|
|
a.Eq(d, []float32{2, 2, 2}, "array should be equal")
|
|
|
|
|
|
- op, err := f.Op("vecadd", []float32{1, 1, 1}, opIn)
|
|
|
|
|
|
+ op := f.Op("vecadd", []float32{1, 1, 1}, opIn)
|
|
|
|
+ _, err = op.Process([]float32{1, 2, 3})
|
|
a.Eq(err, nil, "result should not error")
|
|
a.Eq(err, nil, "result should not error")
|
|
a.NotEq(op, nil, "operation should not be nil")
|
|
a.NotEq(op, nil, "operation should not be nil")
|
|
|
|
|
|
@@ -50,10 +51,12 @@ func TestDefOp(t *testing.T) {
|
|
_, err = f.DefOp("1", "vecadd", []float32{1, 2, 3}, f.GetOp("2")) // r: 4 5 6
|
|
_, err = f.DefOp("1", "vecadd", []float32{1, 2, 3}, f.GetOp("2")) // r: 4 5 6
|
|
a.Eq(err, nil, "doing DefOp")
|
|
a.Eq(err, nil, "doing DefOp")
|
|
|
|
|
|
- op, err := f.Op("vecmul", f.GetOp("1"), []float32{2, 2, 2}) //r:8 10 12
|
|
|
|
- a.Eq(err, nil, "mul operation")
|
|
|
|
|
|
+ op := f.Op("vecmul", f.GetOp("1"), []float32{2, 2, 2}) //r:8 10 12
|
|
a.NotEq(op, nil, "operation not nil")
|
|
a.NotEq(op, nil, "operation not nil")
|
|
|
|
|
|
|
|
+ _, err = op.Process()
|
|
|
|
+ a.Eq(err, nil, "mul operation")
|
|
|
|
+
|
|
desired := []float32{8, 10, 12}
|
|
desired := []float32{8, 10, 12}
|
|
res, _ := op.Process()
|
|
res, _ := op.Process()
|
|
a.Eq(res, desired, fmt.Sprintf("vector result should match:\n%v", f))
|
|
a.Eq(res, desired, fmt.Sprintf("vector result should match:\n%v", f))
|
|
@@ -84,20 +87,20 @@ func TestIDGen(t *testing.T) {
|
|
return newID
|
|
return newID
|
|
})
|
|
})
|
|
|
|
|
|
- i1, err := f.In(0)
|
|
|
|
- a.Eq(err, nil, "should be nil")
|
|
|
|
|
|
+ i1 := f.In(0)
|
|
|
|
+ a.NotEq(i1, nil, "i1 should not be nil")
|
|
a.Eq(i1.ID(), "1", "id should be 1")
|
|
a.Eq(i1.ID(), "1", "id should be 1")
|
|
|
|
|
|
- i2, err := f.In(1)
|
|
|
|
- a.Eq(err, nil, "should be nil")
|
|
|
|
|
|
+ i2 := f.In(1)
|
|
|
|
+ a.NotEq(i2, nil, "i2 should not be nil")
|
|
a.Eq(i2.ID(), "2", "id should be 2")
|
|
a.Eq(i2.ID(), "2", "id should be 2")
|
|
|
|
|
|
- o, err := f.Op("vecadd", i1, i2)
|
|
|
|
- a.Eq(err, nil, "Should not nil")
|
|
|
|
|
|
+ o := f.Op("vecadd", i1, i2)
|
|
|
|
+ a.NotEq(o, nil, "Should not nil")
|
|
a.Eq(o.ID(), "0", "id should be 0")
|
|
a.Eq(o.ID(), "0", "id should be 0")
|
|
|
|
|
|
- o, err = f.Op("vecadd", i1, i2)
|
|
|
|
- a.NotEq(err, nil, "Should not be nil, id generation exausted")
|
|
|
|
|
|
+ o = f.Op("vecadd", i1, i2)
|
|
|
|
+ a.Eq(o, nil, "Should be nil, id generation exausted")
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -106,20 +109,20 @@ func TestSerialize(t *testing.T) {
|
|
f := flow.New()
|
|
f := flow.New()
|
|
var1 := f.Var("var1", []float32{4, 4, 4})
|
|
var1 := f.Var("var1", []float32{4, 4, 4})
|
|
|
|
|
|
- c1, _ := f.Const([]float32{1, 2, 3})
|
|
|
|
- c2, _ := f.Const([]float32{2, 2, 2})
|
|
|
|
|
|
+ c1 := f.Const([]float32{1, 2, 3})
|
|
|
|
+ c2 := f.Const([]float32{2, 2, 2})
|
|
|
|
|
|
- op1, _ := f.Op("vecmul", // op:0 - expected: [12,16,20,24]
|
|
|
|
|
|
+ op1 := f.Op("vecmul", // op:0 - expected: [12,16,20,24]
|
|
f.Var("vec1", []float32{4, 4, 4, 4}),
|
|
f.Var("vec1", []float32{4, 4, 4, 4}),
|
|
- f.Must(f.Op("vecadd", // op:1 - expected: [3,4,5,6]
|
|
|
|
- f.Must(f.Const([]float32{1, 2, 3, 4})),
|
|
|
|
- f.Must(f.Const([]float32{2, 2, 2, 2})),
|
|
|
|
- )),
|
|
|
|
|
|
+ f.Op("vecadd", // op:1 - expected: [3,4,5,6]
|
|
|
|
+ f.Const([]float32{1, 2, 3, 4}),
|
|
|
|
+ f.Const([]float32{2, 2, 2, 2}),
|
|
|
|
+ ),
|
|
)
|
|
)
|
|
- mul1, _ := f.Op("vecmul", c1, op1) // op:2 - expected 12, 32, 60, 0
|
|
|
|
- mul2, _ := f.Op("vecmul", mul1, var1) // op:3 - expected 48, 128, 240, 0
|
|
|
|
- mul3, _ := f.Op("vecmul", c2, mul2) // op:4 - expected 96, 256, 480, 0
|
|
|
|
- mul4, _ := f.Op("vecmul", mul3, f.Must(f.In(0))) // op:5 - expected 96, 512, 1440,0
|
|
|
|
|
|
+ mul1 := f.Op("vecmul", c1, op1) // op:2 - expected 12, 32, 60, 0
|
|
|
|
+ mul2 := f.Op("vecmul", mul1, var1) // op:3 - expected 48, 128, 240, 0
|
|
|
|
+ mul3 := f.Op("vecmul", c2, mul2) // op:4 - expected 96, 256, 480, 0
|
|
|
|
+ mul4 := f.Op("vecmul", mul3, f.In(0)) // op:5 - expected 96, 512, 1440,0
|
|
|
|
|
|
s := bytes.NewBuffer(nil)
|
|
s := bytes.NewBuffer(nil)
|
|
f.Analyse(s, []float32{1, 2, 3, 4})
|
|
f.Analyse(s, []float32{1, 2, 3, 4})
|
|
@@ -143,7 +146,7 @@ func TestConst(t *testing.T) {
|
|
a := assert.A(t)
|
|
a := assert.A(t)
|
|
f := flow.New()
|
|
f := flow.New()
|
|
|
|
|
|
- c, _ := f.Const(1)
|
|
|
|
|
|
+ c := f.Const(1)
|
|
res, err := c.Process()
|
|
res, err := c.Process()
|
|
a.Eq(res, 1, "It should be one")
|
|
a.Eq(res, 1, "It should be one")
|
|
a.Eq(err, nil, "const should not error")
|
|
a.Eq(err, nil, "const should not error")
|
|
@@ -152,11 +155,11 @@ func TestOp(t *testing.T) {
|
|
a := assert.A(t)
|
|
a := assert.A(t)
|
|
f := flow.New()
|
|
f := flow.New()
|
|
|
|
|
|
- add, err := f.Op("vecadd",
|
|
|
|
- f.Must(f.Op("vecmul",
|
|
|
|
|
|
+ add := f.Op("vecadd",
|
|
|
|
+ f.Op("vecmul",
|
|
[]float32{1, 2, 3},
|
|
[]float32{1, 2, 3},
|
|
[]float32{2, 2, 2},
|
|
[]float32{2, 2, 2},
|
|
- )),
|
|
|
|
|
|
+ ),
|
|
[]float32{1, 2, 3},
|
|
[]float32{1, 2, 3},
|
|
)
|
|
)
|
|
res, err := add.Process()
|
|
res, err := add.Process()
|
|
@@ -186,21 +189,20 @@ func TestCache(t *testing.T) {
|
|
a := assert.A(t)
|
|
a := assert.A(t)
|
|
f := flow.New()
|
|
f := flow.New()
|
|
{
|
|
{
|
|
- r, err := f.Op("inc")
|
|
|
|
- a.Eq(err, nil, "should not error giving operation")
|
|
|
|
|
|
+ r := f.Op("inc")
|
|
|
|
+ a.NotEq(r, nil, "should not error giving operation")
|
|
|
|
|
|
- var res interface{}
|
|
|
|
for i := 1; i < 5; i++ {
|
|
for i := 1; i < 5; i++ {
|
|
- res, err = r.Process()
|
|
|
|
|
|
+ res, err := r.Process()
|
|
a.Eq(err, nil)
|
|
a.Eq(err, nil)
|
|
a.Eq(res, i)
|
|
a.Eq(res, i)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
{
|
|
{
|
|
var res flow.Data
|
|
var res flow.Data
|
|
- inc, _ := f.Op("inc")
|
|
|
|
|
|
+ inc := f.Op("inc")
|
|
|
|
|
|
- add, _ := f.Op("add", inc, inc)
|
|
|
|
|
|
+ add := f.Op("add", inc, inc)
|
|
res, _ = add.Process() // 1+1
|
|
res, _ = add.Process() // 1+1
|
|
assert.Eq(t, res, 2)
|
|
assert.Eq(t, res, 2)
|
|
res, _ = add.Process() // 2+2
|
|
res, _ = add.Process() // 2+2
|
|
@@ -228,10 +230,13 @@ func TestLocalRegistry(t *testing.T) {
|
|
|
|
|
|
f := flow.New()
|
|
f := flow.New()
|
|
f.SetRegistry(r)
|
|
f.SetRegistry(r)
|
|
- op, _ := f.Op("test")
|
|
|
|
|
|
+ op := f.Op("test")
|
|
a.NotEq(op, nil, "operation should be valid")
|
|
a.NotEq(op, nil, "operation should be valid")
|
|
|
|
|
|
- op, err := f.Op("none")
|
|
|
|
|
|
+ op = f.Op("none")
|
|
|
|
+ a.NotEq(op, nil, "operation should not be nil")
|
|
|
|
+ _, err := op.Process()
|
|
|
|
+
|
|
a.NotEq(err, nil, "flow should contain an error")
|
|
a.NotEq(err, nil, "flow should contain an error")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -255,11 +260,11 @@ func prepareComplex() (*flow.Flow, flow.Operation) {
|
|
f1 := f.Var("f1", v1)
|
|
f1 := f.Var("f1", v1)
|
|
f2 := f.Var("f2", v2)
|
|
f2 := f.Var("f2", v2)
|
|
|
|
|
|
- mul, _ := f.Op("vecmul", f1, f2) // Doubles 2,4,6,8...
|
|
|
|
- add, _ := f.Op("vecadd", mul, f2) // Sum 4,8,10,12...
|
|
|
|
- mul2, _ := f.Op("vecmul", mul, add) // mul again
|
|
|
|
- mul3, _ := f.Op("vecmul", mul2, f1) // mul with f1
|
|
|
|
- div1, _ := f.Op("vecdiv", mul3, mul2) // div
|
|
|
|
|
|
+ mul := f.Op("vecmul", f1, f2) // Doubles 2,4,6,8...
|
|
|
|
+ add := f.Op("vecadd", mul, f2) // Sum 4,8,10,12...
|
|
|
|
+ mul2 := f.Op("vecmul", mul, add) // mul again
|
|
|
|
+ mul3 := f.Op("vecmul", mul2, f1) // mul with f1
|
|
|
|
+ div1 := f.Op("vecdiv", mul3, mul2) // div
|
|
|
|
|
|
return f, div1
|
|
return f, div1
|
|
}
|
|
}
|