def test_tensordot(self): a = np.array([1.1,1.1,1.1,1.1,1.4,1.3,1.1,1.6,1.1,1.1,1.1,1.2]) a = np.reshape(a,(2,3,2)) ta = tensor.from_numpy(a) res1 = np.tensordot(a, a, axes = 1) tres1 = tensor.tensordot(ta, ta, axes = 1) Tres1 = tensor.to_numpy(tres1) res2 = np.tensordot(a, a, axes = ([0,1],[2,1])) tres2 = tensor.tensordot(ta, ta, axes = ([0,1],[2,1])) Tres2 = tensor.to_numpy(tres2) self.assertAlmostEqual(np.sum(Tres1 - res1), 0., places=3) self.assertAlmostEqual(np.sum(Tres2 - res2), 0., places=3)
def test_tensordot(self): a = np.array( [1.1, 1.1, 1.1, 1.1, 1.4, 1.3, 1.1, 1.6, 1.1, 1.1, 1.1, 1.2]) a = np.reshape(a, (2, 3, 2)) ta = tensor.from_numpy(a) res1 = np.tensordot(a, a, axes=1) tres1 = tensor.tensordot(ta, ta, axes=1) Tres1 = tensor.to_numpy(tres1) self.assertAlmostEqual(np.sum(Tres1 - res1), 0., places=3) np.testing.assert_array_almost_equal(Tres1, res1) res2 = np.tensordot(a, a, axes=([0, 1], [2, 1])) tres2 = tensor.tensordot(ta, ta, axes=([0, 1], [2, 1])) np.testing.assert_array_almost_equal(tensor.to_numpy(tres2), res2)