This file is indexed.

/usr/include/linbox/vector/stream.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
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
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/* linbox/vector/stream.h
 * Copyright (C) 2002 Bradford Hovinen
 *
 * Written by Bradford Hovinen <hovinen@cis.udel.edu>
 *
 * ------------------------------------
 * 2003-02-03 Bradford Hovinen <bghovinen@math.uwaterloo.ca>
 *
 * RandomSparseStream::RandomSparseStream: put probability parameter before
 * vector dimension
 * ------------------------------------
 * 2002-09-05 Bradford Hovinen <bghovine@math.uwaterloo.ca>
 *
 *  - Renamed to stream.h and moved to linbox/vector
 *  - VectorFactory is now called VectorStream, which fits its purpose
 *    somewhat better
 *  - The interface is now closer to the interface for istream
 *  - RandomDenseVectorFactory, et al. are refactored into classes
 *    parameterized on the vector type and specialized appropriately. This
 *    allows, e.g. construction of a random dense vector in sparse
 *    representation and so on.
 *  - New constructor interface for RandomSparseStream accepts proportion of
 *    nonzero entries; removed existing constructors
 *  - Reindented, since the other changes are so numerous that diffs aren't a
 *    big deal anyway
 *
 * ------------------------------------
 * 2002-05-18 Bradford Hovinen <hovinen@cis.udel.edu>
 *
 * Refactor: Create one class StandardBasisFactory, parameterized by vector
 * type, with specializations for dense, sparse map, and sparse associative
 * vectors.
 * 
 * ------------------------------------
 * Modified by Dmitriy Morozov <linbox@foxcub.org>. May 27, 2002.
 *
 * Added parametrization of the VectorCategroy tags by VectorTraits (see 
 * vector-traits.h for more details).
 * 
 * ------------------------------------
 *  
 * See COPYING for license information.
 */

#ifndef __VECTOR_STREAM_H
#define __VECTOR_STREAM_H

#include <vector>
#include <cmath>

#include "linbox/vector/vector-traits.h"
#include "linbox/util/debug.h"
#include "linbox/randiter/nonzero.h"
#include "linbox/randiter/mersenne-twister.h"

namespace LinBox 
{

/** \brief Vector factory

 * This is an abstract base class that generates a sequence of vectors
 * in a generic way. Typical uses would be in tests, where the same test
 * might be run on a sequence of random vectors or on e_1, ..., e_n.
 \ingroup vector
 */
template <class _Vector>
class VectorStream 
{
    public:
	typedef _Vector Vector;
        typedef VectorStream<Vector> Self_t;
     

	virtual ~VectorStream () {}

	/** Get the next vector from the factory and store it in v
	 */

	virtual Vector &get (Vector &v) = 0;

	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }

	/** Get the number of vectors to be constructed in this stream
	 */
	virtual size_t size () const = 0;

	/** Get the number of vectors constructed so far
	 */
	virtual size_t pos () const = 0;

	/** Get the dimension of each vector
	 */
	virtual size_t dim () const = 0;

	/** Return true if and only if the vector stream still has more vectors
	 * to construct
	 */
	virtual operator bool () const = 0;

	/** Reset the vector stream to the beginning.
	 */
	virtual void reset () = 0;

	/** Alias for reset
	 */
	void rewind () { reset (); }

	/** @name Legacy interface
	 * These functions provide compatiblity with older parts of the
	 * library. Their use is deprecated.
	 */

	//@{

	Vector &next (Vector &v) { return get (v); }
	size_t j () const { return pos (); }
	size_t m () const { return size (); }
	size_t n () const { return dim (); }

	//@}
};

/** Constant vector factory
 * Returns the same vector repeatedly
 */
template <class _Vector>
class ConstantVectorStream : public VectorStream<_Vector>
{
    public:
	typedef _Vector Vector;
        typedef ConstantVectorStream<Vector> Self_t;

