1/* vector/gsl_vector_complex_float.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_COMPLEX_FLOAT_H__
21#define __GSL_VECTOR_COMPLEX_FLOAT_H__
22
23#include <stdlib.h>
24#include <gsl/gsl_types.h>
25#include <gsl/gsl_errno.h>
26#include <gsl/gsl_complex.h>
27#include <gsl/gsl_check_range.h>
28#include <gsl/gsl_vector_float.h>
29#include <gsl/gsl_vector_complex.h>
30#include <gsl/gsl_block_complex_float.h>
31
32#undef __BEGIN_DECLS
33#undef __END_DECLS
34#ifdef __cplusplus
35# define __BEGIN_DECLS extern "C" {
36# define __END_DECLS }
37#else
38# define __BEGIN_DECLS /* empty */
39# define __END_DECLS /* empty */
40#endif
41
42__BEGIN_DECLS
43
44typedef struct
45{
46 size_t size;
47 size_t stride;
48 float *data;
49 gsl_block_complex_float *block;
50 int owner;
51} gsl_vector_complex_float;
52
53typedef struct
54{
55 gsl_vector_complex_float vector;
56} _gsl_vector_complex_float_view;
57
58typedef _gsl_vector_complex_float_view gsl_vector_complex_float_view;
59
60typedef struct
61{
62 gsl_vector_complex_float vector;
63} _gsl_vector_complex_float_const_view;
64
65typedef const _gsl_vector_complex_float_const_view gsl_vector_complex_float_const_view;
66
67/* Allocation */
68
69gsl_vector_complex_float *gsl_vector_complex_float_alloc (const size_t n);
70gsl_vector_complex_float *gsl_vector_complex_float_calloc (const size_t n);
71
72gsl_vector_complex_float *
73gsl_vector_complex_float_alloc_from_block (gsl_block_complex_float * b,
74 const size_t offset,
75 const size_t n,
76 const size_t stride);
77
78gsl_vector_complex_float *
79gsl_vector_complex_float_alloc_from_vector (gsl_vector_complex_float * v,
80 const size_t offset,
81 const size_t n,
82 const size_t stride);
83
84void gsl_vector_complex_float_free (gsl_vector_complex_float * v);
85
86/* Views */
87
88_gsl_vector_complex_float_view
89gsl_vector_complex_float_view_array (float *base,
90 size_t n);
91
92_gsl_vector_complex_float_view
93gsl_vector_complex_float_view_array_with_stride (float *base,
94 size_t stride,
95 size_t n);
96
97_gsl_vector_complex_float_const_view
98gsl_vector_complex_float_const_view_array (const float *base,
99 size_t n);
100
101_gsl_vector_complex_float_const_view
102gsl_vector_complex_float_const_view_array_with_stride (const float *base,
103 size_t stride,
104 size_t n);
105
106_gsl_vector_complex_float_view
107gsl_vector_complex_float_subvector (gsl_vector_complex_float *base,
108 size_t i,
109 size_t n);
110
111
112_gsl_vector_complex_float_view
113gsl_vector_complex_float_subvector_with_stride (gsl_vector_complex_float *v,
114 size_t i,
115 size_t stride,
116 size_t n);
117
118_gsl_vector_complex_float_const_view
119gsl_vector_complex_float_const_subvector (const gsl_vector_complex_float *base,
120 size_t i,
121 size_t n);
122
123
124_gsl_vector_complex_float_const_view
125gsl_vector_complex_float_const_subvector_with_stride (const gsl_vector_complex_float *v,
126 size_t i,
127 size_t stride,
128 size_t n);
129
130_gsl_vector_float_view
131gsl_vector_complex_float_real (gsl_vector_complex_float *v);
132
133_gsl_vector_float_view
134gsl_vector_complex_float_imag (gsl_vector_complex_float *v);
135
136_gsl_vector_float_const_view
137gsl_vector_complex_float_const_real (const gsl_vector_complex_float *v);
138
139_gsl_vector_float_const_view
140gsl_vector_complex_float_const_imag (const gsl_vector_complex_float *v);
141
142
143/* Operations */
144
145void gsl_vector_complex_float_set_zero (gsl_vector_complex_float * v);
146void gsl_vector_complex_float_set_all (gsl_vector_complex_float * v,
147 gsl_complex_float z);
148int gsl_vector_complex_float_set_basis (gsl_vector_complex_float * v, size_t i);
149
150int gsl_vector_complex_float_fread (FILE * stream,
151 gsl_vector_complex_float * v);
152int gsl_vector_complex_float_fwrite (FILE * stream,
153 const gsl_vector_complex_float * v);
154int gsl_vector_complex_float_fscanf (FILE * stream,
155 gsl_vector_complex_float * v);
156int gsl_vector_complex_float_fprintf (FILE * stream,
157 const gsl_vector_complex_float * v,
158 const char *format);
159
160int gsl_vector_complex_float_memcpy (gsl_vector_complex_float * dest, const gsl_vector_complex_float * src);
161
162int gsl_vector_complex_float_reverse (gsl_vector_complex_float * v);
163
164int gsl_vector_complex_float_swap (gsl_vector_complex_float * v, gsl_vector_complex_float * w);
165int gsl_vector_complex_float_swap_elements (gsl_vector_complex_float * v, const size_t i, const size_t j);
166
167int gsl_vector_complex_float_equal (const gsl_vector_complex_float * u,
168 const gsl_vector_complex_float * v);
169
170int gsl_vector_complex_float_isnull (const gsl_vector_complex_float * v);
171int gsl_vector_complex_float_ispos (const gsl_vector_complex_float * v);
172int gsl_vector_complex_float_isneg (const gsl_vector_complex_float * v);
173int gsl_vector_complex_float_isnonneg (const gsl_vector_complex_float * v);
174
175int gsl_vector_complex_float_add (gsl_vector_complex_float * a, const gsl_vector_complex_float * b);
176int gsl_vector_complex_float_sub (gsl_vector_complex_float * a, const gsl_vector_complex_float * b);
177int gsl_vector_complex_float_mul (gsl_vector_complex_float * a, const gsl_vector_complex_float * b);
178int gsl_vector_complex_float_div (gsl_vector_complex_float * a, const gsl_vector_complex_float * b);
179int gsl_vector_complex_float_scale (gsl_vector_complex_float * a, const gsl_complex_float x);
180int gsl_vector_complex_float_add_constant (gsl_vector_complex_float * a, const gsl_complex_float x);
181int gsl_vector_complex_float_axpby (const gsl_complex_float alpha, const gsl_vector_complex_float * x, const gsl_complex_float beta, gsl_vector_complex_float * y);
182
183INLINE_DECL gsl_complex_float gsl_vector_complex_float_get (const gsl_vector_complex_float * v, const size_t i);
184INLINE_DECL void gsl_vector_complex_float_set (gsl_vector_complex_float * v, const size_t i, gsl_complex_float z);
185INLINE_DECL gsl_complex_float *gsl_vector_complex_float_ptr (gsl_vector_complex_float * v, const size_t i);
186INLINE_DECL const gsl_complex_float *gsl_vector_complex_float_const_ptr (const gsl_vector_complex_float * v, const size_t i);
187
188#ifdef HAVE_INLINE
189
190INLINE_FUN
191gsl_complex_float
192gsl_vector_complex_float_get (const gsl_vector_complex_float * v,
193 const size_t i)
194{
195#if GSL_RANGE_CHECK
196 if (GSL_RANGE_COND(i >= v->size))
197 {
198 gsl_complex_float zero = {{0, 0}};
199 GSL_ERROR_VAL ("index out of range", GSL_EINVAL, zero);
200 }
201#endif
202 return *GSL_COMPLEX_FLOAT_AT (v, i);
203}
204
205INLINE_FUN
206void
207gsl_vector_complex_float_set (gsl_vector_complex_float * v,
208 const size_t i, gsl_complex_float z)
209{
210#if GSL_RANGE_CHECK
211 if (GSL_RANGE_COND(i >= v->size))
212 {
213 GSL_ERROR_VOID ("index out of range", GSL_EINVAL);
214 }
215#endif
216 *GSL_COMPLEX_FLOAT_AT (v, i) = z;
217}
218
219INLINE_FUN
220gsl_complex_float *
221gsl_vector_complex_float_ptr (gsl_vector_complex_float * v,
222 const size_t i)
223{
224#if GSL_RANGE_CHECK
225 if (GSL_RANGE_COND(i >= v->size))
226 {
227 GSL_ERROR_NULL ("index out of range", GSL_EINVAL);
228 }
229#endif
230 return GSL_COMPLEX_FLOAT_AT (v, i);
231}
232
233INLINE_FUN
234const gsl_complex_float *
235gsl_vector_complex_float_const_ptr (const gsl_vector_complex_float * v,
236 const size_t i)
237{
238#if GSL_RANGE_CHECK
239 if (GSL_RANGE_COND(i >= v->size))
240 {
241 GSL_ERROR_NULL ("index out of range", GSL_EINVAL);
242 }
243#endif
244 return GSL_COMPLEX_FLOAT_AT (v, i);
245}
246
247
248#endif /* HAVE_INLINE */
249
250__END_DECLS
251
252#endif /* __GSL_VECTOR_COMPLEX_FLOAT_H__ */
253