def test_pythonic_ops(self): s = et.Shape((1, 2, 3, 4, 5)) self.assertEqual(s[3], 4) self.assertEqual(s[:2], et.Shape([1, 2])) self.assertIn(3, s) self.assertNotIn(9000, s) s[:2] = [7, 7] self.assertEqual(s, et.Shape([7, 7, 3, 4, 5]))
def test_pythonic_ops(self): a = np.array([1, 2, 3, 4, 5, 6]).reshape(3, 2) t = et.Tensor.from_numpy(a) self.assertEqual(t[0:2].shape(), et.Shape([2, 2])) self.assertEqual(t[0::2].shape(), et.Shape([2, 2])) self.assertEqual(t[0, 0].item(), 1) self.assertEqual(len(t.toHost()), 6) try: t.item() self.fail( "et.Tensor.item() should fail when tensor is not a scalar") except: pass
def test_to_list(self): s = et.Shape((4, 3, 2, 1)) l = s.to_list() self.assertEqual(type(l), list) self.assertEqual(len(l), s.size()) for i in range(4): self.assertEqual(l[i], s[i])
def test_creation(self): a = np.array([1, 2, 3, 4, 5, 6]).reshape(3, 2) t = et.Tensor.from_numpy(a) self.assertEqual(t.shape(), et.Shape([3, 2]))
def test_python_interop(self): s = et.Shape([5, 6, 7, 8]) self.assertEqual(sum(s), 26)
def test_stringify(self): self.assertEqual('<' in str(et.Shape()), False)
def test_reshape(self): a = et.ones((4, 4)) a = a.reshape((16, )) self.assertEqual(a.shape(), et.Shape([ 16, ]))
def test_creation(self): s = et.Shape([60, 60]) self.assertEqual(s.volume(), 3600) self.assertEqual(s.size(), 2) self.assertEqual(len(s), 2) # cppyy should have wrapped this