def test_dotSum(self):
        A = VectorMatrix(Shape(10,10,10))
        B = VectorMatrix(Shape(10,10,10))

        for idx in range(A.size()):
            A.set(idx, (0.1*idx, 0.2*idx, -0.3*idx))
            B.set(idx, (-0.4*idx, 0.5*idx, -0.6*idx))
        self.assertTrue(abs(A.dotSum(B) - 79880040.0) < 0.1)
 def test_vectormatrix_to_numpy_1(self):
   A = VectorMatrix(Shape(10,10,10))
   A.fill((1.0, 2.0, 3.0))
   
   B = A.to_numpy()
   self.assertEquals((10,10,10,3), B.shape)
   self.assertTrue(np.all(B[:,:,:,0] == 1.0))
   self.assertTrue(np.all(B[:,:,:,1] == 2.0))
   self.assertTrue(np.all(B[:,:,:,2] == 3.0))
        def test_vectormatrix_to_numpy_1(self):
            A = VectorMatrix(Shape(10, 10, 10))
            A.fill((1.0, 2.0, 3.0))

            B = A.to_numpy()
            self.assertEquals((10, 10, 10, 3), B.shape)
            self.assertTrue(np.all(B[:, :, :, 0] == 1.0))
            self.assertTrue(np.all(B[:, :, :, 1] == 2.0))
            self.assertTrue(np.all(B[:, :, :, 2] == 3.0))
    def test_fill(self):
        m1 = VectorMatrix(Shape(10, 10, 10));
        m1.fill((1.0, 2.0, 3.0));

        self.assertEqual(m1.get(4, 4, 4), (1.0, 2.0, 3.0))
        self.assertEqual(m1.uniform_value, (1.0, 2.0, 3.0))
        self.assertTrue(m1.isUniform())

        m1.set(4, 4, 4, (3.0, 2.0, 1.0))
        self.assertEqual(m1.get(4, 4, 4), (3.0, 2.0, 1.0))
        self.assertEqual(m1.get(0, 1, 2), (1.0, 2.0, 3.0))
        self.assertFalse(m1.isUniform())
   def test_vectormatrix_to_numpy_2(self):
     def flub(x,y,z): return x*y*z, 42, (5*x)*(2-y) + 8*z
 
     A = VectorMatrix(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 + (3,), B.shape)
     for x,y,z in itertools.product(range(10), range(20), range(30)):
       f = flub(x,y,z)
       self.assertEquals(f[0], B[x,y,z,0])
       self.assertEquals(f[1], B[x,y,z,1])
       self.assertEquals(f[2], B[x,y,z,2])
Beispiel #6
0
  def test_dotSum(self):
    A = VectorMatrix(Shape(10,10,10))
    B = VectorMatrix(Shape(10,10,10))

    for idx in range(A.size()):
      A.set(idx, (0.1*idx, 0.2*idx, -0.3*idx))
      B.set(idx, (-0.4*idx, 0.5*idx, -0.6*idx))
    self.assertTrue(abs(A.dotSum(B) - 79880040.0) < 0.1)
        def test_vectormatrix_to_numpy_2(self):
            def flub(x, y, z):
                return x * y * z, 42, (5 * x) * (2 - y) + 8 * z

            A = VectorMatrix(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 + (3, ), B.shape)
            for x, y, z in itertools.product(range(10), range(20), range(30)):
                f = flub(x, y, z)
                self.assertEquals(f[0], B[x, y, z, 0])
                self.assertEquals(f[1], B[x, y, z, 1])
                self.assertEquals(f[2], B[x, y, z, 2])
Beispiel #8
0
  def test_fill(self):
    m1 = VectorMatrix(Shape(10, 10, 10));
    m1.fill((1.0, 2.0, 3.0));
    
    self.assertEqual(m1.get(4, 4, 4), (1.0, 2.0, 3.0))
    self.assertEqual(m1.uniform_value, (1.0, 2.0, 3.0))
    self.assertTrue(m1.isUniform())

    m1.set(4, 4, 4, (3.0, 2.0, 1.0))
    self.assertEqual(m1.get(4, 4, 4), (3.0, 2.0, 1.0))
    self.assertEqual(m1.get(0, 1, 2), (1.0, 2.0, 3.0))
    self.assertFalse(m1.isUniform())
Beispiel #9
0
 def test_average(self):
   A = VectorMatrix(Shape(10,10,10))
   for idx in range(A.size()):
     A.set(idx, (idx, 2*idx, 3*idx))
   self.assertTrue(A.average() == (999.0/2,2*999.0/2,3*999.0/2))
Beispiel #10
0
 def test_absMax(self):
   A = VectorMatrix(Shape(10,10,10))
   for idx in range(A.size()):
     A.set(idx, (10,10,10))
   A.set(500, (10,20,30))
   self.assertTrue(A.absMax() - 37.41657387 < 0.0001)
Beispiel #11
0
 def test_add_1(self):
   A = VectorMatrix(Shape(100,100,10))
   B = VectorMatrix(Shape(100,100,10))
   for idx in range(A.size()):
     A.set(idx, (1*idx, 2*idx, 3*idx))
     B.set(idx, (4*idx, 5*idx, 6*idx))
   A.add(B, 2.0)
   for idx in range(A.size()):
     self.assertEqual(A.get(idx), (9*idx, 12*idx, 15*idx))
Beispiel #12
0
 def test_fill(self):
   A = VectorMatrix(Shape(100,100,10))
   A.fill((1.0, 2.0, 3.0))
   for idx in range(A.size()):
     self.assertTrue(A.get(idx) == (1.0, 2.0, 3.0))
 def test_average(self):
     A = VectorMatrix(Shape(10,10,10))
     for idx in range(A.size()):
         A.set(idx, (idx, 2*idx, 3*idx))
     self.assertTrue(A.average() == (999.0/2,2*999.0/2,3*999.0/2))
 def test_absMax(self):
     A = VectorMatrix(Shape(10,10,10))
     for idx in range(A.size()):
         A.set(idx, (10,10,10))
     A.set(500, (10,20,30))
     self.assertTrue(A.absMax() - 37.41657387 < 0.0001)
 def test_add_1(self):
     A = VectorMatrix(Shape(100,100,10))
     B = VectorMatrix(Shape(100,100,10))
     for idx in range(A.size()):
         A.set(idx, (1*idx, 2*idx, 3*idx))
         B.set(idx, (4*idx, 5*idx, 6*idx))
     A.add(B, 2.0)
     for idx in range(A.size()):
         self.assertEqual(A.get(idx), (9*idx, 12*idx, 15*idx))
 def test_fill(self):
     A = VectorMatrix(Shape(100,100,10))
     A.fill((1.0, 2.0, 3.0))
     for idx in range(A.size()):
         self.assertTrue(A.get(idx) == (1.0, 2.0, 3.0))