def test_exception_from_cpp(self): try: et.ones((2, )).item() # This is going to throw except et.EtError: pass else: self.fail("Exception thrown from C++ not catched by Python")
def test_assignment(self): a = et.ones((4, 4)) b = et.zeros((4, )) a[0] = b self.assertEqual(a.sum().item(), 12) self.assertEqual(a[:, 0].realize().sum().item(), 3)
def test_contruct_numpy_array(self): t = et.ones((4, 4)) a = np.array(t) self.assertEqual(len(a.shape), 2) self.assertEqual(a.shape[0], 4) self.assertEqual(a.shape[1], 4)
def test_numpy(self): t = et.ones((4, 4)) a = t.numpy() self.assertEqual(len(a.shape), 2)
def test_tensor_assignment(self): t = et.ones((2, 2)) try: t[:2, :2] = et.zeros((1, 1)) except et.EtError: self.fail("Tensor assignment failed")
def test_scalar_assignment(self): t = et.ones((2, 2)) try: t[:2, :2] = 1 except et.EtError: self.fail("Scalar assignment failed")
def test_integer_division_type(self): a = et.ones((1)) b = et.ones((1)) # Unlike Python, PyEtaler follows the C/C++ opetor type conversion self.assertEqual((a / b).dtype(), et.DType.Int32)
def test_view(self): a = et.ones((4, 4)) b = a[:2, :2] b[:] -= 1 self.assertEqual(a.sum().item(), 12)
def test_tolist(self): a = et.ones((9, 3)) self.assertEqual(len(a.tolist()), 9) self.assertEqual(len(a.tolist()[0]), 3) self.assertEqual(type(a.tolist()), list)
def test_tohost(self): a = et.ones((3, 3)) v = a.toHost() self.assertEqual(v.size(), a.size())
def test_reshape(self): a = et.ones((4, 4)) a = a.reshape((16, )) self.assertEqual(a.shape(), et.Shape([ 16, ]))