This file is indexed.

/usr/include/linbox/algorithms/gauss.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
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
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
/* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/* linbox/algorithms/gauss.inl
 * Copyright (C) 1999 Jean-Guillaume Dumas
 *
 * Written by Jean-Guillaume Dumas <Jean-Guillaume.Dumas@imag.fr>
 * Time-stamp: <09 Feb 07 11:25:51 Jean-Guillaume.Dumas@imag.fr> 
 *
 * -----------------------------------------------------------
 * 2003-02-02  Bradford Hovinen  <bghovinen@math.uwaterloo.ca>
 *
 * Ported to new matrix archetype; update interface to meet current
 * standards. Rename gauss_foo as foo and gauss_Uin as upperin
 *
 * Move function definitions to gauss.inl
 * -----------------------------------------------------------
 *
 * See COPYING for license information.
 */

// ========================================================================= //
// (C) The Linbox Group 1999
// Calcul de rang par la méthode de Gauss pivot par ligne, sur matrice creuse
// ========================================================================= //

#ifndef __GAUSS_INL
#define __GAUSS_INL

#include "linbox/algorithms/gauss.h"
#include "linbox/util/commentator.h"

#ifdef __LINBOX_ALL__
#define __LINBOX_COUNT__
#define __LINBOX_OFTEN__
#define __LINBOX_FILLIN__
#endif

namespace LinBox 
{

