(t *testing.T)
| 173 | } |
| 174 | |
| 175 | func TestGraphAddGradientsSums(t *testing.T) { |
| 176 | g := NewGraph() |
| 177 | x, err := Placeholder(g, "x", Float) |
| 178 | if err != nil { |
| 179 | t.Fatal(err) |
| 180 | } |
| 181 | op0, err := g.AddOperation(OpSpec{ |
| 182 | Type: "Square", |
| 183 | Name: "y0", |
| 184 | Input: []Input{x}, |
| 185 | }) |
| 186 | if err != nil { |
| 187 | t.Fatal(err) |
| 188 | } |
| 189 | y0 := op0.Output(0) |
| 190 | op1, err := g.AddOperation(OpSpec{ |
| 191 | Type: "Square", |
| 192 | Name: "y1", |
| 193 | Input: []Input{y0}, |
| 194 | }) |
| 195 | y1 := op1.Output(0) |
| 196 | |
| 197 | grad, err := g.AddGradients("", []Output{y0, y1}, []Output{x}, nil) |
| 198 | if err != nil { |
| 199 | t.Fatal(err) |
| 200 | } |
| 201 | if len(grad) != 1 { |
| 202 | t.Fatal(len(grad)) |
| 203 | } |
| 204 | if grad[0].DataType() != Float { |
| 205 | t.Fatalf("Got DataType %v, wanted %v", grad[0].DataType(), Float) |
| 206 | } |
| 207 | |
| 208 | sess, err := NewSession(g, nil) |
| 209 | if err != nil { |
| 210 | t.Fatal(err) |
| 211 | } |
| 212 | |
| 213 | c, _ := NewTensor(float32(3.0)) |
| 214 | outputs, err := sess.Run( |
| 215 | map[Output]*Tensor{x: c}, |
| 216 | []Output{grad[0]}, |
| 217 | nil) |
| 218 | if err != nil { |
| 219 | t.Fatal(err) |
| 220 | } |
| 221 | if outputs[0].Value().(float32) != 114.0 { |
| 222 | t.Fatalf("Got %v, wanted float 114.0", outputs[0].Value()) |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | func TestGraphAddGradientsWithInitialValues(t *testing.T) { |
| 227 | g := NewGraph() |
nothing calls this directly
no test coverage detected