def test_matrix_to_numpy_1(self): A = Matrix(Shape(10,10,10)) A.fill(42.0) B = A.to_numpy() self.assertEquals((10,10,10), B.shape) self.assertTrue(np.all(B[:,:,:] == 42.0))
def test_matrix_to_numpy_1(self): A = Matrix(Shape(10, 10, 10)) A.fill(42.0) B = A.to_numpy() self.assertEquals((10, 10, 10), B.shape) self.assertTrue(np.all(B[:, :, :] == 42.0))
def test_matrix_to_numpy_2(self): def flub(x,y,z): return x*y*z + 42 + (5*x)*(2-y) + 8*z A = Matrix(Shape(10,20,30)) for x,y,z in itertools.product(range(10), range(20), range(30)): A.set(x,y,z, flub(x,y,z)) B = A.to_numpy() self.assertEquals(A.shape, B.shape) for x,y,z in itertools.product(range(10), range(20), range(30)): self.assertEquals(flub(x,y,z), B[x,y,z])
def test_fill(self): m1 = Matrix(Shape(10, 10, 10)) m1.fill(1.0) self.assertEqual(m1.get(4, 4, 4), 1.0) self.assertEqual(m1.uniform_value, 1.0) self.assertTrue(m1.isUniform()) m1.set(4, 4, 4, 2.0) self.assertEqual(m1.get(4, 4, 4), 2.0) self.assertFalse(m1.isUniform())
def test_matrix_to_numpy_2(self): def flub(x, y, z): return x * y * z + 42 + (5 * x) * (2 - y) + 8 * z A = Matrix(Shape(10, 20, 30)) for x, y, z in itertools.product(range(10), range(20), range(30)): A.set(x, y, z, flub(x, y, z)) B = A.to_numpy() self.assertEquals(A.shape, B.shape) for x, y, z in itertools.product(range(10), range(20), range(30)): self.assertEquals(flub(x, y, z), B[x, y, z])
def test_fill(self): m1 = Matrix(Shape(10, 10, 10)); m1.fill(1.0) self.assertEqual(m1.get(4, 4, 4), 1.0) self.assertEqual(m1.uniform_value, 1.0) self.assertTrue(m1.isUniform()) m1.set(4, 4, 4, 2.0); self.assertEqual(m1.get(4, 4, 4), 2.0) self.assertFalse(m1.isUniform())