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

Method _Pow_helper

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

Source from the content-addressed store, hash-verified

1194 self._Sub_helper(gpu_dev)
1195
1196 def _Pow_helper(self, dev):
1197 X0 = np.array([7, 5, 0.2, 0.1, 0.3, 4]).reshape(3, 2).astype(np.float32)
1198 X1 = np.array([-1.0, 2.0, -1.0, -2.1, 1.0,
1199 -2.0]).reshape(3, 2).astype(np.float32)
1200 XT = np.power(X0, X1)
1201
1202 DY = np.ones((3, 2), dtype=np.float32)
1203 x0 = tensor.from_numpy(X0)
1204 x1 = tensor.from_numpy(X1)
1205 dy = tensor.from_numpy(DY)
1206 x0.to_device(dev)
1207 x1.to_device(dev)
1208 dy.to_device(dev)
1209
1210 result = autograd.pow(x0, x1)
1211 dx0, dx1 = result.creator.backward(dy.data)
1212
1213 G0 = np.multiply(X1, np.power(X0, (X1 - 1.0)))
1214 DX0 = np.multiply(G0, DY)
1215 G1 = np.multiply(np.power(X0, X1), np.log(X0))
1216 DX1 = np.multiply(G1, DY)
1217
1218 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
1219 XT,
1220 decimal=5)
1221 np.testing.assert_array_almost_equal(tensor.to_numpy(
1222 tensor.from_raw_tensor(dx0)),
1223 DX0,
1224 decimal=4)
1225 np.testing.assert_array_almost_equal(tensor.to_numpy(
1226 tensor.from_raw_tensor(dx1)),
1227 DX1,
1228 decimal=4)
1229
1230 def test_Pow_cpu(self):
1231 self._Pow_helper(cpu_dev)

Callers 2

test_Pow_cpuMethod · 0.95
test_Pow_gpuMethod · 0.95

Calls 3

reshapeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected