Skip to content

Commit

Permalink
Add pnl_mat_print_csv
Browse files Browse the repository at this point in the history
  • Loading branch information
jlelong committed Jan 17, 2023
1 parent f7052d1 commit 669d4f2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/include/pnl/pnl_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ extern void pnl_mat_tr(PnlMat*, const PnlMat *M);
extern double pnl_mat_trace (const PnlMat *M);
extern void pnl_mat_print(const PnlMat *M);
extern void pnl_mat_fprint(FILE *fic, const PnlMat *M);
extern void pnl_mat_print_csv(const PnlMat *M, char sep);
extern void pnl_mat_fprint_csv(FILE *fic, const PnlMat *M, char sep);
extern void pnl_mat_fprint_nsp (FILE *fic, const PnlMat *M);
extern void pnl_mat_print_nsp (const PnlMat *M);
extern PnlVect pnl_vect_wrap_mat_row(const PnlMat *M, int i);
Expand Down Expand Up @@ -320,8 +322,9 @@ extern void pnl_mat_int_tr(PnlMatInt *tM, const PnlMatInt *M);
extern void pnl_mat_int_sq_transpose(PnlMatInt *M);
extern int pnl_mat_int_trace (const PnlMatInt *M);
extern void pnl_mat_int_print(const PnlMatInt *M);
extern void pnl_mat_int_print_csv(const PnlMatInt *M, char sep);
extern void pnl_mat_int_print_nsp(const PnlMatInt *M);
extern void pnl_mat_int_fprint(FILE *fic,const PnlMatInt *M);
extern void pnl_mat_int_fprint_csv(FILE *fic,const PnlMatInt *M, char sep);
extern void pnl_mat_int_fprint_nsp(FILE *fic,const PnlMatInt *M);
extern PnlMatInt* pnl_mat_int_create_diag_from_ptr(const int x[], int d);
extern PnlMatInt* pnl_mat_int_create_diag(const PnlVectInt *V);
Expand Down Expand Up @@ -485,8 +488,10 @@ extern void pnl_mat_complex_tr(PnlMatComplex*, const PnlMatComplex *M);
extern void pnl_mat_complex_sq_transpose(PnlMatComplex *M);
extern dcomplex pnl_mat_complex_trace (const PnlMatComplex *M);
extern void pnl_mat_complex_print(const PnlMatComplex *M);
extern void pnl_mat_complex_print_csv(const PnlMatComplex *M, char sep);
extern void pnl_mat_complex_print_nsp(const PnlMatComplex *M);
extern void pnl_mat_complex_fprint(FILE *fic,const PnlMatComplex *M);
extern void pnl_mat_complex_fprint_csv(FILE *fic,const PnlMatComplex *M, char sep);
extern void pnl_mat_complex_fprint_nsp(FILE *fic,const PnlMatComplex *M);
extern PnlMatComplex* pnl_mat_complex_create_diag_from_ptr(const dcomplex x[], int d);
extern PnlMatComplex* pnl_mat_complex_create_diag(const PnlVectComplex *V);
Expand Down
30 changes: 27 additions & 3 deletions src/linalg/matrix_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,25 +538,48 @@ BASE FUNCTION(pnl_mat, trace)(const TYPE(PnlMat) *M)
}

/**
* Print a matrix to a file
* Print a matrix to a csv file
*
* @param fic a file descriptor.
* @param M a TYPE(PnlMat) pointer.
* @param sep a single char used as separator
*/
void FUNCTION(pnl_mat, fprint)(FILE *fic, const TYPE(PnlMat) *M)
void FUNCTION(pnl_mat, fprint_csv)(FILE *fic, const TYPE(PnlMat) *M, char sep)
{
int i, j;
for (i = 0; i < M->m; i++)
{
for (j = 0; j < M->n; j++)
{
fprintf(fic, OUT_FORMAT, OUT_PUT_FORMAT(PNL_MGET(M, i, j)));
if (j != M->n - 1) fprintf(fic, " ");
if (j != M->n - 1) fprintf(fic, "%c", sep);
}
fprintf(fic, "\n");
}
}

/**
* Print a matrix to the standard output
*
* @param M a TYPE(PnlMat) pointer.
* @param sep a single char used as separator
*/
void FUNCTION(pnl_mat, print_csv)(const TYPE(PnlMat) *M, char sep)
{
FUNCTION(pnl_mat, fprint_csv)(stdout, M, sep);
}

/**
* Print a matrix to a file
*
* @param fic a file descriptor.
* @param M a TYPE(PnlMat) pointer.
*/
void FUNCTION(pnl_mat, fprint)(FILE *fic, const TYPE(PnlMat) *M)
{
FUNCTION(pnl_mat, fprint_csv)(stdout, M, ' ');
}

/**
* Print a matrix to the standard output
*
Expand All @@ -567,6 +590,7 @@ void FUNCTION(pnl_mat, print)(const TYPE(PnlMat) *M)
FUNCTION(pnl_mat, fprint)(stdout, M);
}


/**
* Print a TYPE(PnlMat) to a file in a format compatible with Nsp
*
Expand Down

0 comments on commit 669d4f2

Please sign in to comment.