Skip to content

Commit d41a3d6

Browse files
committed
PR comments: mv fixprime generator to random-prime.h ; use bit generator ;
1 parent ee4acf9 commit d41a3d6

File tree

3 files changed

+21
-241
lines changed

3 files changed

+21
-241
lines changed

examples/dixonsolve.C

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
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;
4648
typedef 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-
6051
template<typename _Matrix, typename _EliminationMethod>
6152
int 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

examples/dixonsparseelim.C

Lines changed: 0 additions & 214 deletions
This file was deleted.

linbox/randiter/random-prime.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace LinBox
7575
template<class Trait = IteratorCategories::HeuristicTag>
7676
class PrimeIterator{
7777
protected:
78-
uint64_t _bits; //!< common lenght of all primes
78+
uint64_t _bits; //!< common lenght of all primes
7979
integer _prime; //!< the generated prime.
8080
Givaro::IntPrimeDom _IPD; //!< empty struct dealing with primality.
8181

@@ -316,6 +316,18 @@ namespace LinBox
316316

317317
} while(!_IPD.isprime(_prime));
318318
}
319+
320+
struct FixPrime {
321+
typedef Givaro::Integer Prime_Type;
322+
const Prime_Type _myprime;
323+
FixPrime(const Givaro::Integer& i) : _myprime(i) {}
324+
inline FixPrime &operator ++ () { return *this; }
325+
const Prime_Type &operator * () const { return randomPrime(); }
326+
const Prime_Type & randomPrime() const { return _myprime; }
327+
void setBits(uint64_t bits) {}
328+
template<class _ModField> void setBitsField() { }
329+
};
330+
319331
}
320332

321333
#endif //__LINBOX_random_prime_iterator_H

0 commit comments

Comments
 (0)