25 static int test(
bool verbose);
29 void add(
const R& a,
const T& b, T& result ){ result = a + b; }
32 void multiply(
const R& a,
const T& b, T& result ){ result = a * b; }
35 void divide(
const T& a,
const R& b, T& result ){ result = a / b; }
38 #ifdef HAVE_TEUCHOS_COMPLEX
45 static int test(
bool verbose);
49 void add(
const R& a,
const std::complex<T>& b, std::complex<T>& result )
50 { std::complex<T> tmp( a, 0 ); result = b + tmp; }
53 void multiply(
const R& a,
const std::complex<T>& b, std::complex<T>& result )
54 { std::complex<T> tmp( a, 0 ); result = tmp * b; }
57 void divide(
const std::complex<T>& a,
const R& b, std::complex<T>& result )
58 { std::complex<T> tmp( b, 0 ); result = a / tmp; }
64 int main(
int argc,
char* argv[])
66 int numberFailedTests = 0;
68 if (argc>1)
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose =
true;
75 #ifdef HAVE_TEUCHOS_INST_FLOAT
77 std::cout << std::endl <<
"LAPACK test for float" << std::endl;
78 numberFailedTests += lapackTest<float>(verbose);
81 std::cout << std::endl <<
"LAPACK test for double" << std::endl;
82 numberFailedTests += lapackTest<double>(verbose);
84 #ifdef HAVE_TEUCHOS_COMPLEX
85 #ifdef HAVE_TEUCHOS_INST_COMPLEX_FLOAT
87 std::cout << std::endl <<
"LAPACK test for std::complex<float>" << std::endl;
88 numberFailedTests += lapackTest<std::complex<float> >(verbose);
90 #ifdef HAVE_TEUCHOS_INST_COMPLEX_DOUBLE
92 std::cout << std::endl <<
"LAPACK test for std::complex<double>" << std::endl;
93 numberFailedTests += lapackTest<std::complex<double> >(verbose);
97 if(numberFailedTests > 0)
100 std::cout <<
"Number of failed tests: " << numberFailedTests << std::endl;
101 std::cout <<
"End Result: TEST FAILED" << std::endl;
105 if(numberFailedTests==0)
106 std::cout <<
"End Result: TEST PASSED" << std::endl;
112 template <
typename T>
115 int numberFailedTests = 0;
125 typedef typename STS::magnitudeType MagnitudeType;
129 MagnitudeType m_one = STM::one();
130 T zero = STS::zero();
135 const int n_gesv = 4;
136 std::vector<T> Ad(n_gesv*n_gesv,zero);
137 std::vector<T> bd(n_gesv,zero);
140 Ad[0] = 1; Ad[2] = 1; Ad[5] = 1; Ad[8] = 2; Ad[9] = 1; Ad[10] = 1; Ad[14] = 2; Ad[15] = 2;
141 bd[1] = 2; bd[2] = 1; bd[3] = 2;
143 if (verbose) std::cout <<
"LASCL test ... ";
144 L.
LASCL(char_G, 1, 1, m_one, m_one, n_gesv, n_gesv, &Ad[0], n_gesv, &info);
146 if (verbose) std::cout <<
"passed!" << std::endl;
148 if (verbose) std::cout <<
"FAILED" << std::endl;
152 if (verbose) std::cout <<
"GESV test ... ";
153 L.
GESV(n_gesv, 1, &Ad[0], n_gesv, IPIV, &bd[0], n_gesv, &info);
155 if (verbose) std::cout <<
"passed!" << std::endl;
157 if (verbose) std::cout <<
"FAILED" << std::endl;
161 #if ! (defined(__INTEL_COMPILER) && defined(_WIN32) )
166 if (verbose) std::cout <<
"ILAENV test ... ";
170 if (verbose) std::cout <<
"passed!" << std::endl;
172 if (verbose) std::cout <<
"FAILED!" << std::endl;
179 std::vector<T> Ad2_sub(n_gesv-1, zero), b2(n_gesv, one);
180 std::vector<MagnitudeType> Ad2(n_gesv, m_one);
182 if (verbose) std::cout <<
"PTTRF test ... ";
183 L.
PTTRF(n_gesv, &Ad2[0], &Ad2_sub[0], &info);
185 if (verbose) std::cout <<
"passed!" << std::endl;
187 if (verbose) std::cout <<
"FAILED" << std::endl;
192 std::vector<T> diag_a(n_potrf*n_potrf, zero);
193 for (
int i=0; i<n_potrf; i++)
196 sL.
add( i, one, tmp );
197 diag_a[i*n_potrf + i] = tmp*tmp;
200 if (verbose) std::cout <<
"POTRF test ... ";
201 L.
POTRF(char_U, n_potrf, &diag_a[0], n_potrf, &info);
205 if (verbose) std::cout <<
"FAILED" << std::endl;
210 for (
int i=0; i<n_potrf; i++)
213 sL.
add( i, one, tmp );
214 if ( diag_a[i*n_potrf + i] == tmp )
216 if (verbose && i==(n_potrf-1)) std::cout <<
"passed!" << std::endl;
220 if (verbose) std::cout <<
"FAILED" << std::endl;
227 if (verbose) std::cout <<
"POTRI test ... ";
228 std::vector<T> diag_a_trtri(diag_a);
230 L.
POTRI(char_U, n_potrf, &diag_a[0], n_potrf, &info);
234 if ( info != 0 || (diag_a[n_potrf+1] != tmp) )
236 if (verbose) std::cout <<
"FAILED" << std::endl;
240 if (verbose) std::cout <<
"passed!" << std::endl;
242 if (verbose) std::cout <<
"TRTRI test ... ";
244 int n_trtri = n_potrf;
245 L.
TRTRI( char_U, char_N, n_trtri, &diag_a_trtri[0], n_trtri, &info );
246 for (
int i=0; i<n_trtri; i++)
249 sL.
divide( one, i+1.0, tmp );
255 else if ( diag_a_trtri[i*n_trtri + i] == tmp )
257 if (verbose && i==(n_trtri-1)) std::cout <<
"passed!" << std::endl;
261 if (verbose) std::cout <<
"FAILED" << std::endl;
267 #ifndef TEUCHOSNUMERICS_DISABLE_STEQR_TEST
269 if (verbose) std::cout <<
"STEQR test ... ";
271 const int n_steqr = 10;
272 std::vector<MagnitudeType> diagonal(n_steqr);
273 std::vector<MagnitudeType> subdiagonal(n_steqr-1);
275 for (
int i=0; i < n_steqr; ++i) {
276 diagonal[i] = n_steqr - i;
278 subdiagonal[i] = STM::eps() * (i+1);
281 std::vector<T> scalar_dummy(1,0.0);
282 std::vector<MagnitudeType> mag_dummy(4*n_steqr,0.0);
284 L.
STEQR (char_N, n_steqr, &diagonal[0], &subdiagonal[0],
285 &scalar_dummy[0], n_steqr, &mag_dummy[0], &info);
289 if (verbose) std::cout <<
"STEQR: compute symmetric tridiagonal eigenvalues: "
290 <<
"LAPACK's _STEQR failed with info = "
296 MagnitudeType lambda_min = diagonal[0];
297 MagnitudeType lambda_max = diagonal[n_steqr-1];
298 MagnitudeType exp_lambda_min = STM::one();
299 MagnitudeType exp_lambda_max = STM::one()*n_steqr;
301 if ((fabs(lambda_min-exp_lambda_min)<1e-12) && (fabs(lambda_max-exp_lambda_max)<1e-12))
303 if (verbose) std::cout <<
"passed!" << std::endl;
307 if (verbose) std::cout <<
"FAILED" << std::endl;
311 #endif // TEUCHOSNUMERICS_DISABLE_STEQR_TEST
315 return numberFailedTests;
323 typedef typename STS::magnitudeType MagnitudeType;
327 MagnitudeType m_one = STM::one();
328 T zero = STS::zero();
334 int numberFailedTests = 0;
338 if (verbose) std::cout <<
"LAPY2 test ... ";
339 T x = 3*one, y = 4*one;
340 T lapy = L.
LAPY2(x, y);
341 if ( lapy == 5*one ) {
342 if (verbose) std::cout <<
"passed!" << std::endl;
344 if (verbose) std::cout <<
"FAILED ( " << lapy <<
" != 5 )" << std::endl;
348 if (verbose) std::cout <<
"LAMCH test ... ";
350 T st_eps = L.
LAMCH( char_E );
352 std::cout <<
"[ eps = " << st_eps <<
" ] passed!" << std::endl;
356 std::vector<T> Ad2_sub(n-1, zero), b2(n, one);
357 std::vector<MagnitudeType> Ad2(n, m_one);
359 if (verbose) std::cout <<
"PTTRS test ... ";
360 L.
PTTRS(n, 1, &Ad2[0], &Ad2_sub[0], &b2[0], n, &info);
362 if (verbose) std::cout <<
"passed!" << std::endl;
364 if (verbose) std::cout <<
"FAILED" << std::endl;
368 if (verbose) std::cout <<
"POCON test ... ";
370 std::vector<T> diag_a(n*n);
371 for (
int i=0; i<
n; i++)
373 diag_a[i*n + i] = one;
375 MagnitudeType rcond, anorm = m_one;
376 std::vector<T> work(3*n);
377 std::vector<int> iwork(n);
379 L.
POCON(char_U, n, &diag_a[0], n, anorm, &rcond, &work[0], &iwork[0], &info);
380 if (info != 0 || (rcond != m_one))
382 if (verbose) std::cout <<
"FAILED" << std::endl;
386 if (verbose) std::cout <<
"passed!" << std::endl;
389 return numberFailedTests;
392 #ifdef HAVE_TEUCHOS_COMPLEX
399 typedef typename STS::magnitudeType MagnitudeType;
402 std::complex<T> one = STS::one();
403 MagnitudeType m_one = STM::one();
404 std::complex<T> zero = STS::zero();
410 int numberFailedTests = 0;
416 std::vector<std::complex<T> > Ad2_sub(n-1, zero), b2(n, one);
417 std::vector<MagnitudeType> Ad2(n, m_one);
419 if (verbose) std::cout <<
"PTTRS test ... ";
420 L.
PTTRS(char_L, n, 1, &Ad2[0], &Ad2_sub[0], &b2[0], n, &info);
422 if (verbose) std::cout <<
"passed!" << std::endl;
424 if (verbose) std::cout <<
"FAILED" << std::endl;
428 if (verbose) std::cout <<
"POCON test ... ";
430 std::vector<std::complex<T> > diag_a(n*n);
431 for (
int i=0; i<
n; i++)
433 diag_a[i*n + i] = one;
435 MagnitudeType rcond, anorm = m_one;
436 std::vector<std::complex<T> > work(2*n);
437 std::vector<MagnitudeType> rwork(n);
438 std::vector<int> iwork(n);
440 L.
POCON(char_U, n, &diag_a[0], n, anorm, &rcond, &work[0], &rwork[0], &info);
441 if (info != 0 || (rcond != m_one))
443 if (verbose) std::cout <<
"FAILED" << std::endl;
447 if (verbose) std::cout <<
"passed!" << std::endl;
449 return numberFailedTests;
OrdinalType ILAENV(const OrdinalType &ispec, const std::string &NAME, const std::string &OPTS, const OrdinalType &N1=-1, const OrdinalType &N2=-1, const OrdinalType &N3=-1, const OrdinalType &N4=-1) const
Chooses problem-dependent parameters for the local environment.
Templated serial dense matrix class.
void POTRI(const char &UPLO, const OrdinalType &n, ScalarType *A, const OrdinalType &lda, OrdinalType *info) const
Computes the inverse of a real symmetric positive definite matrix A using the Cholesky factorization ...
void PTTRF(const OrdinalType &n, MagnitudeType *d, ScalarType *e, OrdinalType *info) const
Computes the L*D*L' factorization of a Hermitian/symmetric positive definite tridiagonal matrix A...
void STEQR(const char &COMPZ, const OrdinalType &n, MagnitudeType *D, MagnitudeType *E, ScalarType *Z, const OrdinalType &ldz, MagnitudeType *WORK, OrdinalType *info) const
Computes the eigenvalues and, optionally, eigenvectors of a symmetric tridiagonal n by n matrix A usi...
This structure defines some basic traits for a scalar field type.
static int test(bool verbose)
Templated interface class to LAPACK routines.
void POTRF(const char &UPLO, const OrdinalType &n, ScalarType *A, const OrdinalType &lda, OrdinalType *info) const
Computes Cholesky factorization of a real symmetric positive definite matrix A.
The Templated LAPACK Wrapper Class.
void LASCL(const char &TYPE, const OrdinalType &kl, const OrdinalType &ku, const MagnitudeType cfrom, const MagnitudeType cto, const OrdinalType &m, const OrdinalType &n, ScalarType *A, const OrdinalType &lda, OrdinalType *info) const
Multiplies the m by n matrix A by the real scalar cto/cfrom.
std::string Teuchos_Version()
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
ScalarType LAPY2(const ScalarType &x, const ScalarType &y) const
Computes x^2 + y^2 safely, to avoid overflow.
int main(int argc, char *argv[])
void GESV(const OrdinalType &n, const OrdinalType &nrhs, ScalarType *A, const OrdinalType &lda, OrdinalType *IPIV, ScalarType *B, const OrdinalType &ldb, OrdinalType *info) const
Computes the solution to a real system of linear equations A*X=B, where A is factored through GETRF a...
void add(const R &a, const T &b, T &result)
Templated serial dense vector class.
void POCON(const char &UPLO, const OrdinalType &n, const ScalarType *A, const OrdinalType &lda, const ScalarType &anorm, ScalarType *rcond, ScalarType *WORK, OrdinalType *IWORK, OrdinalType *info) const
Estimates the reciprocal of the condition number (1-norm) of a real symmetric positive definite matri...
void PTTRS(const OrdinalType &n, const OrdinalType &nrhs, const MagnitudeType *d, const ScalarType *e, ScalarType *B, const OrdinalType &ldb, OrdinalType *info) const
Solves a tridiagonal system A*X=B using the *D*L' factorization of A computed by PTTRF.
ScalarType LAMCH(const char &CMACH) const
Determines machine parameters for floating point characteristics.
void TRTRI(const char &UPLO, const char &DIAG, const OrdinalType &n, ScalarType *A, const OrdinalType &lda, OrdinalType *info) const
Computes the inverse of an upper or lower triangular matrix A.
void divide(const T &a, const R &b, T &result)
void multiply(const R &a, const T &b, T &result)
int lapackTest(bool verbose)