Added MACS source
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / matrix / gsl_matrix_char.h
1 /* matrix/gsl_matrix_char.h
2  * 
3  * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or (at
8  * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifndef __GSL_MATRIX_CHAR_H__
21 #define __GSL_MATRIX_CHAR_H__
22
23 #include <stdlib.h>
24 #include <gsl/gsl_types.h>
25 #include <gsl/gsl_errno.h>
26 #include <gsl/gsl_check_range.h>
27 #include <gsl/gsl_vector_char.h>
28
29 #undef __BEGIN_DECLS
30 #undef __END_DECLS
31 #ifdef __cplusplus
32 # define __BEGIN_DECLS extern "C" {
33 # define __END_DECLS }
34 #else
35 # define __BEGIN_DECLS /* empty */
36 # define __END_DECLS /* empty */
37 #endif
38
39 __BEGIN_DECLS
40
41 typedef struct 
42 {
43   size_t size1;
44   size_t size2;
45   size_t tda;
46   char * data;
47   gsl_block_char * block;
48   int owner;
49 } gsl_matrix_char;
50
51 typedef struct
52 {
53   gsl_matrix_char matrix;
54 } _gsl_matrix_char_view;
55
56 typedef _gsl_matrix_char_view gsl_matrix_char_view;
57
58 typedef struct
59 {
60   gsl_matrix_char matrix;
61 } _gsl_matrix_char_const_view;
62
63 typedef const _gsl_matrix_char_const_view gsl_matrix_char_const_view;
64
65 /* Allocation */
66
67 gsl_matrix_char * 
68 gsl_matrix_char_alloc (const size_t n1, const size_t n2);
69
70 gsl_matrix_char * 
71 gsl_matrix_char_calloc (const size_t n1, const size_t n2);
72
73 gsl_matrix_char * 
74 gsl_matrix_char_alloc_from_block (gsl_block_char * b, 
75                                    const size_t offset, 
76                                    const size_t n1, 
77                                    const size_t n2, 
78                                    const size_t d2);
79
80 gsl_matrix_char * 
81 gsl_matrix_char_alloc_from_matrix (gsl_matrix_char * m,
82                                     const size_t k1, 
83                                     const size_t k2,
84                                     const size_t n1, 
85                                     const size_t n2);
86
87 gsl_vector_char * 
88 gsl_vector_char_alloc_row_from_matrix (gsl_matrix_char * m,
89                                         const size_t i);
90
91 gsl_vector_char * 
92 gsl_vector_char_alloc_col_from_matrix (gsl_matrix_char * m,
93                                         const size_t j);
94
95 void gsl_matrix_char_free (gsl_matrix_char * m);
96
97 /* Views */
98
99 _gsl_matrix_char_view 
100 gsl_matrix_char_submatrix (gsl_matrix_char * m, 
101                             const size_t i, const size_t j, 
102                             const size_t n1, const size_t n2);
103
104 _gsl_vector_char_view 
105 gsl_matrix_char_row (gsl_matrix_char * m, const size_t i);
106
107 _gsl_vector_char_view 
108 gsl_matrix_char_column (gsl_matrix_char * m, const size_t j);
109
110 _gsl_vector_char_view 
111 gsl_matrix_char_diagonal (gsl_matrix_char * m);
112
113 _gsl_vector_char_view 
114 gsl_matrix_char_subdiagonal (gsl_matrix_char * m, const size_t k);
115
116 _gsl_vector_char_view 
117 gsl_matrix_char_superdiagonal (gsl_matrix_char * m, const size_t k);
118
119 _gsl_vector_char_view
120 gsl_matrix_char_subrow (gsl_matrix_char * m, const size_t i,
121                          const size_t offset, const size_t n);
122
123 _gsl_vector_char_view
124 gsl_matrix_char_subcolumn (gsl_matrix_char * m, const size_t j,
125                             const size_t offset, const size_t n);
126
127 _gsl_matrix_char_view
128 gsl_matrix_char_view_array (char * base,
129                              const size_t n1, 
130                              const size_t n2);
131
132 _gsl_matrix_char_view
133 gsl_matrix_char_view_array_with_tda (char * base, 
134                                       const size_t n1, 
135                                       const size_t n2,
136                                       const size_t tda);
137
138
139 _gsl_matrix_char_view
140 gsl_matrix_char_view_vector (gsl_vector_char * v,
141                               const size_t n1, 
142                               const size_t n2);
143
144 _gsl_matrix_char_view
145 gsl_matrix_char_view_vector_with_tda (gsl_vector_char * v,
146                                        const size_t n1, 
147                                        const size_t n2,
148                                        const size_t tda);
149
150
151 _gsl_matrix_char_const_view 
152 gsl_matrix_char_const_submatrix (const gsl_matrix_char * m, 
153                                   const size_t i, const size_t j, 
154                                   const size_t n1, const size_t n2);
155
156 _gsl_vector_char_const_view 
157 gsl_matrix_char_const_row (const gsl_matrix_char * m, 
158                             const size_t i);
159
160 _gsl_vector_char_const_view 
161 gsl_matrix_char_const_column (const gsl_matrix_char * m, 
162                                const size_t j);
163
164 _gsl_vector_char_const_view
165 gsl_matrix_char_const_diagonal (const gsl_matrix_char * m);
166
167 _gsl_vector_char_const_view 
168 gsl_matrix_char_const_subdiagonal (const gsl_matrix_char * m, 
169                                     const size_t k);
170
171 _gsl_vector_char_const_view 
172 gsl_matrix_char_const_superdiagonal (const gsl_matrix_char * m, 
173                                       const size_t k);
174
175 _gsl_vector_char_const_view
176 gsl_matrix_char_const_subrow (const gsl_matrix_char * m, const size_t i,
177                                const size_t offset, const size_t n);
178
179 _gsl_vector_char_const_view
180 gsl_matrix_char_const_subcolumn (const gsl_matrix_char * m, const size_t j,
181                                   const size_t offset, const size_t n);
182
183 _gsl_matrix_char_const_view
184 gsl_matrix_char_const_view_array (const char * base,
185                                    const size_t n1, 
186                                    const size_t n2);
187
188 _gsl_matrix_char_const_view
189 gsl_matrix_char_const_view_array_with_tda (const char * base, 
190                                             const size_t n1, 
191                                             const size_t n2,
192                                             const size_t tda);
193
194 _gsl_matrix_char_const_view
195 gsl_matrix_char_const_view_vector (const gsl_vector_char * v,
196                                     const size_t n1, 
197                                     const size_t n2);
198
199 _gsl_matrix_char_const_view
200 gsl_matrix_char_const_view_vector_with_tda (const gsl_vector_char * v,
201                                              const size_t n1, 
202                                              const size_t n2,
203                                              const size_t tda);
204
205 /* Operations */
206
207 char   gsl_matrix_char_get(const gsl_matrix_char * m, const size_t i, const size_t j);
208 void    gsl_matrix_char_set(gsl_matrix_char * m, const size_t i, const size_t j, const char x);
209
210 char * gsl_matrix_char_ptr(gsl_matrix_char * m, const size_t i, const size_t j);
211 const char * gsl_matrix_char_const_ptr(const gsl_matrix_char * m, const size_t i, const size_t j);
212
213 void gsl_matrix_char_set_zero (gsl_matrix_char * m);
214 void gsl_matrix_char_set_identity (gsl_matrix_char * m);
215 void gsl_matrix_char_set_all (gsl_matrix_char * m, char x);
216
217 int gsl_matrix_char_fread (FILE * stream, gsl_matrix_char * m) ;
218 int gsl_matrix_char_fwrite (FILE * stream, const gsl_matrix_char * m) ;
219 int gsl_matrix_char_fscanf (FILE * stream, gsl_matrix_char * m);
220 int gsl_matrix_char_fprintf (FILE * stream, const gsl_matrix_char * m, const char * format);
221  
222 int gsl_matrix_char_memcpy(gsl_matrix_char * dest, const gsl_matrix_char * src);
223 int gsl_matrix_char_swap(gsl_matrix_char * m1, gsl_matrix_char * m2);
224
225 int gsl_matrix_char_swap_rows(gsl_matrix_char * m, const size_t i, const size_t j);
226 int gsl_matrix_char_swap_columns(gsl_matrix_char * m, const size_t i, const size_t j);
227 int gsl_matrix_char_swap_rowcol(gsl_matrix_char * m, const size_t i, const size_t j);
228 int gsl_matrix_char_transpose (gsl_matrix_char * m);
229 int gsl_matrix_char_transpose_memcpy (gsl_matrix_char * dest, const gsl_matrix_char * src);
230
231 char gsl_matrix_char_max (const gsl_matrix_char * m);
232 char gsl_matrix_char_min (const gsl_matrix_char * m);
233 void gsl_matrix_char_minmax (const gsl_matrix_char * m, char * min_out, char * max_out);
234
235 void gsl_matrix_char_max_index (const gsl_matrix_char * m, size_t * imax, size_t *jmax);
236 void gsl_matrix_char_min_index (const gsl_matrix_char * m, size_t * imin, size_t *jmin);
237 void gsl_matrix_char_minmax_index (const gsl_matrix_char * m, size_t * imin, size_t * jmin, size_t * imax, size_t * jmax);
238
239 int gsl_matrix_char_isnull (const gsl_matrix_char * m);
240 int gsl_matrix_char_ispos (const gsl_matrix_char * m);
241 int gsl_matrix_char_isneg (const gsl_matrix_char * m);
242 int gsl_matrix_char_isnonneg (const gsl_matrix_char * m);
243
244 int gsl_matrix_char_add (gsl_matrix_char * a, const gsl_matrix_char * b);
245 int gsl_matrix_char_sub (gsl_matrix_char * a, const gsl_matrix_char * b);
246 int gsl_matrix_char_mul_elements (gsl_matrix_char * a, const gsl_matrix_char * b);
247 int gsl_matrix_char_div_elements (gsl_matrix_char * a, const gsl_matrix_char * b);
248 int gsl_matrix_char_scale (gsl_matrix_char * a, const double x);
249 int gsl_matrix_char_add_constant (gsl_matrix_char * a, const double x);
250 int gsl_matrix_char_add_diagonal (gsl_matrix_char * a, const double x);
251
252 /***********************************************************************/
253 /* The functions below are obsolete                                    */
254 /***********************************************************************/
255 int gsl_matrix_char_get_row(gsl_vector_char * v, const gsl_matrix_char * m, const size_t i);
256 int gsl_matrix_char_get_col(gsl_vector_char * v, const gsl_matrix_char * m, const size_t j);
257 int gsl_matrix_char_set_row(gsl_matrix_char * m, const size_t i, const gsl_vector_char * v);
258 int gsl_matrix_char_set_col(gsl_matrix_char * m, const size_t j, const gsl_vector_char * v);
259
260 /* inline functions if you are using GCC */
261
262 #ifdef HAVE_INLINE
263 extern inline 
264 char
265 gsl_matrix_char_get(const gsl_matrix_char * m, const size_t i, const size_t j)
266 {
267 #if GSL_RANGE_CHECK
268   if (i >= m->size1)
269     {
270       GSL_ERROR_VAL("first index out of range", GSL_EINVAL, 0) ;
271     }
272   else if (j >= m->size2)
273     {
274       GSL_ERROR_VAL("second index out of range", GSL_EINVAL, 0) ;
275     }
276 #endif
277   return m->data[i * m->tda + j] ;
278
279
280 extern inline 
281 void
282 gsl_matrix_char_set(gsl_matrix_char * m, const size_t i, const size_t j, const char x)
283 {
284 #if GSL_RANGE_CHECK
285   if (i >= m->size1)
286     {
287       GSL_ERROR_VOID("first index out of range", GSL_EINVAL) ;
288     }
289   else if (j >= m->size2)
290     {
291       GSL_ERROR_VOID("second index out of range", GSL_EINVAL) ;
292     }
293 #endif
294   m->data[i * m->tda + j] = x ;
295 }
296
297 extern inline 
298 char *
299 gsl_matrix_char_ptr(gsl_matrix_char * m, const size_t i, const size_t j)
300 {
301 #if GSL_RANGE_CHECK
302   if (i >= m->size1)
303     {
304       GSL_ERROR_NULL("first index out of range", GSL_EINVAL) ;
305     }
306   else if (j >= m->size2)
307     {
308       GSL_ERROR_NULL("second index out of range", GSL_EINVAL) ;
309     }
310 #endif
311   return (char *) (m->data + (i * m->tda + j)) ;
312
313
314 extern inline 
315 const char *
316 gsl_matrix_char_const_ptr(const gsl_matrix_char * m, const size_t i, const size_t j)
317 {
318 #if GSL_RANGE_CHECK
319   if (i >= m->size1)
320     {
321       GSL_ERROR_NULL("first index out of range", GSL_EINVAL) ;
322     }
323   else if (j >= m->size2)
324     {
325       GSL_ERROR_NULL("second index out of range", GSL_EINVAL) ;
326     }
327 #endif
328   return (const char *) (m->data + (i * m->tda + j)) ;
329
330
331 #endif
332
333 __END_DECLS
334
335 #endif /* __GSL_MATRIX_CHAR_H__ */