	/** Constructor
	 * Construct a new factory with the given field and vector size.
	 * @param v Vector to return on next
	 * @param m Number of vectors to return (0 for unlimited)
	 */
	ConstantVectorStream (Vector &v, size_t m) : _v (v), _m (m), _j (0) {}

	/** Retrieve vector
	 * @param v Vector to use
	 */
	Vector &get (Vector &v) 
		{ if (_m == 0 || _j < _m) copy (_v.begin (), _v.end (), v.begin ()); return v; }

	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }
	/** Number of vectors to be created
	 */
	size_t size () const { return _m; }

	/** Number of vectors created so far
	 */
	size_t pos () const { return _j; }

	/** Dimension of the space
	 */
	size_t dim () const { return _v.size (); }

	/** Check whether we have reached the end
	 */
	operator bool () const { return _m == 0 || _j < _m; }

	/** Reset the factory to start at the beginning
	 */
	void reset () { _j = 0; }

    private:
	Vector &_v;
	size_t  _m;
	size_t  _j;
};

/** Random dense vector stream
 * Generates a sequence of random dense vectors over a given field
 */
template <class Field, class _Vector = typename LinBox::Vector<Field>::Dense, class RandIter = typename Field::RandIter, class Trait = typename VectorTraits<_Vector>::VectorCategory>
class RandomDenseStream : public VectorStream<_Vector>
{
    public:
	typedef _Vector Vector;
        typedef RandomDenseStream<Field, Vector, RandIter, Trait> Self_t;

	/** Constructor
	 * Construct a new stream with the given field and vector size.
	 * @param F Field over which to create random vectors
	 * @param n Size of vectors
	 * @param m Number of vectors to return (0 for unlimited)
	 */
	RandomDenseStream (const Field &F, size_t n, size_t m = 0);

	/** Constructor
	 * Construct a new stream with the given field and vector size.
	 * @param F Field over which to create random vectors
	 * @param n Size of vectors
	 * @param m Number of vectors to return (0 for unlimited)
	 */
	RandomDenseStream (const Field &F, const RandIter &r, size_t n, size_t m = 0);

	/** Get next element
	 * @param v Vector into which to generate random vector
	 * @return reference to new random vector
	 */
	Vector &get (Vector &v);

	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }
	/** Number of vectors to be created
	 */
	size_t size () const;

	/** Number of vectors created so far
	 */
	size_t pos () const;

	/** Dimension of the space
	 */
	size_t dim () const;

	/** Check whether we have reached the end
	 */
	operator bool () const;

	/** Reset the stream to start at the beginning
	 */
	void reset ();
};

// Specialization of random dense stream for dense vectors

template <class Field, class _Vector, class RandIter>
class RandomDenseStream<Field, _Vector, RandIter, VectorCategories::DenseVectorTag > : public VectorStream<_Vector>
{
    public:
	typedef _Vector Vector;
        typedef RandomDenseStream<Field, Vector, RandIter, VectorCategories::DenseVectorTag > Self_t;

	RandomDenseStream (const Field &F, size_t n, size_t m = 0)
		: _F (F), _r (F), _n (n), _m (m), _j (0)
	{}

	RandomDenseStream (const Field &F, const RandIter &r, size_t n, size_t m = 0)
		: _F (F), _r (r), _n (n), _m (m), _j (0)
	{}

	Vector &get (Vector &v) 
	{
		typename Vector::iterator i;

		if (_m > 0 && _j++ >= _m)
			return v;

		for (i = v.begin (); i != v.end (); i++)
			_r.random (*i);

		return v;
	}

	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }
	size_t size () const { return _m; }
	size_t pos () const { return _j; }
	size_t dim () const { return _n; }
	operator bool () const { return _m == 0 || _j < _m; }
	void reset () { _j = 0; }

    private:
	const Field &_F;
	RandIter     _r;
	size_t       _n;
	size_t       _m;
	size_t       _j;
};

/** Random sparse vector stream
 * Generates a sequence of random sparse vectors over a given field
 */
template <class Field, class _Vector = typename LinBox::Vector<Field>::Sparse, class RandIter = typename Field::RandIter, class Trait = typename VectorTraits<_Vector>::VectorCategory>
class RandomSparseStream : public VectorStream<_Vector>
{
    public:
	typedef _Vector Vector;
        typedef RandomSparseStream<Field, Vector, RandIter, Trait > Self_t;

	/** Constructor
	 * Construct a new stream with the given field and vector size.
	 * @param F Field over which to create random vectors
	 * @param p Proportion of nonzero entries
	 * @param n Size of vectors
	 * @param m Number of vectors to return (0 for unlimited)
	 */
	RandomSparseStream (const Field &F, double p, size_t n, size_t m = 0);

	/** Constructor
	 * Construct a new stream with the given field and vector size.
	 * @param F Field over which to create random vectors
	 * @param n Size of vectors
	 * @param p Proportion of nonzero entries
	 * @param m Number of vectors to return (0 for unlimited)
	 */
	RandomSparseStream (const Field &F, const RandIter &r, double p, size_t n, size_t m = 0);

	/** Get next element
	 * @param v Vector into which to generate random vector
	 * @return reference to new random vector
	 */
	Vector &get (Vector &v);

	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }
	/** Number of vectors to be created
	 */
	size_t size () const;

	/** Number of vectors created so far
	 */
	size_t pos () const;

	/** Dimension of the space
	 */
	size_t dim () const;

	/** Check whether we have reached the end
	 */
	operator bool () const;

	/** Reset the stream to start at the beginning
	 */
	void reset ();

	/** Set the probability of a nonzero entry
	 */
	void setP (double p);
};

// Specialization of RandomSparseStream for dense vectors

template <class Field, class _Vector, class RandIter>
class RandomSparseStream<Field, _Vector, RandIter, VectorCategories::DenseVectorTag > : public VectorStream<_Vector>
{
    public:
	typedef _Vector Vector;
        typedef RandomSparseStream<Field, Vector, RandIter, VectorCategories::DenseVectorTag > Self_t;

	RandomSparseStream (const Field &F, double p, size_t n, size_t m = 0)
		: _F (F), _r1 (F), _r (F, _r1),
		  _n (n), _p (p), _m (m), _j (0),
		  _MT (time (NULL))
		{ linbox_check ((p >= 0.0) && (p <= 1.0)); _F.init (_zero, 0); }

	RandomSparseStream (const Field &F, const RandIter &r, double p, size_t n, size_t m = 0)
		: _F (F), _r1 (r), _r (F, _r1), _n (n), _p (p), _m (m), _j (0),
		  _MT (time (NULL))
		{ linbox_check ((p >= 0.0) && (p <= 1.0)); _F.init (_zero, 0); }

	Vector &get (Vector &v)
	{
		double val;

		if (_m > 0 && _j++ >= _m)
			return v;

		for (typename Vector::iterator i = v.begin (); i != v.end (); ++i) {
			val = _MT.randomDouble ();

			if (val < _p)
				_r.random (*i);
			else
				_F.assign (*i, _zero);
		}

		return v;
	}
	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }

	size_t size () const { return _m; }
	size_t pos () const { return _j; }
	size_t dim () const { return _n; }
	operator bool () const { return _m == 0 || _j < _m; }
	void reset () { _j = 0; }
	void setP (double p) { linbox_check ((p >= 0.0) && (p <= 1.0)); _p = p; }

    private:
	const Field                      &_F;
	typename Field::Element           _zero;
	RandIter                          _r1;
	NonzeroRandIter<Field, RandIter>  _r;
	size_t                            _n;
	double                            _p;
	size_t                            _m;
	size_t                            _j;
	MersenneTwister                   _MT;
};

// Specialization of RandomSparseStream for sparse sequence vectors

