-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathexample_tensordot_test.go
50 lines (42 loc) · 1.22 KB
/
example_tensordot_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
package gorgonia
import (
"fmt"
)
/*
func ExampleTensordot_scalar() {
// Scalars
g := NewGraph()
a := NewScalar(g, Float64, WithValue(2.0), WithName("a"))
b := NewScalar(g, Float64, WithValue(21.0), WithName("b"))
c, err := Tensordot([]int{0}, []int{0}, a, b)
if err != nil {
fmt.Printf("Cannot call Tensordot. Error: %v\n", err)
return
}
vm := NewTapeMachine(g)
if err := vm.RunAll(); err != nil {
fmt.Printf("Cannot perform scalars. Error %v\n", err)
}
fmt.Printf("c: %v (%v) of %v", c.Value(), c.Value().Dtype(), c.Value().Shape())
// Output:
//...
}
*/
func ExampleTensordot_vectors() {
g := NewGraph()
a := NewVector(g, Float64, WithName("a"), WithShape(2), WithInit(RangedFrom(2)))
b := NewVector(g, Float64, WithName("b"), WithShape(2), WithInit(RangedFrom(21)))
c, err := Tensordot([]int{0}, []int{0}, a, b)
if err != nil {
fmt.Printf("Cannot call Tensordot. Error: %v\n", err)
return
}
vm := NewTapeMachine(g)
if err := vm.RunAll(); err != nil {
fmt.Printf("Cannot perform tensordot on vectors. Error %v\n", err)
}
fmt.Printf("a %v b %v ", a.Value(), b.Value())
fmt.Printf("c: %v (%v) of %v", c.Value(), c.Type(), c.Value().Shape())
// Output:
// a [2 3] b [21 22] c: [108] (float64) of (1)
}