MCPcopy Create free account
hub / github.com/apache/singa / cast_test

Method cast_test

test/python/test_operation.py:3095–3111  ·  view source on GitHub ↗
(self, dev)

Source from the content-addressed store, hash-verified

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)

Callers 2

test_cast_cpuMethod · 0.95
test_cast_gpuMethod · 0.95

Calls 2

to_deviceMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected