def test_with(m): i = sage.all.identity_matrix(m.nrows()).column(1).column() assert i.nrows() == m.nrows() mZ = flint.fmpz_mat(m) mQ = flint.fmpq_mat((Integer(1), mZ)) iZ = flint.fmpz_mat(i) iQ = flint.fmpq_mat((Integer(1), iZ)) try: sS = m.solve_right(i) except: write("-") singular_test(mZ, mQ, iZ, iQ) return Xd, d = mZ.solve_right(iZ) S_by_d_sage = sage.all.matrix(ZZ, d * sS) S_by_d = flint.fmpz_mat(S_by_d_sage) if Xd != S_by_d: print "integer solve_right() failed, m=\n", m sys.exit(1) X = flint.fmpq_mat((d, Xd)) Y = mQ.solve_dixon(iQ) assert X == Y write("+") if watch_canonical: " check if raw_str() of X and Y are equal " Xr, Yr = X.raw_str(), Y.raw_str() if Xr != Yr: print "m=\n", m print "Xr=%s" % Xr print "Yr=%s" % Yr
def test_with( m ): ''' sage method only called once, do not need to clean cache ''' global t_sage, t__inv, t_matz, t_Dixon i=sage.all.identity_matrix( m.nrows() ) mZ=flint.fmpz_mat( m ) mQ=flint.fmpq_mat( (Integer(1), mZ) ) iZ=flint.fmpz_mat( i ) iQ=flint.fmpq_mat( (Integer(1),iZ) ) try: t0=time.time() sS=m.inverse() except: t_sage += time.time()-t0 # ups, this subroutine can be removed, so # the whole file could be a dozen lines shorter singular_test( mZ, mQ, iZ, iQ ) return t1=time.time() t_sage += t1-t0 Xd,d=mZ.solve_right(iZ) t2=time.time() t_matz += t2-t1 Y=mQ.solve_dixon( iQ ) t3=time.time() t_Dixon += t3-t2 W=mQ.inverse() t__inv += time.time()-t3
def test_with( m ): i=sage.all.identity_matrix( m.nrows() ) mZ=flint.fmpz_mat( m ) mQ=flint.fmpq_mat( (Integer(1), mZ) ) iZ=flint.fmpz_mat( i ) iQ=flint.fmpq_mat( (Integer(1),iZ) ) try: sS=m.inverse() except: write('-') singular_test( mZ, mQ, iZ, iQ ) return Xd,d=mZ.solve_right(iZ) S_by_d_sage=sage.all.matrix( ZZ, d*sS ) S_by_d=flint.fmpz_mat( S_by_d_sage ) if Xd != S_by_d: print 'integer solve_right() failed, m=\n',m sys.exit(1) X=flint.fmpq_mat( (d, Xd) ) Y=mQ.solve_dixon( iQ ) W=mQ.inverse() assert X == Y assert Y == W write('+') if watch_canonical: ' check if raw_str() of X, Y and W differ ' Xr,Yr,Wr=X.raw_str(),Y.raw_str(),W.raw_str() m_printed=0 if Xr != Yr: print 'm=\n',m print 'Xr=%s' % Xr print 'Yr=%s' % Yr m_printed=1 if Yr != Wr: if not m_printed: print 'm=\n',m print 'Yr=%s' % Yr print 'Wr=%s' % Wr
def test_with(m): global t_sage, t_matz, t_matq i = sage.all.identity_matrix(m.nrows()).column(1).column() mZ = flint.fmpz_mat(m) mQ = flint.fmpq_mat((Integer(1), mZ)) iZ = flint.fmpz_mat(i) iQ = flint.fmpq_mat((Integer(1), iZ)) singular = 0 t0 = time.time() try: sS = m.solve_right(i) except: write("-") singular = 1 t1 = time.time() Xd, d = mZ.solve_right(iZ) t2 = time.time() Y = mQ.solve_dixon(iQ) t3 = time.time() t_sage += t1 - t0 t_matz += t2 - t1 t_matq += t3 - t2 if not singular: write("+")
def flint_0(A): Aq = flint.fmpq_mat((Integer(1), A)) return A, Aq.inverse()