template <class Field, class _Vector, class RandIter>
class RandomSparseStream<Field, _Vector, RandIter, VectorCategories::SparseSequenceVectorTag > : public VectorStream<_Vector>
{
    public:
	typedef _Vector Vector;
        typedef RandomSparseStream<Field, Vector, RandIter, VectorCategories::SparseSequenceVectorTag > Self_t;

	RandomSparseStream (const Field &F, double p, size_t n, size_t m = 0)
		: _F (F), _r1 (F), _r (F, _r1), _n (n), _m (m), _j (0),
		  _MT (time (NULL))
		{ setP (p); }

	RandomSparseStream (const Field &F, const RandIter &r, double p, size_t n, size_t m = 0)
		: _F (F), _r1 (r), _r (F, _r1), _n (n), _p (p), _m (m), _j (0),
		  _MT (time (NULL))
		{ setP (p); }

	Vector &get (Vector &v) 
	{
		typename Field::Element x;
		size_t i = (size_t) -1;
		double val;
		int skip;

		if (_m > 0 && _j++ >= _m)
			return v;

		v.clear ();

		while (1) {
			val = _MT.randomDouble ();
			skip = (int) (ceil (log (val) * _1_log_1mp));

			if (skip <= 0)
				++i;
			else
				i += skip;

			if (i >= _n) break;

			_r.random (x);
			v.push_back (std::pair<size_t, typename Field::Element> (i, x));
		}

		return v;
	}
	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }

	size_t size () const { return _m; }
	size_t pos () const { return _j; }
	size_t dim () const { return _n; }
	operator bool () const { return _m == 0 || _j < _m; }
	void reset () { _j = 0; }

	void setP (double p)
	{
		linbox_check ((p >= 0.0) && (p <= 1.0)); 
		_p = p;
		_1_log_1mp   = 1 / log (1 - _p);
	}

    private:
	const Field                      &_F;
	RandIter                          _r1;
	NonzeroRandIter<Field, RandIter>  _r;
	size_t                            _n;
	double                            _p;
	double                            _1_log_1mp;
	size_t                            _m;
	size_t                            _j;
	MersenneTwister                   _MT;
};

// Specialization of RandomSparseStream for sparse associative vectors

template <class Field, class _Vector, class RandIter>
class RandomSparseStream<Field, _Vector, RandIter, VectorCategories::SparseAssociativeVectorTag > : public VectorStream<_Vector>
{
    public:
	typedef _Vector Vector;
        typedef RandomSparseStream<Field, Vector, RandIter, VectorCategories::SparseAssociativeVectorTag > Self_t;

	RandomSparseStream (const Field &F, double p, size_t n, size_t m = 0)
		: _F (F), _r1 (F), _r (F, _r1),
		  _n (n), _k ((long) (p * n)), _j (0), _m (m),
		  _MT (time (NULL))
	{}

	RandomSparseStream (const Field &F, const RandIter &r, double p, size_t n, size_t m = 0)
		: _F (F), _r1 (F), _r (F, _r1), _n (n), _k ((long) (p * n)), _j (0), _m (m),
		  _MT (time (NULL))
	{}

	Vector &get (Vector &v) 
	{
		typename Field::Element x;
		int i, idx;

		if (_m > 0 && _j++ >= _m)
			return v;

		v.clear ();

		for (i = 0; i < _k; i++) {
			_r.random (x);
			while (!_F.isZero (v[idx = _MT.randomIntRange (0, _n)]));
			v[idx] = x;
		}

		return v;
	}
	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }

	size_t size () const { return _m; }
	size_t pos () const { return _j; }
	size_t dim () const { return _n; }
	operator bool () const { return _m == 0 || _j < _m; }
	void reset () { _j = 0; }
	void setP (double p) { _k = (long) (p * _n); }

    private:
	const Field                      &_F;
	RandIter                          _r1;
	NonzeroRandIter<Field, RandIter>  _r;
	size_t                            _n;
	long                              _k;
	size_t                            _j;
	size_t                            _m;
	MersenneTwister                   _MT;
};

