24 #ifdef HAVE_TEUCHOS_COMPLEX
25 #define STYPE std::complex<double>
32 #ifdef HAVE_TEUCHOS_COMPLEX
33 #define SCALARMAX STYPE(10,0)
35 #define SCALARMAX STYPE(10)
38 template<
typename TYPE>
47 template<
typename TYPE>
59 std::complex<T>
GetRandom( std::complex<T>, std::complex<T> );
71 int main(
int argc,
char* argv[])
81 if (argc>1)
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose =
true;
86 int numberFailedTests = 0;
88 std::string testName =
"", testType =
"";
90 #ifdef HAVE_TEUCHOS_COMPLEX
96 if (verbose) std::cout<<std::endl<<
"********** CHECKING TEUCHOS SERIAL QR SOLVER - " << testType <<
"-VALUED **********"<<std::endl<<std::endl;
102 DVector xhat(n), b(m), xhatt(m);
106 testName =
"Generating right-hand side vector using A*x, where x is a random vector:";
107 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
109 #ifdef HAVE_TEUCHOS_COMPLEX
112 testName =
"Generating right-hand side vector using A^H*x, where x is a random vector:";
113 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
117 testName =
"Generating right-hand side vector using A^T*x, where x is a random vector:";
118 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
136 returnCode = solver1.
factor();
137 testName =
"Simple solve: factor() random A:";
138 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
139 returnCode = solver1.
formQ();
140 testName =
"Simple solve: formQ() random A:";
141 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
144 returnCode = solver1.
solve();
145 testName =
"Simple solve: solve() random A (NO_TRANS):";
147 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
148 testName =
"Simple solve: multiplyQ(TRANS) solveR (NO_TRANS) random A (NO_TRANS):";
151 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
152 for (
OTYPE i=0; i<
n; i++) {tmp(i) = bp(i);}
154 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
157 #ifdef HAVE_TEUCHOS_COMPLEX
158 testName =
"Simple solve: formQ() solve with explicit Q implicit R random A (NO_TRANS):";
161 for (
OTYPE i=0; i<
n; i++) {tmp(i) = bp(i);}
163 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
165 testName =
"Simple solve: formQ() solve with explicit Q explicit R random A (NO_TRANS):";
167 returnCode = solver1.
formR();
168 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
170 for (
OTYPE i=0; i<
n; i++) {tmp(i) = bp(i);}
172 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
175 testName =
"Simple solve: formQ() solve with explicit Q random A (NO_TRANS):";
178 for (
OTYPE i=0; i<
n; i++) {tmp(i) = bp(i);}
180 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
182 testName =
"Simple solve: formQ() solve with explicit Q explicit R random A (NO_TRANS):";
184 returnCode = solver1.
formR();
185 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
187 for (
OTYPE i=0; i<
n; i++) {tmp(i) = bp(i);}
189 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
193 #ifdef HAVE_TEUCHOS_COMPLEX
198 returnCode = solver1.
solve();
199 testName =
"Simple solve: solve() random A (CONJ_TRANS):";
202 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
203 testName =
"Simple solve: solveR (NO_TRANS) multiplyQ(TRANS) random A (CONJ_TRANS):";
206 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
207 for (
OTYPE i=0; i<
n; i++) {tmp2(i) = bp(i);}
209 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
213 testName =
"Simple solve: formQ() solve with explicit Q random A (CONJ_TRANS):";
217 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
228 returnCode = solver1.
solve();
229 testName =
"Simple solve: solve() random A (TRANS):";
232 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
234 testName =
"Simple solve: solveR multiplyQ(TRANS) (NO_TRANS) random A (TRANS):";
236 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
237 for (
OTYPE i=0; i<
n; i++) {tmp2(i) = bp(i);}
239 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
243 testName =
"Simple solve: formQ() solve with explicit Q random A (CONJ_TRANS):";
247 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
266 #ifdef HAVE_TEUCHOS_COMPLEX
283 MagnitudeType smlnum2 = smlnum/2;
304 returnCode = solver2.
factor();
305 testName =
"Solve with matrix equilibration: factor() random A:";
306 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
309 returnCode = solver2.
solve();
310 testName =
"Solve with matrix equilibration: solve() random A (NO_TRANS):";
312 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
314 #ifdef HAVE_TEUCHOS_COMPLEX
319 returnCode = solver2.
solve();
320 testName =
"Solve with matrix equilibration: solve() random A (CONJ_TRANS):";
323 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
330 returnCode = solver2.
solve();
331 testName =
"Solve with matrix equilibration: solve() random A (TRANS):";
334 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
342 returnCode = solver2.
solve();
343 testName =
"Solve with matrix equilibration: solve() without factor() random A (NO_TRANS):";
345 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
350 if(numberFailedTests > 0)
353 std::cout <<
"Number of failed tests: " << numberFailedTests << std::endl;
354 std::cout <<
"End Result: TEST FAILED" << std::endl;
358 if(numberFailedTests == 0)
359 std::cout <<
"End Result: TEST PASSED" << std::endl;
364 template<
typename TYPE>
365 int PrintTestResults(std::string testName, TYPE calculatedResult, TYPE expectedResult,
bool verbose)
368 if(calculatedResult == expectedResult)
370 if(verbose) std::cout << testName <<
" successful." << std::endl;
375 if(verbose) std::cout << testName <<
" unsuccessful." << std::endl;
381 int ReturnCodeCheck(std::string testName,
int returnCode,
int expectedResult,
bool verbose)
384 if(expectedResult == 0)
388 if(verbose) std::cout << testName <<
" test successful." << std::endl;
393 if(verbose) std::cout << testName <<
" test unsuccessful. Return code was " << returnCode <<
"." << std::endl;
401 if(verbose) std::cout << testName <<
" test successful -- failed as expected." << std::endl;
406 if(verbose) std::cout << testName <<
" test unsuccessful -- did not fail as expected. Return code was " << returnCode <<
"." << std::endl;
413 template<
typename TYPE>
420 std::complex<T>
GetRandom( std::complex<T> Low, std::complex<T> High)
422 T lowMag = Low.real();
423 T highMag = High.real();
426 return std::complex<T>( real, imag );
436 double GetRandom(
double Low,
double High)
446 for (
int i=0; i<m; i++)
447 for (
int j=0; j<
n; j++) {
458 for (
int i=0; i<
n; i++) {
479 MagnitudeType temp = norm_diff;
483 if (temp > Tolerance)
int PrintTestResults(std::string, TYPE, TYPE, bool)
Non-member helper functions on the templated serial, dense matrix/vector classes. ...
int setMatrix(const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &A)
Sets the pointers for coefficient matrix.
Templated serial dense matrix class.
int multiplyQ(ETransp transq, SerialDenseMatrix< OrdinalType, ScalarType > &C)
Left multiply the input matrix by the unitary matrix Q or its adjoint.
int solveR(ETransp transr, SerialDenseMatrix< OrdinalType, ScalarType > &C)
Solve input matrix on the left with the upper triangular matrix R or its adjoint. ...
int formQ()
Explicitly forms the unitary matrix Q.
Teuchos::SerialDenseVector< int, std::complex< Real > > DVector
int multiply(ETransp transa, ETransp transb, ScalarType alpha, const SerialDenseMatrix< OrdinalType, ScalarType > &A, const SerialDenseMatrix< OrdinalType, ScalarType > &B, ScalarType beta)
Multiply A * B and add them to this; this = beta * this + alpha*A*B.
Templated class for solving dense linear problems.
This class creates and provides basic support for dense vectors of templated type as a specialization...
int solve()
Computes the solution X to AX = B for the this matrix and the B provided to SetVectors()..
ScalarTraits< ScalarType >::magnitudeType normFrobenius() const
Returns the Frobenius-norm of the matrix.
This structure defines some basic traits for a scalar field type.
A class for solving dense linear problems.
void solveWithTransposeFlag(Teuchos::ETransp trans)
All subsequent function calls will work with the transpose-type set by this method (Teuchos::NO_TRANS...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
TYPE GetRandom(TYPE, TYPE)
int putScalar(const ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Set all values in the matrix to a constant value.
Teuchos::RCP< DMatrix > GetRandomMatrix(int m, int n)
The Templated LAPACK Wrapper Class.
bool CompareVectors(TYPE1 *Vector1, TYPE2 *Vector2, OType Size, TYPE2 Tolerance)
#define TEUCHOS_MAX(x, y)
Teuchos::SerialDenseMatrix< int, std::complex< Real > > DMatrix
std::string Teuchos_Version()
int ReturnCodeCheck(std::string, int, int, bool)
int main(int argc, char *argv[])
OrdinalType numCols() const
Returns the column dimension of this matrix.
void factorWithEquilibration(bool flag)
Causes equilibration to be called just before the matrix factorization as part of the call to factor...
Templated serial dense vector class.
Defines basic traits for the scalar field type.
Teuchos::RCP< DVector > GetRandomVector(int n)
Smart reference counting pointer class for automatic garbage collection.
int formR()
Explicitly forms the upper triangular matrix R.
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > getQ() const
Returns pointer to Q (assuming factorization has been performed).
int factor()
Computes the in-place QR factorization of the matrix using the LAPACK routine _GETRF or the Eigen cla...
Reference-counted pointer class and non-member templated function implementations.
int setVectors(const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &X, const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &B)
Sets the pointers for left and right hand side vector(s).
OrdinalType numRows() const
Returns the row dimension of this matrix.
This class creates and provides basic support for dense rectangular matrix of templated type...