/usr/include/linbox/randiter/unparametric.h is in liblinbox-dev 1.3.2-1.1+b1.
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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | /* Copyright (C) 2010 LinBox
* Written by William J Turner
*
*
*
* ========LICENCE========
* This file is part of the library LinBox.
*
* LinBox is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*/
#ifndef __LINBOX_randiter_unparametric_H
#define __LINBOX_randiter_unparametric_H
#include <ctime>
#include <vector>
#include "linbox/field/unparametric.h"
// #include <fflas-ffpack/field/unparametric.h>
// Namespace in which all LinBox library code resides
namespace LinBox
{
using Givaro::Caster;
// forward declarations
template <class K> class UnparametricField;
// using FFPACK::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::random();
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((unsigned)_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 = (Element) rand();
else
return Caster (x, (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 // __LINBOX_randiter_unparametric_H
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,:0,t0,+0,=s
// Local Variables:
// mode: C++
// tab-width: 8
// indent-tabs-mode: nil
// c-basic-offset: 8
// End:
|