MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TestAddGradientsSums

Function TestAddGradientsSums

tensorflow/go/op/gradients_test.go:94–133  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

92}
93
94func TestAddGradientsSums(t *testing.T) {
95 var (
96 s = NewScope()
97 x = Placeholder(s.SubScope("x"), tf.Float)
98 y0 = Square(s.SubScope("y0"), x)
99 y1 = Square(s.SubScope("y1"), y0)
100 )
101
102 grad := Gradients(s, []tf.Output{y0, y1}, []tf.Output{x})
103 if err := s.Err(); err != nil {
104 t.Fatal(err)
105 }
106 if len(grad) != 1 {
107 t.Fatal(len(grad))
108 }
109 if grad[0].DataType() != tf.Float {
110 t.Fatalf("Got DataType %v, wanted %v", grad[0].DataType(), tf.Float)
111 }
112
113 graph, err := s.Finalize()
114 if err != nil {
115 t.Fatal(err)
116 }
117 sess, err := tf.NewSession(graph, nil)
118 if err != nil {
119 t.Fatal(err)
120 }
121
122 c, _ := tf.NewTensor(float32(3.0))
123 outputs, err := sess.Run(
124 map[tf.Output]*tf.Tensor{x: c},
125 []tf.Output{grad[0]},
126 nil)
127 if err != nil {
128 t.Fatal(err)
129 }
130 if outputs[0].Value().(float32) != 114.0 {
131 t.Fatalf("Got %v, wanted float 114.0", outputs[0].Value())
132 }
133}
134
135func TestAddGradientsWithInitialValues(t *testing.T) {
136 var (

Callers

nothing calls this directly

Calls 11

RunMethod · 0.95
NewScopeFunction · 0.85
SubScopeMethod · 0.80
PlaceholderFunction · 0.70
SquareFunction · 0.70
GradientsFunction · 0.70
ErrMethod · 0.45
DataTypeMethod · 0.45
FinalizeMethod · 0.45
NewSessionMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected