60 , std::ostream*
out,
bool* success )
63 *out <<
"Checking M(i,j) == M.row(i)(j) == M.col(j)(i) == "
64 <<
"M.diag(...)(...) == "
65 <<
"(i + "<<row_offset<<
") + 0.1*(j+"<<col_offset<<
") : ";
74 val = (i+row_offset)+0.1*(j+col_offset);
77 if(out) *out <<
"(M("<<i<<
","<<j<<
") -> "<<Mij<<
") != "<<val<<std::endl;
79 if( Mij != (val = M.row(i)(j)) ) {
81 if(out) *out <<
"M("<<i<<
","<<j<<
") != (M.row("<<i<<
")("<<j<<
") -> "<<val<<
")\n";
83 if( Mij != (val = M.col(j)(i)) ) {
85 if(out) *out <<
"M("<<i<<
","<<j<<
") != (M.col("<<j<<
")("<<i<<
") -> "<<val<<
")\n";
87 const int k = ( i > j ? -i + j : j - i );
89 if( Mij != (val = M.diag(k)(k_i) ) ) {
91 if(out) *out <<
"M("<<i<<
","<<j<<
") != (M.diag("<<k<<
")("<<k_i<<
") -> "<<val<<
")\n";
95 if(out) *out << result << std::endl;
96 if(!result) *success =
false;
105 return "SOME_OVERLAP";
109 return "Invalid value for EOverLap";
124 *out <<
"\n****************************************************"
125 <<
"\n*** Testing DMatrix and DMatrixSlice classes ***"
126 <<
"\n****************************************************\n"
137 { 1.1, 2.1, 3.1, 4.1, 5.1, 6.1,
138 1.2, 2.2, 3.2, 4.2, 5.2, 6.2,
139 1.3, 2.3, 3.3, 4.3, 5.3, 6.3,
140 1.4, 2.4, 3.4, 4.4, 5.4, 6.4,
141 1.5, 2.5, 3.5, 4.5, 5.5, 6.5,
142 1.6, 2.6, 3.6, 4.6, 5.6, 6.6,
143 1.7, 2.7, 3.7, 4.7, 5.7, 6.7,
144 1.8, 2.8, 3.8, 4.8, 5.8, 6.8 };
150 *out <<
"\n***\n*** Testing constructors\n***\n";
153 if(out) *out <<
"\nGenMatrixSlice gms1;\n";
155 if(out) *out <<
"gms1 =\n" << gms1;
156 update_success( result = (gms1.rows() == 0 && gms1.cols() == 0 ), &success );
158 *out <<
"((gms1.rows() -> "<<gms1.rows()
159 <<
") == 0 && (gms1.cols() -> "<<gms1.cols()<<
") == 0 ) : "
160 << result << std::endl;
163 if(out) *out <<
"\nGenMatrixSlice gms2( const_cast<value_type*>(ptr), m*n, m, m, n );\n";
164 const DMatrixSlice gms2( const_cast<value_type*>(ptr), m*
n, m, m, n );
165 if(out) *out <<
"gms2 =\n" << gms2;
167 if(out) *out <<
"\nGenMatrixSlice gms3( const_cast<DMatrixSlice&>(gms2), Range1D(1,m), Range1D(1,n) );\n";
169 if(out) *out <<
"gms3 =\n" << gms3;
173 if(out) *out <<
"\nGenMatrix gm1;\n";
175 if(out) *out <<
"gm1 =\n" << gm1();
176 update_success( result = (gm1.rows() == 0 && gm1.cols() == 0 ), &success );
178 *out <<
"((gm1.rows() -> "<<gm1.rows()
179 <<
") == 0 && (gm1.cols() -> "<<gm1.cols()<<
") == 0 ) : "
180 << result << std::endl;
182 if(out) *out <<
"\nGenMatrix gm2(m,n);\n";
184 if(out) *out <<
"gm2 =\n" << gm2();
186 if(out) *out <<
"\nGenMatrix gm3(1.0,m,n);\n";
188 if(out) *out <<
"gm3 =\n" << gm3();
190 if(out) *out <<
"gm3 == 1.0 : " << result << std::endl;
192 if(out) *out <<
"\nGenMatrix gm4(ptr,m,n);\n";
194 if(out) *out <<
"gm4 =\n" << gm4();
196 if(out) *out <<
"\nGenMatrix gm5(gms2);\n";
198 if(out) *out <<
"gm5 =\n" << gm5();
204 *out <<
"\n***\n*** Testing DMatrixSlice binding\n***\n";
206 if(out) *out <<
"\ngms1.bind(gm4());\n";
208 if(out) *out <<
"gms1 =\n" << gms1();
214 *out <<
"\n***\n*** Testing DMatrix resizing\n***\n";
216 if(out) *out <<
"\ngm1.resize(m,n,1.0);\n";
218 if(out) *out <<
"gm1 =\n" << gm1();
220 if(out) *out <<
"gm1 == 1.0 : " << result << std::endl;
228 *out <<
"\n***\n*** Testing row, col, diag access and element access\n***\n";
230 if(out) *out <<
"\nLet M = gms1\n";
231 check_access( gms1, 0, 0, out, &success );
233 if(out) *out <<
"\nLet M = const_cast<const DMatrixSlice&>(gms1)\n";
234 check_access( const_cast<const DMatrixSlice&>(gms1), 0, 0, out, &success );
238 if(out) *out <<
"\nLet M = gm4\n";
239 check_access( gm4, 0, 0, out, &success );
241 if(out) *out <<
"\nLet M = const_cast<const DMatrix&>(gm4)\n";
242 check_access( const_cast<const DMatrix&>(gm4), 0, 0, out, &success );
248 *out <<
"\n***\n*** Testing submatrix access\n***\n";
250 if(out) *out <<
"\nRange1D r_rng(2,m-1), c_rng(2,n-1);\n";
251 Range1D r_rng(2,m-1), c_rng(2,n-1);
255 if(out) *out <<
"\nLet M = const_cast<DMatrixSlice&>(gms2)(r_rng,c_rng)\n";
256 gms1.bind( const_cast<DMatrixSlice&>(gms2)(r_rng,c_rng) );
257 if(out) *out <<
"M =\n" << gms1;
258 check_access( gms1, 1, 1, out, &success );
260 if(out) *out <<
"\nLet M = const_cast<DMatrixSlice&>(gms2(r_rng,c_rng))\n";
261 gms1.bind( const_cast<DMatrixSlice&>(gms2)(r_rng,c_rng) );
262 if(out) *out <<
"M =\n" << gms1;
263 check_access( gms1, 1, 1, out, &success );
265 if(out) *out <<
"\nLet M = const_cast<DMatrixSlice&>(gms2)(2,m-1,2,n-1)\n";
266 gms1.bind(const_cast<DMatrixSlice&>(gms2)(2,m-1,2,n-1) );
267 if(out) *out <<
"M =\n" << gms1;
268 check_access( gms1, 1, 1, out, &success );
270 if(out) *out <<
"\nLet M = const_cast<DMatrixSlice&>(gms2(2,m-1,2,n-1))\n";
271 gms1.bind( const_cast<DMatrixSlice&>(gms2)(2,m-1,2,n-1) );
272 if(out) *out <<
"M =\n" << gms1;
273 check_access( gms1, 1, 1, out, &success );
277 if(out) *out <<
"\nLet M = gm4(r_rng,c_rng)\n";
278 gms1.bind( gm4(r_rng,c_rng) );
279 if(out) *out <<
"M =\n" << gms1;
280 check_access( gms1, 1, 1, out, &success );
282 if(out) *out <<
"\nLet M = const_cast<const DMatrixSlice&>(gm4)(r_rng,c_rng)\n";
283 gms1.bind( const_cast<const DMatrix&>(gm4)(r_rng,c_rng) );
284 if(out) *out <<
"M =\n" << gms1;
285 check_access( gms1, 1, 1, out, &success );
287 if(out) *out <<
"\nLet M = gm4(2,m-1,2,n-1)\n";
288 gms1.bind( gm4(2,m-1,2,n-1) );
289 if(out) *out <<
"M =\n" << gms1;
290 check_access( gms1, 1, 1, out, &success );
292 if(out) *out <<
"\nLet M = const_cast<const DMatrixSlice&>(gm4)(2,m-1,2,n-1)\n";
293 gms1.bind( const_cast<const DMatrix&>(gm4)(2,m-1,2,n-1) );
294 if(out) *out <<
"M =\n" << gms1;
295 check_access( gms1, 1, 1, out, &success );
301 *out <<
"\n***\n*** matrix overlap\n***\n";
307 if(out) *out <<
"(gms2.overlap(gms2) -> ";
308 ovlap = gms2.overlap(gms2);
310 if(out) *out << overlap_str(ovlap) <<
") == SAME_MEM : " << result << std::endl;
312 if(out) *out <<
"(gms2.overlap(gms2(r_rng,c_rng)) -> ";
313 ovlap = gms2.overlap(gms2(r_rng,c_rng));
315 if(out) *out << overlap_str(ovlap) <<
") == SOME_OVERLAP : " << result << std::endl;
317 if(out) *out <<
"(gms2(1,m/2,1,n/2).overlap(gms2(m/2,m,n/2,n)) -> ";
318 ovlap = gms2(1,m/2,1,n/2).overlap(gms2(m/2,m,n/2,n));
320 if(out) *out << overlap_str(ovlap) <<
") == SOME_OVERLAP : " << result << std::endl;
322 if(out) *out <<
"(gms2(1,m/2,1,n/2).overlap(gms2(m/2+1,m,n/2+1,n)) -> ";
323 ovlap = gms2(1,m/2,1,n/2).overlap(gms2(m/2+1,m,n/2+1,n));
325 if(out) *out << overlap_str(ovlap) <<
") == NO_OVERLAP : " << result << std::endl;
329 if(out) *out <<
"(gm4.overlap(gm4) -> ";
330 ovlap = gm4.overlap(gm4());
332 if(out) *out << overlap_str(ovlap) <<
") == SAME_MEM : " << result << std::endl;
334 if(out) *out <<
"(gm4.overlap(gm4(r_rng,c_rng)) -> ";
335 ovlap = gm4.overlap(gm4(r_rng,c_rng));
337 if(out) *out << overlap_str(ovlap) <<
") == SOME_OVERLAP : " << result << std::endl;
348 *out <<
"\n***\n*** assignment operators\n***\n";
352 if(out) *out <<
"\ngms1.bind(gm1());\n";
355 if(out) *out <<
"\ngms1 = 2.0;\n";
357 if(out) *out <<
"gms1 =\n" << gms1;
359 if(out) *out <<
"gms1 == 2.0 : " << result << std::endl;
361 if(out) *out <<
"\ngms1 = gms2;\n";
363 if(out) *out <<
"gms1 =\n" << gms1;
365 if(out) *out <<
"gms1 == gms2 : " << result << std::endl;
369 if(out) *out <<
"\ngm1 = 3.0;\n";
371 if(out) *out <<
"gm1 =\n" << gm1();
373 if(out) *out <<
"gm1 == 3.0 : " << result << std::endl;
375 if(out) *out <<
"\ngm1.resize(0,0); gm1 = gms2;\n";
378 if(out) *out <<
"gm1 =\n" << gm1();
380 if(out) *out <<
"gm1 == gms2 : " << result << std::endl;
382 if(out) *out <<
"\ngm1.resize(0,0); gm1 = gm4;\n";
385 if(out) *out <<
"gm1 =\n" << gm1();
387 if(out) *out <<
"gm1 == gm4 : " << result << std::endl;
390 catch(
const std::exception& excpt ) {
393 (*out) <<
"\nError, a standard exception was thrown: "
395 << excpt.what() << std::endl;
400 (*out) <<
"\nError, an unknown exception was thrown\n";
406 <<
"\n*** Congradulations, DMatrix and DMatrixSlice seem to check out. ***\n";
409 <<
"\n*** Oops, all of the tests for DMatrix and DMatrixSlice "
410 "where not successful. ***\n";
Teuchos::Ordinal size_type
Typedef for the size type of elements that are used by the library.
AbstractLinAlgPack::size_type size_type
std::string typeName(const T &t)
bool TestGenMatrixClass(std::ostream *out)
. One-based subregion index range class.
const value_type sqrt_eps
const LAPACK_C_Decl::f_int & M
EOverLap
Enumeration for returning the amount of overlap between two objects.
AbstractLinAlgPack::value_type value_type
FortranTypes::f_dbl_prec value_type
Typedef for the value type of elements that is used for the library.
bool update_success(bool result_check, bool *success)
Helper function for updating a flag for if an operation returned false.
bool comp(const DVectorSlice &vs1, const DVectorSlice &vs2)
RangePack::Range1D Range1D