This file is indexed.

/usr/include/linbox/blackbox/quad-matrix.h is in liblinbox-dev 1.3.2-1.1+b1.

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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
/* linbox/blackbox/quad-matrix.h
 * Copyright (C) 2006 LinBox
 * Written by -bds, hui wang
 *  ========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========
 */

#ifndef __LINBOX_quad_matrix_H
#define __LINBOX_quad_matrix_H


#include <algorithm>
#include "linbox/field/hom.h"
#include <vector>
#include <iterator>
//#include "linbox/vector/vector-traits.h"
#include "linbox/util/debug.h"
#include "linbox/linbox-config.h"
#include "linbox/blackbox/blackbox-interface.h"
#include "linbox/blackbox/scalar-matrix.h"
#include "linbox/blackbox/zo.h"
//#include "linbox/blackbox/side-by-side.h"
//#include "linbox/blackbox/over-under.h"

namespace LinBox
{

	template <typename Field>
	class ZeroOne;

	template <typename Field>
	class ScalarMatrix;

	template <typename Field>
	class SideBySide;

	template <typename Field>
	class OverUnder;

	/** A class of striped or block-decomposed zero-one matrices.

	  Right now we implement only side-by-side blocks, which is done to improve cache performance.  This class works especially well on quite sparse matrices whose entries are rather randomly positioned.  The idea is that the vector to be multiplied by each block fits in cache.  It is being more or less randomly accessed, so cache misses are avoided for these random accesses.

	  The possibility exists to set the stripe(block) width by a configure-time parameter.  Also this approach should be used on sparse matrices which are not zero-one.

	  This ZOQuad class is like a tagged union of several BB types.
	  Then SideBySide does not have it's two part types as template parameters.
	  Instead the parts are always ZOQuads.

	  \ingroup blackbox

*/
	template <typename _Field>
	class ZOQuad {
		//friend class ZeroOne<_Field>;
		enum BBtype {zo, sbs, ou};
		const void* _BBp;
		BBtype _tag;
		size_t _r, _c;
		static const unsigned int smallThreshold = 60000;

	protected:
		_Field _field;
	public:
		typedef _Field Field;

		typedef size_t Index;
		typedef std::vector<Index> IndexVector;
		typedef std::vector<IndexVector::iterator> PointerVector;

		// constructors
		ZOQuad() :
			_BBp(0), _r(0), _c(0)
		{}
#if 0
		ZOQuad(const ScalarMatrix<Field>&  A) :
			_BBp(&A), _tag(sm), _r(A.rowdim()), _c(A.coldim())
		{}
#endif
		ZOQuad(const SideBySide<Field>& A) :
			_BBp(&A), _tag(sbs), _r(A.rowdim()), _c(A.coldim())
		{}
		ZOQuad(const OverUnder<Field>& A) :
			_BBp(&A), _tag(ou), _r(A.rowdim()), _c(A.coldim())
		{}
		ZOQuad(const ZeroOne<Field>& A) //:
		// _BBp(&A), _tag(zo), _r(A.rowdim()), _c(A.coldim())
		{
			init(A);
		}

		int init (const ZeroOne<Field>&  A)
		{
			const Field& F = A.field();
			//if ( A.nnz() == 0 )
			if ( A.coldim() <= smallThreshold )
			{
				_BBp = new ZeroOne<Field>(A);
				_tag = zo;
				_r = A.rowdim(); _c = A.coldim();
				const ZeroOne<Field> *B(static_cast< const ZeroOne<Field>* >(_BBp));
				if( !(B->sorted) )
				{
					//		std::cout << " -- init: switch sort " << A.sorted << " " << &(A.sorted) << std::endl;
					B->switch_sort();
					//		std::cout << " -- init: switch sort " << A.sorted << std::endl;
				}
				//std::cout << " -- quad init: " << A.nnz() << " ( zo: " << &A << ", " << _BBp << ", quad: " << this << ")" << std::endl;
				return 0;
			}
			// if A has more rows than cols, make an OverUnder
			/*
			   if ( A.coldim() <= A.rowdim() )
			   {
			   if( !A.sorted ) A.switch_sort();

			   IndexVector firstHalf;
			   PointerVector firstHalfP;
			   std::back_insert_iterator< IndexVector > first(firstHalf);
			   std::back_insert_iterator< PointerVector > firstP(firstHalfP);
			   copy( A._index.begin(), *(A._indexP.begin() + A._indexP.size()/2), first);
			   copy( A._indexP.begin(), A._indexP.begin() + A._indexP.size()/2 + 1, firstP);
			   ZeroOne<Field> U(F, firstHalf, firstHalfP, firstHalfP.size()-1, A._coldim, A.sorted);
			   ZOQuad<Field> *UU = new ZOQuad<Field>(U);

			   IndexVector secondHalf;
			   PointerVector secondHalfP;
			   std::back_insert_iterator< IndexVector > second(secondHalf);
			   std::back_insert_iterator< PointerVector > secondP(secondHalfP);
			   copy( *(A._indexP.begin() + A._indexP.size()/2), A._index.end(), second);
			   copy( A._indexP.begin() + A._indexP.size()/2, A._indexP.end(), secondP);
			   ZeroOne<Field> D(F, secondHalf, secondHalfP, secondHalfP.size()-1, A._coldim, A.sorted);
			   ZOQuad<Field> *DD = new ZOQuad<Field>(D);

			//Hui works this out!

			_BBp = new OverUnder<Field>(UU, DD);

			_tag = ou;
			_r = A.rowdim(); _c = A.coldim();

			return 1;
			}
			*/
			// else make an sideBySide
			///*
			   else
			   {
				   if( A.sorted ) A.switch_sort();

				   IndexVector firstHalf;
				   PointerVector firstHalfP;
				   std::back_insert_iterator< IndexVector > first(firstHalf);
				   std::back_insert_iterator< PointerVector > firstP(firstHalfP);
				   copy( A._index.begin(), *(A._indexP.begin() + A._indexP.size()/2), first);
				   copy( A._indexP.begin(), A._indexP.begin() + A._indexP.size()/2 + 1, firstP);
				   ZeroOne<Field> L(F, firstHalf, firstHalfP, A._rowdim, firstHalfP.size()-1, A.sorted);
				   ZOQuad<Field> *LL = new ZOQuad<Field>(L);

				   IndexVector secondHalf;
				   PointerVector secondHalfP;
				   std::back_insert_iterator< IndexVector > second(secondHalf);
				   std::back_insert_iterator< PointerVector > secondP(secondHalfP);
				   copy( *(A._indexP.begin() + A._indexP.size()/2), A._index.end(), second);
				   copy( A._indexP.begin() + A._indexP.size()/2, A._indexP.end(), secondP);
				   ZeroOne<Field> R(F, secondHalf, secondHalfP, A._rowdim, secondHalfP.size()-1, A.sorted);
				   ZOQuad<Field> *RR = new ZOQuad<Field>(R);

				   //Hui works this out!

				   _BBp = new SideBySide<Field>(LL, RR);

				   _tag = sbs;
				   _r = A.rowdim(); _c = A.coldim();

				   return 2;
			   }
			   //*/
		}
		std::ostream & write(std::ostream & out) const
		{
			switch (_tag)
			{
			case zo:
				{
					const ZeroOne<Field> *A(static_cast< const ZeroOne<Field>* >(_BBp));
					out << "zo(" << A->rowdim() << ", " << A->coldim() << ", " << A->nnz() << ") ";
					break;
				}

#if 0
			case sm:
				{
					const ScalarMatrix<Field> *A(static_cast< const ScalarMatrix<Field>* >(_BBp));
					delete A ; break;
				}
#endif
			case sbs:
				{
					out << "sidebyside(";
					const SideBySide<Field> *A(static_cast< const SideBySide<Field>* >(_BBp));
					(A->_quadLeft)->write(out) << ", ";
					(A->_quadRight)->write(out) << ") ";
					break;
				}
			case ou:
				{
					out << "overunder(";
					const OverUnder<Field> *A(static_cast< const OverUnder<Field>* >(_BBp));
					(A->_quadUp)->write(out) << ", ";
					(A->_quadDown)->write(out) << ") ";
					break;
				}
			}
			return out;
		}

		~ZOQuad()
		{
#if 0
			switch (_tag)
			{
			case zo:
				{
					const ZeroOne<Field> *A(static_cast< const ZeroOne<Field>* >(_BBp));
					delete A ;
					break;
				}
#if 0
			case sm:
				{
					const ScalarMatrix<Field> *A(static_cast< const ScalarMatrix<Field>* >(_BBp));
					delete A ; break;
				}
#endif
			case sbs:
				{
					const SideBySide<Field> *A(static_cast< const SideBySide<Field>* >(_BBp));
					delete A ; break;
				}
			case ou:
				{
					const OverUnder<Field> *A(static_cast< const OverUnder<Field>* >(_BBp));
					delete A ; break;
				}
			}
#endif
		}

		template <typename InVector, typename OutVector>
		OutVector& apply(OutVector& y, const InVector& x) const
		//OutVector& apply(OutVector& y, const InVector& x)
		{
			//std::cout << " zo-quad apply size of x: " << x.size() << " " << " size of y: " << y.size() << endl;
			switch (_tag)
			{
			case zo:
				{
					const ZeroOne<Field> *A(static_cast< const ZeroOne<Field>* >(_BBp));
					//ZeroOne<Field> *A(static_cast< ZeroOne<Field>* >(_BBp));
					//std::cout << "\n apply zo quad -- zo " << "( quad: " << this << ", zo: " << _BBp << "), (" << _r << ", " << _c << "), (" << A->rowdim() << ", " << A->coldim() << ")" << endl;
					A->apply(y, x);
					break;
				}

#if 0
			case sm:
				{

					const ScalarMatrix<Field> *A(static_cast< const ScalarMatrix<Field>* >(_BBp));
					ScalarMatrix<Field> *A(static_cast< ScalarMatrix<Field>* >(_BBp));
					A->apply(y, x);
					break;
				}
#endif
			case sbs:
				{
					const SideBySide<Field> *A(static_cast< const SideBySide<Field>* >(_BBp));
					//SideBySide<Field> *A(static_cast< SideBySide<Field>* >(_BBp));
					//std::cout << "\n apply zo quad -- sbs " << _r << " " << _c << endl;
					A->apply(y, x);
					break;
				}
			case ou:
				{
					const OverUnder<Field> *A(static_cast< const OverUnder<Field>* >(_BBp));
					//OverUnder<Field> *A(static_cast< OverUnder<Field>* >(_BBp));
					//std::cout << "\n apply zo quad -- ou " << _r << " " << _c << endl;
					A->apply(y, x);
					break;
				}
			}
			return y;
		}

		// similar applyTranspose
		template <typename InVector, typename OutVector>
		OutVector& applyTranspose(OutVector& y, const InVector& x) const
		//OutVector& applyTranspose(OutVector& y, const InVector& x)
		{
			switch (_tag)
			{
			case zo:
				{
					//const ZeroOne<Field> *A(static_cast< const ZeroOne<Field>* >(_BBp));
					const ZeroOne<Field> *A(static_cast< const ZeroOne<Field>* >(_BBp));
					A->applyTranspose(y, x);
					break;
				}
#if 0
			case sm:
				{
					const ScalarMatrix<Field> *A(static_cast< const ScalarMatrix<Field>* >(_BBp));
					ScalarMatrix<Field> *A(static_cast< ScalarMatrix<Field>* >(_BBp));
					A->applyTranspose(y, x);
					break;
				}
#endif
			case sbs:
				{
					const SideBySide<Field> *A(static_cast< const SideBySide<Field>* >(_BBp));
					//SideBySide<Field> *A(static_cast< SideBySide<Field>* >(_BBp));
					A->applyTranspose(y, x);
					break;
				}
			case ou:
				{
					const OverUnder<Field> *A(static_cast< const OverUnder<Field>* >(_BBp));
					//OverUnder<Field> *A(static_cast< OverUnder<Field>* >(_BBp));
					A->applyTranspose(y, x);
					break;
				}
			}
			return y;
		}

		size_t rowdim() const
		{
			switch (_tag)
			{
			case zo:
				{
					const ZeroOne<Field> *A(static_cast< const ZeroOne<Field>* >(_BBp));
					return A->rowdim();
				}
			case sbs:
				{
					const SideBySide<Field> *A(static_cast< const SideBySide<Field>* >(_BBp));
					return A->rowdim();
				}
			case ou:
				{
					const OverUnder<Field> *A(static_cast< const OverUnder<Field>* >(_BBp));
					return A->rowdim();
				}
			}
			return 0;
		}
		size_t coldim() const
		{
			switch (_tag)
			{
			case zo:
				{
					const ZeroOne<Field> *A(static_cast< const ZeroOne<Field>* >(_BBp));
					return A->coldim();
				}
			case sbs:
				{
					const SideBySide<Field> *A(static_cast< const SideBySide<Field>* >(_BBp));
					return A->coldim();
				}
			case ou:
				{
					const OverUnder<Field> *A(static_cast< const OverUnder<Field>* >(_BBp));
					return A->coldim();
				}
			}
			return 0;
		}
		const Field& field() const
		{
			switch (_tag)
			{
			case zo:
				{
					const ZeroOne<Field> *A(static_cast< const ZeroOne<Field>* >(_BBp));
					return A->field();
				}
#if 0
			case sm:
				{
					const ScalarMatrix<Field> *A(static_cast< const ScalarMatrix<Field>* >(_BBp));
					return A->field();
				}
#endif
			case sbs:
				{
					const SideBySide<Field> *A(static_cast< const SideBySide<Field>* >(_BBp));
					return A->field();
				}
			case ou:
				{
					const OverUnder<Field> *A(static_cast< const OverUnder<Field>* >(_BBp));
					return A->field();
				}
			}
			// silly business to avoid a warning ( no return statement warning )
			const ScalarMatrix<Field> *A(static_cast< const ScalarMatrix<Field>* >(_BBp));
			return A->field();
		}
	}; //ZOQuad

	template <typename Field>
	class SideBySide {
		typedef ZOQuad<Field> Quad;
	public://temp
		const Quad *_quadLeft, *_quadRight;
	public:
		SideBySide(const Quad* A, const Quad* B) :
			_quadLeft(A), _quadRight(B)
		{}
		//~SideBySide() {delete _quadLeft; delete _quadRight;}

		template <typename InVector, typename OutVector>
		OutVector& apply(OutVector& y, const InVector& x) const
		//OutVector& apply(OutVector& y, const InVector& x)
		{
			std::vector<typename Field::Element> z(y.size());
			VectorDomain<Field> VD(field());
			//std::vector<typename Field::Element> x_1( x.begin(), x.begin() + _quadLeft->coldim() );
			//std::vector<typename Field::Element> x_2( x.begin() + _quadLeft->coldim(), x.end() );
			Subvector<typename InVector::const_iterator> x_1(x.begin(), x.begin()+_quadLeft->coldim());
			Subvector<typename InVector::const_iterator> x_2(x.begin()+_quadLeft->coldim(), x.end());
			//std::cout << " side-by-side apply size of x: " << x.size() << " " << " size of y: " << y.size() << endl;
			//std::cout << " side-by-side apply size of x_1: " << x_1.size() << " " << " size of x_2: " << x_2.size() << endl;
			_quadLeft->apply (y, x_1);
			_quadRight->apply (z, x_2);
			VD.addin(y, z);

			return y;
		}

		template <typename InVector, typename OutVector>
		OutVector& applyTranspose(OutVector& y, const InVector& x) const
		//OutVector& applyTranspose(OutVector& y, const InVector& x)
		{
			//std::vector<typename Field::Element> y_1( y.begin(), y.begin() + _quadLeft->coldim() );
			//std::vector<typename Field::Element> y_2( y.begin() + _quadLeft->coldim(), y.end() );
			Subvector<typename OutVector::iterator, typename OutVector::const_iterator> y_1(y.begin(), y.begin()+_quadLeft->coldim());
			Subvector<typename OutVector::iterator, typename OutVector::const_iterator> y_2(y.begin()+_quadLeft->coldim(), y.end());
			_quadLeft->applyTranspose (y_1, x);
			_quadRight->applyTranspose (y_2, x);
			copy(y_1.begin(), y_1.end(), y.begin());
			copy(y_2.begin(), y_2.end(), y.begin() + y_1.size());
			return y;
		}

		size_t rowdim()const{return _quadLeft->rowdim();}
		size_t coldim()const{return _quadLeft->coldim() + _quadRight->coldim();}
		const Field& field()const {return _quadLeft->field();}
	};

	template <typename Field>
	class OverUnder {
		typedef ZOQuad<Field> Quad;
	public://temp
		const Quad *_quadUp, *_quadDown;
	public:
		OverUnder(const Quad* A, const Quad* B) :
			_quadUp(A), _quadDown(B)
		{}
		//~OverUnder() {delete _quadUp; delete _quadDown;}

		template <typename InVector, typename OutVector>
		OutVector& apply(OutVector& y, const InVector& x) const
		//OutVector& apply(OutVector& y, const InVector& x)
		{
			//std::vector<typename Field::Element> y_1( y.begin(), y.begin() + _quadUp->rowdim() );
			//std::vector<typename Field::Element> y_2( y.begin() + _quadUp->rowdim(), y.end() );
			Subvector<typename OutVector::iterator, typename OutVector::const_iterator> y_1(y.begin(), y.begin()+_quadUp->rowdim());
			Subvector<typename OutVector::iterator, typename OutVector::const_iterator> y_2(y.begin()+_quadUp->rowdim(), y.end());
			//if ((_A_ptr == 0) || (_B_ptr == 0)) { throw error }
			//std::cout << " over-under apply size of x: " << x.size() << " " << " size of y: " << y.size() << endl;
			//std::cout << " over-under apply size of y_1: " << y_1.size() << " " << " size of y_2: " << y_2.size() << endl;
			_quadUp->apply (y_1, x);
			_quadDown->apply (y_2, x);
			//copy(y_1.begin(), y_1.end(), y.begin());
			//copy(y_2.begin(), y_2.end(), y.begin() + y_1.size());

			return y;
		}

		template <typename InVector, typename OutVector>
		OutVector& applyTranspose(OutVector& y, const InVector& x) const
		//OutVector& applyTranspose(OutVector& y, const InVector& x)
		{
			std::vector<typename Field::Element> z(y.size());
			VectorDomain<Field> VD(field());
			std::vector<typename Field::Element> x_1( x.begin(), x.begin() + _quadUp->rowdim() );
			std::vector<typename Field::Element> x_2( x.begin() + _quadUp->rowdim(), x.end() );
			//Subvector<typename InVector::iterator, typename InVector::const_iterator> x_1(x.begin(), x.begin()+_quadUp->rowdim());
			//Subvector<typename InVector::iterator, typename InVector::const_iterator> x_2(x.begin()+_quadUp->rowdim(), x.end());
			_quadUp->applyTranspose (y, x_1);
			_quadDown->applyTranspose (z, x_2);
			VD.addin(y, z);
			return y;
		}

		size_t coldim() const{return _quadUp->coldim();}
		size_t rowdim() const{return _quadUp->rowdim() + _quadDown->rowdim();}
		const Field& field() const {return _quadUp->field();}
	};

	// similar class OverUnder<Field>

} //namespace LinBox

#endif // __LINBOX_quad_matrix_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: