--- ray/src/util/rmatrix.h 2014/05/31 05:02:37 2.1 +++ ray/src/util/rmatrix.h 2014/08/01 23:37:24 2.3 @@ -1,4 +1,4 @@ -/* RCSid $Id: rmatrix.h,v 2.1 2014/05/31 05:02:37 greg Exp $ */ +/* RCSid $Id: rmatrix.h,v 2.3 2014/08/01 23:37:24 greg Exp $ */ /* * Header file for general matrix routines. */ @@ -15,13 +15,12 @@ extern "C" { /* General plane-ordered component matrix */ typedef struct { int nrows, ncols, ncomp; + char *info; double mtx[1]; /* extends struct */ } RMATRIX; -#define rmx_indx(rm,r,c,i) (((i)*(rm)->nrows+(r))*(rm)->ncols+(c)) +#define rmx_lval(rm,r,c,i) (rm)->mtx[((i)*(rm)->nrows+(r))*(rm)->ncols+(c)] -#define rmx_lval(rm,r,c,i) (rm)->mtx[rmx_indx(rm,r,c,i)] - #define rmx_free(rm) free(rm) /* Allocate a nr x nc matrix with n components */ @@ -30,6 +29,9 @@ extern RMATRIX *rmx_alloc(int nr, int nc, int n); /* Load matrix from supported file type */ extern RMATRIX *rmx_load(const char *fname); +/* Append header information associated with matrix data */ +extern int rmx_addinfo(RMATRIX *rm, const char *info); + /* Write matrix to file type indicated by dt */ extern long rmx_write(const RMATRIX *rm, int dtype, FILE *fp); @@ -39,8 +41,8 @@ extern RMATRIX *rmx_identity(int dim, int n); /* Duplicate the given matrix */ extern RMATRIX *rmx_copy(const RMATRIX *rm); -/* Swap rows and columns in the given matrix in situ */ -extern int rmx_transpose(RMATRIX *rm); +/* Allocate and assign transposed matrix */ +extern RMATRIX *rmx_transpose(const RMATRIX *rm); /* Multiply (concatenate) two matrices and allocate the result */ extern RMATRIX *rmx_multiply(const RMATRIX *m1, const RMATRIX *m2);