This file is indexed.

/usr/include/linbox/fflas/fflas_bounds.inl 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
/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/* fflas/fflas_bounds.inl
 * Copyright (C) 2008 Clement Pernet
 *
 * Written by Clement Pernet <Clement.Pernet@imag.fr>
 *
 * See COPYING for license information.
 */

#ifdef _LINBOX_LINBOX_CONFIG_H
#define FFLAS_INT_TYPE Integer
#else
#define FFLAS_INT_TYPE long unsigned int
#endif

/**
 * MatMulParameters
 *
 * \brief Computes the threshold parameters for the cascade
 *        Matmul algorithm
 *
 * 
 * \param F Finite Field/Ring of the computation.
 * \param k Common dimension of A and B, in the product A x B
 * \param bet Computing AB + beta C
 * \param delayedDim Returns the size of blocks that can be multiplied
 *                   over Z with no overflow
 * \param base Returns the type of BLAS representation to use
 * \param winoRecLevel Returns the number of recursion levels of
 *                     Strassen-Winograd's algorithm to perform
 * \param winoLevelProvided tells whether the user forced the number of
 *                          recursive level of Winograd's algorithm
 */
template <class Field>
inline void FFLAS::MatMulParameters (const Field& F,
				     const size_t k,
				     const typename Field::Element& beta,
				     size_t& delayedDim,
				     FFLAS_BASE& base,
				     size_t& winoRecLevel,
				     bool winoLevelProvided) {

	// Strategy : determine Winograd's recursion first, then choose appropriate
	// floating point representation, and finally the blocking dimension.
	// Can be improved for some cases.

	if (!winoLevelProvided)
		winoRecLevel = WinoSteps (k);
	base = BaseCompute (F, winoRecLevel);
	delayedDim = DotProdBound (F, winoRecLevel, beta, base);

	size_t n = k;
	size_t winoDel = winoRecLevel;

	// Computes the delayedDim, only depending on the recursive levels
	// that must be performed over Z
	while (winoDel > 0 && delayedDim < n) {
		winoDel--;
		delayedDim = DotProdBound (F, winoDel, beta, base);
		n >>= 1;
	}
	delayedDim = MIN (n, delayedDim);
}

/**
 * DotProdBound
 *
 * \brief  computes the maximal size for delaying the modular reduction
 *         in a dotproduct
 *
 * This is the default version assuming a conversion to a positive modular representation
 * 
 * \param F Finite Field/Ring of the computation
 * \param winoRecLevel Number of recusrive Strassen-Winograd levels (if any, 0 otherwise)
 * \param beta Computing AB + beta C
 * \param base Type of floating point representation for delayed modular computations
 * 
 */
template <class Field>
inline size_t FFLAS::DotProdBound (const Field& F,
				   const size_t w, 
				   const typename Field::Element& beta,
				   const FFLAS_BASE base) {
	
	FFLAS_INT_TYPE p;
	F.characteristic(p);
	typename Field::Element mone;
	F.init (mone, -1.0);

	unsigned long mantissa =
		(base == FflasDouble) ? DOUBLE_MANTISSA : FLOAT_MANTISSA;

	if (p == 0)
		return 1;
	
	double kmax;
	if (w > 0) {
		double c = computeFactor (F,w);
		double d = (double (1ULL << mantissa) /(c*c) + 1);
		if (d < 2)
			return 1;
		kmax = floor (d * (1ULL << w));
	} else {
		////// A fixer: (p-1)/2 si balanced

		double c = p-1;
		double cplt=0;
		if (!F.isZero (beta)){
			if (F.isOne (beta) || F.areEqual (beta, mone)) cplt = c;
			else cplt = c*c;
		}
		kmax = floor ( (double ((1ULL << mantissa) - cplt)) / (c*c));
		if (kmax  <= 1)
			return 1;
		}
	//kmax--; // we computed a strict upper bound
	return  (size_t) MIN (kmax, 1ULL << 31);
}

/**
 * Internal function for the bound computation
 * Generic implementation for positive representations
 */
template <class Field>
inline double FFLAS::computeFactor (const Field& F, const size_t w){
	FFLAS_INT_TYPE p;
	F.characteristic(p);
	size_t ex=1;
	for (size_t i=0; i < w; ++i) 	ex *= 3;
	return double(p - 1) * (1 + ex) / 2;
}

/**
 * WinoSteps
 *
 * \brief Computes the number of recursive levels to perform
 *
 * \param m the common dimension in the product AxB
 * 
 */
inline size_t FFLAS::WinoSteps (const size_t m) {
	size_t w = 0;
	size_t mt = m;
	while (mt >= WINOTHRESHOLD) {w++; mt >>= 1;}
	return w;
}

/**
 * BaseCompute
 *
 * \brief Determines the type of floating point representation to convert to,
 *        for BLAS computations
 * \param F Finite Field/Ring of the computation
 * \param w Number of recursive levels in Winograd's algorithm
 * 
 */
template <class Field>
inline FFLAS::FFLAS_BASE FFLAS::BaseCompute (const Field& F, const size_t w){
	
	FFLAS_INT_TYPE pi;
	F.characteristic(pi);
	FFLAS_BASE base;
	switch (w) {
	case 0: base = (pi < FLOAT_DOUBLE_THRESHOLD_0)? FflasFloat : FflasDouble;
		break;
	case 1:  base = (pi < FLOAT_DOUBLE_THRESHOLD_1)? FflasFloat : FflasDouble;
		break;
	case 2:  base = (pi < FLOAT_DOUBLE_THRESHOLD_2)? FflasFloat : FflasDouble;
		break;
	default: base = FflasDouble;
		break;
	}
	return base;
}


/*************************************************************************************
 * Specializations for ModularPositive and ModularBalanced over double and float
 *************************************************************************************/

template <class Element>
inline double computeFactor (const ModularBalanced<Element>& F, const size_t w){
	FFLAS_INT_TYPE p;
	F.characteristic(p);
	size_t ex=1;
	for (size_t i=0; i < w; ++i) 	ex *= 3;
	return  (p - 1) * ex / 2; 
}

template <>
inline FFLAS::FFLAS_BASE FFLAS::BaseCompute (const Modular<double>& F,
					     const size_t w){
	return FflasDouble;
}

template <>
inline FFLAS::FFLAS_BASE FFLAS::BaseCompute (const Modular<float>& F,
					     const size_t w){
	return FflasFloat;
}

template <>
inline FFLAS::FFLAS_BASE FFLAS::BaseCompute (const ModularBalanced<double>& F,
					     const size_t w){
	return FflasDouble;
}

template <>
inline FFLAS::FFLAS_BASE FFLAS::BaseCompute (const ModularBalanced<float>& F,
					     const size_t w){
	return FflasFloat;
}

/**
 * TRSMBound
 *
 * \brief  computes the maximal size for delaying the modular reduction
 *         in a triangular system resolution
 *
 * This is the default version over an arbitrary field.
 * It is currently never used (the recursive algorithm is run until n=1 in this case)
 * 
 * \param F Finite Field/Ring of the computation
 * 
 */
template <class Field>
inline size_t FFLAS::TRSMBound (const Field& F) {
	return 1;	
}

/**
 * Specialization for positive modular representation over double
 * Computes nmax s.t. (p-1)/2*(p^{nmax-1} + (p-2)^{nmax-1}) < 2^53
 * See [Dumas Giorgi Pernet 06, arXiv:cs/0601133]
 */
template<>
inline size_t FFLAS::TRSMBound (const Modular<double>& F){

	FFLAS_INT_TYPE pi;
	F.characteristic(pi);
	FFLAS_INT_TYPE p = pi, p1 = 1, p2 = 1;
	size_t nmax = 0;
	FFLAS_INT_TYPE max = ( (FFLAS_INT_TYPE)(1ULL << (DOUBLE_MANTISSA + 1) ) / (p - 1));
	while ( (p1 + p2) < max ){
		p1*=p;
		p2*=p-2;
		nmax++;
	}
	return nmax;
}


/**
 * Specialization for positive modular representation over float
 * Computes nmax s.t. (p-1)/2*(p^{nmax-1} + (p-2)^{nmax-1}) < 2^24
 * See [Dumas Giorgi Pernet 06, arXiv:cs/0601133]
 */
template<>
inline size_t FFLAS::TRSMBound (const Modular<float>& F){

	FFLAS_INT_TYPE pi;
	F.characteristic(pi);
	FFLAS_INT_TYPE p = pi, p1 = 1, p2 = 1;
	size_t nmax = 0;
	FFLAS_INT_TYPE max = ( (FFLAS_INT_TYPE)(1ULL << (FLOAT_MANTISSA + 1) ) / (p - 1));
	while ( (p1 + p2) < max ){
		p1*=p;
		p2*=p-2;
		nmax++;
	}
	return nmax;
}

/**
 * Specialization for balanced modular representation over double
 * Computes nmax s.t. (p-1)/2*(((p+1)/2)^{nmax-1}) < 2^53
 * See [Dumas Giorgi Pernet 06, arXiv:cs/0601133]
 */
template<>
inline size_t FFLAS::TRSMBound (const ModularBalanced<double>& F){

	FFLAS_INT_TYPE pi;
	F.characteristic (pi);
	FFLAS_INT_TYPE p = (pi + 1) / 2, p1 = 1;
	size_t nmax = 0;
	FFLAS_INT_TYPE max = ((FFLAS_INT_TYPE)(1ULL << (DOUBLE_MANTISSA + 1)) / ((FFLAS_INT_TYPE)(p - 1)));
	while (p1 < max){
		p1 *= p;
		nmax++;
	}
	return nmax;
}

/**
 * Specialization for balanced modular representation over float
 * Computes nmax s.t. (p-1)/2*(((p+1)/2)^{nmax-1}) < 2^24
 * See [Dumas Giorgi Pernet 06, arXiv:cs/0601133]
 */
template<>
inline size_t FFLAS::TRSMBound (const ModularBalanced<float>& F){

	FFLAS_INT_TYPE pi;
	F.characteristic (pi);
	FFLAS_INT_TYPE p = (pi + 1) / 2, p1 = 1;
	size_t nmax = 0;
	FFLAS_INT_TYPE max = ((FFLAS_INT_TYPE)(1ULL << (FLOAT_MANTISSA + 1)) / ((FFLAS_INT_TYPE) (pi - 1)));
	while (p1 < max){
		p1 *= p;
		nmax++;
	}
	return nmax;

}