| 186 | } |
| 187 | |
| 188 | func TestValidateGradientsNames(t *testing.T) { |
| 189 | var ( |
| 190 | s = NewScope() |
| 191 | x = Placeholder(s.SubScope("x"), tf.Float) |
| 192 | y0 = Square(s.SubScope("y0"), x) |
| 193 | ) |
| 194 | |
| 195 | grads0 := Gradients(s, []tf.Output{y0}, []tf.Output{x}) |
| 196 | if err := s.Err(); err != nil { |
| 197 | t.Fatal(err) |
| 198 | } |
| 199 | if !strings.HasPrefix(grads0[0].Op.Name(), "Gradients/") { |
| 200 | t.Fatalf("Got name %v, wanted started with Gradients/", grads0[0].Op.Name()) |
| 201 | } |
| 202 | |
| 203 | sub := s.SubScope("sub") |
| 204 | grads1 := Gradients(sub, []tf.Output{y0}, []tf.Output{x}) |
| 205 | if err := s.Err(); err != nil { |
| 206 | t.Fatal(err) |
| 207 | } |
| 208 | if !strings.HasPrefix(grads1[0].Op.Name(), "sub/Gradients/") { |
| 209 | t.Fatalf("Got name %v, wanted started with sub/Gradients/", grads1[0].Op.Name()) |
| 210 | } |
| 211 | |
| 212 | Gradients(sub, []tf.Output{y0}, []tf.Output{x}) |
| 213 | if err := s.Err(); err == nil { |
| 214 | t.Error("Gradients should have failed if executed more than once for scope of the same namespace") |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | func TestAddGradientsWithControlDependencies(t *testing.T) { |
| 219 | var ( |