17 #define STYPE std::complex<double>
19 template<
typename TYPE>
28 int main(
int argc,
char* argv[])
33 if (argc>1)
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose =
true;
38 int numberFailedTests = 0;
40 std::string testName =
"";
42 if (verbose) std::cout<<std::endl<<
"********** CHECKING TEUCHOS SERIAL BANDED DENSE MATRIX **********"<<std::endl<<std::endl;
46 if (verbose) std::cout <<
"default constructor -- construct empty matrix ";
48 if (verbose) std::cout <<
"unsuccessful."<<std::endl;
51 if (verbose) std::cout <<
"successful."<<std::endl;
57 if (verbose) std::cout <<
"constructor 1 -- empty matrix with given dimensions ";
58 if ( Con1Test.
numRows()!=4 || Con1Test.
numCols()!=4 || Con1Test( 1, 2 )!=0.0 ) {
59 if (verbose) std::cout <<
"unsuccessful."<<std::endl;
62 if (verbose) std::cout <<
"successful."<<std::endl;
68 a[4] = 5; a[8] = 11; a[12] = 17; a[16] = 23;
69 a[1] = 0; a[5] = 6; a[9] = 12; a[13] = 18; a[17] = 24;
70 a[2] = 1; a[6] = 7; a[10] = 13; a[14] = 19;
71 a[3] = 2; a[7] = 8; a[11] = 14;
74 C2T1ER.
shape(5, 5, 2, 1);
75 C2T1ER(0, 0) = 0; C2T1ER(0, 1) = 5;
76 C2T1ER(1, 0) = 1; C2T1ER(1, 1) = 6; C2T1ER(1, 2) = 11;
77 C2T1ER(2, 0) = 2; C2T1ER(2, 1) = 7; C2T1ER(2, 2) = 12; C2T1ER(2, 3) = 17;
78 C2T1ER(3, 1) = 8; C2T1ER(3, 2) = 13; C2T1ER(3, 3) = 18; C2T1ER(3, 4) = 23;
79 C2T1ER(4, 2) = 14; C2T1ER(4, 3) = 19; C2T1ER(4, 4) = 24;
83 numberFailedTests +=
PrintTestResults(
"constructor 2 -- construct matrix from array subrange", Con2Test1, C2T1ER, verbose);
88 if(verbose) std::cout <<
"constructor 3 -- copy constructor ";
89 if ( Con3TestCopy != C2T1ER ) {
90 if (verbose) std::cout <<
"unsuccessful."<<std::endl;
93 if (verbose) std::cout <<
"successful."<<std::endl;
97 if(verbose) std::cout <<
"constructor 3 -- copy constructor (transposed) ";
98 if ( Con3TestCopyTrans(0, 2) != C2T1ER(2, 0) ) {
99 if (verbose) std::cout <<
"unsuccessful."<<std::endl;
102 if (verbose) std::cout <<
"successful."<<std::endl;
109 C4TS.
shape( 3, 3, 2, 1 );
110 C4TS(0, 0) = 12; C4TS(0, 1) = 17;
111 C4TS(1, 0) = 13; C4TS(1, 1) = 18; C4TS(1, 2) = 23;
112 C4TS(2, 0) = 14; C4TS(2, 1) = 19; C4TS(2, 2) = 24;
115 numberFailedTests +=
PrintTestResults(
"constructor 4 -- submatrix copy", Con4TestCopy1, C4TS, verbose);
117 numberFailedTests +=
PrintTestResults(
"constructor 4 -- full matrix copy", Con4TestCopy2, Con4TestOrig, verbose);
119 numberFailedTests +=
PrintTestResults(
"constructor 4 -- full matrix view", Con4TestView1, Con4TestOrig, verbose);
121 numberFailedTests +=
PrintTestResults(
"constructor 4 -- submatrix view", Con4TestView2, C4TS, verbose);
126 AAA.
shape( 5, 5, 2, 1 );
127 AAA(0, 0) = 0; AAA(0, 1) = 5;
128 AAA(1, 0) = 1; AAA(1, 1) = 6; AAA(1, 2) = 11;
129 AAA(2, 0) = 2; AAA(2, 1) = 7; AAA(2, 2) = 12; AAA(2, 3) = 17;
130 AAA(3, 1) = 8; AAA(3, 2) = 13; AAA(3, 3) = 18; AAA(3, 4) = 23;
131 AAA(4, 2) = 14; AAA(4, 3) = 19; AAA(4, 4) = 24;
137 numberFailedTests +=
PrintTestResults(
"normFrobenius of a 5x5", AAA.normFrobenius(), 4.0, verbose);
146 testName =
"random() -- enter random entries into matrix";
147 returnCode = CCC.random();
148 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
150 testName =
"putScalar() -- set every entry of this matrix to 1.0";
152 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
156 if (verbose) std::cout <<
"assign() -- copy the values of an input matrix ";
158 if (verbose) std::cout<<
"successful" <<std::endl;
160 if (verbose) std::cout<<
"unsuccessful" <<std::endl;
167 if (verbose) std::cout <<
"operator= -- small(empty) = large(view) ";
168 if (CCCtest1.
numRows()==3 && CCCtest1.
values()==CCC.values()) {
169 if (verbose) std::cout<<
"successful" <<std::endl;
171 if (verbose) std::cout<<
"unsuccessful" <<std::endl;
175 if (verbose) std::cout <<
"operator= -- small(view) = large(copy) ";
176 if (CCCtest1.
numRows()==5 && CCCtest1.
values()!=CCC.values()) {
177 if (verbose) std::cout<<
"successful"<<std::endl;
179 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
185 if (verbose) std::cout <<
"operator= -- large(copy) = small(copy) ";
187 if (verbose) std::cout<<
"successful"<<std::endl;
189 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
193 if (verbose) std::cout <<
"operator= -- large(copy) = small(view) ";
195 if(verbose) std::cout<<
"successful" <<std::endl;
197 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
201 CCCtest1 += CCCtest3;
202 if (verbose) std::cout <<
"operator+= -- add two matrices of the same size, but different leading dimension ";
203 if (CCCtest1(1,1)==2.0) {
204 if(verbose) std::cout<<
"successful" <<std::endl;
206 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
209 if (verbose) std::cout <<
"operator+= -- add two matrices of different size (nothing should change) ";
211 if (CCCtest1(1,1)==2.0) {
212 if(verbose) std::cout<<
"successful" <<std::endl;
214 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
224 if (verbose) std::cout <<
"operator*= -- scale matrix by some number ";
226 if (ScalTest(5, 7) == 8.0) {
227 if (verbose) std::cout<<
"successful." <<std::endl;
229 if (verbose) std::cout<<
"unsuccessful." <<std::endl;
237 if(numberFailedTests > 0)
240 std::cout <<
"Number of failed tests: " << numberFailedTests << std::endl;
241 std::cout <<
"End Result: TEST FAILED" << std::endl;
245 if(numberFailedTests == 0)
246 std::cout <<
"End Result: TEST PASSED" << std::endl;
251 template<
typename TYPE>
252 int PrintTestResults(std::string testName, TYPE calculatedResult, TYPE expectedResult,
bool verbose)
255 if(calculatedResult == expectedResult)
257 if(verbose) std::cout << testName <<
" successful." << std::endl;
262 if(verbose) std::cout << testName <<
" unsuccessful." << std::endl;
268 int ReturnCodeCheck(std::string testName,
int returnCode,
int expectedResult,
bool verbose)
271 if(expectedResult == 0)
275 if(verbose) std::cout << testName <<
" test successful." << std::endl;
280 if(verbose) std::cout << testName <<
" test unsuccessful. Return code was " << returnCode <<
"." << std::endl;
288 if(verbose) std::cout << testName <<
" test successful -- failed as expected." << std::endl;
293 if(verbose) std::cout << testName <<
" test unsuccessful -- did not fail as expected. Return code was " << returnCode <<
"." << std::endl;
bool empty() const
Returns whether this matrix is empty.
OrdinalType numRows() const
Returns the row dimension of this matrix.
int PrintTestResults(std::string, TYPE, TYPE, bool)
Non-member helper functions on the templated serial, dense matrix/vector classes. ...
Templated serial dense matrix class.
int shape(OrdinalType numRows, OrdinalType numCols, OrdinalType kl, OrdinalType ku)
Shape method for changing the size of a SerialBandDenseMatrix, initializing entries to zero...
ScalarTraits< ScalarType >::magnitudeType normInf() const
Returns the Infinity-norm of the matrix.
Teuchos::SerialDenseVector< int, std::complex< Real > > DVector
ScalarTraits< ScalarType >::magnitudeType normOne() const
Returns the 1-norm of the matrix.
SerialBandDenseMatrix< OrdinalType, ScalarType > & assign(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
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.
OrdinalType stride() const
Returns the stride between the columns of this matrix in memory.
ScalarType * values() const
Data array access method.
Templated serial dense matrix class.
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Returns the Frobenius-norm of the matrix.
This class creates and provides basic support for banded dense matrices of templated type...
Teuchos::SerialDenseMatrix< int, std::complex< Real > > DMatrix
std::string Teuchos_Version()
int ReturnCodeCheck(std::string, int, int, bool)
int main(int argc, char *argv[])
Teuchos::SerialBandDenseMatrix< OTYPE, STYPE > BDMatrix
Templated serial dense vector class.
OrdinalType numCols() const
Returns the column dimension of this matrix.
static T one()
Returns representation of one for this scalar type.
This class creates and provides basic support for dense rectangular matrix of templated type...