49 #define STYPE std::complex<double> 51 template<
typename TYPE>
60 int main(
int argc,
char* argv[])
65 if (argc>1)
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose =
true;
70 int numberFailedTests = 0;
72 std::string testName =
"";
74 if (verbose) std::cout<<std::endl<<
"********** CHECKING TEUCHOS SERIAL SYMMETRIC DENSE MATRIX **********"<<std::endl<<std::endl;
78 if (verbose) std::cout <<
"default constructor -- construct empty matrix ";
80 if (verbose) std::cout <<
"unsuccessful."<<std::endl;
83 if (verbose) std::cout <<
"successful."<<std::endl;
89 if (verbose) std::cout <<
"constructor 1 -- empty matrix with given dimensions ";
90 if ( Con1Test.
numRows()!=4 || Con1Test.
numCols()!=4 || Con1Test( 1, 2 )!=0.0 ) {
91 if (verbose) std::cout <<
"unsuccessful."<<std::endl;
94 if (verbose) std::cout <<
"successful."<<std::endl;
100 for(i = 0; i < 9; i++)
105 Con2Test1ExpRes.
shape(3);
106 Con2Test1ExpRes(0, 0) = 0;
107 Con2Test1ExpRes(1, 0) = 1; Con2Test1ExpRes(1, 1) = 4;
108 Con2Test1ExpRes(2, 0) = 2; Con2Test1ExpRes(2, 1) = 5; Con2Test1ExpRes(2, 2) = 8;
112 numberFailedTests +=
PrintTestResults(
"constructor 2 -- construct matrix from array subrange", Con2Test1, Con2Test1ExpRes, verbose);
117 SDMatrix Con3TestCopy( Con2Test1ExpRes );
118 if(verbose) std::cout <<
"constructor 3 -- copy constructor ";
119 if ( Con3TestCopy != Con2Test1ExpRes ) {
120 if (verbose) std::cout <<
"unsuccessful."<<std::endl;
123 if (verbose) std::cout <<
"successful."<<std::endl;
126 SDMatrix Con3TestCopyTrans( Con2Test1ExpRes );
128 if(verbose) std::cout <<
"constructor 3 -- copy constructor (upper active storage) ";
129 if ( Con3TestCopyTrans(2, 0) != Con2Test1ExpRes(2, 0) ) {
130 if (verbose) std::cout <<
"unsuccessful."<<std::endl;
133 if (verbose) std::cout <<
"successful."<<std::endl;
140 Con4TestSubmatrix.
shape( 2 );
141 Con4TestSubmatrix(0, 0) = 4;
142 Con4TestSubmatrix(1, 0) = 5; Con4TestSubmatrix(1, 1) = 8;
144 numberFailedTests +=
PrintTestResults(
"constructor 4 -- submatrix copy", Con4TestCopy1, Con4TestSubmatrix, verbose);
146 numberFailedTests +=
PrintTestResults(
"constructor 4 -- full matrix copy", Con4TestCopy2, Con4TestOrig, verbose);
148 numberFailedTests +=
PrintTestResults(
"constructor 4 -- full matrix view", Con4TestView1, Con4TestSubmatrix, verbose);
150 numberFailedTests +=
PrintTestResults(
"constructor 4 -- submatrix view", Con4TestView2, Con4TestOrig, verbose);
157 AAA(1, 0) = 1; AAA(1, 1) = 8;
158 AAA(2, 0) = 2; AAA(2, 1) = 3; AAA(2, 2) = 8;
163 numberFailedTests +=
PrintTestResults(
"normFrobenius of a 3x3", AAA.normFrobenius(), 3.0, verbose);
172 AAA(1, 0) = 1; AAA(1, 1) = 8;
173 AAA(2, 0) = 2; AAA(2, 1) = 3; AAA(2, 2) = 8;
175 DMatrix My_Prod( 4, 3 ), My_GenMatrix( 4, 3 );
180 numberFailedTests +=
PrintTestResults(
"multiply() -- general times symmetric matrix (storage = lower tri)", My_Prod.normOne(), 52.0, verbose);
184 numberFailedTests +=
PrintTestResults(
"multiply() -- general times symmetric matrix (storage = upper tri)", My_Prod.normOne(), 44.0, verbose);
190 testName =
"random() -- enter random entries into matrix";
191 returnCode = CCC.random();
192 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
194 testName =
"putScalar() -- set every entry of this matrix to 1.0";
196 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
200 if (verbose) std::cout <<
"assign() -- copy the values of an input matrix ";
202 if (verbose) std::cout<<
"successful" <<std::endl;
204 if (verbose) std::cout<<
"unsuccessful" <<std::endl;
211 if (verbose) std::cout <<
"operator= -- small(empty) = large(view) ";
212 if (CCCtest1.
numRows()==3 && CCCtest1.
values()==CCC.values()) {
213 if (verbose) std::cout<<
"successful" <<std::endl;
215 if (verbose) std::cout<<
"unsuccessful" <<std::endl;
219 if (verbose) std::cout <<
"operator= -- small(view) = large(copy) ";
220 if (CCCtest1.
numRows()==5 && CCCtest1.
values()!=CCC.values()) {
221 if (verbose) std::cout<<
"successful"<<std::endl;
223 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
229 if (verbose) std::cout <<
"operator= -- large(copy) = small(copy) ";
231 if (verbose) std::cout<<
"successful"<<std::endl;
233 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
237 if (verbose) std::cout <<
"operator= -- large(copy) = small(view) ";
239 if(verbose) std::cout<<
"successful" <<std::endl;
241 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
246 CCCtest1 += CCCtest3;
247 if (verbose) std::cout <<
"operator+= -- add two matrices of the same size, but different leading dimension ";
248 if (CCCtest1(1,1)==2.0) {
249 if(verbose) std::cout<<
"successful" <<std::endl;
251 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
254 if (verbose) std::cout <<
"operator+= -- add two matrices of different size (nothing should change) ";
256 if (CCCtest1(1,1)==2.0) {
257 if(verbose) std::cout<<
"successful" <<std::endl;
259 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
269 if (verbose) std::cout <<
"operator*= -- scale matrix by some number ";
271 if (ScalTest(7, 1) == 8.0) {
272 if (verbose) std::cout<<
"successful." <<std::endl;
274 if (verbose) std::cout<<
"unsuccessful." <<std::endl;
283 A1(0,0) = 1.0, A1(1,1) = 2.0;
284 A2(0,0) = 1.0, A2(1,1) = 2.0, A2(2,2) = 3.00;
287 SDMatrix C1upper(3), C1lower(3), C2upper(2), C2lower(2);
288 C1upper.setUpper(); C2upper.setUpper();
289 C1lower.setLower(); C2lower.
setLower();
295 Teuchos::symMatTripleProduct<OTYPE,STYPE>(
Teuchos::NO_TRANS, alpha, A1, W, C1upper );
296 Teuchos::symMatTripleProduct<OTYPE,STYPE>(
Teuchos::NO_TRANS, alpha, A1, W, C1lower );
300 Teuchos::symMatTripleProduct<OTYPE,STYPE>(
Teuchos::TRANS, alpha, A2, W, C2upper );
301 Teuchos::symMatTripleProduct<OTYPE,STYPE>(
Teuchos::TRANS, alpha, A2, W, C2lower );
303 if (verbose) std::cout <<
"triple product -- compute C = W'*A*W or C = W*A*W' ";
304 if (C1upper(2,1)==C1result && C1lower(1,2)==C1result && C2upper(1,0)==C2result && C2lower(0,1)==C2result) {
305 if (verbose) std::cout<<
"successful." <<std::endl;
307 if (verbose) std::cout<<
"unsuccessful." <<std::endl;
316 if(numberFailedTests > 0)
319 std::cout <<
"Number of failed tests: " << numberFailedTests << std::endl;
320 std::cout <<
"End Result: TEST FAILED" << std::endl;
324 if(numberFailedTests == 0)
325 std::cout <<
"End Result: TEST PASSED" << std::endl;
330 template<
typename TYPE>
331 int PrintTestResults(std::string testName, TYPE calculatedResult, TYPE expectedResult,
bool verbose)
334 if(calculatedResult == expectedResult)
336 if(verbose) std::cout << testName <<
" successful." << std::endl;
341 if(verbose) std::cout << testName <<
" unsuccessful." << std::endl;
347 int ReturnCodeCheck(std::string testName,
int returnCode,
int expectedResult,
bool verbose)
350 if(expectedResult == 0)
354 if(verbose) std::cout << testName <<
" test successful." << std::endl;
359 if(verbose) std::cout << testName <<
" test unsuccessful. Return code was " << returnCode <<
"." << std::endl;
367 if(verbose) std::cout << testName <<
" test successful -- failed as expected." << std::endl;
372 if(verbose) std::cout << testName <<
" test unsuccessful -- did not fail as expected. Return code was " << returnCode <<
"." << std::endl;
ScalarTraits< ScalarType >::magnitudeType normInf() const
Returns the Infinity-norm of the matrix.
OrdinalType numCols() const
Returns the column dimension of this matrix.
Non-member helper functions on the templated serial, dense matrix/vector classes. ...
Templated serial dense matrix class.
bool empty() const
Returns whether this matrix is empty.
Teuchos::SerialDenseMatrix< OTYPE, STYPE > DMatrix
int shape(OrdinalType numRowsCols)
Set dimensions of a Teuchos::SerialSymDenseMatrix object; init values to zero.
This class creates and provides basic support for symmetric, positive-definite dense matrices of temp...
Teuchos::SerialDenseVector< OTYPE, STYPE > DVector
This class creates and provides basic support for dense vectors of templated type as a specialization...
This structure defines some basic traits for a scalar field type.
void setLower()
Specify that the lower triangle of the this matrix should be used.
Teuchos::SerialSymDenseMatrix< OTYPE, STYPE > SDMatrix
void setUpper()
Specify that the upper triangle of the this matrix should be used.
OrdinalType numRows() const
Returns the row dimension of this matrix.
int main(int argc, char *argv[])
int PrintTestResults(std::string, TYPE, TYPE, bool)
std::string Teuchos_Version()
int ReturnCodeCheck(std::string, int, int, bool)
Templated serial, dense, symmetric matrix class.
Templated serial dense vector class.
ScalarTraits< ScalarType >::magnitudeType normOne() const
Returns the 1-norm of the matrix.
SerialSymDenseMatrix< OrdinalType, ScalarType > & assign(const SerialSymDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
static T one()
Returns representation of one for this scalar type.
ScalarType * values() const
Returns the pointer to the ScalarType data array contained in the object.
OrdinalType stride() const
Returns the stride between the columns of this matrix in memory.
This class creates and provides basic support for dense rectangular matrix of templated type...
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Returns the Frobenius-norm of the matrix.