This file is indexed.

/usr/include/linbox/solutions/det.h is in liblinbox-dev 1.4.2-3.

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
/* linbox/solutions/det.h
 * Copyright (C) 2001, 2002 LinBox
 * Time-stamp: <04 Oct 11 16:42:52 Jean-Guillaume.Dumas@imag.fr>
 *
 *
 * ========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========
 */

/*! @file solutions/det.h
 * @ingroup solutions
 * @brief NO DOC
 */

#ifndef __LINBOX_det_H
#define __LINBOX_det_H

#include "linbox/blackbox/diagonal.h"
#include "linbox/blackbox/compose.h"
#include "linbox/solutions/methods.h"
#include "linbox/solutions/getentry.h"
#include "linbox/vector/blas-vector.h"

#include "linbox/matrix/dense-matrix.h"
#include "linbox/algorithms/blackbox-container.h"
#include "linbox/algorithms/blackbox-container-symmetric.h"
#include "linbox/algorithms/massey-domain.h"
#include "linbox/matrix/matrix-domain.h"
#include "linbox/algorithms/gauss.h"
#include "linbox/vector/vector-traits.h"
#include "linbox/util/prime-stream.h"
#include "linbox/util/debug.h"
#include "linbox/util/mpicpp.h"


// Namespace in which all LinBox library code resides
namespace LinBox
{
	/** \brief Compute the determinant of A.
	 *
	 * The determinant of a linear operator A, represented as a
	 * black box, is computed over the ring or field of A.
	 *
	 * @param d    Field element into which to store the result
	 * @param A    Black box of which to compute the determinant
	 * @param tag  optional tag.  Specifies Integer, Rational or modular ring/field
	 * @param M    optional method.  The default is Method::Hybrid(), Other options
	 include Blackbox, Elimination, Wiedemann, BlasElimination and SparseElimination.
	 Sometimes it helps to 	 indicate properties of the matrix in the method object
	 (for instance symmetry). See class Method for details.
	 \ingroup solutions
	 */
	template< class Blackbox, class DetMethod, class DomainCategory>
	typename Blackbox::Field::Element &det (typename Blackbox::Field::Element          &d,
						const Blackbox                             &A,
						const DomainCategory                     &tag,
						const DetMethod                           &Meth);

	// The det where A can be modified in place
	// Default is to use the generic det (might copy)
	template< class Blackbox, class DetMethod, class DomainCategory>
	typename Blackbox::Field::Element &detin (typename Blackbox::Field::Element	&d,
						  Blackbox                             	&A,
						  const DomainCategory			&tag,
						  const DetMethod			&Meth)
	{
		return det(d, A, tag, Meth);
	}

	// The det with default Method
	template<class Blackbox>
	typename Blackbox::Field::Element &det (typename Blackbox::Field::Element	&d,
						const Blackbox				&A)
	{
		return det(d, A, Method::Hybrid());
	}

	// The det where A can be modified in place
	template<class Blackbox>
	typename Blackbox::Field::Element &detin (typename Blackbox::Field::Element	&d,
						  Blackbox				&A)
	{
		return detin(d, A, Method::Hybrid());
	}

	// The det with category specializer
	template <class Blackbox, class MyMethod>
	typename Blackbox::Field::Element &det (typename Blackbox::Field::Element	&d,
						const Blackbox				&A,
						const MyMethod				&Meth)
	{
		return det(d, A, typename FieldTraits<typename Blackbox::Field>::categoryTag(), Meth);
	}

	// The in place det with category specializer
	template <class Blackbox, class MyMethod>
	typename Blackbox::Field::Element &detin (typename Blackbox::Field::Element     &d,
						  Blackbox                              &A,
						  const MyMethod                        &Meth)
	{
		return detin(d, A, typename FieldTraits<typename Blackbox::Field>::categoryTag(), Meth);
	}

	// The det with Hybrid Method
	template<class Blackbox>
	typename Blackbox::Field::Element &det (typename Blackbox::Field::Element	&d,
						const Blackbox				&A,
						const RingCategories::ModularTag	&tag,
						const Method::Hybrid			&Meth)
	{
		// not yet a hybrid

		if (useBB(A))
			return det(d, A, tag, Method::Blackbox(Meth));
		else

			return det(d, A, tag, Method::Elimination(Meth));
	}
	template<class Blackbox>
	typename Blackbox::Field::Element &detin (typename Blackbox::Field::Element	&d,
						  Blackbox				&A,
						  const RingCategories::ModularTag	&tag,
						  const Method::Hybrid			&Meth)
	{
		// not yet a hybrid
		/*
		   if (useBB(A))
		   return det(d, A, tag, Method::Blackbox(Meth));
		   else
		   */
		return detin(d, A, tag, Method::Elimination(Meth));
	}

	// The det with Hybrid Method on BlasMatrix
	template<class Field>
	typename Field::Element &det (typename Field::Element         	&d,
				      const BlasMatrix<Field>		&A,
				      const RingCategories::ModularTag	&tag,
				      const Method::Hybrid		&Meth)
	{
		return det(d, A, tag, Method::Elimination(Meth));
	}

	template<class Field>
	typename Field::Element &detin (typename Field::Element         	&d,
					BlasMatrix<Field>			&A,
					const RingCategories::ModularTag	&tag,
					const Method::Hybrid			&Meth)
	{
		return detin(d, A, tag, Method::Elimination(Meth));
	}

	// Forward declaration saves us from including blackbox/toeplitz.h
	template<class A, class B> class Toeplitz;

	// Toeplitz determinant
	template<class CField, class PField >
	typename CField::Element& det(typename CField::Element		& res,
				      const Toeplitz<CField,PField>	& A )
	{
		if (A.coldim() != A.rowdim())
			throw LinboxError("LinBox ERROR: matrix must be square for determinant computation\n");
		return A.det(res);
	}
	template<class CField, class PField >
	typename CField::Element& detin(typename CField::Element	& res,
					Toeplitz<CField,PField>		& A )
	{
		if (A.coldim() != A.rowdim())
			throw LinboxError("LinBox ERROR: matrix must be square for determinant computation\n");
		return A.det(res);
	}
	// The det with BlackBox Method
	template<class Blackbox>
	typename Blackbox::Field::Element &det (
						typename Blackbox::Field::Element       &d,
						const Blackbox                          &A,
						const RingCategories::ModularTag        &tag,
						const Method::Blackbox			&Meth)
	{
		return det(d, A, tag, Method::Wiedemann(Meth));
	}


	// The det with Wiedemann, finite field.
	template <class Blackbox>
	typename Blackbox::Field::Element &det (typename Blackbox::Field::Element	&d,
						const Blackbox				&A,
						const RingCategories::ModularTag	&tag,
						const Method::Wiedemann			&Meth)
	{
		if (A.coldim() != A.rowdim())
			throw LinboxError("LinBox ERROR: matrix must be square for determinant computation\n");

		typedef typename Blackbox::Field Field;
		Field F = A.field();
		typedef BlasVector<Field> Polynomial;

		if(Meth.symmetric()) {
			commentator().start ("Symmetric Wiedemann Determinant", "sdet");
			linbox_check (A.coldim () == A.rowdim ());
			Polynomial               phi(F);
			unsigned long            deg;
			typename Field::RandIter iter (F);

			// Precondition here to separate the eigenvalues, so that
			// minpoly (B) = charpoly (B) with high probability
			// Here there is an extra diagonal computation
			// The probability of success is also divided by two, as
			// diag^2 contains only squares and squares are half the total elements
			BlasVector<Field> diag (A.field(),A.coldim ());

			typename Field::Element pi;
			size_t i;
			size_t iternum = 1;
			do {
				F.assign(pi, F.one);
				for (i = 0; i < A.coldim (); i++) {
					do iter.random (diag[i]); while (F.isZero (diag[i]));
					F.mulin (pi, diag[i]);
				}

				Diagonal<Field> D (diag);
				Compose<Blackbox,Diagonal<Field> > B0 (&A, &D);
				typedef Compose<Diagonal<Field>,Compose<Blackbox,Diagonal<Field> > > Blackbox1;
				Blackbox1 B(&D, &B0);

				BlackboxContainerSymmetric<Field, Blackbox1> TF (&B, F, iter);

				MasseyDomain<Field, BlackboxContainerSymmetric<Field, Blackbox1> > WD (&TF, Meth.earlyTermThreshold ());

				WD.minpoly (phi, deg);
#if 0
				std::cout << "\tdet: iteration # " << iternum << "\tMinpoly deg= "
				<< phi.size() << "\n" ;
				std::cout << "[" ;
				for(typename Polynomial::const_iterator refs =  phi.begin();
				    refs != phi.end() ;
				    ++refs )
					std::cout << (*refs) << " " ;
				std::cout << "]" << std::endl;
#endif

				++iternum;
			} while ( (phi.size () < A.coldim () + 1) && ( !F.isZero (phi[0]) ) );


				// Divided twice since multiplied twice by the diagonal matrix
				F.div (d, phi[0], pi);
				F.divin (d, pi);

				if ( (deg & 1) == 1)
					F.negin (d);

				commentator().stop ("done", NULL, "sdet");

				return d;
		}
		else {
			commentator().start ("Wiedemann Determinant", "wdet");
			linbox_check (A.coldim () == A.rowdim ());

			Polynomial               phi(F);
			unsigned long            deg;
			typename Field::RandIter iter (F);

			// Precondition here to separate the eigenvalues, so that
			// minpoly (B) = charpoly (B) with high probability
			BlasVector<Field> diag (F,A.coldim ());

			typename Field::Element pi;
			size_t i;
			size_t iternum = 1;
			do {
				F.assign(pi, F.one);
				for (i = 0; i < A.coldim (); i++) {
					do iter.random (diag[i]); while (F.isZero (diag[i]));
					F.mulin (pi, diag[i]);
				}

				Diagonal<Field> D (diag);

				Compose<Blackbox,Diagonal<Field> > B (&A, &D);

				typedef Compose<Blackbox,Diagonal<Field> > Blackbox1;

				BlackboxContainer<Field, Blackbox1> TF (&B, F, iter);

				MasseyDomain<Field, BlackboxContainer<Field, Blackbox1> > WD (&TF, Meth.earlyTermThreshold ());

				WD.minpoly (phi, deg);

				++iternum;
			} while ( (phi.size () < A.coldim () + 1) && ( !F.isZero (phi[0]) ) );

				F.div (d, phi[0], pi);

				if ( (deg & 1) == 1)
					F.negin (d);


				commentator().stop ("done", NULL, "wdet");

				return d;
		}
	}



	// the det with Blas, finite field.
	template <class Blackbox>
	typename Blackbox::Field::Element &det (typename Blackbox::Field::Element       &d,
						const Blackbox                          &A,
						const RingCategories::ModularTag        &tag,
						const Method::BlasElimination           &Meth)
	{
		if (A.coldim() != A.rowdim())
			throw LinboxError("LinBox ERROR: matrix must be square for determinant computation\n");

		typedef typename Blackbox::Field Field;
		Field F = A.field();

		commentator().start ("Blas Determinant", "blasdet");

		linbox_check (A.coldim () == A.rowdim ());

		BlasMatrix<Field> B(A);
		BlasMatrixDomain<Field> BMD(F);
		d= BMD.detin(B);
		commentator().stop ("done", NULL, "blasdet");

		return d;
	}

	template <class Blackbox>
	typename Blackbox::Field::Element &det (typename Blackbox::Field::Element	&d,
						const Blackbox  			&A,
						const RingCategories::ModularTag  	&tag,
						const Method::SparseElimination		&Meth)
	{
		if (A.coldim() != A.rowdim())
			throw LinboxError("LinBox ERROR: matrix must be square for determinant computation\n");

		typedef typename Blackbox::Field Field;
		commentator().start ("Sparse Elimination Determinant", "SEDet");
		// We make a copy as these data will be destroyed
		SparseMatrix<Field, SparseMatrixFormat::SparseSeq> A1 (A.field(), A.rowdim(), A.coldim());
		typename Blackbox::Field::Element tmp;
		for(size_t i = 0; i < A.rowdim() ; ++i)
			for(size_t j = 0; j < A.coldim(); ++j)
				A1.setEntry(i,j,getEntry(tmp, A, i, j));
		GaussDomain<Field> GD ( A1.field() );
		GD.detin (d, A1, Meth.strategy ());
		commentator().stop ("done", NULL, "SEDet");
		return d;

	}


	template <class Field, class Vector>
	typename Field::Element &det (typename Field::Element	&d,
				      const SparseMatrix<Field, Vector>	&A,
				      const RingCategories::ModularTag  	&tag,
				      const Method::SparseElimination		&Meth)
	{
		if (A.coldim() != A.rowdim())
			throw LinboxError("LinBox ERROR: matrix must be square for determinant computation\n");
		commentator().start ("Sparse Elimination Determinant", "SEDet");
		// We make a copy as these data will be destroyed
		SparseMatrix<Field, SparseMatrixFormat::SparseSeq> A1 (A);
		GaussDomain<Field> GD ( A.field() );
		GD.detin (d, A1, Meth.strategy ());
		commentator().stop ("done", NULL, "SEdet");
		return d;
	}

	template <class Field>
	typename Field::Element &detin (typename Field::Element         	&d,
					SparseMatrix<Field, SparseMatrixFormat::SparseSeq>  &A,
					const RingCategories::ModularTag  	&tag,
					const Method::SparseElimination     	&Meth)
	{
		if (A.coldim() != A.rowdim())
			throw LinboxError("LinBox ERROR: matrix must be square for determinant computation\n");
		commentator().start ("Sparse Elimination Determinant in place", "SEDetin");
		GaussDomain<Field> GD ( A.field() );
		GD.detin (d, A, Meth.strategy ());
		commentator().stop ("done", NULL, "SEdetin");
		return d;
	}


	// The det with Elimination Method
	template<class Field, class Vector>
	typename Field::Element &det (typename Field::Element		&d,
				      const SparseMatrix<Field, Vector>	&A,
				      const RingCategories::ModularTag	&tag,
				      const Method::Elimination		&Meth)
	{
		return det(d, A, tag, Method::SparseElimination(Meth));
	}


	template <class Field>
	typename Field::Element &detin (typename Field::Element         	&d,
					SparseMatrix<Field, SparseMatrixFormat::SparseSeq>  &A,
					const RingCategories::ModularTag  	&tag,
					const Method::Elimination     		&Meth)
	{
		return detin(d, A, tag, Method::SparseElimination(Meth));
	}

	template<class Field, class Vector>
	typename Field::Element &detin (typename Field::Element			&d,
					SparseMatrix<Field, Vector> 		&A,
					const RingCategories::ModularTag      	&tag,
					const Method::Elimination		&Meth)
	{
		// Matrix is not of type SparseMatrix<..SparseSeq> otherwise previous specialization would occur
		// will copy A into SparseMatrix<..SparseSeq> or BlasMatrix
		const Field& F = A.field();
		integer c; F.characteristic(c);
		if ((c < LinBox::BlasBound) && ((A.rowdim() < 300) || (A.coldim() < 300) || (A.size() > (A.coldim()*A.rowdim()/100))))
			return det(d, A, tag, Method::BlasElimination(Meth));
		else
			return det(d, A, tag, Method::SparseElimination(Meth));
	}


	// The det with Elimination Method
	template<class Blackbox>
	typename Blackbox::Field::Element &det (typename Blackbox::Field::Element	&d,
						const Blackbox				&A,
						const RingCategories::ModularTag	&tag,
						const Method::Elimination		&Meth)
	{
		// Matrix is not of type SparseMatrix otherwise previous specialization would occur
		// will copy A into BlasMatrix
		return det(d, A, tag, Method::BlasElimination(Meth));
	}


	template<class Blackbox>
	typename Blackbox::Field::Element &detin (typename Blackbox::Field::Element	&d,
						  Blackbox                            	&A,
						  const RingCategories::ModularTag      &tag,
						  const Method::Elimination		&Meth)
	{
		// Matrix is not of type SparseMatrix not of type BlasMatrix
                // otherwise previous specialization would occur
		// will copy A into BlasMatrix
		return det(d, A, tag, Method::BlasElimination(Meth));
	}

	template<class Field>
	typename Field::Element &detin (typename Field::Element			&d,
                                        BlasMatrix<Field>			&A,
                                        const RingCategories::ModularTag	&tag,
					const Method::Elimination		&Meth)
	{
		return detin(d, A);
	}

	template<class Field>
	typename Field::Element &detin (typename Field::Element			&d,
                                        BlasMatrix<Field>			&A,
                                        const RingCategories::ModularTag	&tag,
					const Method::BlasElimination		&Meth)
	{
		return detin(d, A);
	}



	// This should work for a BlasMatrix too ?
	/** Rank of Blackbox \p A.
	  * \ingroup solutions
	  * A will be modified.
	  * \param[out]  d determinant of \p A.
	  * \param       A this BlasMatrix matrix will be modified in place in the process.
	  * \return \p d
	  */
	template <class Field>
	typename Field::Element &detin (typename Field::Element             &d,
					BlasMatrix<Field>                  &A)
	{
		if (A.coldim() != A.rowdim())
			throw LinboxError("LinBox ERROR: matrix must be square for determinant computation\n");

		Field F = A.field();

		commentator().start ("Determinant", "detin");
		linbox_check (A.coldim () == A.rowdim ());

		BlasMatrixDomain<Field> BMD(F);
		d= BMD.detin(static_cast<BlasMatrix<Field>& > (A));
		commentator().stop ("done", NULL, "detin");

		return d;
	}
} // end of LinBox namespace

#include "linbox/ring/modular.h"
//#include "linbox/field/givaro-zpz.h"

#ifdef __LINBOX_HAVE_MPI
#include "linbox/algorithms/cra-mpi.h"
#else
#ifdef __LINBOX_HAVE_KAAPI //use the kaapi version instead of the usual version if this macro is defined
#include "linbox/algorithms/cra-kaapi.h"
#else
#include "linbox/algorithms/cra-domain.h"
#endif
#endif

#include "linbox/algorithms/cra-early-single.h"
#include "linbox/randiter/random-prime.h"
#include "linbox/algorithms/matrix-hom.h"
#include <typeinfo>
namespace LinBox
{

	template <class Blackbox, class MyMethod>
	struct IntegerModularDet {
		const Blackbox &A;
		const MyMethod &M;

		IntegerModularDet(const Blackbox& b, const MyMethod& n) :
			A(b), M(n)
		{}


		template<typename Field>
		typename Field::Element& operator()(typename Field::Element& d, const Field& F) const
		{
			typedef typename Blackbox::template rebind<Field>::other FBlackbox;
			FBlackbox Ap(A, F);
			detin( d, Ap, RingCategories::ModularTag(), M);
			return d;
		}
	};


