/usr/include/linbox/randiter/unparametric.h is in liblinbox-dev 1.1.6~rc0-4.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | /* File: src/wrappers/by_scope/random/unparam_randiter.h
* Author: William J Turner for the LinBox group
*/
#ifndef ___RANDITER_UNPARAMETRIC_H
#define ___RANDITER_UNPARAMETRIC_H
#include <vector>
// Namespace in which all LinBox library code resides
namespace LinBox
{
// forward declarations
template <class K> class UnparametricField;
/** Unparameterized random field element generator template.
* Implements LinBox random field element generator common object interface
* for unparameterized fields.
* Used to generate efficient field classes for unparameterized fields.
* Constructs LinBox unparameterized random field element generators from
* field types K.
* In particular, constructs LinBox random field element generators for
* unparameterized fields from field types that
* adhere to the operations for double, for
* example UnparametricRandIter< float >.
* Can be used as a pattern to write a particular
* field interface, such as, UnparametricRandIter< SaclibQ > as
* a template specialization.
* This implementation uses the standard C++ random number generator. Thus,
* only one random field element generator can be used at a time since
* creating a new one will re-seed the built-in generator and affect all
* current LinBox generators.
* @param K unparameterized field class
*/
template <class K> class UnparametricRandIter
{
public:
/** @name Common Object Interface.
* These methods are required of all LinBox random field element generators.
*/
//@{
/** Field element type.
* The field element must contain a default constructor,
* a copy constructor, a destructor, and an assignment operator.
*/
typedef K Element;
/** Constructor from field, sampling size, and seed.
* The random field element iterator works in the field F, is seeded
* by seed, and it returns any one element with probability no more
* than 1/min(size, F.cardinality(c)).
* A sampling size of zero means to sample from the entire field.
* A seed of zero means to use some arbitrary seed for the generator.
* This implementation sets the sampling size to be no more than the
* cardinality of the field.
* @param F LinBox field archetype object in which to do arithmetic
* @param size constant integer reference of sample size from which to
* sample (default = 0)
* @param seed constant integer reference from which to seed random number
* generator (default = 0)
*/
UnparametricRandIter(
const UnparametricField<K>& F,
const integer& size = 0,
const integer& seed = 0
)
: _size(size), _seed(seed)
{
if (_seed == integer(0)) _seed = integer(time(NULL));
integer cardinality; F.cardinality(cardinality);
if ( (cardinality != integer(-1)) && (_size > cardinality) )
_size = cardinality;
#ifdef TRACE
cout << "created random generator with size " << _size
<< " and seed " << _seed << endl;
#endif // TRACE
// Seed random number generator
srand(static_cast<long>(_seed));
} // UnparametricRandIter(const UnparametricField<K>&, const integer&, const integer&)
/** Copy constructor.
* Constructs UnparametricRandIter object by copying the random field
* element generator.
* This is required to allow generator objects to be passed by value
* into functions.
* In this implementation, this means copying the random field element
* generator to which R._randIter_ptr points.
* @param R UnparametricRandIter object.
*/
UnparametricRandIter(const UnparametricRandIter& R)
: _size(R._size), _seed(R._seed) {}
/** Destructor.
* This destructs the random field element generator object.
* In this implementation, this destroys the generator by deleting
* the random generator object to which _randIter_ptr points.
*/
~UnparametricRandIter(void) {}
/** Assignment operator.
* Assigns UnparametricRandIter object R to generator.
* In this implementation, this means copying the generator to
* which R._randIter_ptr points.
* @param R UnparametricRandIter object.
*/
UnparametricRandIter& operator=(const UnparametricRandIter& R)
{
if (this != &R) // guard against self-assignment
{
_size = R._size;
_seed = R._seed;
}
return *this;
}
/** Random field element creator.
* This returns a random field element from the information supplied
* at the creation of the generator.
* @return random field element
*/
Element& random (Element& x) const
{
// Create new random elements
if (_size == 0)
return x = rand();
else
return x = static_cast<integer>((double(rand())/RAND_MAX)*double(_size));
} // element& operator() (void)
//@} Common Object Iterface
/** @name Implementation-Specific Methods.
* These methods are not required of all
* \Ref{LinBox Random field element generators}
* and are included only for this implementation of the archetype.
*/
//@{
/// Default constructor
UnparametricRandIter(void) : _size(0), _seed(0) { time(NULL); }
//@}
private:
/// Sampling size
integer _size;
/// Seed
integer _seed;
}; // template <class K> class UnparametricRandIter
} // namespace LinBox
#endif // ___RANDITER_UNPARAMETRIC_H
|