File: test-ntl-sylvester.C

package info (click to toggle)
linbox 1.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,940 kB
  • sloc: cpp: 108,392; lisp: 5,469; makefile: 1,345; sh: 1,244; csh: 131; python: 74; perl: 2
file content (187 lines) | stat: -rw-r--r-- 5,267 bytes parent folder | download | duplicates (4)
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
/*-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *    test-ntl-sylvester.C
 *    Copyright (C) 2003 Austin Lobo, B. David Saunders
 *    Copyright (C) LinBox
 *
 *    Tests for  Sylvester matrix specification with ntl Arithmetic,
 *    for 2 polynomials in one variable.
 *    LinBox version 2003
 *
 * ========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========
 *
 * Function definitions for block Lanczos iteration
 *-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/

/*! @file  tests/test-ntl-sylvester.C
 * @ingroup tests
 * @brief no doc.
 * @test no doc
 */


#include <linbox/linbox-config.h>
#include <iostream>
#include <fstream>

#include "linbox/ring/ntl.h"

#include "linbox/integer.h"
#include "linbox/blackbox/ntl-sylvester.h"
#include "test-generic.h"



using namespace std;
using namespace LinBox;

int main(int argc, char* argv[])
{
	LinBox::commentator().getMessageClass (INTERNAL_DESCRIPTION).setMaxDepth (2);
	ostream &report = LinBox::commentator().report(
						     LinBox::Commentator::LEVEL_IMPORTANT,
						     INTERNAL_DESCRIPTION );
	bool pass = true;

	static size_t n = 1000;
	static int64_t q = 134217689;
	//   q = 101;
	static int iterations = 1;

	static Argument args[] = {
		{ 'n', "-n N", "Set dimension of test matrices to NxN.", TYPE_INT, &n },
//		{ 'q', "-q Q", "Operate over the \"field\" GF(Q) [1].",
//			TYPE_INT, &q },
		{ 'i', "-i I", "Perform each test for I iterations.",
			TYPE_INT, &iterations },
		END_OF_ARGUMENTS
	};

	LinBox::parseArguments (argc, argv, args);




	//------ Read q and construct F(q)
	NTL::ZZ modulus; 	// prime modulus
	modulus = q;
	size_t  m = n-3;
	// std::cout << std::endl << "Enter a prime number for the modulus of the field: ";
	// std::cin >> modulus;
	report <<  "The modulus is " << modulus << std::endl;
	report <<  "Dimension (m+n) is " << m+n << std::endl;
	NTL::ZZ_p::init(modulus); // NOTE: This is essential for using NTL

	LinBox::commentator().start("Sylvester black box test suite", "Sylvester");
	report <<"Dimension(m+n)= " << m+n << "\t modulus= " << q << endl;

	// typedef Givaro::ZRing<NTL::ZZ_p> Field;
	typedef LinBox::NTL_ZZ_p Field;
	// typedef Field::Element element;
	typedef LinBox::BlasVector<Field> Vector;

	// Now we are using the NTL wrapper as the field, call the instance F
	Field F(q); // XXX same bug ?

	// Use the default constructor to create a matrix
	// LinBox::Sylvester<Field> T(F);

	// Use a special constructor to construct a matrix of dim TSIZE

	Vector pdata(F,n), qdata(F,m);

	report << "\n\tpx:=";

	for (size_t i=pdata.size()-1; i > 0; i-- ) {
		pdata[i] = NTL::random_ZZ_p() ;
		report << pdata[i] << "*X^" << i << " + ";
	}
	pdata[0] = NTL::random_ZZ_p() ;
	report << pdata[0];

	report << std::endl;
	report << "\nqx is: \n\t";

	for (size_t i=qdata.size()-1; i > 0; i-- ) {
		qdata[i] = NTL::random_ZZ_p() ;
		report << qdata[i] << "*X^" << i << " + ";
	}

	qdata[0] = NTL::random_ZZ_p() ;
	report << qdata[0];
	report << std::endl;


	// LinBox::Sylvester<Field> TT(F,pdata,qdata);
	LinBox::Sylvester<Field> TT(pdata,qdata);
	report << "The matrix is: " << std::endl;
	TT.print(report);

#if 0 /* this is not a test */
	//  TT.printcp( "cpout.txt");
	//  TT.print(report);

	report << std::endl;


	// Create an interesting input vector called idata
	Vector idata(F, TT.sysdim() ), odata( F, TT.sysdim() );
	report << "A random col vector:\npx:=[" << std::endl;

	for (unsigned int i=0; i < idata.size(); i++) {
		idata[i] = NTL::random_ZZ_p() ;

		if (i!= idata.size()-1)     report << idata[i] << ",";
	}
	report << "]\n";

	TT.apply(odata, idata);
	report << "\n\nTesting  apply :--------------------- \nResult is[";

	for (unsigned int i = 0; i < odata.size(); i++)
		report << odata[i] << " ";

	report << "]\n";

	// Apply the matrix to the vector just created
	// Testing the apply function when both input and output are over ZZ_p

	report << "Testing apply Transpose:----------------- \nResult is[";

	TT.applyTranspose(odata, idata);

	for (unsigned int i = 0; i < odata.size(); i++)
		report << odata[i] << " ";
#endif

	pass = testBlackboxNoRW(TT);
	report <<"<====\tDone Sylvester matrix black box test suite" << endl;


	LinBox::commentator().stop(MSG_STATUS (pass),"Sylvester black box test suite");
	return pass ? 0 : -1;

}

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