/usr/include/givaro/givrnsfixed.inl is in libgivaro-dev 3.7.2-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 | // Copyright(c)'1994-2011 by The Givaro group
// This file is part of Givaro.
// Givaro is governed by the CeCILL-B license under French law
// and abiding by the rules of distribution of free software.
// see the COPYRIGHT file for more details.
// Time-stamp: <08 Mar 11 16:23:50 Jean-Guillaume.Dumas@imag.fr>
// ==========================================================================
// Description:
// Chinese Remainder Algorithm.
#ifndef __GIVARO_arithmodu_fixedprimes_INL
#define __GIVARO_arithmodu_fixedprimes_INL
#include "givaro/givpower.h"
namespace Givaro {
template<class Ints>
template<class smallIntVector>
Ints& RNSsystemFixed<Ints>::RnsToRingLeft( Ints& I, const smallIntVector& residues, const int level, const int col )
{
if (level) {
int lowercol=col<<1, lowercolnext=lowercol+1;
int lowerlevel=level-1;
Ints u0;
RnsToRingLeft(u0, residues, lowerlevel, lowercol);
RnsToRingRight(I, residues, lowerlevel, lowercolnext);
I -= u0; // u1-u0
I *= _primes[(size_t)lowerlevel][(size_t)lowercolnext]; // (u1-u0) * (p0(p0^{-1} mod p1))
I += u0; // (u1-u0)*M01+u0
return Integer::modin(I, _primes[(size_t)level][(size_t)col]);// (u1-u0)*M01 +u0 mod p0p1, between 0 and p0p1-1
}
else {
return I=residues[(size_t)col];
}
}
template<class Ints>
template<class smallIntVector>
Ints& RNSsystemFixed<Ints>::RnsToRingRight( Ints& I, const smallIntVector& residues, const int level, const int col )
{
if (level) {
int lowercol=col<<1, lowercolnext=lowercol+1;
int lowerlevel=level-1;
Ints u0;
RnsToRingLeft(u0, residues, lowerlevel, lowercol);
RnsToRingRight(I, residues, lowerlevel, lowercolnext);
I -= u0; // u1-u0
I *= _primes[(size_t)lowerlevel][(size_t)lowercolnext]; // (u1-u0) * (p0(p0^{-1} mod p1))
return I += u0; // (u1-u0)*M01+u0
} else {
return I=residues[(size_t)col];
}
}
// Convert to an Ints:
template<class Ints>
template<class smallIntVector>
Ints& RNSsystemFixed<Ints>::RnsToRing( Ints& I, const smallIntVector& rns)
{
int ir = (int)_RNS.Primes().size();
typename RNS_t::array Reds( (size_t)ir );
for(int i = (int)_primes.size(); i-- ;) {
int is = (int)_primes[(size_t)i].size();
if (is & 1) {
RnsToRingLeft(Reds[--ir], rns, i, --is);
}
}
return _RNS.RnsToRing( I, Reds);
}
// -- free memory allocated in array !
template<class Ints>
RNSsystemFixed<Ints>::~RNSsystemFixed()
{}
template<class Ints>
RNSsystemFixed<Ints>::RNSsystemFixed () :
_primes(0)
{}
template<class Ints>
RNSsystemFixed<Ints>::RNSsystemFixed (const Self_t& R) :
_primes(R._primes, givWithCopy())
{}
// -- Array of primes are given
template<class Ints>
RNSsystemFixed<Ints>::RNSsystemFixed( const array& inprimes) : _primes(0)
{
GIVARO_ASSERT( inprimes.size()>0, "[RNSsystemFixed<Ints>::RNSsystemFixed] bad size of array");
_primes.reserve( GIVINTLOG(inprimes.size()) );
_primes.resize(1);
for(typename array::const_iterator pit = inprimes.begin(); pit != inprimes.end(); ++pit) {
_primes.front().push_back( *pit );
for(int i = 1; i< (int)_primes.size(); ++i) {
int s = (int)_primes[(size_t)i-1].size();
if (s & 1) break;
else {
Ints& p0(_primes[(size_t)i-1][(size_t)s-2]), & p1(_primes[(size_t)i-1][(size_t)s-1]);
Ints prod(p0*p1);
inv(p1, p0, p1) *= p0;
_primes[(size_t)i].push_back( prod );
}
}
int lastp = int(_primes.size()-1);
if (! (_primes.back().size() & 1)) {
// std::cout << '[';
// for(int j=0; j<_primes.back().size(); ++j)
// std::cout << ' ' << _primes.back()[j];
// std::cout << ']' << std::endl;
array newlevel;
int s = (int)_primes.back().size();
Ints& p0(_primes[(size_t)lastp][(size_t)s-2]), & p1(_primes[(size_t)lastp][(size_t)s-1]);
newlevel.push_back( p0*p1 );
inv(p1, p0, p1) *= p0;
_primes.push_back( newlevel );
}
// std::cout << std::endl << "----------------" << std::endl;
// std::cout << '[';
// for(int i=0; i<_primes.size(); ++i) {
// std::cout << '[';
// for(int j=0; j<_primes[i].size(); ++j)
// std::cout << ' ' << _primes[i][j];
// std::cout << ']' << std::endl;
// }
// std::cout << ']' << std::endl;
// std::cout << "----------------" << std::endl;
}
int numodd=0;
for(int i = (int)_primes.size(); i-- ; )
if (_primes[(size_t)i].size() & 1) ++numodd;
typename RNS_t::domains Mods((size_t)numodd);
for(int i = (int)_primes.size(); i-- ; ) {
if (_primes[(size_t)i].size() & 1)
Mods[--numodd] = _primes[(size_t)i].back();
}
_RNS.setPrimes( Mods );
}
template<class Ints>
const typename RNSsystemFixed<Ints>::tree& RNSsystemFixed<Ints>::Primes() const
{
return _primes;
}
template<class Ints>
const Ints RNSsystemFixed<Ints>::ith(const size_t i) const
{
return _primes.front()[i];
}
} // namespace Givaro
#endif
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s:syntax=cpp.doxygen
|