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

Method _xor_broadcast_helper

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

Source from the content-addressed store, hash-verified

2168 self._or_broadcast_helper(gpu_dev)
2169
2170 def _xor_broadcast_helper(self, dev):
2171 cases = [
2172 ([3, 4, 5], [5]), # 3d vs 1d
2173 ([3, 4, 5], [4, 5]), # 3d vs 2d
2174 ([3, 4, 5, 6], [5, 6]), # 4d vs 2d
2175 ([3, 4, 5, 6], [4, 5, 6]), # 4d vs 3d
2176 ([1, 4, 1, 6], [3, 1, 5, 6]) # 4d vs 4d
2177 ]
2178 for in1, in2 in cases:
2179 x = (np.random.randn(*in1) > 0).astype(np.float32)
2180 x1 = (np.random.randn(*in2) > 0).astype(np.float32)
2181 y = np.logical_xor(x, x1)
2182
2183 x = tensor.from_numpy(x)
2184 x1 = tensor.from_numpy(x1)
2185 x.to_device(dev)
2186 x1.to_device(dev)
2187
2188 result = autograd._xor(x, x1)
2189 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
2190 y,
2191 decimal=5)
2192
2193 def test_xor_broadcast_cpu(self):
2194 self._xor_broadcast_helper(cpu_dev)

Callers 2

Calls 1

to_deviceMethod · 0.45

Tested by

no test coverage detected