Example #1
0
def test_lu_matmul(self):
        L, U, P = ra.lu(self.exMatrix)
        PM = P @ self.exMatrix
        LU = L @ U
        PiLU = ra.inv(P) @ L @ U
        
        myEqual = lambda x,y: all(x.value.flat == y.value.flat)
        self.assertTrue(myEqual(PM, LU))
        self.assertTrue(myEqual(self.exMatrix, PiLU))
Example #2
0
 def setUp(self):
     self.exMatrix = ra.RationalMatrix((10*np.random.rand(5,5)).astype(int))
     self.exMatrix2 = ra.RationalMatrix((10*np.random.rand(5,5)).astype(int))
     self.matAdd1 = self.exMatrix + self.exMatrix2
     self.matAdd2 = self.exMatrix2 + self.exMatrix
     self.intAdd1 = 5 + self.exMatrix
     self.intAdd2 = self.exMatrix + 5
     self.fracAdd1 = Fr(1,3) + self.exMatrix
     self.fracAdd2 = self.exMatrix + Fr(1,3)
     self.floatAdd1 = 0.5 + self.exMatrix
     self.floatAdd2 = self.exMatrix + 0.5
Example #3
0
 def setUp(self):
     self.exMatrix = ra.RationalMatrix((10*np.random.rand(5,5)).astype(int))
     self.intMultiply1 = 5 * self.exMatrix
     self.intMultiply2 = self.exMatrix * 5
     self.fracMultiply1 = Fr(1,3) * self.exMatrix
     self.fracMultiply2 = self.exMatrix * Fr(1,3)
     self.floatMultiply1 = 0.5 * self.exMatrix
     self.floatMultiply2 = self.exMatrix * 0.5
Example #4
0
 def setUp(self):
     self.exColumnVector = ra.RationalVector((10*np.random.rand(5,1)).astype(int))
     self.intMultiply1 = 5 * self.exColumnVector
     self.intMultiply2 = self.exColumnVector * 5
     self.fracMultiply1 = Fr(1,3) * self.exColumnVector
     self.fracMultiply2 = self.exColumnVector * Fr(1,3)
     self.floatMultiply1 = 0.5 * self.exColumnVector
     self.floatMultiply2 = self.exColumnVector * 0.5
Example #5
0
 def test_inverse(self):
     invM = ra.inv(self.exMatrix)
     self.assertEqual(invM.value[1,2], Fr(63, 3800))
     self.assertEqual(invM.value[1,4], Fr(-99, 3800))
     self.assertEqual(invM.value[3,3], Fr(1))
     self.assertEqual(invM.value[0,3], Fr(0))
     self.assertEqual(type(invM.value[1,4]), Fr)
     self.assertEqual(type(invM), ra.RationalMatrix)
     self.assertEqual(invM.value.shape, (5, 5))
Example #6
0
 def setUp(self):
     self.exMatrix = ra.RationalMatrix(np.zeros((5,5)).astype(int))
     self.exMatrix.value[2,4] = Fr(11,7)
     self.exMatrix.value[1,2] = Fr(3,5)
     
     self.exColumnVector = ra.RationalVector(np.zeros((5,1)).astype(int))
     self.exColumnVector.value[2] = Fr(3,4)
     self.exColumnVector.value[4] = Fr(9,2)
     
     self.exRowVector = ra.RationalVector(np.zeros((1,5)).astype(int))
     self.exRowVector.value[0][2] = Fr(5,7)
     self.exRowVector.value[0][0] = Fr(9,2)
     
     self.mulMM = self.exMatrix @ self.exMatrix
     self.mulMC = self.exMatrix @ self.exColumnVector
     self.mulCR = self.exColumnVector @ self.exRowVector
     self.mulRM = self.exRowVector @ self.exMatrix
     self.mulRC = self.exRowVector @ self.exColumnVector
Example #7
0
 def test_inverse_matmul(self):
     invM = ra.inv(self.exMatrix)
     I1 = invM @ self.exMatrix
     I2 = self.exMatrix @ invM
     
     myEqual = lambda x,y: all(x.value.flat == y.value.flat)
     self.assertTrue(myEqual(I1, I2))
     self.assertEqual(I1.value[2,2], Fr(1))
     self.assertEqual(I1.value[1,2], Fr(0))
     self.assertEqual(type(I1.value[1,4]), Fr)
     self.assertEqual(type(I1), ra.RationalMatrix)
     self.assertEqual(I1.value.shape, (5, 5))