    template <class _Field>
    template <class Vector, class D>
    void GaussDomain<_Field>::eliminate (Vector              &lignecourante,
                                         const Vector        &lignepivot,
                                         const unsigned long &indcol,
                                         const long &indpermut,
                                         D                   &columns)
    {

	typedef typename Vector::value_type E;
        
	unsigned long k = indcol - 1;
	unsigned long nj = lignecourante.size () ;
//         std::cerr << "BEGIN ELIMINATE, k: " << k << ", nj: " << nj << ", indpermut: " << indpermut << ", indcol: " << indcol << std::endl;
//         std::cerr << "lignepivot: [";
//         for(typename Vector::const_iterator refs =  lignepivot.begin();
//             refs != lignepivot.end() ;
//             ++refs )
//             std::cerr << '(' << refs->first << ';' << refs->second << ')';
//         std::cerr << "], lignecour: [";
//         for(typename Vector::const_iterator refs =  lignecourante.begin();
//             refs != lignecourante.end() ;
//             ++refs )
//             std::cerr << '(' << refs->first << ';' << refs->second << ')';
//         std::cerr << ']' << std::endl;
	if (nj > 0) {
            unsigned long j_head = 0;

            for (; j_head < nj; ++j_head)
                if (static_cast<long>(lignecourante[j_head].first) >= indpermut) break;
//         std::cerr << "ELIMINATE, j_head: " << j_head << std::endl;

            if (j_head < nj) {
                if (static_cast<long>(lignecourante[j_head].first) == indpermut) {
                        // -------------------------------------------
                        // Permutation
                    if ( indpermut != static_cast<long>(k)) {
                        if (lignecourante[0].first == k) {
                                // non zero  <--> non zero
                            Element tmp;
                            _F.assign (tmp, lignecourante[0].second);
                            _F.assign (lignecourante[0].second,
                                       lignecourante[j_head].second);
                            _F.assign (lignecourante[j_head].second, tmp);
                        } else {
                                // zero <--> non zero
                            E tmp = lignecourante[j_head];
                            --columns[tmp.first];
                            ++columns[k];
                            tmp.first = k;

                            for (long l = j_head; l > 0; l--)
                                lignecourante[l] = lignecourante[l-1];

                            lignecourante[0] = tmp;
                        } 
                        j_head = 0;
                    }
                        // -------------------------------------------
                        // Elimination
                    unsigned long npiv = lignepivot.size ();
                    Vector construit (nj + npiv);

                        // construit : <-- j
                        // courante  : <-- m
                        // pivot     : <-- l
                    unsigned long j = 0;
                    unsigned long m = j_head + 1;

                        // A[i,k] <-- - A[i,k] / A[k,k]
                    Element headcoeff;
                    _F.divin (_F.neg (headcoeff, lignecourante[j_head].second),
                              lignepivot[0].second);

                    --columns[lignecourante[j_head].first];
        
                        // if A[k,j]=0, then A[i,j] <-- A[i,j]
                    while (j < j_head) {
                        construit[j] = lignecourante[j];
                        j++;
                    }

                    unsigned long j_piv;

                    unsigned long l = 0;

                    for (; l < npiv; l++)
                        if (lignepivot[l].first > k) break;

                        // for all j such that (j>k) and A[k,j]!=0
                    while (l < npiv) {
                        j_piv = lignepivot[l].first;

                            // if A[k,j]=0, then A[i,j] <-- A[i,j]
                        while ((m < nj) && (lignecourante[m].first < j_piv))
                            construit[j++] = lignecourante[m++];

                            // if A[i,j]!=0, then A[i,j] <-- A[i,j] - A[i,k]*A[k,j]
                        if ((m < nj) && (lignecourante[m].first == j_piv)) {
                            Element tmp;

                            _F.axpy (tmp, headcoeff, lignepivot[l].second,
                                     lignecourante[m].second);

                            if (! _F.isZero (tmp)) {
                                _F.assign (lignecourante[m].second, tmp);
                                construit[j++] = lignecourante[m++];
                            } else
                                --columns[lignecourante[m++].first];
                        } else {
                            Element tmp;

                            _F.mul (tmp, headcoeff, lignepivot[l].second);

                            if (! _F.isZero (tmp)) {
                                ++columns[j_piv];
                                construit[j++] = E (j_piv, tmp);
                            }
                        }

                        l++;
                    }
        
                        // if A[k,j]=0, then A[i,j] <-- A[i,j] 
                    while (m<nj)
                        construit[j++] = lignecourante[m++];
        
                    construit.resize (j);
                    lignecourante = construit;
                } else {
                        // -------------------------------------------
                        // j_head < nj but nothing under the pivot
                        // Permutation
//                 std::cerr << "----------------------------------------------------------" << std::endl;
//                 std::cerr << "j_head < nj" << std::endl;
//                 std::cerr << "j_head: " << j_head << ", nj: " << nj << ", k:" << k 
// //                         // << "lignepivot: " << lignepivot 
// //                         // << ", lignecour: " << lignecourante 
//                           << std::endl;
//                 std::cerr << "----------------------------------------------------------" << std::endl;
                    if (indpermut != static_cast<long>(k)) {
                        if (j_head>0) {
                            unsigned long l = 0;

                            for (; l < nj; ++l)
                                if (lignecourante[l].first >= k) break;
                        
                            if ((l < nj) && (lignecourante[l].first == k))  {
                                    // non zero <--> zero
                                E tmp = lignecourante[l];
                                --columns[k];
                                ++columns[indpermut];
                                tmp.first = indpermut;
                            
                                unsigned long bjh = j_head-1;
                                for (; l < bjh; ++l)
                                    lignecourante[l] = lignecourante[l + 1];
                            
                                lignecourante[bjh] = tmp;
                            } // else // zero <--> zero
                        } // else // zero <--> zero
                    } 
                }
            } else {
                    // -------------------------------------------
                    // j_head >= nj > 0
//                 std::cerr << "----------------------------------------------------------" << std::endl;
//                 std::cerr << "j_head >= nj > 0" << std::endl;
//                 std::cerr << "j_head: " << j_head << ", nj: " << nj << ", k:" << k 
// //                         // << "lignepivot: " << lignepivot 
// //                         // << ", lignecour: " << lignecourante 
//                           << std::endl;
//                 std::cerr << "----------------------------------------------------------" << std::endl;
                if (indpermut != static_cast<long>(k)) {
                    unsigned long l = 0;

                    for (; l < nj; ++l)
                        if (lignecourante[l].first >= k) break;

                    if ((l < nj) && (lignecourante[l].first == k))  {
                            // non zero <--> zero
                        E tmp = lignecourante[l];
                        --columns[k];
                        ++columns[indpermut];
                        tmp.first = indpermut;

                        unsigned long bjh = nj - 1;
                        for (; l < bjh; ++l)
                            lignecourante[l] = lignecourante[l + 1];

                        lignecourante[bjh] = tmp;
                    } // else
                        // zero <--> zero
                }
            
            }
        }


//         std::cerr << "END ELIMINATE, k: " << k << ", nj: " << nj << ", indpermut: " << indpermut << ", indcol: " << indcol << std::endl;
//         std::cerr << "lignepivot: [";
//         for(typename Vector::const_iterator refs =  lignepivot.begin();
//             refs != lignepivot.end() ;
//             ++refs )
//             std::cerr << '(' << refs->first << ';' << refs->second << ')';
//         std::cerr << "], lignecour: [";
//         for(typename Vector::const_iterator refs =  lignecourante.begin();
//             refs != lignecourante.end() ;
//             ++refs )
//             std::cerr << '(' << refs->first << ';' << refs->second << ')';
//         std::cerr << ']' << std::endl;

    }
    

    template <class _Field>
    template <class Vector>
    void GaussDomain<_Field>::eliminate (Vector              &lignecourante,
                                         const Vector        &lignepivot,
                                         const unsigned long &indcol,
                                         const long &indpermut)
    {
	typedef typename Vector::value_type E;

	unsigned long k = indcol - 1;
	unsigned long nj = lignecourante.size () ;

	if (nj > 0) {
            unsigned long j_head = 0;

            for (; j_head < nj; ++j_head)
                if (static_cast<long>(lignecourante[j_head].first) >= indpermut) break;

            if (j_head < nj) {
                if (static_cast<long>(lignecourante[j_head].first) == indpermut) {
                        // -------------------------------------------
                        // Permutation
                    if (indpermut != static_cast<long>(k)) {
                        if (lignecourante[0].first == k) {     
                                // non zero  <--> non zero
                            Element tmp;
                            _F.assign (tmp, lignecourante[0].second) ;
                            _F.assign (lignecourante[0].second,
                                       lignecourante[j_head].second);
                            _F.assign (lignecourante[j_head].second, tmp);
                        } else {
                                // zero <--> non zero
                            E tmp = lignecourante[j_head];
                            tmp.first = k;
                            for (long l = j_head; l > 0; l--)
                                lignecourante[l] = lignecourante[l-1];
                            lignecourante[0] = tmp;
                        }

                        j_head = 0;
                    }
                        // -------------------------------------------
                        // Elimination
                    unsigned long npiv = lignepivot.size ();
                    Vector construit (nj + npiv);
                        // construit : <-- j
                        // courante  : <-- m
                        // pivot     : <-- l
                    unsigned long j = 0;
                    unsigned long m = j_head + 1;

                        // A[i,k] <-- - A[i,k] / A[k,k]

                    Element headcoeff;
                    _F.divin (_F.neg (headcoeff, lignecourante[j_head].second),
                              lignepivot[0].second);

                        // if A[k,j]=0, then A[i,j] <-- A[i,j]
                    while (j < j_head) {
                        construit[j] = lignecourante[j];
                        j++;
                    }

                    unsigned long j_piv;
                    unsigned long l = 0;

                    for (; l < npiv; l++)
                        if (lignepivot[l].first > k) break;

                        // for all j such that (j>k) and A[k,j]!=0
                    while (l < npiv) {
                        j_piv = lignepivot[l].first;

                            // if A[k,j]=0, then A[i,j] <-- A[i,j]
                        while ((m < nj) && (lignecourante[m].first < j_piv))
                            construit[j++] = lignecourante[m++];

                            // if A[i,j]!=0, then A[i,j] <-- A[i,j] - A[i,k]*A[k,j]
                        if ((m < nj) && (lignecourante[m].first == j_piv)) {
                            Element tmp;
                            _F.axpy (tmp, headcoeff, lignepivot[l].second,
                                     lignecourante[m].second);

                            if (! _F.isZero (tmp)) {
                                _F.assign (lignecourante[m].second, tmp);
                                construit[j++] = lignecourante[m++];
                            } else
                                ++m;
                    
                        } else {
                            Element tmp;
                            _F.mul (tmp, headcoeff, lignepivot[l].second);
                            if (! _F.isZero (tmp))
                                construit[j++] = E (j_piv, tmp);
                        }
                        l++;
                    }
        
                        // if A[k,j]=0, then A[i,j] <-- A[i,j] 
                    while (m < nj)
                        construit[j++] = lignecourante[m++];

                    construit.resize (j);
                    lignecourante = construit;
                } else {
                        // -------------------------------------------
                        // j_head < nj but nothing under the pivot
                        // Permutation
                    if (indpermut != static_cast<long>(k)) {
                        if (j_head > 0) {
                            unsigned long l = 0;

                            for (; l < nj; ++l)
                                if (lignecourante[l].first >= k) break;

                            if ((l < nj) && (lignecourante[l].first == k))  {
                                    // non zero <--> zero
                                E tmp = lignecourante[l];
                                tmp.first = indpermut;

                                unsigned long bjh = j_head -1;
                                for (; l < bjh; l++)
                                    lignecourante[l] = lignecourante[l + 1];

                                lignecourante[bjh] = tmp;
                            } // else // zero <--> zero
                        } // else // zero <--> zero
                    }
                }
            } else {
                    // -------------------------------------------
                    // -------------------------------------------
                    // j_head >= nj > 0
//                 std::cerr << "----------------------------------------------------------" << std::endl;
//                 std::cerr << "j_head >= nj > 0" << std::endl;
//                 std::cerr << "j_head: " << j_head << ", nj: " << nj << ", k:" << k 
//                         // << "lignepivot: " << lignepivot 
//                         //  << ", lignecour: " << lignecourante 
//                           << std::endl;
//                 std::cerr << "----------------------------------------------------------" << std::endl;
                if (indpermut != static_cast<long>(k)) {
                    unsigned long l = 0;

                    for (; l < nj; ++l)
                        if (lignecourante[l].first >= k) break;

                    if ((l < nj) && (lignecourante[l].first == k))  {
                            // non zero <--> zero
                        E tmp = lignecourante[l];
                        tmp.first = indpermut;

                        unsigned long bjh = nj - 1;
                        for (; l < bjh; l++)
                            lignecourante[l] = lignecourante[l + 1];

                        lignecourante[bjh] = tmp;
                    } // else
                        // zero <--> zero
                }
            }
	}
    }

    template <class _Field>
    template<class Vector>
    void GaussDomain<_Field>::Upper (Vector        &lignecur,
                                     const Vector  &lignepivot,
                                     unsigned long  indcol,
                                     long  indpermut)
    {
        static typename _Field::Element zero = _F.init(zero);
        
	long n = lignecur.size () ;
	long k = indcol - 1 ;

            // permutation if one has been performed to compute the pivot
	if (indpermut != k) {
            typename Vector::value_type tmp = lignecur[k];
            lignecur[k] = lignecur[indpermut];
            lignecur[indpermut] = tmp;
	}

	typename Vector::value_type headcoeff;
	_F.divin (_F.neg (headcoeff, lignecur[k]), lignepivot[k]);
        
        

            // LU in place
	_F.assign (lignecur[k], zero);
	for (long j = k; ++j < n;)
            _F.axpyin (lignecur[j], headcoeff, lignepivot[j]) ;
    }

    template <class _Field>
    template <class Vector>
    void GaussDomain<_Field>::LU (Vector        &lignecur,
                                  const Vector  &lignepivot,
                                  unsigned long  indcol,
                                  long  indpermut)
    {
	long n = lignecur.size ();
	long k = indcol - 1;

            // permutation if one has been performed to compute the pivot
	if (indpermut != k) {
            typename Vector::value_type tmp = lignecur[k];
            lignecur[k] = lignecur[indpermut];
            lignecur[indpermut] = tmp;
	}

	typename Vector::value_type headcoeff;
            // LU in place
	_F.div (headcoeff, lignecur[k], lignepivot[k]);
	_F.assign (lignecur[k], headcoeff);
	_F.negin (headcoeff);
	for (long j = k; ++j < n;)
            _F.axpyin (lignecur[j],headcoeff,lignepivot[j]);
    }

    template <class _Field>
    template <class Vector, class D>
    void GaussDomain<_Field>::SparseFindPivot (Vector        	&lignepivot,
                                               unsigned long 	&indcol,
                                               long 		&indpermut,
                                               D             	&columns,
                                               Element		&determinant)
    {
 //        std::cerr << "SFP BEG : lignepivot: [";
//         for(typename Vector::const_iterator refs =  lignepivot.begin();
//             refs != lignepivot.end() ;
//             ++refs )
//             std::cerr << '(' << refs->first << ';' << refs->second << ')';
//         std::cerr << "]" << std::endl;
	typedef typename Vector::value_type E;    

	long nj =  lignepivot.size ();
        bool pivoting = false;

	if (nj > 0) {
            indpermut = lignepivot[0].first;

            long ds = --columns[indpermut], dl, p = 0;

            for (long j = 1; j < nj; ++j) {
                if ((dl = --columns[lignepivot[j].first]) < ds) {
                    ds = dl;
                    p = j;
                }
            }

            if (p != 0) {
                pivoting = true;
                if (indpermut == static_cast<long>(indcol)) {
                    Element ttm;
                    _F.assign (ttm, lignepivot[p].second);
                    indpermut = lignepivot[p].first;
                    _F.assign (lignepivot[p].second, lignepivot[0].second);
                    _F.assign (lignepivot[0].second, ttm);
                } else {
                    E ttm = lignepivot[p];
                    indpermut = ttm.first;

                    for (long m = p; m; --m)
                        lignepivot[m] = lignepivot[m-1];

                    lignepivot[0] = ttm;
                }
            }

            _F.mulin(determinant, lignepivot[0].second);
            if (indpermut != static_cast<long>(indcol)) {
                    // no need to decrement/increment, already done during the search
                lignepivot[0].first = indcol;
                pivoting = true;
            }

            if (pivoting) _F.negin(determinant);
            ++indcol;
	} else
            indpermut = -1;
//         std::cerr << "SFP END : lignepivot: [";
//         for(typename Vector::const_iterator refs =  lignepivot.begin();
//             refs != lignepivot.end() ;
//             ++refs )
//             std::cerr << '(' << refs->first << ';' << refs->second << ')';
//         std::cerr << "]" << std::endl;
    }

    template <class _Field>
    template <class Vector>
    void GaussDomain<_Field>::SparseFindPivot (Vector &lignepivot, unsigned long &indcol, long &indpermut, Element& determinant)
    {
	long nj = lignepivot.size ();

	if (nj > 0) {
            indpermut = lignepivot[0].first;
            _F.mulin(determinant, lignepivot[0].second);
            if (indpermut != static_cast<long>(indcol)){
                lignepivot[0].first = indcol;
                _F.negin(determinant);
            }
            ++indcol;
	} else
            indpermut = -1;
    }


    template <class _Field>
    template <class Vector>
    void GaussDomain<_Field>::FindPivot (Vector &lignepivot, unsigned long &k, long &indpermut)
    { 
            // Dense lignepivot
	long n = lignepivot.size ();
	long j = k;

	for (; j < n ; ++j )
            if (!_F.isZero (lignepivot[j])) break ;

	if (j == n )
            indpermut = -1 ;
	else {
            indpermut = j ;
            if (indpermut != k) {
                typename Vector::value_type tmp = lignepivot[k] ;
                lignepivot[k] = lignepivot[j] ;
                lignepivot[j] = tmp ;
            }

            ++k;
	}
    }

