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

Method _squeeze_helper

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

Source from the content-addressed store, hash-verified

1677 self._Div_helper(gpu_dev)
1678
1679 def _squeeze_helper(self, dev):
1680 x = np.random.randn(3, 1, 2, 1, 1)
1681 y = x.reshape(3, 2)
1682 dy = np.random.randn(3, 2)
1683 grad = dy.reshape(3, 1, 2, 1, 1)
1684
1685 x = tensor.from_numpy(x)
1686 dy = tensor.from_numpy(dy)
1687 x.to_device(dev)
1688 dy.to_device(dev)
1689
1690 result = autograd.squeeze(x, [1, 3, 4])
1691 dx = result.creator.backward(dy.data)
1692
1693 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
1694 y,
1695 decimal=5)
1696 np.testing.assert_array_almost_equal(tensor.to_numpy(
1697 tensor.from_raw_tensor(dx)),
1698 grad,
1699 decimal=5)
1700
1701 def test_squeeze_cpu(self):
1702 self._squeeze_helper(cpu_dev)

Callers 2

test_squeeze_cpuMethod · 0.95
test_squeeze_gpuMethod · 0.95

Calls 3

reshapeMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected