This file is indexed.

/usr/include/linbox/field/modular-balanced-float.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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/* linbox/field/modular-float.h
 * Copyright (C) 2003 Pascal Giorgi
 *               2008 Clement Pernet
 * Written by Clement Pernet <clement.pernet@gmail.com>
 *            Pascal Giorgi <pascal.giorgi@ens-lyon.fr>
 *
 * ------------------------------------
 *
 * See COPYING for license information.
 */




#ifndef __LINBOX_MODULAR_BALANCED_FLOAT_H
#define __LINBOX_MODULAR_BALANCED_FLOAT_H


#include "linbox/linbox-config.h"
#include "linbox/integer.h"
#include "linbox/vector/vector-domain.h"
#include "linbox/field/field-interface.h"
#include "linbox/field/field-traits.h"
#include "linbox/util/field-axpy.h"
#include "linbox/util/debug.h"
#include <math.h>
#include <linbox/field/field-traits.h>




// Namespace in which all LinBox code resides
namespace LinBox { 
	
	template< class Element >
	class ModularBalanced;

	template< class Element >
	class ModularBalancedRandIter;

	template <class Field, class RandIter>
	class NonZeroRandIter;

	template <class Ring>
	struct ClassifyRing; 

	template <class Element>
	struct ClassifyRing<ModularBalanced<Element> >;

	template <>
	struct ClassifyRing<ModularBalanced<float> >{
		typedef RingCategories::ModularTag categoryTag;
	};

	class MultiModFloat;
	
	/// \ingroup field
	template <>
	class ModularBalanced<float> : public FieldInterface {

	protected:

		float  modulus;
		float half_mod;
		unsigned long   lmodulus;
		
	public:	       
		friend class FieldAXPY<ModularBalanced<float> >;
		friend class DotProductDomain<ModularBalanced<float> >;
		friend class MultiModFloat;
			       
		typedef float Element;
		typedef ModularBalancedRandIter<float> RandIter;
		typedef NonzeroRandIter<ModularBalanced<float>,ModularBalancedRandIter<float> > NonZeroRandIter;

		static ClassifyRing <ModularBalanced<float> >::categoryTag
		getCategory() {
			return ClassifyRing<ModularBalanced<float> >::categoryTag();
		}

		ModularBalanced () {}

		ModularBalanced (int32 p, int exp = 1)  : modulus((float)p),
							  half_mod( (p-1.)/2),
							  lmodulus (p) 
		{
			if(modulus <= 1)
				throw PreconditionFailed(__FUNCTION__,
							 __LINE__,
							 "modulus must be > 1");
			if( exp != 1 ) throw PreconditionFailed(__FUNCTION__,
								__LINE__,
								"exponent must be 1");
			integer max;
			if (modulus > (float) FieldTraits<ModularBalanced<float> >::maxModulus(max))
				throw PreconditionFailed (__FUNCTION__,
							  __LINE__,
							  "modulus is too big");
		}

		ModularBalanced (float p) : modulus (p),
					     half_mod ((p-1)/2),
					     lmodulus ((unsigned long)p) {
			if (modulus <= 1)
				throw PreconditionFailed(__FUNCTION__,
							 __LINE__,
							 "modulus must be > 1");
			integer max;
			if (modulus > (float) FieldTraits<ModularBalanced<float> >::maxModulus(max))
				throw PreconditionFailed (__FUNCTION__,
							  __LINE__,
							  "modulus is too big");
		}

		ModularBalanced (long int p) : modulus((float)p),
					       half_mod ((p-1)/2),
					       lmodulus(p) {
			if ((float) modulus <= 1)
				throw PreconditionFailed(__FUNCTION__,__LINE__,"modulus must be > 1");
			integer max;
			if ((float) modulus > (float) FieldTraits<ModularBalanced<float> >::maxModulus(max))
				throw PreconditionFailed (__FUNCTION__,
							  __LINE__,
							  "modulus is too big");
		}

		ModularBalanced (const integer& p) : modulus((float) p),
						     half_mod ((p-1)/2),
						     lmodulus(p){
			if(modulus <= 1)
				throw PreconditionFailed(__FUNCTION__,__LINE__,"modulus must be > 1");
	             	if(modulus > getMaxModulus())
				throw PreconditionFailed(__FUNCTION__,__LINE__,"modulus is too big");
				
		}

		ModularBalanced (const ModularBalanced<float>& mf) :
			modulus (mf.modulus),
			half_mod (mf.half_mod),
			lmodulus (mf.lmodulus) {}

		const ModularBalanced &operator= (const ModularBalanced<float> &F) {
			modulus = F.modulus;
			half_mod = F.half_mod;
			lmodulus= F.lmodulus;
			return *this;
		}

	
		inline integer &cardinality (integer &c) const{ 
			return c = integer(modulus);
		}

		inline integer &characteristic (integer &c) const {
			return c = integer(modulus); 
		}

		inline integer &convert (integer &x, const Element &y) const { 
			if ( y < 0. ) return x = integer (y + modulus) ;
			else return x = integer (y);
		}

		inline float &convert (float &x, const Element& y) const {
			return x=y;
		}
		
		std::ostream &write (std::ostream &os) const {
			return os << "float mod " << int(modulus);
		}
		
		std::istream &read (std::istream &is) {
			is >> modulus; 
			if(modulus <= 1) 
				throw PreconditionFailed (__FUNCTION__,
							 __LINE__,
							  "modulus must be > 1");
		 	if(modulus > getMaxModulus()) 
				throw PreconditionFailed (__FUNCTION__,
							 __LINE__,
							 "modulus is too big");
			return is;
		}
		
		std::ostream &write (std::ostream &os, const Element &x) const {
			return os << int(x);
		}

		std::istream &read (std::istream &is, Element &x) const {
			integer tmp;
                            // JGD : should'nt it be float tmp ???
			is >> tmp;
			init(x,tmp); 
			return is;
		}
		

		inline Element &init (Element &x, const integer &y) const  {
// 			return x = (Element)mpz_fdiv_ui(y.get_mpz(),lmodulus );
			return x = (Element)(y%lmodulus);
		}

		inline Element& init(Element& x, const float y =0) const {		  

			x = fmod (y, modulus);
			if (x > half_mod) return   x -= modulus;
			else if (x < - half_mod) return x += modulus;
			else return x;
		}
		
		inline Element& assign(Element& x, const Element& y) const {
			return x = y;
		}
		
		inline bool areEqual (const Element &x, const Element &y) const {
			return x == y;
		}

		inline  bool isZero (const Element &x) const {
			return x == 0.; 
		}
		
		inline bool isOne (const Element &x) const {
			return x == 1.; 
		}

		inline bool isMinusOne (const Element &x) const {
			return (x == -1.); 
		}

		inline Element &add (Element &x,
				     const Element &y,
				     const Element &z) const {
			x = y + z;
			if ( x > half_mod ) return x -= modulus;
			if ( x < -half_mod ) return x += modulus;
			return x;
		}
 
		inline Element &sub (Element &x,
				     const Element &y,
				     const Element &z) const {
			x = y - z;
			if (x > half_mod) return x -= modulus;
			if (x < -half_mod) return x += modulus;
			return x;
		}
		
		inline Element &mul (Element &x, const Element &y, const Element &z) const {		
			x = y * z;
			return init (x,x);
		}
 
		inline Element &div (Element &x, const Element &y, const Element &z) const {
			Element temp;
			inv (temp, z);
			return mul (x, y, temp);
		}
 
		inline Element &neg (Element &x, const Element &y) const {
			return x = -y;
		}
 
		inline Element &inv (Element &x, const Element &y) const {
			// The extended Euclidean algoritm 
			int x_int, y_int, q, tx, ty, temp;
			x_int = int (modulus);
			y_int = (y < 0.) ? int(y + modulus) : int(y);
			tx = 0; 
			ty = 1;
		  
			while (y_int != 0) {
				// always: gcd (modulus,residue) = gcd (x_int,y_int)
				//         sx*modulus + tx*residue = x_int
				//         sy*modulus + ty*residue = y_int
				q = x_int / y_int; // integer quotient
				temp = y_int; y_int = x_int - q * y_int;
				x_int = temp;
				temp = ty; ty = tx - q * ty;
				tx = temp;
			}
			if (tx > half_mod ) return x = tx - modulus;
			if ( tx < -half_mod ) return x = tx + modulus;
			return x = (float) tx;
		}

		inline Element &axpy (Element &r, 
				      const Element &a, 
				      const Element &x, 
				      const Element &y) const {
			r = a * x + y;
			return init (r, r);
		}

		inline Element &addin (Element &x, const Element &y) const {
			x += y;
			if ( x > half_mod ) return x -= modulus;
			if ( x < -half_mod ) return x += modulus; 
			return x;
		}
 
		inline Element &subin (Element &x, const Element &y) const {
			x -= y;
			if ( x > half_mod ) return x -= modulus;
			if ( x < -half_mod ) return x += modulus; 
			return x;
		}
 
		inline Element &mulin (Element &x, const Element &y) const {
			return mul(x,x,y);
		}
 
		inline Element &divin (Element &x, const Element &y) const {
			return div(x,x,y);
		}
 
		inline Element &negin (Element &x) const {
			return x = -x;
		}
		
		inline Element &invin (Element &x) const {
			return inv (x, x);
		}
		
		inline Element &axpyin (Element &r, const Element &a, const Element &x) const {
			r += a * x;
			return init (r, r);
		}

		static inline float getMaxModulus()
			{ return 2048.; } // 2^11
		
	};

	template <>
	class FieldAXPY<ModularBalanced<float> > {	  
	public:
		
		typedef float Element;
		typedef ModularBalanced<float> Field;
		
		FieldAXPY (const Field &F) : _F (F),
					     _y(0.) , _bound( (float) (((1ULL << 24) - (int) (_F.modulus*_F.modulus)))) {}
	  
		FieldAXPY (const FieldAXPY &faxpy) : _F (faxpy._F),
		_y(faxpy._y), _bound(faxpy._bound) {}
	  
		FieldAXPY<ModularBalanced<float> > &operator = (const FieldAXPY &faxpy) {
			_F = faxpy._F; 
			_y= faxpy._y;
			_bound= faxpy._bound;
			return *this; 
		}
	  
            inline Element& mulacc (const Element &a, const Element &x) {
		    //                 Element tmp= a*x;	
		    //                 return accumulate(tmp);
		    return accumulate(a*x);
            }
            
            inline Element& accumulate (const Element &tmp) {   
		    _y += tmp;
		    if (_y > _bound)
			    return _y = fmod (_y, _F.modulus);
		    else
			    return _y;
            }
            inline Element& subumulate (const Element &tmp) {   
		    _y -= tmp;
		    if (_y < 0)
			    return _y += _F.modulus;
		    else
			    return _y;
            }
	    
	    inline Element& get (Element &y) {
			_y = fmod (_y, _F.modulus);
			return y=_y ;
		}
	  
		inline FieldAXPY &assign (const Element y) {
			_y = y; 
			return *this;
		}

		inline void reset() {
			_y = 0.;
		}
            
            inline Element& set (const Element &tmp) {   
                _y = tmp;
                if (_y > _bound)
                    return _y = fmod (_y, _F.modulus);
                else
                    return _y;
            }
	  
					     private:
	  		Field _F;
		float _y;
		float _bound;		
	};
	
	
	template <>
	class DotProductDomain<ModularBalanced<float> > : private virtual VectorDomainBase<ModularBalanced<float> > {
	private:
		float _bound;
		size_t _nmax;
	  
	public:	  
		typedef float Element;	  
		DotProductDomain (const ModularBalanced<float> &F)
			: VectorDomainBase<ModularBalanced<float> > (F), _bound( (float) ( (1ULL<<24) - (int) (_F.modulus*_F.modulus)))
			{
				_nmax= (size_t)floor((float(1<<11)* float(1<<11)*2.)/ (_F.modulus * _F.modulus));
			}
	  
	protected:
		template <class Vector1, class Vector2>
		inline Element &dotSpecializedDD (Element &res, const Vector1 &v1, const Vector2 &v2) const {
	    
			float y = 0.;
			float t = 0.;
			if (v1.size() < _nmax) {
				for (size_t i = 0; i< v1.size();++i)
					y += v1[i] * v2[i] ;				
				y = fmod(y, _F.modulus);
			}
			else{			
				size_t i=0;
				for (;i< v1.size()- _nmax ;i=i+_nmax){
					for (size_t j=i;j<i+_nmax;++j)
						y += v1[j] * v2[j];
					t+=fmod(y, _F.modulus);
					y=0.;							
				}
				for (;i < v1.size();++i)
					y += v1[i] * v2[i];
				t+=fmod(y, _F.modulus);
				y = fmod(t, _F.modulus);
			}
			return res = y;
		}

		template <class Vector1, class Vector2>
		inline Element &dotSpecializedDSP (Element &res, const Vector1 &v1, const Vector2 &v2) const {		  
				    
			float y = 0.;
			float t =0.;
			

			if (v1.first.size() < _nmax) {
				for (size_t i=0;i<v1.first.size();++i)
					y+= v1.second[i] * v2[v1.first[i]];
				y = fmod(y, _F.modulus);
			}
			else {			
				size_t i=0;
				for (;i< v1.first.size()- _nmax ;i=i+_nmax){
					for (size_t j=i;j<i+_nmax;++j)
						y += v1.second[j] * v2[v1.first[j]];
					t+=fmod(y, _F.modulus);
					y=0.;							
				}
				for (;i < v1.first.size();++i)
					y += v1.second[i] * v2[v1.first[i]];
				t+= fmod(y, _F.modulus);
				y = fmod(t, _F.modulus);
			}
			return res = y;
		}
	};
	}

#include "linbox/randiter/modular-balanced.h"
#include "linbox/randiter/nonzero.h"

#endif