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

Method _negative_helper

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

Source from the content-addressed store, hash-verified

2046 self._xor_helper(gpu_dev)
2047
2048 def _negative_helper(self, dev):
2049 X = np.array([0.1, 0, 0.4, 1. - 4, 0.9,
2050 -2.0]).reshape(3, 2).astype(np.float32)
2051 XT = np.negative(X)
2052 DY = np.ones((3, 2), dtype=np.float32)
2053
2054 x = tensor.from_numpy(X)
2055 dy = tensor.from_numpy(DY)
2056 x.to_device(dev)
2057 dy.to_device(dev)
2058
2059 result = autograd.negative(x)
2060 dx = result.creator.backward(dy.data)
2061 DX = np.negative(DY)
2062
2063 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
2064 XT,
2065 decimal=5)
2066 np.testing.assert_array_almost_equal(tensor.to_numpy(
2067 tensor.from_raw_tensor(dx)),
2068 DX,
2069 decimal=5)
2070
2071 def test_negative_cpu(self):
2072 self._negative_helper(cpu_dev)

Callers 2

test_negative_cpuMethod · 0.95
test_negative_gpuMethod · 0.95

Calls 3

reshapeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected