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

Method _shape_helper

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

Source from the content-addressed store, hash-verified

1706 self._squeeze_helper(gpu_dev)
1707
1708 def _shape_helper(self, dev):
1709 x = np.array([0.1, -1.0, 0.4, 4.0, -0.9,
1710 9.0]).reshape(3, 2).astype(np.float32)
1711 y = list(x.shape)
1712 dy = np.ones((3, 2), dtype=np.float32)
1713 grad = list(dy.shape)
1714
1715 x = tensor.from_numpy(x)
1716 dy = tensor.from_numpy(dy)
1717 x.to_device(dev)
1718 dy.to_device(dev)
1719
1720 result = autograd.shape(x)
1721 dx = result.creator.backward(dy.data)
1722
1723 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
1724 y,
1725 decimal=5)
1726 np.testing.assert_array_almost_equal(dx, grad, decimal=5)
1727
1728 def test_shape_cpu(self):
1729 self._shape_helper(cpu_dev)

Callers 2

test_shape_cpuMethod · 0.95
test_shape_gpuMethod · 0.95

Calls 4

shapeMethod · 0.80
reshapeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected