1 /* Copyright (C) LinBox
2  *
3  *  Author: Zhendong Wan, mods -bds
4  *
5  * ========LICENCE========
6  * This file is part of the library LinBox.
7  *
8   * LinBox is free software: you can redistribute it and/or modify
9  * it under the terms of the  GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  * ========LICENCE========
22  */
23 
24 
25 /*! @file  tests/test-smith-form-binary.C
26  * @ingroup tests
27  * @brief Test the EGV divide and conquer SNF alg.
28  */
29 
30 #include "linbox/linbox-config.h"
31 
32 #ifdef __LINBOX_HAVE_NTL
33 #include "linbox/ring/ntl.h"
34 #endif
35 #include "linbox/randiter/random-prime.h"
36 #include "linbox/algorithms/matrix-rank.h"
37 #include "linbox/algorithms/last-invariant-factor.h"
38 #include "linbox/algorithms/one-invariant-factor.h"
39 #include "linbox/algorithms/smith-form-binary.h"
40 #include "linbox/blackbox/scompose.h"
41 #include "linbox/blackbox/random-matrix.h"
42 #include "linbox/algorithms/rational-solver.h"
43 //#include <time.h>
44 #include <givaro/modular.h>
45 
46 #include "linbox/util/commentator.h"
47 //#include "linbox/vector/stream.h"
48 //#include "test-common.h"
49 using namespace LinBox;
50 
51 #include "test-smith-form.h"
52 
main(int argc,char ** argv)53 int main(int argc, char** argv)
54 {
55 	bool pass = true;
56 
57 	static size_t m =2;
58 	static size_t n =5;
59 
60 	static Argument args[] = {
61 		{ 'm', "-m M", "Set row dimension of test matrices to M.", TYPE_INT,     &m },
62 		{ 'n', "-n N", "Set col dimension  of test matrices to N.", TYPE_INT,     &n },
63 		END_OF_ARGUMENTS
64 	};
65 
66 	parseArguments (argc, argv, args);
67 
68 	commentator().start("SmithFormBinary test suite", "SmithFormBinary");
69 
70 	commentator().report() << std::endl << "EGV++ algorithm test suite with LinBox/Givaro ZRing:\n";
71 	{
72 //		typedef Givaro::IntegerDom Ring;
73 		typedef Givaro::ZRing<Integer> PIR;
74 		PIR R;
75 
76 		typedef Givaro::Modular<int64_t> Field;
77 		typedef RationalSolver<PIR, Field, PrimeIterator<IteratorCategories::HeuristicTag> > Solver;
78 		typedef LastInvariantFactor<PIR, Solver> LIF;
79 		typedef OneInvariantFactor<PIR, LIF, SCompose, RandomMatrix>  OIF;
80 		typedef SmithFormBinary<PIR, OIF, MatrixRank<PIR, Field > > SF;
81 
82 		SF sf;
83 		sf. setOIFThreshold (30);
84 		sf. setLIFThreshold (30);
85 
86 	size_t k = std::min(m,n);
87 	DenseMatrix<PIR> A(R,m,n);
88 	BlasVector<PIR> d(R,k), x(R,k), bumps(R,k), lumps(R,19);
89 	for (size_t i = 0; i <10; ++i) lumps[i] = i;
90 	for (size_t i = 10; i <19; ++i) lumps[i] = i-19;
91 
92 	makeBumps(bumps, 0);
93 	makeSNFExample(A,d,bumps,lumps);
94 	sf.smithFormBinary (x, A);
95 	pass = pass and checkSNFExample(d,x);
96 
97 	makeBumps(bumps, 1);
98 	makeSNFExample(A,d,bumps,lumps);
99 	sf.smithFormBinary (x, A);
100 	pass = pass and checkSNFExample(d,x);
101 
102 	makeBumps(bumps, 2);
103 	makeSNFExample(A,d,bumps,lumps);
104 	sf.smithFormBinary (x, A);
105 	pass = pass and checkSNFExample(d,x);
106 
107 	makeBumps(bumps, 3);
108 	makeSNFExample(A,d,bumps,lumps);
109 	sf.smithFormBinary (x, A);
110 	pass = pass and checkSNFExample(d,x);
111 
112 	}
113 
114 #if 0
115 #ifdef __LINBOX_HAVE_NTL
116 // NTL_ZZ not working here
117 	{
118 		typedef NTL_ZZ Ring;
119 
120 		Ring R; Ring::RandIter gen(R);
121 
122 		commentator().report() << std::endl << "EGV++ algorithm test suite with NTL_ZZ :\n";
123 		commentator().getMessageClass (INTERNAL_DESCRIPTION).setMaxDepth (5);
124 
125 		//RandomDenseStream<Ring> s1 (R, gen, n, (unsigned int)iterations);
126 		RandomDenseStream<Ring> s1 (R, gen, n, 1);
127 
128 		typedef Givaro::Modular<int32_t> Field;
129 		typedef RationalSolver<Ring, Field, PrimeIterator<IteratorCategories::HeuristicTag> > Solver;
130 		typedef LastInvariantFactor<Ring, Solver> LIF;
131 		typedef OneInvariantFactor<Ring, LIF, SCompose, RandomMatrix>  OIF;
132 		typedef SmithFormBinary<Ring, OIF, MatrixRank<Ring, Field > > SF;
133 
134 		SF sf;
135 		sf. setOIFThreshold (30);
136 		sf. setLIFThreshold (30);
137 
138 		if (!testRandom(R, sf, s1)) pass = false;
139 	}
140 #endif
141 #endif
142 
143 	commentator().stop("SmithFormBinary test suite");
144 	return pass ? 0 : -1;
145 }
146 
147 // Local Variables:
148 // mode: C++
149 // tab-width: 4
150 // indent-tabs-mode: nil
151 // c-basic-offset: 4
152 // End:
153 // vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
154