diff --git a/src/lina.c b/src/lina.c index dfec26c..9514fca 100644 --- a/src/lina.c +++ b/src/lina.c @@ -565,4 +565,34 @@ double *lina_loadMatrixFromStream(FILE *fp, int *width, int *height, char **erro *height = j; return matrix; -} \ No newline at end of file +} + +/* Function: lina_saveMatrixToStream +** +** Save to the stream [fp] a matrix encoding it as an +** ASCII sequence in the form: +** +** [a b c .. , d e f .. , ..] +** +** For instance, the 4x4 identity matrix will +** be ancoded as: +** +** [1 0 0 0, 0 1 0 0, 0 0 1 0, 0 0 0 1] +** +** Since the matrix is in row-major order, the caller must +** specify the collumns and the rows of the matrix +** through [width] and [height] input arguments. +** +** If an error occurres, a negative integer is returned +** and a human-readable description of what happened +** is returned through the [error] pointer. +** +** Notes: +** - It can be called multiple times on a stream to write +** more than one matrix on it. +** +** - The [error] pointer is optional (it can be NULL). +** +** - If the stream [fp] is NULL, then [stdout] is used. +*/ +int lina_saveMatrixToStream(FILE *fp, int *width, int *height, char **error); diff --git a/src/lina.h b/src/lina.h index af7f745..a34cee6 100644 --- a/src/lina.h +++ b/src/lina.h @@ -3,4 +3,5 @@ void lina_dot(double *A, double *B, double *C, int m, int n, int l); void lina_add(double *A, double *B, double *C, int m, int n); void lina_scale(double *A, double *B, double k, int m, int n); void lina_transpose(double *A, double *B, int m, int n); -double *lina_loadMatrixFromStream(FILE *fp, int *width, int *height, char **error); \ No newline at end of file +double *lina_loadMatrixFromStream(FILE *fp, int *width, int *height, char **error); +int lina_saveMatrixToStream(FILE *fp, int *width, int *height, char **error); \ No newline at end of file