This file is indexed.

/usr/include/linbox/blackbox/blas-blackbox.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
/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* linbox/blackbox/blas-blackbox.h
 * Copyright (C) 2004 Pascal Giorgi 
 *
 * Written by :
 *               Pascal Giorgi  pascal.giorgi@ens-lyon.fr
 *               
 *
 * This library 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 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., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */


#ifndef __BLAS_BLACKBOX_H
#define __BLAS_BLACKBOX_H

#include <linbox/matrix/blas-matrix.h>
#include <linbox/fflas/fflas.h>
#include <linbox/matrix/matrix-domain.h>
#include <linbox/field/hom.h>
#include <linbox/field/multimod-field.h>
#include <linbox/util/matrix-stream.h>

namespace LinBox {
	
	template <class Field>
	bool checkBlasApply(const Field &F, size_t n) {

		integer chara, card;
		F.characteristic(chara);
		F.cardinality(card);
		
		if ((chara != card) || chara == 0)
			return false;
		else
			if (n*chara*chara < integer("9007199254740992"))
				return true;
			else
				return false;
	}


	/** \brief dense matrix representation for BLAS based elimination. \ingroup blackbox
	 *
	 *  A BlasBlackbox can be constructed from any blackbox matrix. This costs n blackbox
	 * matrix vector products in general, but is efficiently done from a DenseMatrix 
	 * or SparseMatrix.
	 */
	template <class _Field>
	class BlasBlackbox : public BlasMatrix<typename _Field::Element> 
	{

	public:

		typedef _Field Field;
		typedef typename Field::Element Element;
                typedef BlasBlackbox<_Field> Self_t;

		BlasBlackbox () {}

		BlasBlackbox (const Field& F) :  _F(F), _MD(F), _VD(F) 
		{ _F.init(_One,1UL), _F.init(_Zero,0UL);_use_fflas=false;}

		BlasBlackbox (const Field& F, const size_t m, const size_t n) 
			: BlasMatrix<Element> (m,n),  _F(F), _MD(F), _VD(F), _row(m) , _col(n) 
		{ 
			_F.init(_One,1UL), _F.init(_Zero,0UL);
			typename BlasMatrix<Element>::RawIterator it = this->rawBegin();
			for (; it != this->rawEnd(); ++it)
				_F.init(*it, 0);
			_use_fflas= checkBlasApply(_F, _col);
		}

		BlasBlackbox(MatrixStream<Field> &ms)
			: BlasMatrix<Element> (ms), _F(ms.getField()), _MD(ms.getField()), _VD(ms.getField()) 
		{
			ms.getRows(_row);
			ms.getColumns(_col);
			_use_fflas= checkBlasApply(_F, _col);
		}
		


		BlasBlackbox (const Field& F, BlasMatrix<Element>& M) 
			: BlasMatrix<Element> (M),  _F(F), _MD(F) , _VD(F),  _row(M.rowdim()), _col(M.coldim()) 
		{ _F.init(_One,1UL), _F.init(_Zero,0UL); _use_fflas= checkBlasApply(_F, _col); }


 		template< class Blackbox >
 		BlasBlackbox (const Blackbox& M)
 			: BlasMatrix<Element> (M), _F(M.field()), _MD(M.field()), _VD(M.field()), _row(M.rowdim()), _col(M.coldim()) 
		{_F.init( _One, 1UL ); _F.init( _Zero, 0UL ); _use_fflas= checkBlasApply(_F, _col);}
		

		BlasBlackbox (const BlasBlackbox<Field>& M)
			: BlasMatrix< Element> (M), _F(M._F), _MD(M._F), _VD(M._F), 
			  _row(M._row), _col(M._col), _One(M._One), _Zero(M._Zero) {_use_fflas= checkBlasApply(_F, _col);}

		BlasBlackbox (const BlasBlackbox<Field>& M, const size_t i0, const size_t j0, const size_t m, const size_t n)
			: BlasMatrix< Element> (M,i0,j0,m,n), _F(M._F), _MD(M._F), _VD(M._F), 
			  _row(m), _col(n), _One(M._One), _Zero(M._Zero) {_use_fflas= checkBlasApply(_F, _col);}
		

		BlasBlackbox (const Field &F, const BlasBlackbox<Field>& M)
			: BlasMatrix< Element> (M), _F(M._F), _MD(M._F), _VD(F),
			  _row(M._row), _col(M._col), _One(M._One), _Zero(M._Zero) {_use_fflas= checkBlasApply(_F, _col);}

		template <class Vector1, class Vector2> 
		Vector1&  apply (Vector1& y, const Vector2& x) const 
		{
			
			if (_use_fflas){
       
				FFLAS::fgemv( _F, FFLAS::FflasNoTrans, 
					      this->_row, this->_col,
					      this->_One,
					      this->_ptr, this->_stride,
					      &x[0],1,
					      this->_Zero,
					      &y[0],1);  
			}			
			else {
				_MD. vectorMul (y, *this, x);

				//typename BlasMatrix<Element>::ConstRowIterator i = this->rowBegin ();
				//typename Vector1::iterator j = y.begin ();
				
				//for (; j != y.end (); ++j, ++i)
				//	_VD.dot (*j, *i, x);
			}
			return y;
		}

		template <class Vector1, class Vector2>
		Vector1&  applyTranspose (Vector1& y, const Vector2& x) const  
		{

			if (_use_fflas)
				FFLAS::fgemv( this->_F, FFLAS::FflasTrans, 
					      this->_row, this->_col,
					      this->_One,
					      this->_ptr, this->_stride,
					      &x[0],1,
					      this->_Zero,
					      &y[0],1);  
			
			else {
				typename BlasMatrix<Element>::ConstColIterator i = this->colBegin ();
				typename Vector1::iterator j = y.begin ();
				
				for (; j != y.end (); ++j, ++i)
					_VD.dot (*j, x, *i);
			}
      
			return y;
		}  

            
		template<typename _Tp1>
		struct rebind
		{
                    typedef BlasBlackbox<_Tp1> other; 
                    
                    void operator() (other *& Ap, const Self_t& A, const _Tp1& F) {
                        Ap = new other(F, A.rowdim(), A.coldim());
                        typename Self_t::ConstRawIterator A_p;
                        typename other::RawIterator Ap_p;
                        Hom<Field, _Tp1> hom(A. field(), F);
                        for (A_p = A. rawBegin(), Ap_p = Ap -> rawBegin();
                             A_p != A. rawEnd(); ++ A_p, ++ Ap_p) 
				hom.image (*Ap_p, *A_p);
                    }
                };

		size_t rowdim() const {return _row;}

		size_t coldim() const {return _col;}


		const Field &field() const  {return _F;}
		Field &field() {return const_cast<Field&>(_F);}
		
		/*
		  std::vector<Element>& apply(std::vector<Element>& y, const std::vector<Element>& x) const {
   
		  FFLAS::fgemv( _F, FFLAS::FflasNoTrans, 
		  this->_row, this->_col,
		  this->_One,
		  _ptr, _stride,
		  &x[0],1,
		  this->_Zero,
		  &y[0],1);  
		  return y;
		  }
		*/


		/** Read the blackbox from an input stream
		 * @param file Input stream from which to read
		 */
		std::istream &read (std::istream &file){
			return BlasMatrix<Element>::read(file, _F);

		}

		/** Write the blackbox to an output stream
		 * @param os Output stream to which to write		 
		 */
		std::ostream &write (std::ostream &os) const {
			return DenseSubmatrix<Element>::write(os, _F);
		}

		

	protected:
		
		const Field                 & _F;  
		MatrixDomain<Field>    _MD; 
		VectorDomain<Field>    _VD;  
		size_t                _row,_col;
		Element              _One,_Zero;
		bool                  _use_fflas;


	}; // end of class BlasBlackbox

	template <class Field>
	struct MatrixTraits< BlasBlackbox<Field> >
	{
		typedef BlasBlackbox<Field> MatrixType;
		typedef typename MatrixCategories::RowColMatrixTag MatrixCategory;
	};

	template <class Field>
	struct MatrixTraits< const BlasBlackbox<Field> >
	{
		typedef const BlasBlackbox<Field> MatrixType;
		typedef typename MatrixCategories::RowColMatrixTag MatrixCategory;
	};

	template <class Field>
	class MatrixContainerTrait<BlasBlackbox<Field> > {
	public:
		typedef MatrixContainerCategory::BlasContainer Type;
	};

	template <class Field>
	class MatrixContainerTrait<const BlasBlackbox<Field> > {
	public:
		typedef MatrixContainerCategory::BlasContainer Type;
	};
	
    



	template<>
	class BlasBlackbox<MultiModDouble> {


	public:

		typedef MultiModDouble         Field;
		typedef std::vector<double>  Element;
                typedef BlasBlackbox<MultiModDouble> Self_t;

		//BlasBlackbox () {}
		
		BlasBlackbox (const MultiModDouble& F) :  _F(F) , _rep(F.size()), _entry(F.size())
		{}

		BlasBlackbox (const Field& F, size_t m, size_t n, bool alloc=true) 
			:  _F(F), _row(m) , _col(n) , _rep(F.size()),  _entry(F.size())
		{ 			
			for (size_t i=0;i<_rep.size();++i)
				if (alloc)_rep[i]       =  new BlasBlackbox<Modular<double> > (F.getBase(i), m, n);
			}
		
		BlasBlackbox (const BlasBlackbox<MultiModDouble> & A): _F(A._F),_row(A._row), _col(A._col), 
								       _rep(A._rep.size()), _entry(A._entry) {

			for (size_t i=0;i<_rep.size();++i)
				_rep[i]= new  BlasBlackbox<Modular<double> > (const_cast<BlasBlackbox<Modular<double> >& >( *A._rep[i]));
		}


		const BlasBlackbox<MultiModDouble>& operator=(const BlasBlackbox<MultiModDouble> & A){			
			//_F   = A._F;		
			_row = A._row;
			_col = A._col;
			_rep = std::vector<BlasBlackbox<Modular<double> >* >(A._rep.size());		
			_entry = A._entry;
			for (size_t i=0;i<_rep.size();++i)
				_rep[i]= new  BlasBlackbox<Modular<double> > (const_cast<BlasBlackbox<Modular<double> >& >( *A._rep[i]));
			return *this;
		}
  

		~BlasBlackbox() {for (size_t i=0; i< _rep.size();++i) {delete _rep[i];} }

		template <class Vector1, class Vector2> 
		Vector1&  apply (Vector1& y, const Vector2& x) const 
		{	
			for (size_t i=0;i<_rep.size();++i) {				
				std::vector<double> x_tmp(x.size()), y_tmp(y.size());
				for (size_t j=0;j<x.size();++j)
					x_tmp[j]= x[j][i];		
								
				_rep[i]->apply(y_tmp, x_tmp);
			
				for (size_t j=0;j<y.size();++j){
					y[j][i]=y_tmp[j];				

				}
			}
			
			return y;
		}

		template <class Vector1, class Vector2>
		Vector1&  applyTranspose (Vector1& y, const Vector2& x) const  
		{
			for (size_t i=0;i<_rep.size();++i) {
				std::vector<double> x_tmp(x.size()), y_tmp(y.size());
				for (size_t j=0;j<x.size();++j)
					x_tmp[i]= x[j][i];

				_rep[i]->applyTranspose(y_tmp, x_tmp);
				
				for (size_t j=0;j<y.size();++j)
					y[j][i]=y_tmp[i];
			}
			
			return y;
		}  

            /*
		template<typename _Tp1>
		struct rebind
		{
                    typedef BlasBlackbox<_Tp1> other; 
                    
                    void operator() (other *& Ap, const Self_t& A, const _Tp1& F) {
                        Ap = new other(F, A.rowdim(), A.coldim());
			Hom<Field, _Tp1> hom(A. field(), F);
			
			hom.image (*Ap_p, *A_p);
                    }
                };
	    */

		size_t rowdim() const {return _row;}

		size_t coldim() const {return _col;}


		const Field &field() const  {return _F;}
		
		
		std::ostream& write(std::ostream& os) const {
			for (size_t i=0;i<_rep.size();++i)
				_rep[i]->write(os);
			return os;
		}


		void setEntry (size_t i, size_t j, const Element &a_ij){
			for (size_t i=0; i< _rep.size();++i)
				_rep[i]->setEntry(i,j,a_ij[i]);
		}
		
		
		const Element& getEntry (size_t i, size_t j){		
			for (size_t i=0; i< _rep.size();++i)
				_entry[i]=_rep[i]->getEntry(i,j);
			return _entry;
		}
	
		BlasBlackbox<Modular<double> >*& getMatrix(size_t i) {return _rep[i];}

	protected:
		
		const MultiModDouble                 &_F;  
		const std::vector<MatrixDomain<Modular<double> > >   _MD; 
		size_t                  _row,_col;
		Element                _One,_Zero;		
		std::vector<BlasBlackbox<Modular<double> >* > _rep;
		std::vector<double>       _entry;     
	};

		
		
	

	template <>
	class MatrixContainerTrait<BlasBlackbox<MultiModDouble> > {
	public:
		typedef MatrixContainerCategory::Blackbox Type;
	};



} // end of namespace LinBox

#endif