Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:03:50

0001 /* matrix/gsl_matrix_ushort.h
0002  * 
0003  * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
0004  * 
0005  * This program is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation; either version 3 of the License, or (at
0008  * your option) any later version.
0009  * 
0010  * This program is distributed in the hope that it will be useful, but
0011  * WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * General Public License for more details.
0014  * 
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program; if not, write to the Free Software
0017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #ifndef __GSL_MATRIX_USHORT_H__
0021 #define __GSL_MATRIX_USHORT_H__
0022 
0023 #include <stdlib.h>
0024 #include <gsl/gsl_types.h>
0025 #include <gsl/gsl_errno.h>
0026 #include <gsl/gsl_inline.h>
0027 #include <gsl/gsl_check_range.h>
0028 #include <gsl/gsl_vector_ushort.h>
0029 #include <gsl/gsl_blas_types.h>
0030 
0031 #undef __BEGIN_DECLS
0032 #undef __END_DECLS
0033 #ifdef __cplusplus
0034 # define __BEGIN_DECLS extern "C" {
0035 # define __END_DECLS }
0036 #else
0037 # define __BEGIN_DECLS /* empty */
0038 # define __END_DECLS /* empty */
0039 #endif
0040 
0041 __BEGIN_DECLS
0042 
0043 typedef struct 
0044 {
0045   size_t size1;
0046   size_t size2;
0047   size_t tda;
0048   unsigned short * data;
0049   gsl_block_ushort * block;
0050   int owner;
0051 } gsl_matrix_ushort;
0052 
0053 typedef struct
0054 {
0055   gsl_matrix_ushort matrix;
0056 } _gsl_matrix_ushort_view;
0057 
0058 typedef _gsl_matrix_ushort_view gsl_matrix_ushort_view;
0059 
0060 typedef struct
0061 {
0062   gsl_matrix_ushort matrix;
0063 } _gsl_matrix_ushort_const_view;
0064 
0065 typedef const _gsl_matrix_ushort_const_view gsl_matrix_ushort_const_view;
0066 
0067 /* Allocation */
0068 
0069 gsl_matrix_ushort * 
0070 gsl_matrix_ushort_alloc (const size_t n1, const size_t n2);
0071 
0072 gsl_matrix_ushort * 
0073 gsl_matrix_ushort_calloc (const size_t n1, const size_t n2);
0074 
0075 gsl_matrix_ushort * 
0076 gsl_matrix_ushort_alloc_from_block (gsl_block_ushort * b, 
0077                                    const size_t offset, 
0078                                    const size_t n1, 
0079                                    const size_t n2, 
0080                                    const size_t d2);
0081 
0082 gsl_matrix_ushort * 
0083 gsl_matrix_ushort_alloc_from_matrix (gsl_matrix_ushort * m,
0084                                     const size_t k1, 
0085                                     const size_t k2,
0086                                     const size_t n1, 
0087                                     const size_t n2);
0088 
0089 gsl_vector_ushort * 
0090 gsl_vector_ushort_alloc_row_from_matrix (gsl_matrix_ushort * m,
0091                                         const size_t i);
0092 
0093 gsl_vector_ushort * 
0094 gsl_vector_ushort_alloc_col_from_matrix (gsl_matrix_ushort * m,
0095                                         const size_t j);
0096 
0097 void gsl_matrix_ushort_free (gsl_matrix_ushort * m);
0098 
0099 /* Views */
0100 
0101 _gsl_matrix_ushort_view 
0102 gsl_matrix_ushort_submatrix (gsl_matrix_ushort * m, 
0103                             const size_t i, const size_t j, 
0104                             const size_t n1, const size_t n2);
0105 
0106 _gsl_vector_ushort_view 
0107 gsl_matrix_ushort_row (gsl_matrix_ushort * m, const size_t i);
0108 
0109 _gsl_vector_ushort_view 
0110 gsl_matrix_ushort_column (gsl_matrix_ushort * m, const size_t j);
0111 
0112 _gsl_vector_ushort_view 
0113 gsl_matrix_ushort_diagonal (gsl_matrix_ushort * m);
0114 
0115 _gsl_vector_ushort_view 
0116 gsl_matrix_ushort_subdiagonal (gsl_matrix_ushort * m, const size_t k);
0117 
0118 _gsl_vector_ushort_view 
0119 gsl_matrix_ushort_superdiagonal (gsl_matrix_ushort * m, const size_t k);
0120 
0121 _gsl_vector_ushort_view
0122 gsl_matrix_ushort_subrow (gsl_matrix_ushort * m, const size_t i,
0123                          const size_t offset, const size_t n);
0124 
0125 _gsl_vector_ushort_view
0126 gsl_matrix_ushort_subcolumn (gsl_matrix_ushort * m, const size_t j,
0127                             const size_t offset, const size_t n);
0128 
0129 _gsl_matrix_ushort_view
0130 gsl_matrix_ushort_view_array (unsigned short * base,
0131                              const size_t n1, 
0132                              const size_t n2);
0133 
0134 _gsl_matrix_ushort_view
0135 gsl_matrix_ushort_view_array_with_tda (unsigned short * base, 
0136                                       const size_t n1, 
0137                                       const size_t n2,
0138                                       const size_t tda);
0139 
0140 
0141 _gsl_matrix_ushort_view
0142 gsl_matrix_ushort_view_vector (gsl_vector_ushort * v,
0143                               const size_t n1, 
0144                               const size_t n2);
0145 
0146 _gsl_matrix_ushort_view
0147 gsl_matrix_ushort_view_vector_with_tda (gsl_vector_ushort * v,
0148                                        const size_t n1, 
0149                                        const size_t n2,
0150                                        const size_t tda);
0151 
0152 
0153 _gsl_matrix_ushort_const_view 
0154 gsl_matrix_ushort_const_submatrix (const gsl_matrix_ushort * m, 
0155                                   const size_t i, const size_t j, 
0156                                   const size_t n1, const size_t n2);
0157 
0158 _gsl_vector_ushort_const_view 
0159 gsl_matrix_ushort_const_row (const gsl_matrix_ushort * m, 
0160                             const size_t i);
0161 
0162 _gsl_vector_ushort_const_view 
0163 gsl_matrix_ushort_const_column (const gsl_matrix_ushort * m, 
0164                                const size_t j);
0165 
0166 _gsl_vector_ushort_const_view
0167 gsl_matrix_ushort_const_diagonal (const gsl_matrix_ushort * m);
0168 
0169 _gsl_vector_ushort_const_view 
0170 gsl_matrix_ushort_const_subdiagonal (const gsl_matrix_ushort * m, 
0171                                     const size_t k);
0172 
0173 _gsl_vector_ushort_const_view 
0174 gsl_matrix_ushort_const_superdiagonal (const gsl_matrix_ushort * m, 
0175                                       const size_t k);
0176 
0177 _gsl_vector_ushort_const_view
0178 gsl_matrix_ushort_const_subrow (const gsl_matrix_ushort * m, const size_t i,
0179                                const size_t offset, const size_t n);
0180 
0181 _gsl_vector_ushort_const_view
0182 gsl_matrix_ushort_const_subcolumn (const gsl_matrix_ushort * m, const size_t j,
0183                                   const size_t offset, const size_t n);
0184 
0185 _gsl_matrix_ushort_const_view
0186 gsl_matrix_ushort_const_view_array (const unsigned short * base,
0187                                    const size_t n1, 
0188                                    const size_t n2);
0189 
0190 _gsl_matrix_ushort_const_view
0191 gsl_matrix_ushort_const_view_array_with_tda (const unsigned short * base, 
0192                                             const size_t n1, 
0193                                             const size_t n2,
0194                                             const size_t tda);
0195 
0196 _gsl_matrix_ushort_const_view
0197 gsl_matrix_ushort_const_view_vector (const gsl_vector_ushort * v,
0198                                     const size_t n1, 
0199                                     const size_t n2);
0200 
0201 _gsl_matrix_ushort_const_view
0202 gsl_matrix_ushort_const_view_vector_with_tda (const gsl_vector_ushort * v,
0203                                              const size_t n1, 
0204                                              const size_t n2,
0205                                              const size_t tda);
0206 
0207 /* Operations */
0208 
0209 void gsl_matrix_ushort_set_zero (gsl_matrix_ushort * m);
0210 void gsl_matrix_ushort_set_identity (gsl_matrix_ushort * m);
0211 void gsl_matrix_ushort_set_all (gsl_matrix_ushort * m, unsigned short x);
0212 
0213 int gsl_matrix_ushort_fread (FILE * stream, gsl_matrix_ushort * m) ;
0214 int gsl_matrix_ushort_fwrite (FILE * stream, const gsl_matrix_ushort * m) ;
0215 int gsl_matrix_ushort_fscanf (FILE * stream, gsl_matrix_ushort * m);
0216 int gsl_matrix_ushort_fprintf (FILE * stream, const gsl_matrix_ushort * m, const char * format);
0217  
0218 int gsl_matrix_ushort_memcpy(gsl_matrix_ushort * dest, const gsl_matrix_ushort * src);
0219 int gsl_matrix_ushort_swap(gsl_matrix_ushort * m1, gsl_matrix_ushort * m2);
0220 int gsl_matrix_ushort_tricpy(CBLAS_UPLO_t Uplo, CBLAS_DIAG_t Diag, gsl_matrix_ushort * dest, const gsl_matrix_ushort * src);
0221 
0222 int gsl_matrix_ushort_swap_rows(gsl_matrix_ushort * m, const size_t i, const size_t j);
0223 int gsl_matrix_ushort_swap_columns(gsl_matrix_ushort * m, const size_t i, const size_t j);
0224 int gsl_matrix_ushort_swap_rowcol(gsl_matrix_ushort * m, const size_t i, const size_t j);
0225 int gsl_matrix_ushort_transpose (gsl_matrix_ushort * m);
0226 int gsl_matrix_ushort_transpose_memcpy (gsl_matrix_ushort * dest, const gsl_matrix_ushort * src);
0227 int gsl_matrix_ushort_transpose_tricpy (CBLAS_UPLO_t Uplo_src, CBLAS_DIAG_t Diag, gsl_matrix_ushort * dest, const gsl_matrix_ushort * src);
0228 
0229 unsigned short gsl_matrix_ushort_max (const gsl_matrix_ushort * m);
0230 unsigned short gsl_matrix_ushort_min (const gsl_matrix_ushort * m);
0231 void gsl_matrix_ushort_minmax (const gsl_matrix_ushort * m, unsigned short * min_out, unsigned short * max_out);
0232 
0233 void gsl_matrix_ushort_max_index (const gsl_matrix_ushort * m, size_t * imax, size_t *jmax);
0234 void gsl_matrix_ushort_min_index (const gsl_matrix_ushort * m, size_t * imin, size_t *jmin);
0235 void gsl_matrix_ushort_minmax_index (const gsl_matrix_ushort * m, size_t * imin, size_t * jmin, size_t * imax, size_t * jmax);
0236 
0237 int gsl_matrix_ushort_equal (const gsl_matrix_ushort * a, const gsl_matrix_ushort * b);
0238 
0239 int gsl_matrix_ushort_isnull (const gsl_matrix_ushort * m);
0240 int gsl_matrix_ushort_ispos (const gsl_matrix_ushort * m);
0241 int gsl_matrix_ushort_isneg (const gsl_matrix_ushort * m);
0242 int gsl_matrix_ushort_isnonneg (const gsl_matrix_ushort * m);
0243 
0244 unsigned short gsl_matrix_ushort_norm1 (const gsl_matrix_ushort * m);
0245 
0246 int gsl_matrix_ushort_add (gsl_matrix_ushort * a, const gsl_matrix_ushort * b);
0247 int gsl_matrix_ushort_sub (gsl_matrix_ushort * a, const gsl_matrix_ushort * b);
0248 int gsl_matrix_ushort_mul_elements (gsl_matrix_ushort * a, const gsl_matrix_ushort * b);
0249 int gsl_matrix_ushort_div_elements (gsl_matrix_ushort * a, const gsl_matrix_ushort * b);
0250 int gsl_matrix_ushort_scale (gsl_matrix_ushort * a, const unsigned short x);
0251 int gsl_matrix_ushort_scale_rows (gsl_matrix_ushort * a, const gsl_vector_ushort * x);
0252 int gsl_matrix_ushort_scale_columns (gsl_matrix_ushort * a, const gsl_vector_ushort * x);
0253 int gsl_matrix_ushort_add_constant (gsl_matrix_ushort * a, const unsigned short x);
0254 int gsl_matrix_ushort_add_diagonal (gsl_matrix_ushort * a, const unsigned short x);
0255 
0256 /***********************************************************************/
0257 /* The functions below are obsolete                                    */
0258 /***********************************************************************/
0259 int gsl_matrix_ushort_get_row(gsl_vector_ushort * v, const gsl_matrix_ushort * m, const size_t i);
0260 int gsl_matrix_ushort_get_col(gsl_vector_ushort * v, const gsl_matrix_ushort * m, const size_t j);
0261 int gsl_matrix_ushort_set_row(gsl_matrix_ushort * m, const size_t i, const gsl_vector_ushort * v);
0262 int gsl_matrix_ushort_set_col(gsl_matrix_ushort * m, const size_t j, const gsl_vector_ushort * v);
0263 /***********************************************************************/
0264 
0265 /* inline functions if you are using GCC */
0266 
0267 INLINE_DECL unsigned short   gsl_matrix_ushort_get(const gsl_matrix_ushort * m, const size_t i, const size_t j);
0268 INLINE_DECL void    gsl_matrix_ushort_set(gsl_matrix_ushort * m, const size_t i, const size_t j, const unsigned short x);
0269 INLINE_DECL unsigned short * gsl_matrix_ushort_ptr(gsl_matrix_ushort * m, const size_t i, const size_t j);
0270 INLINE_DECL const unsigned short * gsl_matrix_ushort_const_ptr(const gsl_matrix_ushort * m, const size_t i, const size_t j);
0271 
0272 #ifdef HAVE_INLINE
0273 INLINE_FUN 
0274 unsigned short
0275 gsl_matrix_ushort_get(const gsl_matrix_ushort * m, const size_t i, const size_t j)
0276 {
0277 #if GSL_RANGE_CHECK
0278   if (GSL_RANGE_COND(1)) 
0279     {
0280       if (i >= m->size1)
0281         {
0282           GSL_ERROR_VAL("first index out of range", GSL_EINVAL, 0) ;
0283         }
0284       else if (j >= m->size2)
0285         {
0286           GSL_ERROR_VAL("second index out of range", GSL_EINVAL, 0) ;
0287         }
0288     }
0289 #endif
0290   return m->data[i * m->tda + j] ;
0291 } 
0292 
0293 INLINE_FUN 
0294 void
0295 gsl_matrix_ushort_set(gsl_matrix_ushort * m, const size_t i, const size_t j, const unsigned short x)
0296 {
0297 #if GSL_RANGE_CHECK
0298   if (GSL_RANGE_COND(1)) 
0299     {
0300       if (i >= m->size1)
0301         {
0302           GSL_ERROR_VOID("first index out of range", GSL_EINVAL) ;
0303         }
0304       else if (j >= m->size2)
0305         {
0306           GSL_ERROR_VOID("second index out of range", GSL_EINVAL) ;
0307         }
0308     }
0309 #endif
0310   m->data[i * m->tda + j] = x ;
0311 }
0312 
0313 INLINE_FUN 
0314 unsigned short *
0315 gsl_matrix_ushort_ptr(gsl_matrix_ushort * m, const size_t i, const size_t j)
0316 {
0317 #if GSL_RANGE_CHECK
0318   if (GSL_RANGE_COND(1)) 
0319     {
0320       if (i >= m->size1)
0321         {
0322           GSL_ERROR_NULL("first index out of range", GSL_EINVAL) ;
0323         }
0324       else if (j >= m->size2)
0325         {
0326           GSL_ERROR_NULL("second index out of range", GSL_EINVAL) ;
0327         }
0328     }
0329 #endif
0330   return (unsigned short *) (m->data + (i * m->tda + j)) ;
0331 } 
0332 
0333 INLINE_FUN 
0334 const unsigned short *
0335 gsl_matrix_ushort_const_ptr(const gsl_matrix_ushort * m, const size_t i, const size_t j)
0336 {
0337 #if GSL_RANGE_CHECK
0338   if (GSL_RANGE_COND(1)) 
0339     {
0340       if (i >= m->size1)
0341         {
0342           GSL_ERROR_NULL("first index out of range", GSL_EINVAL) ;
0343         }
0344       else if (j >= m->size2)
0345         {
0346           GSL_ERROR_NULL("second index out of range", GSL_EINVAL) ;
0347         }
0348     }
0349 #endif
0350   return (const unsigned short *) (m->data + (i * m->tda + j)) ;
0351 } 
0352 
0353 #endif
0354 
0355 __END_DECLS
0356 
0357 #endif /* __GSL_MATRIX_USHORT_H__ */