Exemple #1
0
 def testNoHashCollisionAfterTranspose(self):
     n = 2
     m = 3
     _, B = expr_testutils.GetMatricesSumMul(n, m, expr_impl=ExprSymbolic)
     X = B.Marginalize(axis=1)
     Y = (B.Marginalize(axis=1)).Transpose()
     self.assertNotEquals(X, Y)
  def testEnd2EndNoHashCollision(self):
    n = 2
    m = 3
    A, B = expr_testutils.GetMatricesSumMul(n, m, expr_impl=ExprZp)
    B = B.Transpose()

    A1 = copy.copy(A)
    B1 = copy.copy(B)
    B1 = B1.Marginalize(axis=1)
    A1 = A1.Multiply(B1)
    A1 = A1.Marginalize(axis=0)
    s1 = ('(np.sum((np.dot(A, (np.sum((B.transpose()), axis=1,'
        ' keepdims=True)))), axis=0, keepdims=True))')
    self.assertEquals(s1, A1.comp[NUMPY])

    A2 = copy.copy(A)
    B2 = copy.copy(B)
    A2 = A2.Marginalize(axis=1)
    B2 = B2.Marginalize(axis=0)
    B2 = B2.Multiply(A2)
    s2 = ('(np.dot((np.sum((B.transpose()), axis=0, keepdims=True)),'
        ' (np.sum(A, axis=1, keepdims=True))))')
    self.assertEquals(s2, B2.comp[NUMPY])
    self.assertEquals((1, 1), A1.expressions.shape)
    self.assertEquals((1, 1), B2.expressions.shape)
    print "DEBUG:"
    print A1.expressions[0, 0].PrintDebug()
    print B2.expressions[0, 0].PrintDebug()
    self.assertNotEquals(A1, B2)
Exemple #3
0
 def testSumMultiplyWorks(self):
     n = 2
     m = 3
     A = expr_testutils.GetMatricesSumMul(n, m, expr_impl=ExprSymbolic)[0]
     B = A.Marginalize(axis=0)
     B = B.Marginalize(axis=1)
     A = A.Marginalize(axis=0)
     A = A.Marginalize(axis=1)
     self.assertEquals(A, B)
Exemple #4
0
 def testNoHashCollisionTwoMatricesWithOne(self):
     # (((B.sum(axis=1)) * (A.sum(axis=0))).sum(axis=1))
     n = 2
     m = 3
     A, B = expr_testutils.GetMatricesSumMul(n, m, expr_impl=ExprSymbolic)
     X = B.Marginalize(axis=1)
     Y = A.Marginalize(axis=0)
     Z = (X.Multiply(Y)).Marginalize(axis=1)
     self.assertNotEquals(X, Z)
 def testSumMultiplyWorks(self):
   n = 2
   m = 3
   A, B = expr_testutils.GetMatricesSumMul(n, m, expr_impl=ExprZp)
   B = B.Transpose()
   #A.PrintDebug()
   #B.PrintDebug()
   B.Marginalize(axis=0)
   A.Marginalize(axis=1)
   #A.PrintDebug()
   #B.PrintDebug()
   A.Multiply(B)
   #A.PrintDebug()
   self.assertEquals(1, 1)
Exemple #6
0
 def testAddSubNumber(self):
     n = 2
     m = 3
     C = expr_testutils.GetMatricesSumMul(n, m, expr_impl=ExprSymbolic)[0]
     D = C.Add(10)
     D = D.Sub(4)
     C = C.Marginalize(axis=0).Marginalize(axis=1)
     D = D.Marginalize(axis=0).Marginalize(axis=1)
     self.assertNotEquals(C, D)
     A = np.array(np.random.randn(n, m))
     print A
     val_C = eval(C.comp[NUMPY])
     val_D = eval(D.comp[NUMPY])
     self.assertTrue(abs(val_C + 6 * 2 * 3 - val_D) < 1e-4)
Exemple #7
0
 def testMultiplyNumber(self):
     n = 2
     m = 3
     C = expr_testutils.GetMatricesSumMul(n, m, expr_impl=ExprSymbolic)[0]
     D = C.ElementwiseMultiply(10)
     C = C.Marginalize(axis=0).Marginalize(axis=1)
     D = D.Marginalize(axis=0).Marginalize(axis=1)
     print "C", C
     print "D", D
     self.assertEquals(C, D)
     A = np.array(np.random.randn(n, m))
     print A
     val_C = eval(C.comp[NUMPY])
     val_D = eval(D.comp[NUMPY])
     self.assertTrue(abs(10 * val_C - val_D) < 1e-4)
Exemple #8
0
 def testSubMatrices(self):
     n = 2
     m = 3
     A = np.array(np.random.randn(n, m))
     B = np.array(np.random.randn(n, m))
     print A
     print B
     C, D = expr_testutils.GetMatricesSumMul(n, m, expr_impl=ExprSymbolic)
     E = D.Marginalize(axis=0).Marginalize(axis=1)
     val_E = eval(E.comp[NUMPY])
     D = D.Sub(C)
     C = C.Marginalize(axis=0).Marginalize(axis=1)
     D = D.Marginalize(axis=0).Marginalize(axis=1)
     self.assertNotEquals(C, D)
     val_C = eval(C.comp[NUMPY])
     val_D = eval(D.comp[NUMPY])
     print D.comp
     self.assertTrue(abs(val_E - val_C - val_D) < 1e-4)