47 int main(
int argc,
char* argv[])
49 int numberFailedTests = 0;
51 if (argc>1)
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose =
true;
65 typedef STS::magnitudeType MagnitudeType;
72 std::vector<double> Ad(n_gesv*n_gesv,0.0);
73 std::vector<double> bd(n_gesv,0.0);
74 std::vector<float> Af(n_gesv*n_gesv,0.0);
75 std::vector<float> bf(n_gesv,0.0);
78 Ad[0] = 1; Ad[2] = 1; Ad[5] = 1; Ad[8] = 2; Ad[9] = 1; Ad[10] = 1; Ad[14] = 2; Ad[15] = 2;
79 bd[1] = 2; bd[2] = 1; bd[3] = 2;
80 Af[0] = 1; Af[2] = 1; Af[5] = 1; Af[8] = 2; Af[9] = 1; Af[10] = 1; Af[14] = 2; Af[15] = 2;
81 bf[1] = 2; bf[2] = 1; bf[3] = 2;
83 if (verbose) std::cout <<
"GESV test ... ";
84 L.
GESV(n_gesv, 1, &Ad[0], n_gesv, IPIV, &bd[0], n_gesv, &info);
85 M.
GESV(n_gesv, 1, &Af[0], n_gesv, IPIV, &bf[0], n_gesv, &info);
86 for(
int i = 0; i < 4; i++)
89 if (verbose && i==3) std::cout <<
"passed!" << std::endl;
91 if (verbose) std::cout <<
"FAILED" << std::endl;
97 if (verbose) std::cout <<
"LAPY2 test ... ";
99 float flapy = M.
LAPY2(fx, fy);
100 double dx = 3, dy = 4;
101 double dlapy = L.
LAPY2(dx, dy);
102 if ( dlapy == flapy && dlapy == 5.0 && flapy == 5.0
f ) {
103 if (verbose) std::cout <<
"passed!" << std::endl;
105 if (verbose) std::cout <<
"FAILED (" << dlapy <<
" != " << flapy <<
")" << std::endl;
109 if (verbose) std::cout <<
"LAMCH test ... ";
112 double d_eps = L.
LAMCH( char_E );
113 float f_eps = M.
LAMCH( char_E );
115 std::cout <<
"[ Double-precision eps = " << d_eps <<
", single-precision eps = " << f_eps <<
" ] passed!" << std::endl;
117 if (verbose) std::cout <<
"POTRF test ... ";
120 std::vector<double> diag_a(n_potrf*n_potrf, 0.0);
121 for (
int i=0; i<n_potrf; i++)
122 diag_a[i*n_potrf + i] = (i+1)*(i+1);
123 L.
POTRF(char_U, n_potrf, &diag_a[0], n_potrf, &info);
127 if (verbose) std::cout <<
"FAILED" << std::endl;
132 for (
int i=0; i<n_potrf; i++)
134 if ( diag_a[i*n_potrf + i] == (i+1) )
136 if (verbose && i==(n_potrf-1)) std::cout <<
"passed!" << std::endl;
140 if (verbose) std::cout <<
"FAILED" << std::endl;
147 if (verbose) std::cout <<
"POCON test ... ";
149 double anorm = (n_potrf*n_potrf), rcond;
150 std::vector<double> work(3*n_potrf);
151 std::vector<int> iwork(n_potrf);
153 L.
POCON(char_U, n_potrf, &diag_a[0], n_potrf, anorm, &rcond, &work[0], &iwork[0], &info);
154 if (info != 0 || (rcond != 1.0/anorm))
157 if (verbose) std::cout <<
"FAILED" << std::endl;
161 if (verbose) std::cout <<
"passed!" << std::endl;
164 if (verbose) std::cout <<
"POTRI test ... ";
165 std::vector<double> diag_a_trtri(diag_a);
167 L.
POTRI(char_U, n_potrf, &diag_a[0], n_potrf, &info);
169 if (info != 0 || (diag_a[n_potrf+1] != 1.0/4.0))
172 if (verbose) std::cout <<
"FAILED" << std::endl;
176 if (verbose) std::cout <<
"passed!" << std::endl;
179 if (verbose) std::cout <<
"TRTRI test ... ";
181 int n_trtri = n_potrf;
182 L.
TRTRI( char_U, char_N, n_trtri, &diag_a_trtri[0], n_trtri, &info );
183 for (
int i=0; i<n_trtri; i++)
185 if ( diag_a_trtri[i*n_trtri + i] == 1.0/(i+1) )
187 if (verbose && i==(n_trtri-1)) std::cout <<
"passed!" << std::endl;
191 if (verbose) std::cout <<
"FAILED" << std::endl;
198 #if ! (defined(__INTEL_COMPILER) && defined(_WIN32) )
203 if (verbose) std::cout <<
"ILAENV test ... ";
207 if (verbose) std::cout <<
"passed!" << std::endl;
209 if (verbose) std::cout <<
"FAILED!" << std::endl;
215 if (verbose) std::cout <<
"STEQR test ... ";
217 #ifndef TEUCHOSNUMERICS_DISABLE_STEQR_TEST
219 const int n_steqr = 10;
220 std::vector<MagnitudeType> diagonal(n_steqr);
221 std::vector<MagnitudeType> subdiagonal(n_steqr-1);
223 for (
int i=0; i < n_steqr; ++i) {
224 diagonal[i] = n_steqr - i;
226 subdiagonal[i] = STM::eps() * (i+1);
229 std::vector<double> scalar_dummy(1,0.0);
230 std::vector<MagnitudeType> mag_dummy(4*n_steqr,0.0);
232 L.
STEQR (char_N, n_steqr, &diagonal[0], &subdiagonal[0],
233 &scalar_dummy[0], n_steqr, &mag_dummy[0], &info);
237 if (verbose) std::cout <<
"STEQR: compute symmetric tridiagonal eigenvalues: "
238 <<
"LAPACK's _STEQR failed with info = "
244 MagnitudeType lambda_min = diagonal[0];
245 MagnitudeType lambda_max = diagonal[n_steqr-1];
246 MagnitudeType exp_lambda_min = STM::one();
247 MagnitudeType exp_lambda_max = STM::one()*n_steqr;
249 if ((fabs(lambda_min-exp_lambda_min)<1e-12) && (fabs(lambda_max-exp_lambda_max)<1e-12))
251 if (verbose) std::cout <<
"passed!" << std::endl;
255 if (verbose) std::cout <<
"FAILED" << std::endl;
259 #else // TEUCHOSNUMERICS_DISABLE_STEQR_TEST
261 if (verbose) std::cout <<
"SKIPPED!\n";
263 #endif // TEUCHOSNUMERICS_DISABLE_STEQR_TEST
265 if(numberFailedTests > 0)
268 std::cout <<
"Number of failed tests: " << numberFailedTests << std::endl;
269 std::cout <<
"End Result: TEST FAILED" << std::endl;
273 if(numberFailedTests==0)
274 std::cout <<
"End Result: TEST PASSED" << std::endl;
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.
void TRTRI(const char &UPLO, const char &DIAG, const OrdinalType &n, const ScalarType *A, const OrdinalType &lda, OrdinalType *info) const
Computes the inverse of an upper or lower triangular matrix A.
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 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.
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.
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 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...
ScalarType LAMCH(const char &CMACH) const
Determines machine parameters for floating point characteristics.