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

Method _and_broadcast_helper

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

Source from the content-addressed store, hash-verified

2108 self._reciprocal_helper(gpu_dev)
2109
2110 def _and_broadcast_helper(self, dev):
2111 cases = [
2112 ([3, 4, 5], [5]), # 3d vs 1d
2113 ([3, 4, 5], [4, 5]), # 3d vs 2d
2114 ([3, 4, 5, 6], [5, 6]), # 4d vs 2d
2115 ([3, 4, 5, 6], [4, 5, 6]), # 4d vs 3d
2116 ([1, 4, 1, 6], [3, 1, 5, 6]) # 4d vs 4d
2117 ]
2118 for in1, in2 in cases:
2119 x = (np.random.randn(*in1) > 0).astype(np.float32)
2120 x1 = (np.random.randn(*in2) > 0).astype(np.float32)
2121 y = np.logical_and(x, x1)
2122
2123 x = tensor.from_numpy(x)
2124 x1 = tensor.from_numpy(x1)
2125 x.to_device(dev)
2126 x1.to_device(dev)
2127
2128 result = autograd._and(x, x1)
2129 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
2130 y,
2131 decimal=5)
2132
2133 def test_and_broadcast_cpu(self):
2134 self._and_broadcast_helper(cpu_dev)

Callers 2

Calls 1

to_deviceMethod · 0.45

Tested by

no test coverage detected