1 /* vector/gsl_vector_short.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_VECTOR_SHORT_H__
21 #define __GSL_VECTOR_SHORT_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_block_short.h>
33 # define __BEGIN_DECLS extern "C" {
34 # define __END_DECLS }
36 # define __BEGIN_DECLS /* empty */
37 # define __END_DECLS /* empty */
47 gsl_block_short *block;
54 gsl_vector_short vector;
55 } _gsl_vector_short_view;
57 typedef _gsl_vector_short_view gsl_vector_short_view;
61 gsl_vector_short vector;
62 } _gsl_vector_short_const_view;
64 typedef const _gsl_vector_short_const_view gsl_vector_short_const_view;
69 gsl_vector_short *gsl_vector_short_alloc (const size_t n);
70 gsl_vector_short *gsl_vector_short_calloc (const size_t n);
72 gsl_vector_short *gsl_vector_short_alloc_from_block (gsl_block_short * b,
77 gsl_vector_short *gsl_vector_short_alloc_from_vector (gsl_vector_short * v,
82 void gsl_vector_short_free (gsl_vector_short * v);
86 _gsl_vector_short_view
87 gsl_vector_short_view_array (short *v, size_t n);
89 _gsl_vector_short_view
90 gsl_vector_short_view_array_with_stride (short *base,
94 _gsl_vector_short_const_view
95 gsl_vector_short_const_view_array (const short *v, size_t n);
97 _gsl_vector_short_const_view
98 gsl_vector_short_const_view_array_with_stride (const short *base,
102 _gsl_vector_short_view
103 gsl_vector_short_subvector (gsl_vector_short *v,
107 _gsl_vector_short_view
108 gsl_vector_short_subvector_with_stride (gsl_vector_short *v,
113 _gsl_vector_short_const_view
114 gsl_vector_short_const_subvector (const gsl_vector_short *v,
118 _gsl_vector_short_const_view
119 gsl_vector_short_const_subvector_with_stride (const gsl_vector_short *v,
126 void gsl_vector_short_set_zero (gsl_vector_short * v);
127 void gsl_vector_short_set_all (gsl_vector_short * v, short x);
128 int gsl_vector_short_set_basis (gsl_vector_short * v, size_t i);
130 int gsl_vector_short_fread (FILE * stream, gsl_vector_short * v);
131 int gsl_vector_short_fwrite (FILE * stream, const gsl_vector_short * v);
132 int gsl_vector_short_fscanf (FILE * stream, gsl_vector_short * v);
133 int gsl_vector_short_fprintf (FILE * stream, const gsl_vector_short * v,
136 int gsl_vector_short_memcpy (gsl_vector_short * dest, const gsl_vector_short * src);
138 int gsl_vector_short_reverse (gsl_vector_short * v);
140 int gsl_vector_short_swap (gsl_vector_short * v, gsl_vector_short * w);
141 int gsl_vector_short_swap_elements (gsl_vector_short * v, const size_t i, const size_t j);
143 short gsl_vector_short_max (const gsl_vector_short * v);
144 short gsl_vector_short_min (const gsl_vector_short * v);
145 void gsl_vector_short_minmax (const gsl_vector_short * v, short * min_out, short * max_out);
147 size_t gsl_vector_short_max_index (const gsl_vector_short * v);
148 size_t gsl_vector_short_min_index (const gsl_vector_short * v);
149 void gsl_vector_short_minmax_index (const gsl_vector_short * v, size_t * imin, size_t * imax);
151 int gsl_vector_short_add (gsl_vector_short * a, const gsl_vector_short * b);
152 int gsl_vector_short_sub (gsl_vector_short * a, const gsl_vector_short * b);
153 int gsl_vector_short_mul (gsl_vector_short * a, const gsl_vector_short * b);
154 int gsl_vector_short_div (gsl_vector_short * a, const gsl_vector_short * b);
155 int gsl_vector_short_scale (gsl_vector_short * a, const double x);
156 int gsl_vector_short_add_constant (gsl_vector_short * a, const double x);
158 int gsl_vector_short_equal (const gsl_vector_short * u,
159 const gsl_vector_short * v);
161 int gsl_vector_short_isnull (const gsl_vector_short * v);
162 int gsl_vector_short_ispos (const gsl_vector_short * v);
163 int gsl_vector_short_isneg (const gsl_vector_short * v);
164 int gsl_vector_short_isnonneg (const gsl_vector_short * v);
166 INLINE_DECL short gsl_vector_short_get (const gsl_vector_short * v, const size_t i);
167 INLINE_DECL void gsl_vector_short_set (gsl_vector_short * v, const size_t i, short x);
168 INLINE_DECL short * gsl_vector_short_ptr (gsl_vector_short * v, const size_t i);
169 INLINE_DECL const short * gsl_vector_short_const_ptr (const gsl_vector_short * v, const size_t i);
175 gsl_vector_short_get (const gsl_vector_short * v, const size_t i)
178 if (GSL_RANGE_COND(i >= v->size))
180 GSL_ERROR_VAL ("index out of range", GSL_EINVAL, 0);
183 return v->data[i * v->stride];
188 gsl_vector_short_set (gsl_vector_short * v, const size_t i, short x)
191 if (GSL_RANGE_COND(i >= v->size))
193 GSL_ERROR_VOID ("index out of range", GSL_EINVAL);
196 v->data[i * v->stride] = x;
201 gsl_vector_short_ptr (gsl_vector_short * v, const size_t i)
204 if (GSL_RANGE_COND(i >= v->size))
206 GSL_ERROR_NULL ("index out of range", GSL_EINVAL);
209 return (short *) (v->data + i * v->stride);
214 gsl_vector_short_const_ptr (const gsl_vector_short * v, const size_t i)
217 if (GSL_RANGE_COND(i >= v->size))
219 GSL_ERROR_NULL ("index out of range", GSL_EINVAL);
222 return (const short *) (v->data + i * v->stride);
224 #endif /* HAVE_INLINE */
228 #endif /* __GSL_VECTOR_SHORT_H__ */