    template <class _Field>
    template <class Matrix>
    unsigned long& GaussDomain<_Field>::InPlaceLinearPivoting (unsigned long &res,
                                                              Element        &determinant,
                                                              Matrix         &LigneA,
                                                              unsigned long   Ni,
                                                              unsigned long   Nj)
    {
	typedef typename Matrix::Row        Vector;
	typedef typename Vector::value_type E;    

            // Requirements : LigneA is an array of sparse rows
            // In place (LigneA is modified)
            // With reordering (D is a density type. Density is allocated here)
            //    long Ni = LigneA.n_row (), Nj = LigneA.n_col ();
	commentator.start ("Gaussian elimination with reordering",
			   "IPLR", Ni);
	commentator.report (Commentator::LEVEL_NORMAL, INTERNAL_DESCRIPTION)
            << "Gaussian elimination on " << Ni << " x " << Nj << " matrix" << std::endl;

#ifdef __LINBOX_COUNT__
	long long nbelem = 0;
#endif

        _F.init(determinant,1UL);
	Vector Vzer (0);
            // allocation of the column density
        std::vector<size_t> col_density (Nj);

            // assignment of LigneA with the domain object
	for (unsigned long jj = 0; jj < Ni; ++jj) 
            for (unsigned long k = 0; k < LigneA[jj].size (); k++)
                ++col_density[LigneA[jj][k].first];

	long last = Ni - 1;
	long c;
	unsigned long indcol = 0;

#ifdef __LINBOX_OFTEN__
	long sstep = last/40;
	if (sstep > 1000) sstep = 1000;
#else
	long sstep = 1000;
#endif
            // Elimination steps with reordering
	for (long k = 0; k < last; ++k) {
            unsigned long l;
            long p = k, s = LigneA[k].size (), sl;

#ifdef __LINBOX_FILLIN__  
            if ( ! (k % 100) ) {
#else          
                if ( ! (k % sstep) ) {
#endif
                    commentator.progress (k);
#ifdef __LINBOX_FILLIN__            
                    for (sl = 0, l = 0; l < Ni; ++l)
                        sl += LigneA[l].size ();

                    commentator.report (Commentator::LEVEL_IMPORTANT, PARTIAL_RESULT)
                        << "Fillin (" << indcol << "/" << Ni << ") = "
                        << sl << std::endl;
#endif 
                }
	    
                if (s) {
                    for (l = k + 1; l < Ni; ++l)
                        if (((sl = LigneA[l].size ()) < s) && (sl)) {
                            s = sl;
                            p = l;
                        }

                    if (p != k) {
                        _F.negin(determinant);
                        Vector vtm = LigneA[k];
                        LigneA[k] = LigneA[p];
                        LigneA[p] = vtm;
                    }
		    
//                     LigneA.write(std::cerr << "BEF, k:" << k << ", indcol:" << indcol << ", c:" << c)<<std::endl;
                    
                    SparseFindPivot (LigneA[k], indcol, c, col_density, determinant);
//                     LigneA.write(std::cerr << "PIV, k:" << k << ", indcol:" << indcol << ", c:" << c)<<std::endl;
                    if (c != -1)
                        for (l = k + 1; l < Ni; ++l)
                            eliminate (LigneA[l], LigneA[k], indcol, c, col_density);
                    
//                     LigneA.write(std::cerr << "AFT " )<<std::endl;
#ifdef __LINBOX_COUNT__
                    nbelem += LigneA[k].size ();
#endif
                    LigneA[k] = Vzer;
                }
	    	    
            }//for k

            SparseFindPivot (LigneA[last], indcol, c, determinant);
            
#ifdef __LINBOX_COUNT__
            nbelem += LigneA[last].size ();
            commentator.report (Commentator::LEVEL_NORMAL, PARTIAL_RESULT)
                << "Left elements : " << nbelem << std::endl;
#endif
            
#ifdef __LINBOX_FILLIN__  
            long sl = 0, l = 0;
            for (; l < Ni; ++l)
                sl += LigneA[l].size ();
            
            commentator.report (Commentator::LEVEL_IMPORTANT, PARTIAL_RESULT)
                << "Fillin (" << indcol << "/" << Ni << ") = " << sl << std::endl;
#endif
            
            res = indcol;
            
            integer card;
            
            if ((res < Ni) || (res < Nj))
                _F.init(determinant,0UL);
            _F.write(commentator.report (Commentator::LEVEL_NORMAL, PARTIAL_RESULT) 
                     << "Determinant : ", determinant)
                     << " over GF (" << _F.cardinality (card) << ")" << std::endl;
            
            commentator.report (Commentator::LEVEL_NORMAL, PARTIAL_RESULT) 
		<< "Rank : " << res
		<< " over GF (" << card << ")" << std::endl;
            commentator.stop ("done", 0, "IPLR");
            return res;
        }

        template <class _Field>
            template <class Matrix>
            unsigned long& GaussDomain<_Field>::NoReordering (unsigned long &res,
                                                              Element       &determinant,
                                                              Matrix        &LigneA,
                                                              unsigned long  Ni,
                                                              unsigned long  Nj)
            {
                    // Requirements : SLA is an array of sparse rows
                    // IN PLACE.
                    // Without reordering (Pivot is first non-zero in row)
                    //     long Ni = SLA.n_row (), Nj = SLA.n_col ();
                    //    long Ni = LigneA.n_row (), Nj = LigneA.n_col ();
                commentator.start ("Gaussian elimination (no reordering)",
                                   "NoRe", Ni);
                commentator.report (Commentator::LEVEL_NORMAL, INTERNAL_DESCRIPTION) 
                    << "Gaussian elimination on " << Ni << " x " << Nj << " matrix" << std::endl;

                typedef typename Matrix::Row          Vector;
                typedef typename Vector::value_type   E;    
                typedef typename Matrix::Element      Element;    
    
#ifdef __LINBOX_COUNT__
                long long nbelem = 0;
#endif
                Vector Vzer (0);
 
                _F.init(determinant,1UL);
                long last = Ni - 1;
                long c;
                unsigned long indcol (0);
    
                for (long k = 0; k < last; ++k) {
                    if (!(k % 1000))
			commentator.progress (k);

                    unsigned long l;

                    if (!LigneA[k].empty ()) {
			SparseFindPivot (LigneA[k], indcol, c, determinant);
			if (c !=  -1)
                            for (l = k + 1; l < Ni; ++l)
                                eliminate (LigneA[l], LigneA[k], indcol, c);
                        
#ifdef __LINBOX_COUNT__
			nbelem += LigneA[k].size ();
#endif
			LigneA[k] = Vzer;
                    }
                }

                SparseFindPivot ( LigneA[last], indcol, c, determinant);

#ifdef __LINBOX_COUNT__
                nbelem += LigneA[last].size ();
                commentator.report (Commentator::LEVEL_NORMAL, PARTIAL_RESULT) 
                    << "Left elements : " << nbelem << std::endl;
#endif
    
                res = indcol;

                if ((res < Ni) || (res < Nj))
                    _F.init(determinant,0UL);

                integer card;

                _F.write(commentator.report (Commentator::LEVEL_NORMAL, PARTIAL_RESULT) 
                         << "Determinant : ", determinant)
                         << " over GF (" << _F.cardinality (card) << ")" << std::endl;
                
                commentator.report (Commentator::LEVEL_NORMAL, PARTIAL_RESULT) 
                    << "Rank : " << res
                    << " over GF (" << card << ")" << std::endl;
                commentator.stop ("done", 0, "NoRe");
                return res;
            }

        template <class _Field>
            template <class Matrix>
            unsigned long &GaussDomain<_Field>::upperin (unsigned long &res, Matrix &A)
            {
                    // Requirements : A is an array of rows
                    // In place (A is modified)
                    // Without reordering (Pivot is first non-zero in row)
                long Ni = A.rowdim ();
                long last = Ni - 1;
                long c;
                unsigned long indcol = 0;

                for (long k = 0; k < last; ++k) {
                    FindPivot (A[k], indcol, c);
                    if (c != -1)
			for (long l = k + 1; l < Ni; ++l)
                            Upper (A[l], A[k], indcol, c);
                }

                FindPivot (A[last], indcol, c);
                return res = indcol;
            }

        template <class _Field>
            template <class Matrix>
            unsigned long &GaussDomain<_Field>::LUin (unsigned long &res, Matrix &A)
            {
                    // Requirements : A is an array of rows
                    // In place (A is modified)
                    // Without reordering (Pivot is first non-zero in row)

                long Ni = A.rowdim ();
                long last = Ni - 1;
                long c;
                unsigned long indcol = 0;

                for (long k = 0; k < last; ++k) {
                    FindPivot (A[k], indcol, c);
                    if (c != -1)
			for (long l = k + 1; l < Ni; ++l)
                            LU (A[l], A[k], indcol, c);
                }

                FindPivot (A[last], indcol, c);
                return res = indcol;
            }


        template <class _Field>
            template <class Matrix> unsigned long& GaussDomain<_Field>::rankin(unsigned long &rank,
                                                                               Matrix        &A,
                                                                               unsigned long  Ni,
                                                                               unsigned long  Nj,
                                                                               SparseEliminationTraits::PivotStrategy   reord) 
            {
                Element determinant;
                if (reord == SparseEliminationTraits::PIVOT_NONE)
                    return NoReordering(rank, determinant, A,  Ni, Nj);
                else
                    return InPlaceLinearPivoting(rank, determinant, A,  Ni, Nj);
            }

   
        template <class _Field>
            template <class Matrix> unsigned long& GaussDomain<_Field>::rankin(unsigned long &rank,
                                                                               Matrix        &A,
                                                                               SparseEliminationTraits::PivotStrategy   reord) 
            {
                return rankin(rank, A,  A.rowdim (), A.coldim (), reord);
            }

   

        template <class _Field>
            template <class Matrix> unsigned long& GaussDomain<_Field>::rank(unsigned long &rank,
                                                                             const Matrix        &A,
                                                                             SparseEliminationTraits::PivotStrategy   reord) 
            {
                return rank(rank, A,  A.rowdim (), A.coldim (), reord);
            }

        template <class _Field>
            template <class Matrix> unsigned long& GaussDomain<_Field>::rank(unsigned long &rank,
                                                                             const Matrix        &A,
                                                                             unsigned long  Ni,
                                                                             unsigned long  Nj,
                                                                             SparseEliminationTraits::PivotStrategy   reord) 
            {
                Matrix CopyA(Ni);
                for(unsigned long i = 0; i < Ni; ++i)
                    CopyA[i] = A[i];
                Element determinant;
                if (reord == SparseEliminationTraits::PIVOT_NONE)
                    return NoReordering(rank, determinant, CopyA,  Ni, Nj);
                else {
                    return InPlaceLinearPivoting(rank, determinant, CopyA,  Ni, Nj);
                }
    
            }


        template <class _Field>
            template <class Matrix> typename GaussDomain<_Field>::Element& GaussDomain<_Field>::detin(Element        &determinant,
                                                                                                      Matrix        &A,
                                                                                                      unsigned long  Ni,
                                                                                                      unsigned long  Nj,
                                                                                                      SparseEliminationTraits::PivotStrategy   reord) 
            {
                unsigned long rank;
                if (reord == SparseEliminationTraits::PIVOT_NONE)
                    NoReordering(rank, determinant, A,  Ni, Nj);
                else
                    InPlaceLinearPivoting(rank, determinant, A,  Ni, Nj);
                return determinant;
            }

   
        template <class _Field>
            template <class Matrix> typename GaussDomain<_Field>::Element& GaussDomain<_Field>::detin(Element &determinant,
                                                                                                      Matrix  &A,
                                                                                                      SparseEliminationTraits::PivotStrategy   reord) 
            {
                return detin(determinant, A,  A.rowdim (), A.coldim (), reord);
            }

   

        template <class _Field>
            template <class Matrix> typename GaussDomain<_Field>::Element& GaussDomain<_Field>::det(Element        &determinant,
                                                                                           const Matrix   &A,
                                                                                           SparseEliminationTraits::PivotStrategy   reord) 
            {
                return det(determinant, A,  A.rowdim (), A.coldim (), reord);
            }

        template <class _Field>
            template <class Matrix> typename GaussDomain<_Field>::Element& GaussDomain<_Field>::det(Element       &determinant,
                                                                                           const Matrix  &A,
                                                                                           unsigned long  Ni,
                                                                                           unsigned long  Nj,
                                                                                           SparseEliminationTraits::PivotStrategy   reord) 
            {
                Matrix CopyA(Ni);
                for(unsigned long i = 0; i < Ni; ++i)
                    CopyA[i] = A[i];
                unsigned long rank;
                if (reord == SparseEliminationTraits::PIVOT_NONE)
                    NoReordering(rank, determinant, CopyA,  Ni, Nj);
                else {
                    InPlaceLinearPivoting(rank, determinant, CopyA,  Ni, Nj);
                }
                return determinant;
            }




    } // namespace LinBox

#endif // __GAUSS_INL