Example #8
0
 def setUp(self):
     self.exRowVector = ra.RationalVector((10*np.random.rand(1,5)).astype(int))
     self.exRowVector2 = ra.RationalVector((10*np.random.rand(1,5)).astype(int))
     self.exColumnVector = ra.RationalVector((10*np.random.rand(5,1)).astype(int))
     self.exColumnVector2 = ra.RationalVector((10*np.random.rand(5,1)).astype(int))
     
     self.rowVecAdd1 = self.exRowVector + self.exRowVector2
     self.rowVecAdd2 = self.exRowVector2 + self.exRowVector
     self.colVecAdd1 = self.exColumnVector + self.exColumnVector2
     self.colVecAdd2 = self.exColumnVector2 + self.exColumnVector
     self.intRowAdd1 = 5 + self.exRowVector
     self.intRowAdd2 = self.exRowVector + 5
     self.fracRowAdd1 = Fr(1,3) + self.exRowVector
     self.fracRowAdd2 = self.exRowVector + Fr(1,3)
     self.floatRowAdd1 = 0.5 + self.exRowVector
     self.floatRowAdd2 = self.exRowVector + 0.5
     self.intColAdd1 = 5 + self.exColumnVector
     self.intColAdd2 = self.exColumnVector + 5
     self.fracColAdd1 = Fr(1,3) + self.exColumnVector
     self.fracColAdd2 = self.exColumnVector + Fr(1,3)
     self.floatColAdd1 = 0.5 + self.exColumnVector
     self.floatColAdd2 = self.exColumnVector + 0.5
Example #9
0
 def test_lu_decomposition(self):
     L, U, P = ra.lu(self.exMatrix)
     self.assertEqual(L.value[4,2], Fr(3, 71))
     self.assertEqual(L.value[2,4], Fr(0))
     self.assertEqual(U.value[4,4], Fr(760, 497))
     self.assertEqual(U.value[2,4], Fr(1))
     self.assertEqual(U.value[2,1], Fr(0))
     self.assertEqual(P.value[4,2], Fr(1))
     self.assertEqual(P.value[4,3], Fr(0))
     
     self.assertEqual(type(L.value[1,4]), Fr)
     self.assertEqual(type(L), ra.RationalMatrix)
     self.assertEqual(L.value.shape, (5, 5))
     self.assertEqual(type(U.value[1,4]), Fr)
     self.assertEqual(type(U), ra.RationalMatrix)
     self.assertEqual(U.value.shape, (5, 5))
     self.assertEqual(type(P.value[1,4]), Fr)
     self.assertEqual(type(P), ra.RationalMatrix)
     self.assertEqual(P.value.shape, (5, 5))
Example #10
0
 def setUp(self):
     self.exMatrix = ra.RationalMatrix(np.identity(5).astype(int))
     self.exMatrix.value[2,4] = Fr(11,7)
     self.exMatrix.value[1,2] = Fr(3,5)
     self.exMatrix.value[4,2] = Fr(71,3)
Example #11
0
 def setUp(self):
     self.exMatrixA = ra.RationalMatrix((10*np.random.rand(5,5)).astype(int))
     self.exMatrixB = ra.RationalMatrix((10*np.random.rand(5,5)).astype(int))
     self.exMatrixC = ra.RationalMatrix((10*np.random.rand(5,5)).astype(int))
     self.exMatrixD = ra.RationalMatrix((10*np.random.rand(5,5)).astype(int))
Example #12
0
 def setUp(self):
     self.exMatrix = ra.RationalMatrix(np.zeros((5,5)).astype(int))
     self.exColumnVector = ra.RationalVector(np.zeros((5,1)).astype(int))
     self.exRowVector = ra.RationalVector(np.zeros((1,5)).astype(int))
Example #13
0
 def setUp(self):
     self.exMatrix = ra.RationalMatrix((10*np.random.rand(5,5)).astype(int))
     self.exRowVector = ra.RationalVector((10*np.random.rand(1,5)).astype(int))
     self.exColumnVector = ra.RationalVector((10*np.random.rand(5,1)).astype(int))