3434#include "linbox/util/args-parser.h"
3535#include "linbox/util/error.h"
3636#include "linbox/util/matrix-stream.h"
37+ #include "linbox/randiter/random-prime.h"
38+ #include <givaro/givrandom.h>
3739
3840// DenseLU
3941#include "linbox/matrix/dense-matrix.h"
@@ -46,17 +48,6 @@ typedef Givaro::ZRing<Givaro::Integer> Ints;
4648typedef DenseVector < Ints > ZVector ;
4749
4850
49- struct FixPrime {
50- typedef Givaro ::Integer Prime_Type ;
51- const Prime_Type _myprime ;
52- FixPrime (const Givaro ::Integer & i ) : _myprime (i ) {}
53- inline FixPrime & operator ++ () { return * this ; }
54- const Prime_Type & operator * () const { return randomPrime (); }
55- const Prime_Type & randomPrime () const { return _myprime ; }
56- void setBits (uint64_t bits ) {}
57- template < class _ModField > void setBitsField () { }
58- };
59-
6051template < typename _Matrix , typename _EliminationMethod >
6152int test (_Matrix A , std ::string vector_file , bool inv , bool pp , bool sparse_elim ) {
6253 // TODO : git rm dixondenseLU dixonsparseelim
@@ -96,22 +87,13 @@ int test(_Matrix A, std::string vector_file, bool inv, bool pp, bool sparse_elim
9687
9788 if (createB ) {
9889 ZVector U (ZZ , A .coldim ());
90+ Givaro ::GivRandom bgen ( BaseTimer ::seed () );
9991 if (inv ) {
10092 std ::cerr << "Creating a random {-1,1} vector " << std ::endl ;
101- srand48 ( BaseTimer ::seed () );
102- for (auto& it :B )
103- if (drand48 () < 0.5 )
104- it = -1 ;
105- else
106- it = 1 ;
93+ for (auto& it :B ) it = (bgen .brand ()?1 :-1 );
10794 } else {
10895 std ::cerr << "Creating a random consistant {-1,1} vector " << std ::endl ;
109- srand48 ( BaseTimer ::seed () );
110- for (FFPACK ::rns_double ::integer & it :U )
111- if (drand48 () < 0.5 )
112- it = -1 ;
113- else
114- it = 1 ;
96+ for (FFPACK ::rns_double ::integer & it :U ) it = (bgen .brand ()?1 :-1 );
11597
11698 // B = A U
11799 A .apply (B ,U );
@@ -142,8 +124,8 @@ int test(_Matrix A, std::string vector_file, bool inv, bool pp, bool sparse_elim
142124 Ints ::Element d ;
143125 Method ::Dixon m (M );
144126 typedef Givaro ::Modular < double > Field ;
145- // 0.7213475205 is an upper approximation of 1/(2log(2))
146- size_t bitsize ((size_t )( 26 - ( int ) ceil ( log (( double ) A .rowdim ()) * 0.7213475205 )));
127+
128+ const size_t bitsize ((size_t ) FieldTraits < Field > :: bestBitSize ( A .rowdim ()));
147129 Givaro ::Integer randomPrime ( * (PrimeIterator < > (bitsize )) );
148130
149131 FixPrime fixedprime ( randomPrime );
@@ -244,7 +226,7 @@ int main (int argc, char **argv) {
244226 Argument as [ ] = {
245227 { 'm' , "-m FILE" , "Set the input file for the matrix." , TYPE_STR , & matrix_file },
246228 { 'v' , "-v FILE" , "Set the input file for the vector." , TYPE_STR , & vector_file },
247- { 'i' , "-i" , "whether the matrix is invertible." , TYPE_BOOL , & inv },
229+ { 'i' , "-i" , "whether the matrix is known to be invertible." , TYPE_BOOL , & inv },
248230 { 'p' , "-p" , "whether you want to pretty print the matrix." , TYPE_BOOL , & pp },
249231 { 's' , "-s" , "whether to use sparse elimination." , TYPE_BOOL , & sparse_elim },
250232 END_OF_ARGUMENTS
0 commit comments