Skip to content

Commit

Permalink
Use DATA_DIR for linear algebra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jlelong committed Nov 4, 2023
1 parent ab6262f commit 0e9dc9f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 70 deletions.
7 changes: 4 additions & 3 deletions examples/lapack_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "pnl/pnl_matrix.h"
#include "pnl/pnl_random.h"
#define DATA_DIR "Data"
#include "tests_utils.h"


Expand Down Expand Up @@ -135,8 +136,8 @@ static void pnl_mat_log_test ()
static void pnl_mat_complex_exp_test ()
{
PnlMatComplex *A, *expA, *sol;
A = pnl_mat_complex_create_from_file ("Data/Acomplex.txt");
sol = pnl_mat_complex_create_from_file ("Data/expAcomplex.txt");
A = pnl_mat_complex_create_from_file (DATA_FILE("Acomplex.txt"));
sol = pnl_mat_complex_create_from_file (DATA_FILE("expAcomplex.txt"));
expA = pnl_mat_complex_new ();
pnl_mat_complex_exp (expA, A);

Expand All @@ -149,7 +150,7 @@ static void pnl_mat_complex_exp_test ()
static void pnl_mat_complex_log_test ()
{
PnlMatComplex *A, *logA, *explogA;
A = pnl_mat_complex_create_from_file ("Data/expAcomplex.txt");
A = pnl_mat_complex_create_from_file (DATA_FILE("expAcomplex.txt"));
logA = pnl_mat_complex_new ();
explogA = pnl_mat_complex_new ();
pnl_mat_complex_log (logA, A);
Expand Down
113 changes: 57 additions & 56 deletions examples/matrix_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "pnl/pnl_matrix.h"
#include "pnl/pnl_random.h"
#define DATA_DIR "Data"
#include "tests_utils.h"

/* static double function_prod(double x, double y) {return x*y;} */
Expand Down Expand Up @@ -348,9 +349,9 @@ static void pnl_mat_plus_double_test()
static void pnl_mat_mult_mat_test()
{
PnlMat *A, *B, *AB, *res;
A = pnl_mat_create_from_file ("Data/A.txt");
B = pnl_mat_create_from_file ("Data/B.txt");
AB = pnl_mat_create_from_file ("Data/AB.txt");
A = pnl_mat_create_from_file (DATA_FILE("A.txt"));
B = pnl_mat_create_from_file (DATA_FILE("B.txt"));
AB = pnl_mat_create_from_file (DATA_FILE("AB.txt"));
res = pnl_mat_mult_mat (A, B);

pnl_test_mat_eq_abs(AB, res, 1E-12, "mat_mult_mat", "");
Expand All @@ -364,9 +365,9 @@ static void pnl_mat_mult_mat_test()
static void pnl_mat_kron_test()
{
PnlMat *A, *B, *AB, *res;
A = pnl_mat_create_from_file ("Data/A.txt");
B = pnl_mat_create_from_file ("Data/B.txt");
AB = pnl_mat_create_from_file ("Data/kron_A_B.txt");
A = pnl_mat_create_from_file (DATA_FILE("A.txt"));
B = pnl_mat_create_from_file (DATA_FILE("B.txt"));
AB = pnl_mat_create_from_file (DATA_FILE("kron_A_B.txt"));
res = pnl_mat_kron(A, B);

pnl_test_mat_eq_abs(AB, res, 1E-12, "mat_kron", "");
Expand All @@ -380,9 +381,9 @@ static void pnl_mat_kron_test()
static void pnl_mat_mult_mat_inplace_test()
{
PnlMat *A, *B, *AB, *res;
A = pnl_mat_create_from_file ("Data/A.txt");
B = pnl_mat_create_from_file ("Data/B.txt");
AB = pnl_mat_create_from_file ("Data/AB.txt");
A = pnl_mat_create_from_file (DATA_FILE("A.txt"));
B = pnl_mat_create_from_file (DATA_FILE("B.txt"));
AB = pnl_mat_create_from_file (DATA_FILE("AB.txt"));
res = pnl_mat_new ();
pnl_mat_mult_mat_inplace (res, A, B);

Expand All @@ -399,9 +400,9 @@ static void pnl_mat_mult_vect_test()
PnlMat *A;
PnlVect *Ax, *x, *y;

A = pnl_mat_create_from_file ("Data/A.txt");
Ax = pnl_vect_create_from_file ("Data/Ax.txt");
x = pnl_vect_create_from_file ("Data/x.txt");
A = pnl_mat_create_from_file (DATA_FILE("A.txt"));
Ax = pnl_vect_create_from_file (DATA_FILE("Ax.txt"));
x = pnl_vect_create_from_file (DATA_FILE("x.txt"));

y = pnl_vect_new ();
pnl_mat_mult_vect_inplace (y, A, x);
Expand Down Expand Up @@ -702,10 +703,10 @@ static void pnl_mat_sum_test()
pnl_test_eq_abs ( sum, pnl_mat_sum(M), 1E-12, "mat_sum", "");
pnl_mat_free(&M);

M_cumsum_c = pnl_mat_create_from_file("Data/cumsum_A_c.txt");
M_cumsum_r = pnl_mat_create_from_file("Data/cumsum_A_r.txt");
M_cumsum_c = pnl_mat_create_from_file(DATA_FILE("cumsum_A_c.txt"));
M_cumsum_r = pnl_mat_create_from_file(DATA_FILE("cumsum_A_r.txt"));

Mcopy = pnl_mat_create_from_file ("Data/A.txt");
Mcopy = pnl_mat_create_from_file (DATA_FILE("A.txt"));
M = pnl_mat_new ();

pnl_mat_clone (M, Mcopy);
Expand Down Expand Up @@ -736,10 +737,10 @@ static void pnl_mat_prod_test()
pnl_test_eq_abs ( prod, pnl_mat_prod(M), 1E-12, "mat_prod", "");
pnl_mat_free(&M);

M_cumprod_c = pnl_mat_create_from_file("Data/cumprod_A_c.txt");
M_cumprod_r = pnl_mat_create_from_file("Data/cumprod_A_r.txt");
M_cumprod_c = pnl_mat_create_from_file(DATA_FILE("cumprod_A_c.txt"));
M_cumprod_r = pnl_mat_create_from_file(DATA_FILE("cumprod_A_r.txt"));

Mcopy = pnl_mat_create_from_file ("Data/A.txt");
Mcopy = pnl_mat_create_from_file (DATA_FILE("A.txt"));
M = pnl_mat_new ();

pnl_mat_clone (M, Mcopy);
Expand All @@ -759,10 +760,10 @@ static void pnl_mat_sum_vect_test()
{
PnlMat *M;
PnlVect *V, *M_sum_r, *M_sum_c;
M_sum_c = pnl_vect_create_from_file("Data/sum_A_c.txt");
M_sum_r = pnl_vect_create_from_file("Data/sum_A_r.txt");
M_sum_c = pnl_vect_create_from_file(DATA_FILE("sum_A_c.txt"));
M_sum_r = pnl_vect_create_from_file(DATA_FILE("sum_A_r.txt"));

M = pnl_mat_create_from_file ("Data/A.txt");
M = pnl_mat_create_from_file (DATA_FILE("A.txt"));
V = pnl_vect_new ();

pnl_mat_sum_vect (V, M, 'r');
Expand All @@ -781,10 +782,10 @@ static void pnl_mat_prod_vect_test()
{
PnlMat *M;
PnlVect *V, *M_prod_r, *M_prod_c;
M_prod_c = pnl_vect_create_from_file("Data/prod_A_c.txt");
M_prod_r = pnl_vect_create_from_file("Data/prod_A_r.txt");
M_prod_c = pnl_vect_create_from_file(DATA_FILE("prod_A_c.txt"));
M_prod_r = pnl_vect_create_from_file(DATA_FILE("prod_A_r.txt"));

M = pnl_mat_create_from_file ("Data/A.txt");
M = pnl_mat_create_from_file (DATA_FILE("A.txt"));
V = pnl_vect_new ();

pnl_mat_prod_vect (V, M, 'r');
Expand All @@ -803,14 +804,14 @@ static void pnl_mat_minmax_test()
{
PnlMat *M;
PnlVect *V, *M_max_r, *M_max_c, *M_min_r, *M_min_c, *M_min_star, *M_max_star;
M_max_c = pnl_vect_create_from_file("Data/max_A_c.txt");
M_max_r = pnl_vect_create_from_file("Data/max_A_r.txt");
M_max_star = pnl_vect_create_from_file("Data/max_A_star.txt");
M_min_c = pnl_vect_create_from_file("Data/min_A_c.txt");
M_min_r = pnl_vect_create_from_file("Data/min_A_r.txt");
M_min_star = pnl_vect_create_from_file("Data/min_A_star.txt");

M = pnl_mat_create_from_file ("Data/A.txt");
M_max_c = pnl_vect_create_from_file(DATA_FILE("max_A_c.txt"));
M_max_r = pnl_vect_create_from_file(DATA_FILE("max_A_r.txt"));
M_max_star = pnl_vect_create_from_file(DATA_FILE("max_A_star.txt"));
M_min_c = pnl_vect_create_from_file(DATA_FILE("min_A_c.txt"));
M_min_r = pnl_vect_create_from_file(DATA_FILE("min_A_r.txt"));
M_min_star = pnl_vect_create_from_file(DATA_FILE("min_A_star.txt"));

M = pnl_mat_create_from_file (DATA_FILE("A.txt"));
V = pnl_vect_new ();

pnl_mat_max (V, M, 'r');
Expand Down Expand Up @@ -871,7 +872,7 @@ static void pnl_mat_qsort_test ()
PnlMat *M, *Mclone, *res;
PnlMatInt *t, *res_t;

Mclone = pnl_mat_create_from_file("Data/A.txt");
Mclone = pnl_mat_create_from_file(DATA_FILE("A.txt"));
t = pnl_mat_int_new();
M = pnl_mat_new ();

Expand All @@ -882,8 +883,8 @@ static void pnl_mat_qsort_test ()
*/
pnl_mat_clone (M, Mclone);
pnl_mat_qsort_index (M, t, 'r', 'i');
res = pnl_mat_create_from_file ("Data/sort_A_r_i.txt");
res_t = pnl_mat_int_create_from_file ("Data/sort_A_r_i_index.txt");
res = pnl_mat_create_from_file (DATA_FILE("sort_A_r_i.txt"));
res_t = pnl_mat_int_create_from_file (DATA_FILE("sort_A_r_i_index.txt"));
pnl_mat_int_plus_scalar( res_t, -1);
pnl_test_mat_eq_abs ( M, res, 1E-12, "mat_qsort r i", "");
pnl_test_mat_int_eq ( t, res_t, "mat_qsort r i (index)", "");
Expand All @@ -892,8 +893,8 @@ static void pnl_mat_qsort_test ()

pnl_mat_clone (M, Mclone);
pnl_mat_qsort_index (M, t, 'r', 'd');
res = pnl_mat_create_from_file ("Data/sort_A_r_d.txt");
res_t = pnl_mat_int_create_from_file ("Data/sort_A_r_d_index.txt");
res = pnl_mat_create_from_file (DATA_FILE("sort_A_r_d.txt"));
res_t = pnl_mat_int_create_from_file (DATA_FILE("sort_A_r_d_index.txt"));
pnl_mat_int_plus_scalar( res_t, -1);
pnl_test_mat_eq_abs ( M, res, 1E-12, "mat_qsort r d", "");
pnl_test_mat_int_eq ( t, res_t, "mat_qsort r d (index)", "");
Expand All @@ -902,8 +903,8 @@ static void pnl_mat_qsort_test ()

pnl_mat_clone (M, Mclone);
pnl_mat_qsort_index (M, t, 'c', 'i');
res = pnl_mat_create_from_file ("Data/sort_A_c_i.txt");
res_t = pnl_mat_int_create_from_file ("Data/sort_A_c_i_index.txt");
res = pnl_mat_create_from_file (DATA_FILE("sort_A_c_i.txt"));
res_t = pnl_mat_int_create_from_file (DATA_FILE("sort_A_c_i_index.txt"));
pnl_mat_int_plus_scalar( res_t, -1);
pnl_test_mat_eq_abs ( M, res, 1E-12, "mat_qsort c i", "");
pnl_test_mat_int_eq ( t, res_t, "mat_qsort c i (index)", "");
Expand All @@ -912,8 +913,8 @@ static void pnl_mat_qsort_test ()

pnl_mat_clone (M, Mclone);
pnl_mat_qsort_index (M, t, 'c', 'd');
res = pnl_mat_create_from_file ("Data/sort_A_c_d.txt");
res_t = pnl_mat_int_create_from_file ("Data/sort_A_c_d_index.txt");
res = pnl_mat_create_from_file (DATA_FILE("sort_A_c_d.txt"));
res_t = pnl_mat_int_create_from_file (DATA_FILE("sort_A_c_d_index.txt"));
pnl_mat_int_plus_scalar( res_t, -1);
pnl_test_mat_eq_abs ( M, res, 1E-12, "mat_qsort c d", "");
pnl_test_mat_int_eq ( t, res_t, "mat_qsort c d (index)", "");
Expand Down Expand Up @@ -1253,7 +1254,7 @@ static void pnl_mat_complex_complex_syslin_test ()
static void pnl_mat_create_from_file_test ()
{
PnlMat *M, *res;
M = pnl_mat_create_from_file ("Data/Test_read_mat.dat");
M = pnl_mat_create_from_file (DATA_FILE("Test_read_mat.dat"));
res = pnl_mat_create_from_list (4, 6, 1.,2.,3.,4.,5.,6., 7.,8.,9.,10.,11.,12., 13.,14.,15.,16.,17.,18., 19.,20.,21.,22.,23.,24.);
pnl_test_mat_eq_abs (M, res, 1E-18, "mat_create_from_file", "");
pnl_mat_free (&M);
Expand All @@ -1268,12 +1269,12 @@ static void pnl_mat_dgemm_test()

alpha = 1.3;
beta = 0.5;
expec = pnl_mat_create_from_file ("Data/alpha_AB_beta_C.txt");
A = pnl_mat_create_from_file ("Data/A.txt");
tA = pnl_mat_create_from_file ("Data/tA.txt");
B = pnl_mat_create_from_file ("Data/B.txt");
tB = pnl_mat_create_from_file ("Data/tB.txt");
Cclone = pnl_mat_create_from_file ("Data/C.txt");
expec = pnl_mat_create_from_file (DATA_FILE("alpha_AB_beta_C.txt"));
A = pnl_mat_create_from_file (DATA_FILE("A.txt"));
tA = pnl_mat_create_from_file (DATA_FILE("tA.txt"));
B = pnl_mat_create_from_file (DATA_FILE("B.txt"));
tB = pnl_mat_create_from_file (DATA_FILE("tB.txt"));
Cclone = pnl_mat_create_from_file (DATA_FILE("C.txt"));
C = pnl_mat_new ();


Expand Down Expand Up @@ -1313,11 +1314,11 @@ static void pnl_mat_dgemv_test ()
beta = 0.5;


expec = pnl_vect_create_from_file ("Data/alpha_Ax_beta_y.txt");
A = pnl_mat_create_from_file ("Data/A.txt");
tA = pnl_mat_create_from_file ("Data/tA.txt");
x = pnl_vect_create_from_file ("Data/x.txt");
yclone = pnl_vect_create_from_file ("Data/y.txt");
expec = pnl_vect_create_from_file (DATA_FILE("alpha_Ax_beta_y.txt"));
A = pnl_mat_create_from_file (DATA_FILE("A.txt"));
tA = pnl_mat_create_from_file (DATA_FILE("tA.txt"));
x = pnl_vect_create_from_file (DATA_FILE("x.txt"));
yclone = pnl_vect_create_from_file (DATA_FILE("y.txt"));
y = pnl_vect_new ();

pnl_vect_clone (y, yclone);
Expand All @@ -1341,9 +1342,9 @@ static void pnl_mat_mult_vect_transpose_test ()
PnlMat *tA;
PnlVect *x, *y1, *Ax;

tA = pnl_mat_create_from_file ("Data/tA.txt");
Ax = pnl_vect_create_from_file ("Data/Ax.txt");
x = pnl_vect_create_from_file ("Data/x.txt");
tA = pnl_mat_create_from_file (DATA_FILE("tA.txt"));
Ax = pnl_vect_create_from_file (DATA_FILE("Ax.txt"));
x = pnl_vect_create_from_file (DATA_FILE("x.txt"));
y1 = pnl_vect_new ();
pnl_mat_mult_vect_transpose_inplace (y1, tA, x);
pnl_test_vect_eq_abs (y1, Ax, 1E-12, "mat_mult_vect_transpose_inplace", "");
Expand Down
13 changes: 7 additions & 6 deletions examples/solver_iterativ_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <math.h>
#include "pnl/pnl_matrix.h"
#include "pnl/pnl_linalgsolver.h"
#define DATA_DIR "Data"
#include "tests_utils.h"


Expand All @@ -40,8 +41,8 @@ void Test_Solver_sym(void )
x1=pnl_vect_create_from_scalar(Size,2);
x2=pnl_vect_create_from_scalar(Size,2);
x3=pnl_vect_create_from_scalar(Size,2);
M=pnl_mat_create_from_file("Data/Test_mat_sym");
PC=pnl_mat_create_from_file("Data/Test_PCmat");
M=pnl_mat_create_from_file(DATA_FILE("Test_mat_sym"));
PC=pnl_mat_create_from_file(DATA_FILE("Test_PCmat"));

Solver=pnl_cg_solver_create(b->size,20,1e-6);
Solver2=pnl_bicg_solver_create(b->size,20,1e-6);
Expand Down Expand Up @@ -71,12 +72,12 @@ void Test_Solver_no_sym(void )
PnlBicgSolver* Solver2;
PnlGmresSolver* Solver3;
Size=20;
b = pnl_vect_create_from_file ("Data/Test_vect_rhs.dat");
res = pnl_vect_create_from_file ("Data/Test_res.dat");
b = pnl_vect_create_from_file (DATA_FILE("Test_vect_rhs.dat"));
res = pnl_vect_create_from_file (DATA_FILE("Test_res.dat"));
x1=pnl_vect_create_from_scalar(Size,0.0);
x2=pnl_vect_create_from_scalar(Size,0.0);
Q=pnl_mat_create_from_file("Data/Test_mat_no_sym.dat");
PC=pnl_mat_create_from_file("Data/Test_PCmat_20.dat");
Q=pnl_mat_create_from_file(DATA_FILE("Test_mat_no_sym.dat"));
PC=pnl_mat_create_from_file(DATA_FILE("Test_PCmat_20.dat"));

Solver2=pnl_bicg_solver_create(b->size,100,1e-6);
Solver3=pnl_gmres_solver_create(b->size,100,20,1e-6);
Expand Down
11 changes: 6 additions & 5 deletions examples/spmatrix_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "pnl/pnl_matrix.h"
#include "pnl/pnl_sp_matrix.h"
#include "pnl/pnl_random.h"
#define DATA_DIR "Data"
#include "tests_utils.h"

const double PRECISION=1E-6;
Expand Down Expand Up @@ -115,8 +116,8 @@ static void sp_clone_test ()

static void sp_create_from_file_test()
{
PnlSpMat *Msparse = pnl_sp_mat_create_from_file("Data/sparse_M.txt");
PnlMat *Mfull = pnl_mat_create_from_file("Data/full_M.txt");
PnlSpMat *Msparse = pnl_sp_mat_create_from_file(DATA_FILE("sparse_M.txt"));
PnlMat *Mfull = pnl_mat_create_from_file(DATA_FILE("full_M.txt"));
PnlSpMat *Msparse_from_full = pnl_sp_mat_create_from_mat(Mfull);
if (pnl_sp_mat_isequal(Msparse, Msparse_from_full, PRECISION))
pnl_test_set_ok ("sp_mat_create_from_file");
Expand Down Expand Up @@ -237,9 +238,9 @@ static void sp_mat_kron ()
PnlMat *A, *B, *AB, *res;
PnlSpMat *Asp, *Bsp, *ressp;
double abserr = 1E-12;
A = pnl_mat_create_from_file ("Data/A.txt");
B = pnl_mat_create_from_file ("Data/B.txt");
AB = pnl_mat_create_from_file ("Data/kron_A_B.txt");
A = pnl_mat_create_from_file (DATA_FILE("A.txt"));
B = pnl_mat_create_from_file (DATA_FILE("B.txt"));
AB = pnl_mat_create_from_file (DATA_FILE("kron_A_B.txt"));
Asp = pnl_sp_mat_create_from_mat (A);
Bsp = pnl_sp_mat_create_from_mat (B);
ressp = pnl_sp_mat_kron (Asp, Bsp);
Expand Down

0 comments on commit 0e9dc9f

Please sign in to comment.