// Specialization of RandomSparseStream for sparse parallel vectors

template <class Field, class _Vector, class RandIter>
class RandomSparseStream<Field, _Vector, RandIter, VectorCategories::SparseParallelVectorTag > : public VectorStream<_Vector>
{
    public:
	typedef _Vector Vector;
        typedef RandomSparseStream<Field, Vector, RandIter, VectorCategories::SparseParallelVectorTag > Self_t;

	RandomSparseStream (const Field &F, double p, size_t n, size_t m = 0)
		: _F (F), _r1 (F), _r (F, _r1), _n (n), _m (m), _j (0),
		  _MT (time (NULL))
		{ setP (p); }

	RandomSparseStream (const Field &F, const RandIter &r, double p, size_t n, size_t m = 0)
		: _F (F), _r1 (r), _r (F, _r1), _n (n), _m (m), _j (0),
		  _MT (time (NULL))
		{ setP (p); }

	Vector &get (Vector &v) 
	{
		typename Field::Element x;
		size_t i = (size_t) -1;
		double val;
		int skip;

		if (_m > 0 && _j++ >= _m)
			return v;

		v.first.clear ();
		v.second.clear ();

		while (1) {
			val = _MT.randomDouble ();
			skip = (int) (ceil (log (val) * _1_log_1mp));

			if (skip <= 0)
				i++;
			else
				i += skip;

			if (i >= _n) break;

			_r.random (x);
			v.first.push_back (i);
			v.second.push_back (x);
		}

		return v;
	}

	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }

	size_t size () const { return _m; }
	size_t pos () const { return _j; }
	size_t dim () const { return _n; }
	operator bool () const { return _m == 0 || _j < _m; }
	void reset () { _j = 0; }

	void setP (double p)
	{
		linbox_check ((p >= 0.0) && (p <= 1.0)); 
		_p = p;
		_1_log_1mp   = 1 / log (1 - _p);
	}

    private:
	const Field                      &_F;
	RandIter                          _r1;
	NonzeroRandIter<Field, RandIter>  _r;
	size_t                            _n;
	double                            _p;
	double                            _1_log_1mp;
	size_t                            _m;
	size_t                            _j;
	MersenneTwister                   _MT;
};

/** Stream for e_1,...,e_n
 * Generates the sequence e_1,...,e_n over a given field
 * 
 * This class is generic with respect to the underlying vector
 * representation.
 */

template <class Field, class _Vector, class Trait = typename VectorTraits<_Vector>::VectorCategory>
class StandardBasisStream : public VectorStream<_Vector>
{
    public:
	typedef _Vector Vector;
        typedef StandardBasisStream<Field, Vector, Trait > Self_t;

	/** Constructor
	 * Construct a new stream with the given field and vector size.
	 * @param F Field over which to create vectors
	 * @param n Size of vectors
	 */
	StandardBasisStream (Field &F, size_t n);

	/** Get next element
	 * @param v Vector into which to generate vector
	 * @return reference to new vector
	 */
	Vector &get (Vector &v);

	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }
	/** Number of vectors to be created
	 */
	size_t size () const;

	/** Number of vectors created so far
	 */
	size_t pos () const;

	/** Dimension of the space
	 */
	size_t dim () const;

	/** Check whether we have reached the end
	 */
	operator bool () const;

	/** Reset the stream to start at the beginning
	 */
	void reset ();

    private:
	const Field              &_F;
	size_t                    _n;
	size_t                    _j;
};

// Specialization of standard basis stream for dense vectors

template <class Field, class _Vector>
class StandardBasisStream<Field, _Vector, VectorCategories::DenseVectorTag > : public VectorStream<_Vector>
{
    public:
	typedef _Vector Vector;
        typedef StandardBasisStream<Field, Vector, VectorCategories::DenseVectorTag > Self_t;

	StandardBasisStream (const Field &F, size_t n)
		: _F (F), _n (n), _j (0)
	{}

