| 73 | |
| 74 | |
| 75 | def _ctensor_eq_ndarray(t1, np1): |
| 76 | d = t1.device() |
| 77 | t1.ToHost() |
| 78 | if t1.data_type() == singa_api.kInt: |
| 79 | np.testing.assert_array_almost_equal(t1.GetIntValue(t1.Size()), |
| 80 | np1.flatten()) |
| 81 | elif t1.data_type() == singa_api.kFloat32: |
| 82 | np.testing.assert_array_almost_equal(t1.GetFloatValue(t1.Size()), |
| 83 | np1.flatten()) |
| 84 | |
| 85 | if np1.dtype == np.float32: |
| 86 | np.testing.assert_equal(t1.data_type(), singa_api.kFloat32) |
| 87 | elif np1.dtype == np.int32: |
| 88 | np.testing.assert_equal(t1.data_type(), singa_api.kInt) |
| 89 | |
| 90 | np.testing.assert_array_almost_equal(t1.shape(), np1.shape) |
| 91 | t1.ToDevice(d) |
| 92 | |
| 93 | |
| 94 | def print_t(t1): |