1 |
greg |
2.4 |
/* RCSid $Id: rmatrix.h,v 2.3 2014/08/01 23:37:24 greg Exp $ */ |
2 |
greg |
2.1 |
/* |
3 |
|
|
* Header file for general matrix routines. |
4 |
|
|
*/ |
5 |
|
|
|
6 |
|
|
#ifndef _RAD_RMATRIX_H_ |
7 |
|
|
#define _RAD_RMATRIX_H_ |
8 |
|
|
|
9 |
|
|
#include "cmatrix.h" |
10 |
|
|
|
11 |
|
|
#ifdef __cplusplus |
12 |
|
|
extern "C" { |
13 |
|
|
#endif |
14 |
|
|
|
15 |
|
|
/* General plane-ordered component matrix */ |
16 |
|
|
typedef struct { |
17 |
|
|
int nrows, ncols, ncomp; |
18 |
greg |
2.4 |
int dtype; |
19 |
greg |
2.3 |
char *info; |
20 |
greg |
2.1 |
double mtx[1]; /* extends struct */ |
21 |
|
|
} RMATRIX; |
22 |
|
|
|
23 |
greg |
2.2 |
#define rmx_lval(rm,r,c,i) (rm)->mtx[((i)*(rm)->nrows+(r))*(rm)->ncols+(c)] |
24 |
greg |
2.1 |
|
25 |
|
|
/* Allocate a nr x nc matrix with n components */ |
26 |
|
|
extern RMATRIX *rmx_alloc(int nr, int nc, int n); |
27 |
|
|
|
28 |
greg |
2.4 |
/* Free a RMATRIX array */ |
29 |
|
|
extern void rmx_free(RMATRIX *rm); |
30 |
|
|
|
31 |
|
|
/* Resolve data type based on two input types (returns 0 for mismatch) */ |
32 |
|
|
extern int rmx_newtype(int dtyp1, int dtyp2); |
33 |
|
|
|
34 |
greg |
2.1 |
/* Load matrix from supported file type */ |
35 |
|
|
extern RMATRIX *rmx_load(const char *fname); |
36 |
|
|
|
37 |
greg |
2.3 |
/* Append header information associated with matrix data */ |
38 |
|
|
extern int rmx_addinfo(RMATRIX *rm, const char *info); |
39 |
|
|
|
40 |
greg |
2.4 |
/* Write matrix to file type indicated by dtype */ |
41 |
greg |
2.1 |
extern long rmx_write(const RMATRIX *rm, int dtype, FILE *fp); |
42 |
|
|
|
43 |
|
|
/* Allocate and assign square identity matrix with n components */ |
44 |
|
|
extern RMATRIX *rmx_identity(int dim, int n); |
45 |
|
|
|
46 |
|
|
/* Duplicate the given matrix */ |
47 |
|
|
extern RMATRIX *rmx_copy(const RMATRIX *rm); |
48 |
|
|
|
49 |
greg |
2.2 |
/* Allocate and assign transposed matrix */ |
50 |
|
|
extern RMATRIX *rmx_transpose(const RMATRIX *rm); |
51 |
greg |
2.1 |
|
52 |
|
|
/* Multiply (concatenate) two matrices and allocate the result */ |
53 |
|
|
extern RMATRIX *rmx_multiply(const RMATRIX *m1, const RMATRIX *m2); |
54 |
|
|
|
55 |
|
|
/* Sum second matrix into first, applying scale factor beforehand */ |
56 |
|
|
extern int rmx_sum(RMATRIX *msum, const RMATRIX *madd, const double sf[]); |
57 |
|
|
|
58 |
|
|
/* Scale the given matrix by the indicated scalar component vector */ |
59 |
|
|
extern int rmx_scale(RMATRIX *rm, const double sf[]); |
60 |
|
|
|
61 |
|
|
/* Allocate new matrix and apply component transformation */ |
62 |
|
|
extern RMATRIX *rmx_transform(const RMATRIX *msrc, int n, const double cmat[]); |
63 |
|
|
|
64 |
|
|
/* Convert a color matrix to newly allocated RMATRIX buffer */ |
65 |
|
|
extern RMATRIX *rmx_from_cmatrix(const CMATRIX *cm); |
66 |
|
|
|
67 |
|
|
/* Convert general matrix to newly allocated CMATRIX buffer */ |
68 |
|
|
extern CMATRIX *cm_from_rmatrix(const RMATRIX *rm); |
69 |
|
|
|
70 |
|
|
#ifdef __cplusplus |
71 |
|
|
} |
72 |
|
|
#endif |
73 |
|
|
#endif /* _RAD_RMATRIX_H_ */ |