	Vector &get (Vector &v) 
	{
		static typename Field::Element zero;
		typename Vector::iterator i;
		size_t idx;

		for (i = v.begin (), idx = 0; i != v.end (); i++, idx++) {
			if (idx == _j)
				_F.init (*i, 1);
			else
				_F.assign (*i, zero);
		}

		_j++;

		return v;
	}

	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }
	size_t size () const { return _n; }
	size_t pos () const { return _j; }
	size_t dim () const { return _n; }
	operator bool () const { return _j < _n; }
	void reset () { _j = 0; }

    private:
	const Field              &_F;
	size_t                    _n;
	size_t                    _j;
};

// Specialization of standard basis stream for sparse sequence vectors

template <class Field, class _Vector>
class StandardBasisStream<Field, _Vector, VectorCategories::SparseSequenceVectorTag > : public VectorStream<_Vector>
{
    public:
	typedef _Vector Vector;
        typedef StandardBasisStream<Field, Vector, VectorCategories::SparseSequenceVectorTag > Self_t;

	StandardBasisStream (Field &F, size_t n)
		: _F (F), _n (n), _j (0)
	{ _F.init (_one, 1); }

	Vector &get (Vector &v) 
	{
		v.clear ();

		if (_j < _n)
			v.push_back (std::pair <size_t, typename Field::Element> (_j++, _one));

		return v;
	}
	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }

	size_t size () const { return _n; }
	size_t pos () const { return _j; }
	size_t dim () const { return _n; }
	operator bool () const { return _j < _n; }
	void reset () { _j = 0; }

    private:
	const Field              &_F;
	size_t                    _n;
	size_t                    _j;
	typename Field::Element   _one;
};

// Specialization of standard basis stream for sparse associative vectors

template <class Field, class _Vector>
class StandardBasisStream<Field, _Vector, VectorCategories::SparseAssociativeVectorTag > : public VectorStream<_Vector>
{
    public:
	typedef _Vector Vector;
        typedef StandardBasisStream<Field, Vector, VectorCategories::SparseAssociativeVectorTag > Self_t;

	StandardBasisStream (Field &F, size_t n)
		: _F (F), _n (n), _j (0)
	{ _F.init (_one, 1); }

	Vector &get (Vector &v) 
	{
		v.clear ();

		if (_j < _n)
			v.insert (std::pair <size_t, typename Field::Element> (_j++, _one));

		return v;
	}

	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }
	size_t pos () const { return _j; }
	size_t size () const { return _n; }
	size_t dim () const { return _n; }
	operator bool () const { return _j < _n; }
	void reset () { _j = 0; }

    private:
	const Field              &_F;
	size_t                    _n;
	size_t                    _j;
	typename Field::Element   _one;
};

// Specialization of standard basis stream for sparse parallel vectors

template <class Field, class _Vector>
class StandardBasisStream<Field, _Vector, VectorCategories::SparseParallelVectorTag > : public VectorStream<_Vector>
{
    public:
	typedef _Vector Vector;
        typedef StandardBasisStream<Field, Vector, VectorCategories::SparseParallelVectorTag> Self_t;

	StandardBasisStream (Field &F, size_t n)
		: _F (F), _n (n), _j (0)
	{ _F.init (_one, 1); }

	Vector &get (Vector &v) 
	{
		v.first.clear ();
		v.second.clear ();

		if (_j < _n) {
			v.first.push_back (_j++);
			v.second.push_back (_one);
		}

		return v;
	}

	/** Extraction operator form
	 */
	Self_t &operator >> (Vector &v)
		{ get (v); return *this; }
	size_t size () const { return _n; }
	size_t pos () const { return _j; }
	size_t dim () const { return _n; }
	operator bool () const { return _j < _n; }
	void reset () { _j = 0; }

    private:
	const Field              &_F;
	size_t                    _n;
	size_t                    _j;
	typename Field::Element   _one;
};

} // namespace LinBox

#endif // __VECTOR_STREAM_H