26 #ifdef HAVE_TEUCHOS_COMPLEX
27 #define STYPE std::complex<double>
34 #ifdef HAVE_TEUCHOS_COMPLEX
35 #define SCALARMAX STYPE(10,0)
37 #define SCALARMAX STYPE(10)
40 template<
typename TYPE>
50 template<
typename TYPE>
62 std::complex<T>
GetRandom( std::complex<T>, std::complex<T> );
75 int main(
int argc,
char* argv[])
83 if (argc>1)
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose =
true;
88 int numberFailedTests = 0, failedComparison = 0;
90 std::string testName =
"", testType =
"";
92 #ifdef HAVE_TEUCHOS_COMPLEX
98 if (verbose) std::cout<<std::endl<<
"********** CHECKING TEUCHOS SERIAL SPD DENSE SOLVER - " << testType <<
"-VALUED **********"<<std::endl<<std::endl;
106 for (
int j=0; j<
n; ++j) {
107 for (
int i=0; i<=j; ++i) {
108 (*A1full)(i,j) = (*A1)(i,j);
111 for (
int j=0; j<
n; ++j) {
112 for (
int i=j+1; i<
n; ++i) {
119 testName =
"Generating right-hand side vector using A*x, where x is a random vector:";
120 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
133 returnCode = solver1.
factor();
134 testName =
"Simple solve: factor() random A:";
135 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
138 returnCode = solver1.
solve();
139 testName =
"Simple solve: solve() random A (NO_TRANS):";
141 if(verbose && failedComparison>0) std::cout <<
"COMPARISON FAILED : ";
142 numberFailedTests += failedComparison;
143 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
146 #ifdef HAVE_TEUCHOSNUMERICS_EIGEN
154 for (
int j=0; j<
n; ++j) {
155 for (
int i=0; i<=j; ++i) {
156 (*A2full)(i,j) = (*A2)(i,j);
159 for (
int j=0; j<
n; ++j) {
160 for (
int i=j+1; i<
n; ++i) {
178 returnCode = solver2.
factor();
179 testName =
"Solve with iterative refinement: factor() random A:";
180 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
183 returnCode = solver2.
solve();
184 testName =
"Solve with iterative refinement: solve() random A (NO_TRANS):";
186 if(verbose && failedComparison>0) std::cout <<
"COMPARISON FAILED : ";
187 numberFailedTests += failedComparison;
188 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
199 for (
int j=0; j<
n; ++j) {
200 for (
int i=0; i<=j; ++i) {
201 (*A3full)(i,j) = (*A3)(i,j);
204 for (
int j=0; j<
n; ++j) {
205 for (
int i=j+1; i<
n; ++i) {
226 returnCode = solver3.
factor();
227 testName =
"Solve with matrix equilibration: factor() random A:";
228 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
231 returnCode = solver3.
solve();
232 testName =
"Solve with matrix equilibration: solve() random A (NO_TRANS):";
234 if(verbose && failedComparison>0) std::cout <<
"COMPARISON FAILED : ";
235 numberFailedTests += failedComparison;
236 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
241 returnCode = solver3.
solve();
242 testName =
"Solve with matrix equilibration: solve() without factor() random A (NO_TRANS):";
244 if(verbose && failedComparison>0) std::cout <<
"COMPARISON FAILED : ";
245 numberFailedTests += failedComparison;
246 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
251 if(numberFailedTests > 0)
254 std::cout <<
"Number of failed tests: " << numberFailedTests << std::endl;
255 std::cout <<
"End Result: TEST FAILED" << std::endl;
259 if(numberFailedTests == 0)
260 std::cout <<
"End Result: TEST PASSED" << std::endl;
266 template<
typename TYPE>
267 int PrintTestResults(std::string testName, TYPE calculatedResult, TYPE expectedResult,
bool verbose)
270 if(calculatedResult == expectedResult)
272 if(verbose) std::cout << testName <<
" successful." << std::endl;
277 if(verbose) std::cout << testName <<
" unsuccessful." << std::endl;
283 int ReturnCodeCheck(std::string testName,
int returnCode,
int expectedResult,
bool verbose)
286 if(expectedResult == 0)
290 if(verbose) std::cout << testName <<
" test successful." << std::endl;
295 if(verbose) std::cout << testName <<
" test unsuccessful. Return code was " << returnCode <<
"." << std::endl;
303 if(verbose) std::cout << testName <<
" test successful -- failed as expected." << std::endl;
308 if(verbose) std::cout << testName <<
" test unsuccessful -- did not fail as expected. Return code was " << returnCode <<
"." << std::endl;
315 template<
typename TYPE>
322 std::complex<T>
GetRandom( std::complex<T> Low, std::complex<T> High)
324 T lowMag = Low.real();
325 T highMag = High.real();
328 return std::complex<T>( real, imag );
338 double GetRandom(
double Low,
double High)
362 for (
int i=0; i<
n; ++i) {
372 for (
int j=0; j<
n; ++j) {
373 for (
int i=0; i<=j; ++i) {
374 (*mat)(i,j) = (*tmp2)(i,j);
386 for (
int i=0; i<m; i++)
387 for (
int j=0; j<
n; j++)
398 for (
int i=0; i<
n; i++)
418 MagnitudeType temp = norm_diff;
422 if (temp > Tolerance)
void solveToRefinedSolution(bool flag)
Causes all solves to compute solution to best ability using iterative refinement. ...
SerialSymDenseMatrix< OTYPE, STYPE > SDMatrix
Teuchos::RCP< SDMatrix > GetRandomSpdMatrix(int n)
A class for constructing and using Hermitian positive definite dense matrices.
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 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.
int factor()
Computes the in-place Cholesky factorization of the matrix using the LAPACK routine DPOTRF...
This class creates and provides basic support for symmetric, positive-definite dense matrices of temp...
Templated class for solving dense linear problems.
This class creates and provides basic support for dense vectors of templated type as a specialization...
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 setUpper()
Specify that the upper triangle of the this matrix should be used.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
int setMatrix(const RCP< SerialSymDenseMatrix< OrdinalType, ScalarType > > &A_in)
Sets the pointers for coefficient matrix.
TYPE GetRandom(TYPE, TYPE)
int solve()
Computes the solution X to AX = B for the this matrix and the B provided to SetVectors()..
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).
Teuchos::RCP< DMatrix > GetRandomMatrix(int m, int n)
bool CompareVectors(TYPE1 *Vector1, TYPE2 *Vector2, OType Size, TYPE2 Tolerance)
Teuchos::SerialDenseMatrix< int, std::complex< Real > > DMatrix
std::string Teuchos_Version()
int ReturnCodeCheck(std::string, int, int, bool)
Templated serial, dense, symmetric matrix class.
int main(int argc, char *argv[])
Templated class for constructing and using Hermitian positive definite dense matrices.
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.
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.
This class creates and provides basic support for dense rectangular matrix of templated type...