(self, dev)
| 3093 | self.noneZero_test(gpu_dev) |
| 3094 | |
| 3095 | def cast_test(self, dev): |
| 3096 | config = [ |
| 3097 | (np.float32, np.int32, tensor.int32), |
| 3098 | (np.int32, np.float32, tensor.float32), |
| 3099 | ] |
| 3100 | for t1, t2, t3 in config: |
| 3101 | X = np.array([[1, 0], [1, 1]]).astype(t1) |
| 3102 | y = np.array([[1, 0], [1, 1]]).astype(t2) |
| 3103 | |
| 3104 | x = tensor.from_numpy(X) |
| 3105 | x.to_device(dev) |
| 3106 | |
| 3107 | result = autograd.cast(x, t3) |
| 3108 | result_np = tensor.to_numpy(result) |
| 3109 | assert result_np.dtype == y.dtype, "type %s != %s." % ( |
| 3110 | result_np.dtype, y.dtype) |
| 3111 | np.testing.assert_array_almost_equal(result_np, y, decimal=5) |
| 3112 | |
| 3113 | def test_cast_cpu(self): |
| 3114 | self.cast_test(cpu_dev) |
no test coverage detected