/usr/include/fflas-ffpack/field/rns-integer.h is in fflas-ffpack-common 2.2.2-4.
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 | /* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
/*
* Copyright (C) 2014 the FFLAS-FFPACK group
*
* Written by Pascal Giorgi <pascal.giorgi@lirmm.fr>
*
*
* ========LICENCE========
* This file is part of the library FFLAS-FFPACK.
*
* FFLAS-FFPACK 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 field/rns-integer.h
* @ingroup field
* @brief representation of <code>Z</code> using RNS representation (note: fixed precision)
*/
#ifndef __FFPACK_unparametric_rns_integer_H
#define __FFPACK_unparametric_rns_integer_H
#include <givaro/givinteger.h>
#include "fflas-ffpack/field/rns-double.h"
namespace FFPACK {
template<typename RNS>
class RNSInteger {
protected:
const RNS *_rns; // the rns structure
typedef typename RNS::BasisElement BasisElement;
typedef Givaro::Integer integer;
public:
typedef typename RNS::Element Element;
typedef typename RNS::Element_ptr Element_ptr;
typedef typename RNS::ConstElement_ptr ConstElement_ptr;
Element one, mOne,zero;
RNSInteger(const RNS& myrns) : _rns(&myrns)
{
init(one,1);
init(zero,0);
init(mOne,-1);
}
template<typename T>
RNSInteger(const T &F) : _rns(&(F.rns()))
{
init(one,1);
init(zero,0);
init(mOne,-1);
}
const RNS& rns() const {return *_rns;}
size_t size() const {return _rns->_size;}
bool isOne(const Element& x) const {
bool isone=true;
for (size_t i=0;i<_rns->_size;i++)
isone&= (one._ptr[i]== x._ptr[i]);
return isone;
}
bool isMOne(const Element& x) const {
bool ismone=true;
for (size_t i=0;i<_rns->_size;i++)
ismone&= (mOne._ptr[i]== x._ptr[i]);
return ismone;
}
bool isZero(const Element& x) const {
bool iszero=true;
for (size_t i=0;i<_rns->_size;i++)
iszero&= (zero._ptr[i]== x._ptr[i]);
return iszero;
}
integer characteristic(integer &p) const { return p=0;}
integer cardinality(integer &p) const { return p=-1;}
Element& init(Element& x) const{
if (x._ptr == NULL){
x._ptr = FFLAS::fflas_new<BasisElement>(_rns->_size);
x._stride=1;
x._alloc=true;
}
return x;
}
Element& init(Element& x, const Givaro::Integer& y) const{
init(x);
size_t k =(y.bitsize())/16+((y.bitsize())%16?1:0);
_rns->init(1,1,x._ptr,x._stride, &y,1,k);
return x;
}
Element& reduce (Element& x, const Element& y) const {return assign (x,y);}
Element& reduce (Element& x) const {return x;}
Givaro::Integer convert(Givaro::Integer& x, const Element& y)const {
_rns->convert(1,1,integer(0),&x,1,y._ptr,y._stride);
return x;
}
Element& assign(Element& x, const Element& y) const {
for(size_t i=0;i<_rns->_size;i++)
x._ptr[i*x._stride] = y._ptr[i*y._stride];
return x;
}
std::ostream& write(std::ostream& os, const Element& y) const {
os<<"[ "<< (long) (y._ptr)[0];
for(size_t i=1;i<_rns->_size;i++)
os<<" , "<< (long) (y._ptr)[i*y._stride];
return os<<" ]";
}
std::ostream& write(std::ostream& os) const {
os<<"M:=[ "<< (long) _rns->_basis[0];
for(size_t i=1;i<_rns->_size;i++)
os<<" , "<< (long) _rns->_basis[i];
return os<<" ]"<<std::endl;
}
}; // end of class Unparametric<rns_double>
} // end of namespace FFPACK
namespace FFLAS {
// specialization for the fflas alloc function
template<>
inline FFPACK::rns_double_elt_ptr
fflas_new(const FFPACK::RNSInteger<FFPACK::rns_double> &F, const size_t m, const size_t n, const Alignment align){
double *ptr=FFLAS::fflas_new<double>(m*n*F.size(), align);
return FFPACK::rns_double_elt_ptr(ptr,m*n);
}
// function to convert from integer to RNS (note: this is not the finit function from FFLAS, extra k)
template<typename RNS>
void finit_rns(const FFPACK::RNSInteger<RNS> &F, const size_t m, const size_t n, size_t k,
const Givaro::Integer *B, const size_t ldb, typename FFPACK::RNSInteger<RNS>::Element_ptr A)
{
F.rns().init(m,n,A._ptr,A._stride, B,ldb,k);
}
// function to convert from RNS to integer (note: this is not the fconvert function from FFLAS, extra alpha)
template<typename RNS>
void fconvert_rns(const FFPACK::RNSInteger<RNS> &F, const size_t m, const size_t n,
Givaro::Integer alpha, Givaro::Integer *B, const size_t ldb, typename FFPACK::RNSInteger<RNS>::ConstElement_ptr A)
{
F.rns().convert(m,n,alpha,B,ldb,A._ptr,A._stride);
}
} // end of namespace FFLAS
#endif // __FFPACK_unparametric_rns_integer_H
|