/usr/include/linbox/algorithms/rns.h is in liblinbox-dev 1.3.2-1.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 | /* Copyright (C) 2011 LinBox
* Written by BB <brice.boyer@imag.fr>
*
*
*
* ========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========
*/
/*! @file algorithms/rns.h
* @ingroup algorithms
* @brief <b>R</b>esidue <b>N</b>umber <b>S</b>ystem tools.
* NO DOC
*/
#ifndef __LINBOX_algorithms_rns_H
#define __LINBOX_algorithms_rns_H
#include "linbox/integer.h"
#include <givaro/givrns.h> // Chinese Remainder of an array of elements
#include <givaro/givrnsfixed.h> // Chinese Remainder with fixed primes
namespace LinBox
{
/*! RNS.
* Creates a RNS than can recover any number between \c 0 and \c q-1 if
* \c Unsigned=true or \c -q+1 and \c q-1 otherwise (where \c q=2<up>\c
* _bits_</up>).
* @todo template by field and ring
*/
template<bool Unsigned>
class RNS {
private:
typedef std::vector<unsigned long> Fvect ;
typedef std::vector<integer> Ivect ;
typedef Modular<double> Field ;
Fvect _primes_; //!< vector of integers, pairwise coprime (or pairwise different primes)
unsigned long _size_; //!< number of primes
unsigned long _bit_; //!< max number of bit reachable. @todo why not max int reachable to save maybe a couple primes ? bof.
integer _maxint_; //!< max reachable integer.
integer _midint_; //!< in signed case, the mid one.
unsigned long _ps_; //!< prime size (minimum)
typedef Givaro::RNSsystem<Integer, Field > CRTSystem;
typedef typename CRTSystem::domains Domains;
typedef typename CRTSystem::array Elements;
// typedef typename CRTSystem::ring Ring;
CRTSystem _CRT_ ;
Domains _PrimeDoms_ ;
#ifdef __LINBOX_HAVE_IML
//! @todo IML wrapper here
#endif
public:
/*! Create a RNS able to recover any integer of at most l bits.
* Builds \c ceil(l/ps) different primes for the RNS
* @param l max recoverable bits
* @param ps bitsize of the primes (defaulting to 21 because...)
*/
RNS(unsigned long l, unsigned long ps=21) ;
/*x Create a RNS with given primes.
* @param primes given basis of primes
* @param l recoverable bits. If not given or 0, then it is computed. Giving it will reduce initialization time.
* @warning both \c l and \c primes 'integrity' are not checked. Use \c checkRNS() member to perform the check.
*
*/
// RNS(Ivect & primes, unsigned long l = 0) ;
// void addPrime( double prime);
// void addPrime( unsigned long newl);
// bool checkRNS() ;
// cra
/*! Inits cra.
*/
void initCRA() ;
/*! Computes \c result corresponding to the \c residues.
*
*/
void cra(integer & result, const std::vector<double> & residues);
/*! Computes \c result corresponding to the \c residues.
*
*/
void cra(std::vector<integer> & result, const std::vector<std::vector<double> > & residues);
/*! Computes \c result corresponding to the iteration.
*
*/
template<typename Iteration>
void cra(Ivect & result, Iteration & iter) ;
template<class Tinteger, class Tresidue>
void cra(Tinteger & result, Tresidue & residues);
template<class Tinteger, class Tresidue>
void convert(Tinteger & result, Tresidue & residues) ;
// mixed radix
};
template<bool Unsigned>
class RNSfixed {
private:
typedef std::vector<unsigned long> Fvect ;
typedef std::vector<integer> Ivect ;
typedef Modular<double> Field ;
Fvect _primes_; //!< vector of integers, pairwise coprime (or pairwise different primes)
unsigned long _size_; //!< number of primes
unsigned long _bit_; //!< max number of bit reachable. @todo why not max int reachable to save maybe a couple primes ? bof.
integer _maxint_; //!< max reachable integer.
integer _midint_; //!< in signed case, the mid one.
unsigned long _ps_; //!< prime size (minimum)
typedef Givaro::RNSsystemFixed<Integer> CRTSystemFixed;
typedef CRTSystemFixed::array Prime_t;
// typedef typename CRTSystem::domains Domains;
// typedef typename CRTSystem::array Elements;
// typedef typename CRTSystem::ring Ring;
CRTSystemFixed _CRT_ ;
Prime_t _Primes_ ;
#ifdef __LINBOX_HAVE_IML
#endif
public:
/*! Create a RNSfixed able to recover any integer of at most l bits.
* Builds \c ceil(l/ps) different primes for the RNSfixed
* @param l max recoverable bits
* @param ps bitsize of the primes (defaulting to 21 because...)
*/
RNSfixed(unsigned long l, unsigned long ps=21) ;
/*x Create a RNSfixed with given primes.
* @param primes given basis of primes
* @param l recoverable bits. If not given or 0, then it is computed. Giving it will reduce initialization time.
* @warning both \c l and \c primes 'integrity' are not checked. Use \c checkRNSfixed() member to perform the check.
*
*/
// RNSfixed(Ivect & primes, unsigned long l = 0) ;
// void addPrime( double prime);
// void addPrime( unsigned long newl);
// bool checkRNSfixed() ;
// cra
/*! Inits cra.
*/
void initCRA() ;
/*! Computes \c result corresponding to the \c residues.
*
*/
void cra(integer & result, const std::vector<double> & residues);
/*! Computes \c result corresponding to the \c residues.
*
*/
void cra(std::vector<integer> & result, const std::vector<std::vector<double> > & residues);
/*! Computes \c result corresponding to the iteration.
*
*/
template<class Iteration>
void cra(Ivect & result, Iteration & iter) ;
template<class Tinteger, class Tresidue>
void cra(Tinteger & result, Tresidue & residues);
template<class Tinteger, class Tresidue>
void convert(Tinteger & result, Tresidue & residues) ;
// mixed radix
};
}
#include "rns.inl"
#endif // __LINBOX_algorithms_rns_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:
|