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

Method _transpose_helper

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

Source from the content-addressed store, hash-verified

1364 self._Sqrt_helper(gpu_dev)
1365
1366 def _transpose_helper(self, dev):
1367 x = np.random.randn(3, 2, 1)
1368 y = x.transpose(1, 2, 0)
1369 dy = np.random.randn(*(y.shape))
1370 grad = dy.transpose((2, 0, 1))
1371
1372 x = tensor.from_numpy(x)
1373 dy = tensor.from_numpy(dy)
1374 x.to_device(dev)
1375 dy.to_device(dev)
1376
1377 result = autograd.transpose(x, (1, 2, 0))
1378 dx = result.creator.backward(dy.data)
1379 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
1380 y,
1381 decimal=5)
1382 np.testing.assert_array_almost_equal(tensor.to_numpy(
1383 tensor.from_raw_tensor(dx)),
1384 grad,
1385 decimal=5)
1386
1387 def test_transpose_cpu(self):
1388 self._transpose_helper(cpu_dev)

Callers 2

test_transpose_cpuMethod · 0.95
test_transpose_gpuMethod · 0.95

Calls 3

transposeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected