49#define STYPE std::complex<double>
51template<
typename TYPE>
60int 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 BANDED 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 a[4] = 5; a[8] = 11; a[12] = 17; a[16] = 23;
101 a[1] = 0; a[5] = 6; a[9] = 12; a[13] = 18; a[17] = 24;
102 a[2] = 1; a[6] = 7; a[10] = 13; a[14] = 19;
103 a[3] = 2; a[7] = 8; a[11] = 14;
106 C2T1ER.
shape(5, 5, 2, 1);
107 C2T1ER(0, 0) = 0; C2T1ER(0, 1) = 5;
108 C2T1ER(1, 0) = 1; C2T1ER(1, 1) = 6; C2T1ER(1, 2) = 11;
109 C2T1ER(2, 0) = 2; C2T1ER(2, 1) = 7; C2T1ER(2, 2) = 12; C2T1ER(2, 3) = 17;
110 C2T1ER(3, 1) = 8; C2T1ER(3, 2) = 13; C2T1ER(3, 3) = 18; C2T1ER(3, 4) = 23;
111 C2T1ER(4, 2) = 14; C2T1ER(4, 3) = 19; C2T1ER(4, 4) = 24;
115 numberFailedTests +=
PrintTestResults(
"constructor 2 -- construct matrix from array subrange", Con2Test1, C2T1ER, verbose);
120 if(verbose) std::cout <<
"constructor 3 -- copy constructor ";
121 if ( Con3TestCopy != C2T1ER ) {
122 if (verbose) std::cout <<
"unsuccessful."<<std::endl;
125 if (verbose) std::cout <<
"successful."<<std::endl;
129 if(verbose) std::cout <<
"constructor 3 -- copy constructor (transposed) ";
130 if ( Con3TestCopyTrans(0, 2) != C2T1ER(2, 0) ) {
131 if (verbose) std::cout <<
"unsuccessful."<<std::endl;
134 if (verbose) std::cout <<
"successful."<<std::endl;
141 C4TS.
shape( 3, 3, 2, 1 );
142 C4TS(0, 0) = 12; C4TS(0, 1) = 17;
143 C4TS(1, 0) = 13; C4TS(1, 1) = 18; C4TS(1, 2) = 23;
144 C4TS(2, 0) = 14; C4TS(2, 1) = 19; C4TS(2, 2) = 24;
147 numberFailedTests +=
PrintTestResults(
"constructor 4 -- submatrix copy", Con4TestCopy1, C4TS, verbose);
149 numberFailedTests +=
PrintTestResults(
"constructor 4 -- full matrix copy", Con4TestCopy2, Con4TestOrig, verbose);
151 numberFailedTests +=
PrintTestResults(
"constructor 4 -- full matrix view", Con4TestView1, Con4TestOrig, verbose);
153 numberFailedTests +=
PrintTestResults(
"constructor 4 -- submatrix view", Con4TestView2, C4TS, verbose);
158 AAA.
shape( 5, 5, 2, 1 );
159 AAA(0, 0) = 0; AAA(0, 1) = 5;
160 AAA(1, 0) = 1; AAA(1, 1) = 6; AAA(1, 2) = 11;
161 AAA(2, 0) = 2; AAA(2, 1) = 7; AAA(2, 2) = 12; AAA(2, 3) = 17;
162 AAA(3, 1) = 8; AAA(3, 2) = 13; AAA(3, 3) = 18; AAA(3, 4) = 23;
163 AAA(4, 2) = 14; AAA(4, 3) = 19; AAA(4, 4) = 24;
178 testName =
"random() -- enter random entries into matrix";
179 returnCode = CCC.
random();
180 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
182 testName =
"putScalar() -- set every entry of this matrix to 1.0";
184 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
188 if (verbose) std::cout <<
"assign() -- copy the values of an input matrix ";
190 if (verbose) std::cout<<
"successful" <<std::endl;
192 if (verbose) std::cout<<
"unsuccessful" <<std::endl;
199 if (verbose) std::cout <<
"operator= -- small(empty) = large(view) ";
201 if (verbose) std::cout<<
"successful" <<std::endl;
203 if (verbose) std::cout<<
"unsuccessful" <<std::endl;
207 if (verbose) std::cout <<
"operator= -- small(view) = large(copy) ";
209 if (verbose) std::cout<<
"successful"<<std::endl;
211 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
217 if (verbose) std::cout <<
"operator= -- large(copy) = small(copy) ";
219 if (verbose) std::cout<<
"successful"<<std::endl;
221 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
225 if (verbose) std::cout <<
"operator= -- large(copy) = small(view) ";
227 if(verbose) std::cout<<
"successful" <<std::endl;
229 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
233 CCCtest1 += CCCtest3;
234 if (verbose) std::cout <<
"operator+= -- add two matrices of the same size, but different leading dimension ";
235 if (CCCtest1(1,1)==2.0) {
236 if(verbose) std::cout<<
"successful" <<std::endl;
238 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
241 if (verbose) std::cout <<
"operator+= -- add two matrices of different size (nothing should change) ";
243 if (CCCtest1(1,1)==2.0) {
244 if(verbose) std::cout<<
"successful" <<std::endl;
246 if (verbose) std::cout<<
"unsuccessful"<<std::endl;
256 if (verbose) std::cout <<
"operator*= -- scale matrix by some number ";
258 if (ScalTest(5, 7) == 8.0) {
259 if (verbose) std::cout<<
"successful." <<std::endl;
261 if (verbose) std::cout<<
"unsuccessful." <<std::endl;
269 if(numberFailedTests > 0)
272 std::cout <<
"Number of failed tests: " << numberFailedTests << std::endl;
273 std::cout <<
"End Result: TEST FAILED" << std::endl;
277 if(numberFailedTests == 0)
278 std::cout <<
"End Result: TEST PASSED" << std::endl;
283template<
typename TYPE>
284int PrintTestResults(std::string testName, TYPE calculatedResult, TYPE expectedResult,
bool verbose)
287 if(calculatedResult == expectedResult)
289 if(verbose) std::cout << testName <<
" successful." << std::endl;
294 if(verbose) std::cout << testName <<
" unsuccessful." << std::endl;
300int ReturnCodeCheck(std::string testName,
int returnCode,
int expectedResult,
bool verbose)
303 if(expectedResult == 0)
307 if(verbose) std::cout << testName <<
" test successful." << std::endl;
312 if(verbose) std::cout << testName <<
" test unsuccessful. Return code was " << returnCode <<
"." << std::endl;
320 if(verbose) std::cout << testName <<
" test successful -- failed as expected." << std::endl;
325 if(verbose) std::cout << testName <<
" test unsuccessful -- did not fail as expected. Return code was " << returnCode <<
"." << std::endl;
Templated serial dense matrix class.
Non-member helper functions on the templated serial, dense matrix/vector classes.
Templated serial dense matrix class.
Templated serial dense vector class.
This class creates and provides basic support for banded dense matrices of templated type.
int random()
Set all values in the matrix to be random numbers.
OrdinalType numCols() const
Returns the column dimension of this matrix.
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Returns the Frobenius-norm of the matrix.
bool empty() const
Returns whether this matrix is empty.
ScalarType * values() const
Data array access method.
OrdinalType numRows() const
Returns the row dimension of this matrix.
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Set all values in the matrix to a constant value.
OrdinalType stride() const
Returns the stride between the columns of this matrix in memory.
SerialBandDenseMatrix< OrdinalType, ScalarType > & assign(const SerialBandDenseMatrix< OrdinalType, ScalarType > &Source)
Copies values from one matrix to another.
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.
ScalarTraits< ScalarType >::magnitudeType normOne() const
Returns the 1-norm of the matrix.
This class creates and provides basic support for dense rectangular matrix of templated type.
This class creates and provides basic support for dense vectors of templated type as a specialization...
Teuchos::SerialBandDenseMatrix< OTYPE, STYPE > BDMatrix
Teuchos::SerialDenseVector< OTYPE, STYPE > DVector
int PrintTestResults(std::string, TYPE, TYPE, bool)
Teuchos::SerialDenseMatrix< OTYPE, STYPE > DMatrix
int ReturnCodeCheck(std::string, int, int, bool)
std::string Teuchos_Version()
This structure defines some basic traits for a scalar field type.
static T one()
Returns representation of one for this scalar type.