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

Method _Identity_helper

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

Source from the content-addressed store, hash-verified

664 self._Exp_helper(gpu_dev)
665
666 def _Identity_helper(self, dev):
667 x = np.array([-0.9, -0.3, -0.1, 0.1, 0.5,
668 0.9]).reshape(3, 2).astype(np.float32)
669 y = x.copy()
670 grad = np.ones(x.shape)
671 x = tensor.from_numpy(x)
672 x.to_device(dev)
673
674 result = autograd.identity(x)
675 dy = tensor.from_numpy(np.ones((3, 2)).astype(np.float32))
676 dy.to_device(dev)
677 dx = result.creator.backward(dy.data)
678
679 np.testing.assert_array_almost_equal(tensor.to_numpy(result),
680 y,
681 decimal=5)
682 np.testing.assert_array_almost_equal(tensor.to_numpy(
683 tensor.from_raw_tensor(dx)),
684 grad,
685 decimal=5)
686 self.check_shape(dx.shape(), (3, 2))
687
688 def test_Identity_cpu(self):
689 self._Identity_helper(cpu_dev)

Callers 2

test_Identity_cpuMethod · 0.95
test_Identity_gpuMethod · 0.95

Calls 6

check_shapeMethod · 0.95
shapeMethod · 0.80
reshapeMethod · 0.45
copyMethod · 0.45
to_deviceMethod · 0.45
backwardMethod · 0.45

Tested by

no test coverage detected