checkin of 0.3.0
[pspp-builds.git] / src / matrix.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18    02111-1307, USA. */
19
20 #if !matrix_h
21 #define matrix_h 1
22 \f
23 /* Vector representation. */
24 struct vector
25   {
26     int n;
27     int m;
28     double *data;
29   };
30
31 /* Allocate vectors. */
32 struct vector *vec_alloc (int n);
33 void vec_realloc (struct vector *, int n);
34 void vec_free (struct vector *);
35
36 /* Vector elements. */
37 #define vec_elem(VEC, INDEX) ((VEC)->data[INDEX])
38
39 /* Set the vector to a constant value. */
40 void vec_init (struct vector *, double);
41
42 /* Print out the vector to stdout. */
43 #if GLOBAL_DEBUGGING
44 void vec_print (const struct vector *);
45 #endif
46
47 /* Sum the vector values. */
48 double vec_total (const struct vector *);
49 \f
50 /* Matrix representation. */
51 struct matrix
52   {
53     int nr, nc;
54     int m;
55     double *data;
56   };
57
58 /* Allocate matrices. */
59 struct matrix *mat_alloc (int nr, int nc);
60 void mat_realloc (struct matrix *, int nr, int nc);
61 void mat_free (struct matrix *);
62
63 /* Matrix elements. */
64 #define mat_elem(MAT, R, C) ((MAT)->data[(C) + (R) * (MAT)->nc])
65
66 /* Set matrix values to a constant. */
67 void mat_init (struct matrix *, double);
68 void mat_init_row (struct matrix *, int r, double);
69 void mat_init_col (struct matrix *, int c, double);
70
71 /* Print out the matrix values to stdout, optionally with row and
72    column labels (for debugging purposes). */
73 #if GLOBAL_DEBUGGING
74 void mat_print (const struct matrix *,
75                 const struct vector *row_labels, const struct vector *col_labels);
76 #endif
77
78 /* Sum matrix values. */
79 void mat_row_totals (const struct matrix *, struct vector *row_tots);
80 void mat_col_totals (const struct matrix *, struct vector *col_tots);
81 double mat_grand_total (const struct matrix *);
82
83 /* Chi-square statistics. */
84 enum
85   {
86     CHISQ_PEARSON,
87     CHISQ_LIKELIHOOD_RATIO,
88     CHISQ_FISHER,
89     CHISQ_CC,
90     CHISQ_LINEAR,
91     N_CHISQ
92   };
93
94 void mat_chisq (const struct matrix *, double chisq[N_CHISQ], int df[N_CHISQ]);
95
96 #endif /* matrix_h */