	template <class Blackbox, class MyMethod>
	typename Blackbox::Field::Element &cra_det (typename Blackbox::Field::Element         &d,
						    const Blackbox                            &A,
						    const RingCategories::IntegerTag          &tag,
						    const MyMethod                            &Meth
#ifdef __LINBOX_HAVE_MPI
						    ,Communicator                             *C = NULL
#endif
						   )
	{
		//  if no parallelism or if this is the parent process
		//  begin the verbose output
#ifdef __LINBOX_HAVE_MPI
		if(!C || C->rank() == 0)
#endif
			commentator().start ("Integer Determinant", "idet");
		// 0.7213475205 is an upper approximation of 1/(2log(2))
		IntegerModularDet<Blackbox, MyMethod> iteration(A, Meth);
		RandomPrimeIterator genprime( 26-(int)ceil(log((double)A.rowdim())*0.7213475205));
		integer dd; // use of integer due to non genericity of cra. PG 2005-08-04

		//  will call regular cra if C=0
#ifdef __LINBOX_HAVE_MPI
		MPIChineseRemainder< EarlySingleCRA< Givaro::Modular<double> > > cra(4UL, C);
		cra(dd, iteration, genprime);
		if(!C || C->rank() == 0){
			A.field().init(d, dd); // convert the result from integer to original type
			commentator().stop ("done", NULL, "det");
		}
#else
		ChineseRemainder< EarlySingleCRA< Givaro::Modular<double> > > cra(4UL);
		cra(dd, iteration, genprime);
		A.field().init(d, dd); // convert the result from integer to original type
		commentator().stop ("done", NULL, "idet");
#endif

		return d;
	}

} // end of LinBox namespace

//#if 0
#ifdef __LINBOX_HAVE_NTL
# include "linbox/algorithms/hybrid-det.h"
# define SOLUTION_CRA_DET lif_cra_det
#else
# define SOLUTION_CRA_DET cra_det
#endif

#include "linbox/algorithms/rational-cra2.h"
#include "linbox/algorithms/varprec-cra-early-single.h"
#include "linbox/algorithms/det-rational.h"
namespace LinBox
{

	template <class Blackbox, class MyMethod>
	typename Blackbox::Field::Element &det (typename Blackbox::Field::Element         &d,
						const Blackbox                            &A,
						const RingCategories::IntegerTag          &tag,
						const MyMethod                            &Meth)
	{
		if (A.coldim() != A.rowdim())
			throw LinboxError("LinBox ERROR: matrix must be square for determinant computation\n");
		return SOLUTION_CRA_DET(d, A, tag, Meth);
	}

	template< class Blackbox, class MyMethod>
	typename Blackbox::Field::Element &det (typename Blackbox::Field::Element         &d,
						const Blackbox                            &A,
						const RingCategories::RationalTag       &tag,
						const MyMethod                          &Meth)
	{
		if (A.coldim() != A.rowdim())
			throw LinboxError("LinBox ERROR: matrix must be square for determinant computation\n");

		commentator().start ("Rational Determinant", "rdet");

		Integer num,den;

		IntegerModularDet<Blackbox, MyMethod> iteration(A, Meth);
		RandomPrimeIterator genprime( (unsigned int)( 26-(int)ceil(log((double)A.rowdim())*0.7213475205)));
		RationalRemainder2< VarPrecEarlySingleCRA< Givaro::Modular<double> > > rra(4UL);

		rra(num,den, iteration, genprime);

		A.field().init(d, num,den); // convert the result from integer to original type

		commentator().stop ("done", NULL, "rdet");
		return d;
	}

	template<class Field, class MyMethod>
	typename Field::Element &det (typename Field::Element                 &d,
				      const BlasMatrix<Field>                &A,
				      const RingCategories::RationalTag       &tag,
				      const MyMethod                          &Meth)
	{
		if (A.coldim() != A.rowdim())
			throw LinboxError("LinBox ERROR: matrix must be square for determinant computation\n");

		commentator().start ("Dense Rational Determinant", "rdet");

		rational_det(d,A,Meth);

		commentator().stop ("done", NULL, "rdet");
		return d;
	}

} // end of LinBox namespace

#ifdef __LINBOX_HAVE_MPI
namespace LinBox
{

	template <class Blackbox>
	typename Blackbox::Field::Element &det (typename Blackbox::Field::Element       &d,
						const Blackbox                          &A,
						/*const*/ Communicator			&C)
	{
		return det(d, A, Method::Hybrid(C));
	}
}
#endif //__LINBOX_HAVE_MPI

#endif // __LINBOX_det_H


// Local Variables:
// mode: C++
// tab-width: 8
// indent-tabs-mode: nil
// c-basic-offset: 8
// End:
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s