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

Method _reshape_helper

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

Source from the content-addressed store, hash-verified

1492 self._mul_helper(gpu_dev)
1493
1494 def _reshape_helper(self, dev):
1495 x = np.array([0.1, -1.0, 0.4, 4.0, -0.9,
1496 9.0]).reshape(3, 2).astype(np.float32)
1497 y = x.reshape(2, 3)
1498 dy = np.array([1, 2, 3, 4, 5, 6]).reshape(2, 3).astype(np.float32)
1499 grad = dy.reshape(3, 2)
1500
1501 x = tensor.from_numpy(x)
1502 dy = tensor.from_numpy(dy)
1503 x.to_device(dev)
1504 dy.to_device(dev)
1505
1506 result = autograd.reshape(x, (2, 3))
1507 dx = result.creator.backward(dy.data)
1508
1509 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
1510 y,
1511 decimal=5)
1512 np.testing.assert_array_almost_equal(tensor.to_numpy(
1513 tensor.from_raw_tensor(dx)),
1514 grad,
1515 decimal=5)
1516
1517 def test_reshape_cpu(self):
1518 self._reshape_helper(cpu_dev)

Callers 2

test_reshape_cpuMethod · 0.95
test_reshape_gpuMethod · 0.95

Calls 3

reshapeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected