1 /* matrix/gsl_matrix_ushort.h
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
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.
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.
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.
20 #ifndef __GSL_MATRIX_USHORT_H__
21 #define __GSL_MATRIX_USHORT_H__
24 #include <gsl/gsl_types.h>
25 #include <gsl/gsl_errno.h>
26 #include <gsl/gsl_inline.h>
27 #include <gsl/gsl_check_range.h>
28 #include <gsl/gsl_vector_ushort.h>
29 #include <gsl/gsl_blas_types.h>
34 # define __BEGIN_DECLS extern "C" {
35 # define __END_DECLS }
37 # define __BEGIN_DECLS /* empty */
38 # define __END_DECLS /* empty */
48 unsigned short * data;
49 gsl_block_ushort * block;
55 gsl_matrix_ushort matrix;
56 } _gsl_matrix_ushort_view;
58 typedef _gsl_matrix_ushort_view gsl_matrix_ushort_view;
62 gsl_matrix_ushort matrix;
63 } _gsl_matrix_ushort_const_view;
65 typedef const _gsl_matrix_ushort_const_view gsl_matrix_ushort_const_view;
70 gsl_matrix_ushort_alloc (const size_t n1, const size_t n2);
73 gsl_matrix_ushort_calloc (const size_t n1, const size_t n2);
76 gsl_matrix_ushort_alloc_from_block (gsl_block_ushort * b,
83 gsl_matrix_ushort_alloc_from_matrix (gsl_matrix_ushort * m,
90 gsl_vector_ushort_alloc_row_from_matrix (gsl_matrix_ushort * m,
94 gsl_vector_ushort_alloc_col_from_matrix (gsl_matrix_ushort * m,
97 void gsl_matrix_ushort_free (gsl_matrix_ushort * m);
101 _gsl_matrix_ushort_view
102 gsl_matrix_ushort_submatrix (gsl_matrix_ushort * m,
103 const size_t i, const size_t j,
104 const size_t n1, const size_t n2);
106 _gsl_vector_ushort_view
107 gsl_matrix_ushort_row (gsl_matrix_ushort * m, const size_t i);
109 _gsl_vector_ushort_view
110 gsl_matrix_ushort_column (gsl_matrix_ushort * m, const size_t j);
112 _gsl_vector_ushort_view
113 gsl_matrix_ushort_diagonal (gsl_matrix_ushort * m);
115 _gsl_vector_ushort_view
116 gsl_matrix_ushort_subdiagonal (gsl_matrix_ushort * m, const size_t k);
118 _gsl_vector_ushort_view
119 gsl_matrix_ushort_superdiagonal (gsl_matrix_ushort * m, const size_t k);
121 _gsl_vector_ushort_view
122 gsl_matrix_ushort_subrow (gsl_matrix_ushort * m, const size_t i,
123 const size_t offset, const size_t n);
125 _gsl_vector_ushort_view
126 gsl_matrix_ushort_subcolumn (gsl_matrix_ushort * m, const size_t j,
127 const size_t offset, const size_t n);
129 _gsl_matrix_ushort_view
130 gsl_matrix_ushort_view_array (unsigned short * base,
134 _gsl_matrix_ushort_view
135 gsl_matrix_ushort_view_array_with_tda (unsigned short * base,
141 _gsl_matrix_ushort_view
142 gsl_matrix_ushort_view_vector (gsl_vector_ushort * v,
146 _gsl_matrix_ushort_view
147 gsl_matrix_ushort_view_vector_with_tda (gsl_vector_ushort * v,
153 _gsl_matrix_ushort_const_view
154 gsl_matrix_ushort_const_submatrix (const gsl_matrix_ushort * m,
155 const size_t i, const size_t j,
156 const size_t n1, const size_t n2);
158 _gsl_vector_ushort_const_view
159 gsl_matrix_ushort_const_row (const gsl_matrix_ushort * m,
162 _gsl_vector_ushort_const_view
163 gsl_matrix_ushort_const_column (const gsl_matrix_ushort * m,
166 _gsl_vector_ushort_const_view
167 gsl_matrix_ushort_const_diagonal (const gsl_matrix_ushort * m);
169 _gsl_vector_ushort_const_view
170 gsl_matrix_ushort_const_subdiagonal (const gsl_matrix_ushort * m,
173 _gsl_vector_ushort_const_view
174 gsl_matrix_ushort_const_superdiagonal (const gsl_matrix_ushort * m,
177 _gsl_vector_ushort_const_view
178 gsl_matrix_ushort_const_subrow (const gsl_matrix_ushort * m, const size_t i,
179 const size_t offset, const size_t n);
181 _gsl_vector_ushort_const_view
182 gsl_matrix_ushort_const_subcolumn (const gsl_matrix_ushort * m, const size_t j,
183 const size_t offset, const size_t n);
185 _gsl_matrix_ushort_const_view
186 gsl_matrix_ushort_const_view_array (const unsigned short * base,
190 _gsl_matrix_ushort_const_view
191 gsl_matrix_ushort_const_view_array_with_tda (const unsigned short * base,
196 _gsl_matrix_ushort_const_view
197 gsl_matrix_ushort_const_view_vector (const gsl_vector_ushort * v,
201 _gsl_matrix_ushort_const_view
202 gsl_matrix_ushort_const_view_vector_with_tda (const gsl_vector_ushort * v,
209 void gsl_matrix_ushort_set_zero (gsl_matrix_ushort * m);
210 void gsl_matrix_ushort_set_identity (gsl_matrix_ushort * m);
211 void gsl_matrix_ushort_set_all (gsl_matrix_ushort * m, unsigned short x);
213 int gsl_matrix_ushort_fread (FILE * stream, gsl_matrix_ushort * m) ;
214 int gsl_matrix_ushort_fwrite (FILE * stream, const gsl_matrix_ushort * m) ;
215 int gsl_matrix_ushort_fscanf (FILE * stream, gsl_matrix_ushort * m);
216 int gsl_matrix_ushort_fprintf (FILE * stream, const gsl_matrix_ushort * m, const char * format);
218 int gsl_matrix_ushort_memcpy(gsl_matrix_ushort * dest, const gsl_matrix_ushort * src);
219 int gsl_matrix_ushort_swap(gsl_matrix_ushort * m1, gsl_matrix_ushort * m2);
220 int gsl_matrix_ushort_tricpy(CBLAS_UPLO_t Uplo, CBLAS_DIAG_t Diag, gsl_matrix_ushort * dest, const gsl_matrix_ushort * src);
222 int gsl_matrix_ushort_swap_rows(gsl_matrix_ushort * m, const size_t i, const size_t j);
223 int gsl_matrix_ushort_swap_columns(gsl_matrix_ushort * m, const size_t i, const size_t j);
224 int gsl_matrix_ushort_swap_rowcol(gsl_matrix_ushort * m, const size_t i, const size_t j);
225 int gsl_matrix_ushort_transpose (gsl_matrix_ushort * m);
226 int gsl_matrix_ushort_transpose_memcpy (gsl_matrix_ushort * dest, const gsl_matrix_ushort * src);
227 int gsl_matrix_ushort_transpose_tricpy (CBLAS_UPLO_t Uplo_src, CBLAS_DIAG_t Diag, gsl_matrix_ushort * dest, const gsl_matrix_ushort * src);
229 unsigned short gsl_matrix_ushort_max (const gsl_matrix_ushort * m);
230 unsigned short gsl_matrix_ushort_min (const gsl_matrix_ushort * m);
231 void gsl_matrix_ushort_minmax (const gsl_matrix_ushort * m, unsigned short * min_out, unsigned short * max_out);
233 void gsl_matrix_ushort_max_index (const gsl_matrix_ushort * m, size_t * imax, size_t *jmax);
234 void gsl_matrix_ushort_min_index (const gsl_matrix_ushort * m, size_t * imin, size_t *jmin);
235 void gsl_matrix_ushort_minmax_index (const gsl_matrix_ushort * m, size_t * imin, size_t * jmin, size_t * imax, size_t * jmax);
237 int gsl_matrix_ushort_equal (const gsl_matrix_ushort * a, const gsl_matrix_ushort * b);
239 int gsl_matrix_ushort_isnull (const gsl_matrix_ushort * m);
240 int gsl_matrix_ushort_ispos (const gsl_matrix_ushort * m);
241 int gsl_matrix_ushort_isneg (const gsl_matrix_ushort * m);
242 int gsl_matrix_ushort_isnonneg (const gsl_matrix_ushort * m);
244 unsigned short gsl_matrix_ushort_norm1 (const gsl_matrix_ushort * m);
246 int gsl_matrix_ushort_add (gsl_matrix_ushort * a, const gsl_matrix_ushort * b);
247 int gsl_matrix_ushort_sub (gsl_matrix_ushort * a, const gsl_matrix_ushort * b);
248 int gsl_matrix_ushort_mul_elements (gsl_matrix_ushort * a, const gsl_matrix_ushort * b);
249 int gsl_matrix_ushort_div_elements (gsl_matrix_ushort * a, const gsl_matrix_ushort * b);
250 int gsl_matrix_ushort_scale (gsl_matrix_ushort * a, const unsigned short x);
251 int gsl_matrix_ushort_scale_rows (gsl_matrix_ushort * a, const gsl_vector_ushort * x);
252 int gsl_matrix_ushort_scale_columns (gsl_matrix_ushort * a, const gsl_vector_ushort * x);
253 int gsl_matrix_ushort_add_constant (gsl_matrix_ushort * a, const unsigned short x);
254 int gsl_matrix_ushort_add_diagonal (gsl_matrix_ushort * a, const unsigned short x);
256 /***********************************************************************/
257 /* The functions below are obsolete */
258 /***********************************************************************/
259 int gsl_matrix_ushort_get_row(gsl_vector_ushort * v, const gsl_matrix_ushort * m, const size_t i);
260 int gsl_matrix_ushort_get_col(gsl_vector_ushort * v, const gsl_matrix_ushort * m, const size_t j);
261 int gsl_matrix_ushort_set_row(gsl_matrix_ushort * m, const size_t i, const gsl_vector_ushort * v);
262 int gsl_matrix_ushort_set_col(gsl_matrix_ushort * m, const size_t j, const gsl_vector_ushort * v);
263 /***********************************************************************/
265 /* inline functions if you are using GCC */
267 INLINE_DECL unsigned short gsl_matrix_ushort_get(const gsl_matrix_ushort * m, const size_t i, const size_t j);
268 INLINE_DECL void gsl_matrix_ushort_set(gsl_matrix_ushort * m, const size_t i, const size_t j, const unsigned short x);
269 INLINE_DECL unsigned short * gsl_matrix_ushort_ptr(gsl_matrix_ushort * m, const size_t i, const size_t j);
270 INLINE_DECL const unsigned short * gsl_matrix_ushort_const_ptr(const gsl_matrix_ushort * m, const size_t i, const size_t j);
275 gsl_matrix_ushort_get(const gsl_matrix_ushort * m, const size_t i, const size_t j)
278 if (GSL_RANGE_COND(1))
282 GSL_ERROR_VAL("first index out of range", GSL_EINVAL, 0) ;
284 else if (j >= m->size2)
286 GSL_ERROR_VAL("second index out of range", GSL_EINVAL, 0) ;
290 return m->data[i * m->tda + j] ;
295 gsl_matrix_ushort_set(gsl_matrix_ushort * m, const size_t i, const size_t j, const unsigned short x)
298 if (GSL_RANGE_COND(1))
302 GSL_ERROR_VOID("first index out of range", GSL_EINVAL) ;
304 else if (j >= m->size2)
306 GSL_ERROR_VOID("second index out of range", GSL_EINVAL) ;
310 m->data[i * m->tda + j] = x ;
315 gsl_matrix_ushort_ptr(gsl_matrix_ushort * m, const size_t i, const size_t j)
318 if (GSL_RANGE_COND(1))
322 GSL_ERROR_NULL("first index out of range", GSL_EINVAL) ;
324 else if (j >= m->size2)
326 GSL_ERROR_NULL("second index out of range", GSL_EINVAL) ;
330 return (unsigned short *) (m->data + (i * m->tda + j)) ;
334 const unsigned short *
335 gsl_matrix_ushort_const_ptr(const gsl_matrix_ushort * m, const size_t i, const size_t j)
338 if (GSL_RANGE_COND(1))
342 GSL_ERROR_NULL("first index out of range", GSL_EINVAL) ;
344 else if (j >= m->size2)
346 GSL_ERROR_NULL("second index out of range", GSL_EINVAL) ;
350 return (const unsigned short *) (m->data + (i * m->tda + j)) ;
357 #endif /* __GSL_MATRIX_USHORT_H__ */