23 #ifdef HAVE_TEUCHOS_COMPLEX
24 #define STYPE std::complex<double>
31 #ifdef HAVE_TEUCHOS_COMPLEX
32 #define SCALARMAX STYPE(10,0)
34 #define SCALARMAX STYPE(10)
37 template<
typename TYPE>
46 template<
typename TYPE>
58 std::complex<T>
GetRandom( std::complex<T>, std::complex<T> );
71 int main(
int argc,
char* argv[])
80 if (argc>1)
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose =
true;
85 int numberFailedTests = 0;
87 std::string testName =
"", testType =
"";
89 #ifdef HAVE_TEUCHOS_COMPLEX
95 if (verbose) std::cout<<std::endl<<
"********** CHECKING TEUCHOS SERIAL DENSE SOLVER - " << testType <<
"-VALUED **********"<<std::endl<<std::endl;
104 testName =
"Generating right-hand side vector using A*x, where x is a random vector:";
105 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
108 testName =
"Generating right-hand side vector using A^T*x, where x is a random vector:";
109 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
111 #ifdef HAVE_TEUCHOS_COMPLEX
114 testName =
"Generating right-hand side vector using A^H*x, where x is a random vector:";
115 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
129 returnCode = solver1.
factor();
130 testName =
"Simple solve: factor() random A:";
131 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
134 returnCode = solver1.
solve();
135 testName =
"Simple solve: solve() random A (NO_TRANS):";
137 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
143 returnCode = solver1.
solve();
144 testName =
"Simple solve: solve() random A (TRANS):";
146 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
148 #ifdef HAVE_TEUCHOS_COMPLEX
153 returnCode = solver1.
solve();
154 testName =
"Simple solve: solve() random A (CONJ_TRANS):";
156 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
160 returnCode = solver1.
invert();
161 testName =
"Simple solve: invert() random A:";
162 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
166 testName =
"Computing solution using inverted random A (NO_TRANS):";
168 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
171 testName =
"Computing solution using inverted random A (TRANS):";
173 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
175 #ifdef HAVE_TEUCHOS_COMPLEX
177 testName =
"Computing solution using inverted random A (CONJ_TRANS):";
179 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
183 #ifdef HAVE_TEUCHOSNUMERICS_EIGEN
194 #ifdef HAVE_TEUCHOS_COMPLEX
207 returnCode = solver2.
factor();
208 testName =
"Solve with iterative refinement: factor() random A:";
209 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
212 returnCode = solver2.
solve();
213 testName =
"Solve with iterative refinement: solve() random A (NO_TRANS):";
215 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
221 returnCode = solver2.
solve();
222 testName =
"Solve with iterative refinement: solve() random A (TRANS):";
224 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
226 #ifdef HAVE_TEUCHOS_COMPLEX
231 returnCode = solver2.
solve();
232 testName =
"Solve with iterative refinement: solve() random A (CONJ_TRANS):";
234 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
248 #ifdef HAVE_TEUCHOS_COMPLEX
265 returnCode = solver3.
factor();
266 testName =
"Solve with matrix equilibration: factor() random A:";
267 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
270 returnCode = solver3.
solve();
271 testName =
"Solve with matrix equilibration: solve() random A (NO_TRANS):";
273 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
279 returnCode = solver3.
solve();
280 testName =
"Solve with matrix equilibration: solve() random A (TRANS):";
282 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
284 #ifdef HAVE_TEUCHOS_COMPLEX
289 returnCode = solver3.
solve();
290 testName =
"Solve with matrix equilibration: solve() random A (CONJ_TRANS):";
292 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
301 returnCode = solver3.
solve();
302 testName =
"Solve with matrix equilibration: solve() without factor() random A (NO_TRANS):";
304 numberFailedTests +=
ReturnCodeCheck(testName, returnCode, 0, verbose);
309 if(numberFailedTests > 0)
312 std::cout <<
"Number of failed tests: " << numberFailedTests << std::endl;
313 std::cout <<
"End Result: TEST FAILED" << std::endl;
317 if(numberFailedTests == 0)
318 std::cout <<
"End Result: TEST PASSED" << std::endl;
323 template<
typename TYPE>
324 int PrintTestResults(std::string testName, TYPE calculatedResult, TYPE expectedResult,
bool verbose)
327 if(calculatedResult == expectedResult)
329 if(verbose) std::cout << testName <<
" successful." << std::endl;
334 if(verbose) std::cout << testName <<
" unsuccessful." << std::endl;
340 int ReturnCodeCheck(std::string testName,
int returnCode,
int expectedResult,
bool verbose)
343 if(expectedResult == 0)
347 if(verbose) std::cout << testName <<
" test successful." << std::endl;
352 if(verbose) std::cout << testName <<
" test unsuccessful. Return code was " << returnCode <<
"." << std::endl;
360 if(verbose) std::cout << testName <<
" test successful -- failed as expected." << std::endl;
365 if(verbose) std::cout << testName <<
" test unsuccessful -- did not fail as expected. Return code was " << returnCode <<
"." << std::endl;
372 template<
typename TYPE>
379 std::complex<T>
GetRandom( std::complex<T> Low, std::complex<T> High)
381 T lowMag = Low.real();
382 T highMag = High.real();
385 return std::complex<T>( real, imag );
395 double GetRandom(
double Low,
double High)
405 for (
int i=0; i<m; i++)
406 for (
int j=0; j<
n; j++)
417 for (
int i=0; i<
n; i++)
438 MagnitudeType temp = norm_diff;
442 if (temp > Tolerance)
445 std::cout <<
"COMPARISON FAILED : ";
int PrintTestResults(std::string, TYPE, TYPE, bool)
Non-member helper functions on the templated serial, dense matrix/vector classes. ...
Templated serial dense matrix class.
Teuchos::SerialDenseVector< int, std::complex< Real > > DVector
int solve()
Computes the solution X to AX = B for the this matrix and the B provided to SetVectors()..
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.
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.
void solveToRefinedSolution(bool flag)
Causes all solves to compute solution to best ability using iterative refinement. ...
Templated class for solving dense linear problems.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
TYPE GetRandom(TYPE, TYPE)
void factorWithEquilibration(bool flag)
Causes equilibration to be called just before the matrix factorization as part of the call to factor...
void solveWithTransposeFlag(Teuchos::ETransp trans)
All subsequent function calls will work with the transpose-type set by this method (Teuchos::NO_TRANS...
int invert()
Inverts the this matrix.
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)
int main(int argc, char *argv[])
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).
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 factor()
Computes the in-place LU factorization of the matrix using the LAPACK routine _GETRF.
Reference-counted pointer class and non-member templated function implementations.
A class for solving dense linear problems.
int setMatrix(const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &A)
Sets the pointers for coefficient matrix.
This class creates and provides basic support for dense rectangular matrix of templated type...