17static int utest_nearly_equal(
double a,
double b,
double tol) {
18 return fabs(a - b) <=
tol;
21static void utest_check_identity_2x2(
22 double const a_col_major[4],
double const inv_col_major[4],
23 double tol,
char const * test_name) {
27 a_col_major[0] * inv_col_major[0] + a_col_major[2] * inv_col_major[1],
28 a_col_major[1] * inv_col_major[0] + a_col_major[3] * inv_col_major[1],
29 a_col_major[0] * inv_col_major[2] + a_col_major[2] * inv_col_major[3],
30 a_col_major[1] * inv_col_major[2] + a_col_major[3] * inv_col_major[3]
33 if (!utest_nearly_equal(c[0], 1.0,
tol) ||
34 !utest_nearly_equal(c[1], 0.0,
tol) ||
35 !utest_nearly_equal(c[2], 0.0,
tol) ||
36 !utest_nearly_equal(c[3], 1.0,
tol)) {
37 PUT_ERR_F(
"ERROR in %s: A*Ainv != I", test_name);
41static void utest_symmetrise_from_upper_2x2(
double a_col_major[4]) {
43 a_col_major[1] = a_col_major[2];
48 puts(
"----- yac_lapack_interface basic tests -----");
52 double a[4] = {4.0, 1.0, 2.0, 3.0};
53 double b[2] = {8.0, 7.0};
57 LAPACKE_dgesv(LAPACK_COL_MAJOR, 2, 1, a, 2, ipiv, b, 2);
61 if (!utest_nearly_equal(b[0], 1.0, 1e-12) ||
62 !utest_nearly_equal(b[1], 2.0, 1e-12))
64 "ERROR in LAPACKE_dgesv: wrong solution [%1.16e, %1.16e]", b[0], b[1]);
68 double a_ref[4] = {4.0, 1.0, 2.0, 3.0};
69 double a_inv[4] = {4.0, 1.0, 2.0, 3.0};
73 lapack_int
info = LAPACKE_dgetrf(LAPACK_COL_MAJOR, 2, 2, a_inv, 2, ipiv);
78 info = LAPACKE_dgetri_work(
79 LAPACK_COL_MAJOR, 2, a_inv, 2, ipiv, work, 16);
81 PUT_ERR_F(
"ERROR in LAPACKE_dgetri_work: info=%d", (
int)
info);
84 if (
info == 0) utest_check_identity_2x2(a_ref, a_inv, 1e-12,
"dgetrf+dgetri");
87#ifndef YAC_LAPACK_NO_DSYTR
90 double a_ref[4] = {4.0, 1.0, 1.0, 3.0};
91 double a_inv[4] = {4.0, 1.0, 1.0, 3.0};
96 LAPACKE_dsytrf_work(LAPACK_COL_MAJOR,
'U', 2, a_inv, 2, ipiv, work, 16);
99 PUT_ERR_F(
"ERROR in LAPACKE_dsytrf_work: info=%d", (
int)
info);
102 info = LAPACKE_dsytri_work(
103 LAPACK_COL_MAJOR,
'U', 2, a_inv, 2, ipiv, work);
105 PUT_ERR_F(
"ERROR in LAPACKE_dsytri_work: info=%d", (
int)
info);
109 utest_symmetrise_from_upper_2x2(a_inv);
110 utest_check_identity_2x2(a_ref, a_inv, 1e-12,
"dsytrf+dsytri");
#define PUT_ERR_F(fmt,...)