1/* vector/gsl_vector_ushort.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_VECTOR_USHORT_H__
21#define __GSL_VECTOR_USHORT_H__
22
23#include <stdlib.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_ushort.h>
29
30#undef __BEGIN_DECLS
31#undef __END_DECLS
32#ifdef __cplusplus
33# define __BEGIN_DECLS extern "C" {
34# define __END_DECLS }
35#else
36# define __BEGIN_DECLS /* empty */
37# define __END_DECLS /* empty */
38#endif
39
40__BEGIN_DECLS
41
42typedef struct
43{
44 size_t size;
45 size_t stride;
46 unsigned short *data;
47 gsl_block_ushort *block;
48 int owner;
49}
50gsl_vector_ushort;
51
52typedef struct
53{
54 gsl_vector_ushort vector;
55} _gsl_vector_ushort_view;
56
57typedef _gsl_vector_ushort_view gsl_vector_ushort_view;
58
59typedef struct
60{
61 gsl_vector_ushort vector;
62} _gsl_vector_ushort_const_view;
63
64typedef const _gsl_vector_ushort_const_view gsl_vector_ushort_const_view;
65
66
67/* Allocation */
68
69gsl_vector_ushort *gsl_vector_ushort_alloc (const size_t n);
70gsl_vector_ushort *gsl_vector_ushort_calloc (const size_t n);
71
72gsl_vector_ushort *gsl_vector_ushort_alloc_from_block (gsl_block_ushort * b,
73 const size_t offset,
74 const size_t n,
75 const size_t stride);
76
77gsl_vector_ushort *gsl_vector_ushort_alloc_from_vector (gsl_vector_ushort * v,
78 const size_t offset,
79 const size_t n,
80 const size_t stride);
81
82void gsl_vector_ushort_free (gsl_vector_ushort * v);
83
84/* Views */
85
86_gsl_vector_ushort_view
87gsl_vector_ushort_view_array (unsigned short *v, size_t n);
88
89_gsl_vector_ushort_view
90gsl_vector_ushort_view_array_with_stride (unsigned short *base,
91 size_t stride,
92 size_t n);
93
94_gsl_vector_ushort_const_view
95gsl_vector_ushort_const_view_array (const unsigned short *v, size_t n);
96
97_gsl_vector_ushort_const_view
98gsl_vector_ushort_const_view_array_with_stride (const unsigned short *base,
99 size_t stride,
100 size_t n);
101
102_gsl_vector_ushort_view
103gsl_vector_ushort_subvector (gsl_vector_ushort *v,
104 size_t i,
105 size_t n);
106
107_gsl_vector_ushort_view
108gsl_vector_ushort_subvector_with_stride (gsl_vector_ushort *v,
109 size_t i,
110 size_t stride,
111 size_t n);
112
113_gsl_vector_ushort_const_view
114gsl_vector_ushort_const_subvector (const gsl_vector_ushort *v,
115 size_t i,
116 size_t n);
117
118_gsl_vector_ushort_const_view
119gsl_vector_ushort_const_subvector_with_stride (const gsl_vector_ushort *v,
120 size_t i,
121 size_t stride,
122 size_t n);
123
124/* Operations */
125
126void gsl_vector_ushort_set_zero (gsl_vector_ushort * v);
127void gsl_vector_ushort_set_all (gsl_vector_ushort * v, unsigned short x);
128int gsl_vector_ushort_set_basis (gsl_vector_ushort * v, size_t i);
129
130int gsl_vector_ushort_fread (FILE * stream, gsl_vector_ushort * v);
131int gsl_vector_ushort_fwrite (FILE * stream, const gsl_vector_ushort * v);
132int gsl_vector_ushort_fscanf (FILE * stream, gsl_vector_ushort * v);
133int gsl_vector_ushort_fprintf (FILE * stream, const gsl_vector_ushort * v,
134 const char *format);
135
136int gsl_vector_ushort_memcpy (gsl_vector_ushort * dest, const gsl_vector_ushort * src);
137
138int gsl_vector_ushort_reverse (gsl_vector_ushort * v);
139
140int gsl_vector_ushort_swap (gsl_vector_ushort * v, gsl_vector_ushort * w);
141int gsl_vector_ushort_swap_elements (gsl_vector_ushort * v, const size_t i, const size_t j);
142
143unsigned short gsl_vector_ushort_max (const gsl_vector_ushort * v);
144unsigned short gsl_vector_ushort_min (const gsl_vector_ushort * v);
145void gsl_vector_ushort_minmax (const gsl_vector_ushort * v, unsigned short * min_out, unsigned short * max_out);
146
147size_t gsl_vector_ushort_max_index (const gsl_vector_ushort * v);
148size_t gsl_vector_ushort_min_index (const gsl_vector_ushort * v);
149void gsl_vector_ushort_minmax_index (const gsl_vector_ushort * v, size_t * imin, size_t * imax);
150
151int gsl_vector_ushort_add (gsl_vector_ushort * a, const gsl_vector_ushort * b);
152int gsl_vector_ushort_sub (gsl_vector_ushort * a, const gsl_vector_ushort * b);
153int gsl_vector_ushort_mul (gsl_vector_ushort * a, const gsl_vector_ushort * b);
154int gsl_vector_ushort_div (gsl_vector_ushort * a, const gsl_vector_ushort * b);
155int gsl_vector_ushort_scale (gsl_vector_ushort * a, const unsigned short x);
156int gsl_vector_ushort_add_constant (gsl_vector_ushort * a, const unsigned short x);
157int gsl_vector_ushort_axpby (const unsigned short alpha, const gsl_vector_ushort * x, const unsigned short beta, gsl_vector_ushort * y);
158unsigned short gsl_vector_ushort_sum (const gsl_vector_ushort * a);
159
160int gsl_vector_ushort_equal (const gsl_vector_ushort * u,
161 const gsl_vector_ushort * v);
162
163int gsl_vector_ushort_isnull (const gsl_vector_ushort * v);
164int gsl_vector_ushort_ispos (const gsl_vector_ushort * v);
165int gsl_vector_ushort_isneg (const gsl_vector_ushort * v);
166int gsl_vector_ushort_isnonneg (const gsl_vector_ushort * v);
167
168INLINE_DECL unsigned short gsl_vector_ushort_get (const gsl_vector_ushort * v, const size_t i);
169INLINE_DECL void gsl_vector_ushort_set (gsl_vector_ushort * v, const size_t i, unsigned short x);
170INLINE_DECL unsigned short * gsl_vector_ushort_ptr (gsl_vector_ushort * v, const size_t i);
171INLINE_DECL const unsigned short * gsl_vector_ushort_const_ptr (const gsl_vector_ushort * v, const size_t i);
172
173#ifdef HAVE_INLINE
174
175INLINE_FUN
176unsigned short
177gsl_vector_ushort_get (const gsl_vector_ushort * v, const size_t i)
178{
179#if GSL_RANGE_CHECK
180 if (GSL_RANGE_COND(i >= v->size))
181 {
182 GSL_ERROR_VAL ("index out of range", GSL_EINVAL, 0);
183 }
184#endif
185 return v->data[i * v->stride];
186}
187
188INLINE_FUN
189void
190gsl_vector_ushort_set (gsl_vector_ushort * v, const size_t i, unsigned short x)
191{
192#if GSL_RANGE_CHECK
193 if (GSL_RANGE_COND(i >= v->size))
194 {
195 GSL_ERROR_VOID ("index out of range", GSL_EINVAL);
196 }
197#endif
198 v->data[i * v->stride] = x;
199}
200
201INLINE_FUN
202unsigned short *
203gsl_vector_ushort_ptr (gsl_vector_ushort * v, const size_t i)
204{
205#if GSL_RANGE_CHECK
206 if (GSL_RANGE_COND(i >= v->size))
207 {
208 GSL_ERROR_NULL ("index out of range", GSL_EINVAL);
209 }
210#endif
211 return (unsigned short *) (v->data + i * v->stride);
212}
213
214INLINE_FUN
215const unsigned short *
216gsl_vector_ushort_const_ptr (const gsl_vector_ushort * v, const size_t i)
217{
218#if GSL_RANGE_CHECK
219 if (GSL_RANGE_COND(i >= v->size))
220 {
221 GSL_ERROR_NULL ("index out of range", GSL_EINVAL);
222 }
223#endif
224 return (const unsigned short *) (v->data + i * v->stride);
225}
226#endif /* HAVE_INLINE */
227
228__END_DECLS
229
230#endif /* __GSL_VECTOR_USHORT_H__ */
231
232
233