Exemple #1
0
def test_matrice(S):
 m=S.nrows()
 aF_again=fmpz_mat( S )
 PR,LU=flint.tmod_mat_PLU( aF_again )
 if PR == None:
  print_tmod_mat_PLU_error( S, None, 'empty result' )
  sys.exit(1)
 L_sage,U_sage=flint.export_L_sage(LU),flint.export_U_sage(LU)
 tmod_mat_PLU_error=0
 aS_again = flint.tmod_mat_permute_fmpz_mat( PR, fmpz_mat(S) ).export_sage()
 if not ((aS_again - L_sage * U_sage) % w_modulo).is_zero():
  tmod_mat_PLU_error=1
  print_tmod_mat_PLU_error( S, LU, 'P*S != L*U' )
  print ' left part:\n',tmod_pretty_m(aS_again)
  print 'right part:\n',tmod_pretty_m(L_sage * U_sage)
 WL_inv=flint.tmod_mat_solver( PR, LU )
 Wti,Lti=flint.export_Wti( WL_inv ),flint.export_Lti( WL_inv )
 W=U_sage.matrix_from_rows( range(m-1) )
 if (Wti*W.T) % w_modulo != identity_matrix(ZZ,m-1):
  if not tmod_mat_PLU_error:
   tmod_mat_PLU_error=1
   print_tmod_mat_PLU_error( S, LU, 'Wti check failed' )
  print 'Wti=\n',tmod_pretty_m(Wti)
  print 'U=\n',tmod_pretty_m(U_sage)
  print 'W=\n',tmod_pretty_m(W)
 if (Lti*L_sage.T) % w_modulo != identity_matrix(ZZ,m):
  if not tmod_mat_PLU_error:
   tmod_mat_PLU_error=1
   print_tmod_mat_PLU_error( S, LU, 'Lti check failed' )
  print 'solver out=\n',tmod_pretty_m( WL_inv.export_sage() )
  print 'Lti=\n',tmod_pretty_m(Lti)
  print 'L.T=\n',tmod_pretty_m(L_sage.T)
 if tmod_mat_PLU_error:
  sys.exit(1)
def test_matrice(S,dim):
 t0=time.time()
 PR,LU=flint.tmod_mat_PLU( fmpz_mat( S ) )
 if PR == None:
  print_tmod_mat_PLU_error( S, None, 'empty result' )
  sys.exit(1)
 WL_inv=flint.tmod_mat_solver( PR, LU )
 t0=time.time()-t0
 print 'time=%s' % t0
 d=flint.agnostic_array_export_big( PR, S.nrows(), S.ncols(), 1<<10 )
 pretty_print_big(dim,d)
 return t0
Exemple #3
0
def tmod_pretty_a(a,s):
 r=[]
 for i in range(s):
  r.append( a[i] )
 return r

def tmod_symm_abs(x):
 if x & 0x8000000000000000:
  return w_modulo-x
 return x

print 'startin test'

a32=matrix(ZZ,3,[1,-6,4,-21,7,-48])
PR,LU=flint.tmod_mat_PLU( fmpz_mat(a32) )
LU_inv=flint.tmod_mat_solver(PR, LU)
print tmod_pretty_m( LU.export_sage() ),'\n'
print tmod_pretty_m( LU_inv.export_sage() ),'\n'
print tmod_pretty_m( flint.export_Wti(LU_inv) )
print tmod_pretty_m( flint.export_Lti(LU_inv) )

def test_constructor_export( m ):
 f=flint.tmod_mat_single( fmpz_mat(m) )
 assert f.export_sage() == m % 2**64
 f=flint.nmod_mat_set_fmpz_mat_mod_thalf( fmpz_mat(m) )
 assert f.export_nonnegative_fmpz_mat().export_sage() == m % 2**63

test_constructor_export( identity_matrix( 3 ) )
test_constructor_export( identity_matrix( 4 ).matrix_from_rows(range(3)) )
test_constructor_export( identity_matrix( 4 ).matrix_from_columns(range(3)) )