(self, dev)
| 3451 | self.assertRaises(AssertionError, autograd.ranking_loss, _2d, _1d) |
| 3452 | |
| 3453 | def where_helper(self, dev): |
| 3454 | X = np.array([[1, 2], [3, 4]], dtype=np.float32) |
| 3455 | x = tensor.from_numpy(X) |
| 3456 | x.to_device(dev) |
| 3457 | |
| 3458 | X2 = np.array([[9, 8], [7, 6]], dtype=np.float32) |
| 3459 | x2 = tensor.from_numpy(X2) |
| 3460 | x2.to_device(dev) |
| 3461 | |
| 3462 | condition = [[True, False], [True, True]] |
| 3463 | y_t = np.where(condition, X, X2) |
| 3464 | dx1_t = np.array([[1, 0], [3, 4]], dtype=np.float32) |
| 3465 | dx2_t = np.array([[0, 8], [0, 0]], dtype=np.float32) |
| 3466 | dy = tensor.from_numpy(y_t) |
| 3467 | dy.to_device(dev) |
| 3468 | |
| 3469 | y = autograd.where(x, x2, condition) |
| 3470 | dx1, dx2 = y.creator.backward(dy.data) |
| 3471 | np.testing.assert_array_almost_equal(tensor.to_numpy(y), y_t) |
| 3472 | np.testing.assert_array_almost_equal( |
| 3473 | tensor.to_numpy(tensor.from_raw_tensor(dx1)), dx1_t) |
| 3474 | np.testing.assert_array_almost_equal( |
| 3475 | tensor.to_numpy(tensor.from_raw_tensor(dx2)), dx2_t) |
| 3476 | |
| 3477 | def test_where_cpu(self): |
| 3478 | self.where_helper(cpu_dev) |
no test coverage detected