/usr/include/linbox/field/givaro-zpz.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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | /* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* linbox/field/givaro-zpz.h
* Copyright (C) 2002 Pascal Giorgi
*
* Written by Pascal Giorgi <pascal.giorgi@ens-lyon.fr>
*
* ------------------------------------
*
* See COPYING for license information.
*/
/* WARNING this wrapper works only with an improved version of Givaro.
* This version of givaro won't be available for public yet.
* But it is available on my web page.
* You can send me a mail to get it or for others details.
*/
#ifndef __FIELD_GIVARO_ZPZ
#define __FIELD_GIVARO_ZPZ
#include "linbox/linbox-config.h"
#include "linbox/integer.h"
#include "linbox/field/field-interface.h"
#include "linbox/util/debug.h"
#include "linbox/vector/vector-domain.h"
//-------------------------------------
// Files of Givaro library
#include <givaro/givzpz16std.h>
#include <givaro/givzpz32std.h>
#include <givaro/givzpz16table1.h>
#include <givaro/giv_randiter.h>
#include <linbox/field/field-traits.h>
//--------------------------------------
// Namespace in which all LinBox code resides
namespace LinBox
{
/* This wrappers allows to use three sorts of givaro fields :
* Elements represent by a 32 bits integer
* Elements represent by a 16 bits integer
* Elements represent in Zech log representation by a 16 bits integer
*
* To use this fields with the wrapper below just replace the template
* parameter by the Tag appropriated.
* "Std16" for 16 bits integer
* "Std32" for 32 bits integer
* "Log16" for Zech log representation in 16 bits
*/
template<class Field>
class DotProductDomain;
template<class Field>
class FieldAXPY;
template <class Ring>
struct ClassifyRing;
template <class TAG>
class GivaroZpz;
template<class Tag>
struct ClassifyRing<GivaroZpz<Tag> > {
typedef RingCategories::ModularTag categoryTag;
};
/** \brief wrapper of Givaro's ZpzDom.
\ingroup field
* Most methods are inherited from ZpzDom<Std16>, ZpzDom<Std32>
* and ZpzDom<log16> classes of Givaro.
* These classes allow to construct only finite field with a prime modulus.
*/
template <class TAG> class GivaroZpz : public ZpzDom<TAG>, public FieldInterface
{
private:
/* friend class DotProductDomain<GivaroZpz<TAG> > ;
friend class FieldAXPY<GivaroZpz<TAG> >; */
public:
//typedef integer Integer;
/** Element type.
* This type is inherited from the Givaro class ZpzDom<TAG>
*/
typedef typename ZpzDom<TAG>::Rep Element;
/** RandIter type
* This type is inherited from the Givaro class ZpzDom<TAG>
*/
typedef GIV_randIter< ZpzDom<TAG>, integer > RandIter;
/** Constructor from an integer
* this constructor use the ZpzDom<TAG> constructor
*/
GivaroZpz (const integer &p) : ZpzDom<TAG> (static_cast<typename ZpzDom<TAG>::Residu_t> (p)) {}
/** Constructor from an integer (takes degree of extension as 2nd parameter, must be 1)
* this constructor use the ZpzDom<TAG> constructor
*/
GivaroZpz (const integer &p, const integer& k) : ZpzDom<TAG> (static_cast<typename ZpzDom<TAG>::Residu_t> (p)) {
if (k!=1)
throw PreconditionFailed(__FUNCTION__,__LINE__,"exponent must be 1");
}
/** Copy constructor
* This copy constructor use the ZpzDom<TAG> copy constructor
*/
GivaroZpz (const GivaroZpz<TAG>& F) : ZpzDom<TAG> (F) {}
// Rich Seagraves 7-16-2003
// As is, this operator is an infinite loop
// By not providing an operator= in GivaroZpz,
// the operator= in the base class (ZpzDom<TAG>) is called
// automatically by the rules of C++, which I'm guessing is
// the "Right Thing" for this operator
//
/** Operator =
*/
/*
GivaroZpz<TAG>& operator= (const GivaroZpz<TAG>& F) {
return (*this)=F;
}
*/
/** Characteristic.
* Return integer representing characteristic of the domain.
* @return integer representing characteristic of the domain.
*/
integer &characteristic (integer &c) const
{ return c = integer (static_cast<int> (ZpzDom<TAG>::size ())); }
long characteristic() const
{return static_cast<int>(ZpzDom<TAG>::size());}
/** Cardinality.
* Return integer representing cardinality of the domain.
* @return integer representing cardinality of the domain
*/
integer &cardinality (integer &c) const
{ return c = integer (static_cast<int> (ZpzDom<TAG>::size ())); }
/** Conversion of field base element to an integer.
* This function assumes the output field base element x has already been
* constructed, but that it is not already initialized.
* @return reference to an integer.
* @param x integer to contain output (reference returned).
* @param y constant field base element.
*/
integer &convert (integer &x, const Element &y) const
{ return x = integer (static_cast<int> (y)); }
double &convert (double& x, const Element& y) const
{ return x = (double) y; }
/** Initialization of field base element from an integer.
* Behaves like C++ allocator construct.
* This function assumes the output field base element x has already been
* constructed, but that it is not already initialized.
* @return reference to field base element.
* @param x field base element to contain output (reference returned).
* @param y integer.
*/
Element &init (Element &x , const integer &y = 0) const
{
//
// AU 28/03/07 no cast to long allows to use ZpzDom<integer>
//
//ZpzDom<TAG>::init (x, (long) (y% integer(this->_p)));
ZpzDom<TAG>::init (x, (y% integer(this->_p)));
return x;
}
Element &init (Element &x , const double &y ) const
{
double z = fmod(y, (double) this->_p);
if (z < 0) z += (double) this->_p;
z += 0.5;
return x = static_cast<long>(z); //rounds towards 0
}
static int getMaxModulus();
}; // class GivaroZpz<TAG>
template <> int GivaroZpz<Std32>::getMaxModulus() { return 65535; } // 2^16-1
template <> int GivaroZpz<Std16>::getMaxModulus() { return 255; } // 2^8-1
template <> int GivaroZpz<Log16>::getMaxModulus() { return 32767; } // 2^15 - 1
/** Specialisation of the convert function for the zech log representation
* of givaro-zpz (GivaroZpz<Log16>.
* this function translates the internal representation to the real
* value of the element.
* This can have no sense but can be usefull
* NB : the init function for this specialisation does the same thing.
* the function transaltes the values to her internal representation.
*/
template <> integer& GivaroZpz<Log16>::convert(integer& x, const Element& y) const
{
if (y>=this->_p) return x = 0;
int tmp = _tab_rep2value[y];
return x = integer (tmp);
}
template <> double& GivaroZpz<Log16>::convert(double& x, const Element& y) const
{
if (y>=this->_p) return x = 0.0;
int tmp = _tab_rep2value[y];
return x = (double) tmp;
}
template <> GivaroZpz<Log16>::Element& GivaroZpz<Log16>::init(GivaroZpz<Log16>::Element& x, const double& y) const
{
double z = fmod(y, (double) this->_p);
if (z < 0) z += this->_p;
z += 0.5;
return x = _tab_value2rep[static_cast<long>(z)]; //rounds towards 0
}
template <> GivaroZpz<Log16>::Element& GivaroZpz<Log16>::init(GivaroZpz<Log16>::Element& x, const integer& y) const
{
int tmp =(int) (y % (integer)this->_p);
if (tmp < 0 ) tmp += this->_p;
return x = _tab_value2rep[tmp];
}
/* Specialization of FieldAXPY for GivaroZpz<Std32> Field */
template <>
class FieldAXPY<GivaroZpz<Std32> >
{
public:
typedef GivaroZpz<Std32>::Element Element;
typedef GivaroZpz<Std32> Field;
FieldAXPY (const Field &F) : _F (F) , Corr(uint64(-1) % (uint64)F.characteristic() +1){ _y = 0; }
FieldAXPY (const FieldAXPY &faxpy) : _F (faxpy._F), _y (0) , Corr(faxpy.Corr) {}
FieldAXPY<GivaroZpz<Std32> > &operator = (const FieldAXPY &faxpy)
{ _F = faxpy._F; _y = faxpy._y; Corr = faxpy.Corr; return *this; }
inline uint64& mulacc (const Element &a, const Element &x)
{
uint64 t = (uint64) a * (uint64) x;
_y += t;
if (_y < t)
return _y += Corr;
else
return _y;
}
inline uint64& accumulate (const Element &t)
{
_y += t;
if (_y < (uint64)t)
return _y += Corr;
else
return _y;
}
inline Element &get (Element &y) {
_y %= (uint64) _F.characteristic();
if ((int64) _y < 0) _y += _F.characteristic();
y = (uint32) _y;
return y;
}
inline FieldAXPY &assign (const Element y)
{ _y = y; return *this; }
inline void reset() {
_y = 0;
}
private:
Field _F;
uint64 _y;
uint64 Corr;
};
/* Specialization of FieldAXPY for GivaroZpz<Std32> Field */
template <>
class FieldAXPY<GivaroZpz<Std16> >
{
public:
typedef GivaroZpz<Std16>::Element Element;
typedef GivaroZpz<Std16> Field;
FieldAXPY (const Field &F) : _F (F) , Corr(uint32(-1) % (uint32)F.characteristic() +1){ _y = 0; }
FieldAXPY (const FieldAXPY &faxpy) : _F (faxpy._F), _y (0) , Corr(faxpy.Corr) {}
FieldAXPY<GivaroZpz<Std16> > &operator = (const FieldAXPY &faxpy)
{ _F = faxpy._F; _y = faxpy._y; Corr = faxpy.Corr; return *this; }
inline uint32& mulacc (const Element &a, const Element &x)
{
uint32 t = (uint32) a * (uint32) x;
_y += t;
if (_y < t)
return _y += Corr;
else
return _y;
}
inline uint32& accumulate (const Element &t)
{
_y += t;
if (_y < (uint32)t)
return _y += Corr;
else
return _y;
}
inline Element &get (Element &y) {
_y %= (uint32) _F.characteristic();
if ((int32) _y < 0) _y += _F.characteristic();
y = (uint16) _y;
return y;
}
inline FieldAXPY &assign (const Element y)
{ _y = y; return *this; }
inline void reset() {
_y = 0;
}
private:
Field _F;
uint32 _y;
uint32 Corr;
};
// Specialization of DotProductDomain for GivaroZpz<Std32> field
template <>
class DotProductDomain<GivaroZpz<Std32> > : private virtual VectorDomainBase<GivaroZpz<Std32> >
{
public:
typedef GivaroZpz<Std32>::Element Element;
DotProductDomain (const GivaroZpz<Std32> &F)
: VectorDomainBase<GivaroZpz<Std32> > (F) ,
Corr(uint64(-1) % (uint64)F.characteristic() +1),
Max(uint64(-1))
{}
protected:
template <class Vector1, class Vector2>
inline Element &dotSpecializedDD (Element &res, const Vector1 &v1, const Vector2 &v2) const;
template <class Vector1, class Vector2>
inline Element &dotSpecializedDSP (Element &res, const Vector1 &v1, const Vector2 &v2) const;
private:
uint64 Corr;
uint64 Max;
};
// Specialization of DotProductDomain for GivaroZpz<Std16> field
template <>
class DotProductDomain<GivaroZpz<Std16> > : private virtual VectorDomainBase<GivaroZpz<Std16> >
{
public:
typedef GivaroZpz<Std16>::Element Element;
DotProductDomain (const GivaroZpz<Std16> &F)
: VectorDomainBase<GivaroZpz<Std16> > (F) ,
Corr(uint32(-1) % (uint32)F.characteristic() +1),
Max(uint32(-1))
{}
protected:
template <class Vector1, class Vector2>
inline Element &dotSpecializedDD (Element &res, const Vector1 &v1, const Vector2 &v2) const;
template <class Vector1, class Vector2>
inline Element &dotSpecializedDSP (Element &res, const Vector1 &v1, const Vector2 &v2) const;
private:
uint32 Corr;
uint32 Max;
};
} // namespace LinBox
#include "linbox/field/givaro-zpz.inl"
#endif // __FIELD_GIVARO_ZPZ
|