def testUnimod3x3_2(self): m = sympy.Matrix([15, 21, 35]) m2 = matrix.appendIdentity(m) m3 = matrix.unimod(m2) exp = sympy.Matrix([[1, 1, 1, -1], [0, 7, 0, -3], [0, -7, -5, 6]]) self.assertEqual(exp, m3)
def testUnimod3x3(self): m = sympy.Matrix([9, 5, 17]) m2 = matrix.appendIdentity(m) m3 = matrix.unimod(m2) exp = sympy.Matrix([[1, 0, 7, -2], [0, 1, 5, -2], [0, 0, -17, 5]]) self.assertEqual(exp, m3)
def testUnimod8x8(self): m = sympy.Matrix([865, 4831, -6700, 7496, 8474, 2851, -5451]) m2 = matrix.appendIdentity(m) m3 = matrix.unimod(m2) exp = sympy.Matrix([[1, 150, 0, 0, 0, 0, 52, 51], [0, 148, 1, 0, 0, 0, 49, 50], [0, -198, 0, 0, 0, 1, -71, -67], [0, -233, 0, 0, 0, 0, -88, -83], [0, -373, 0, -1, 0, 0, -132, -127], [0, -566, 0, 0, 1, 0, -198, -192], [0, -753, 0, 0, 0, 0, -261, -256]]) self.assertEqual(exp, m3)
def _invert_matrix(unknowns, coeffs, k_symbols): """ Invert the matrix by unimodular row reduction """ a_transpose = sympy.Matrix(_sorted_coeffs(unknowns, coeffs)) a_transpose_augmented = matrix.appendIdentity(a_transpose) r_t = matrix.unimod(a_transpose_augmented) r = r_t[:, 0] t = r_t[:, 1:] r_transpose = r.transpose() t_transpose = t.transpose() K = sympy.Matrix(k_symbols) r_transpose_K = r_transpose * K if r_transpose_K.shape != (1, 1): raise TypeError('expected 1x1') unknownsMatrix = t_transpose * K print "Unknowns:\n%s\nK:\n%s" % (unknownsMatrix, K) return unknownsMatrix
def testUnimod2x2(self): m = sympy.Matrix([9, 5]) m2 = matrix.appendIdentity(m) m3 = matrix.unimod(m2) exp = sympy.Matrix([[1, -1, 2], [0, 5, -9]]) self.assertEqual(exp, m3)
def testAppend2x2(self): m = sympy.Matrix([5, 9]) m2 = matrix.appendIdentity(m) exp = sympy.Matrix([[5, 1, 0], [9, 0, 1]]) self.assertEqual(exp, m2)
def testGcd2(self): m = sympy.Matrix([[2, 6, 12, 26]]) m2 = matrix.appendIdentity(m) gcd = matrix.calculateGcd(m2) exp = 2 self.assertEqual(exp, gcd)