/usr/include/linbox/vector/random.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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | /* tests/test-sparse0.C (Formerly test-sparse-matrix.C)
* Copyright (C) 2002 William J. Turner
*
* Written by William J. Turner <wjturner@acm.org>
*
* ------------------------------------
* Modified by Dmitriy Morozov <linbox@foxcub.org>. May 28, 2002.
*
* Added parametrization of VectorCategory tags by VectorTraits. See
* vector-traits.h for more details.
*
* ------------------------------------
*
* See COPYING for lincense information.
*/
#ifndef __VECTOR_RANDOM_H
#define __VECTOR_RANDOM_H
#include <utility>
#include "linbox/integer.h"
#include "linbox/vector/vector-traits.h"
// Namespace in which all LinBox library code lives
namespace LinBox
{
/** Random vector generator
* This templated function takes a field and a random field element
* generator and returns a vector of random field elements.
* The vector is dense in the field elements, even if the vector is
* a sparse LinBox vector.
* The funtion is templatized by the field and the vector types being used.
* This function calls another function by the same name with an additional
* parameter of the vector category of the vector it is called with.
* This mechanism is used because functions cannot have partial template
* specializations like classes can.
* This new, extended function can be specialized for specific fields
* and vectors to allow for better performance.
* @return v vector of random field elements
* @param F Field in which arithmetic is done
* @param n integer number of elements in vector
* @param r Random field element generator
\ingroup vector
*/
template <class Field, class Vector>
inline
Vector
randomVector(Field& F, size_t n, typename Field::RandIter& r)
{
return
randomVector<Field, Vector>(
F,
n,
r,
VectorTraits<Vector>::VectorCategory()
);
}
/* Random dense vector generator
* This templated function takes a field and a random field element
* generator and returns a vector of random field elements.
* The funtion is templatized by the field and the vector types being used.
* This function can be specialized for specific fields
* and vectors to allow for better performance.
* @return v vector of random field elements
* @param F Field in which arithmetic is done
* @param n integer number of elements in vector
* @param r Random field element generator
* @param tag category of vector obtained from vector trait
*/
template <class Field, class Vector, class VectorTrait>
inline
Vector
randomVector(
Field& F,
size_t n,
typename Field::RandIter& r,
VectorCategories::DenseVectorTag<VectorTrait> tag
)
{
#ifdef TRACE
cout << "Called dense random vector" << endl;
#endif // TRACE
Vector v(n);
typename Vector::iterator iter;
for (iter = v.begin(); iter != v.end(); iter++)
r.random(*iter);
return v;
} // randomVector(F, r, VectorCategories::DenseVectorTag& tag)
/* Random sparse sequence vector generator
* This templated function takes a field and a random field element
* generator and returns a vector of random field elements.
* The funtion is templatized by the field and the vector types being used.
* This function can be specialized for specific fields
* and vectors to allow for better performance.
* @return v vector of random field elements
* @param F Field in which arithmetic is done
* @param n integer number of elements in vector
* @param r Random field element generator
* @param tag category of vector obtained from vector trait
*/
template <class Field, class Vector, class VectorTrait>
inline
Vector
randomVector(
Field& F,
size_t n,
typename Field::RandIter& r,
VectorCategories::SparseSequenceVectorTag<VectorTrait> tag
)
{
#ifdef TRACE
cout << "Called sparse sequence random vector" << endl
<< " return vector v = " << endl;
#endif // TRACE
Vector v(n);
typename Vector::iterator iter;
size_t i = 0;
for (iter = v.begin(); iter != v.end(); iter++, i++)
{
iter->first = i;
r.random(iter->second);
#ifdef TRACE
cout << " v[" << iter->first << "] = ";
F.write(cout, iter->second);
cout << endl;
#endif // TRACE
}
return v;
} // randomVector(F, r, VectorCategories::SparseSequenceVectorTag& tag)
/* Random sparse associative vector generator
* This templated function takes a field and a random field element
* generator and returns a vector of random field elements.
* The funtion is templatized by the field and the vector types being used.
* This function can be specialized for specific fields
* and vectors to allow for better performance.
* @return v vector of random field elements
* @param F Field in which arithmetic is done
* @param n integer number of elements in vector
* @param r Random field element generator
* @param tag category of vector obtained from vector trait
*/
template <class Field, class Vector, class VectorTrait>
inline
Vector
randomVector(
Field& F,
size_t n,
typename Field::RandIter& r,
VectorCategories::SparseAssociativeVectorTag<VectorTrait> tag
)
{
#ifdef TRACE
cout << "Called sparse associative random vector" << endl
<< " return vector v = " << endl;
#endif // TRACE
Vector v;
typename Field::Element temp;
for (size_t i = 0; i < size_t(n); i++)
{
r.random(temp);
v.insert(make_pair(i, temp));
#ifdef TRACE
cout << " v[" << i << "] = ";
F.write(cout, v[i]);
cout << endl;
#endif // TRACE
}
return v;
} // randomVector(F, r, VectorCategories::SparseAssociativeVectorTag& tag)
}
#endif // __VECTOR_RANDOM_H
|