| 1 | /* vector/gsl_vector_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_FLOAT_H__ |
| 21 | #define __GSL_VECTOR_FLOAT_H__ |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | #include "gsl_types.h" |
| 25 | #include "gsl_errno.h" |
| 26 | #include "gsl_check_range.h" |
| 27 | #include "gsl_block_float.h" |
| 28 | |
| 29 | #undef __BEGIN_DECLS |
| 30 | #undef __END_DECLS |
| 31 | #ifdef __cplusplus |
| 32 | # define __BEGIN_DECLS extern "C" { |
| 33 | # define __END_DECLS } |
| 34 | #else |
| 35 | # define __BEGIN_DECLS /* empty */ |
| 36 | # define __END_DECLS /* empty */ |
| 37 | #endif |
| 38 | |
| 39 | __BEGIN_DECLS |
| 40 | |
| 41 | typedef struct |
| 42 | { |
| 43 | size_t size; |
| 44 | size_t stride; |
| 45 | float *data; |
| 46 | gsl_block_float *block; |
| 47 | int owner; |
| 48 | } |
| 49 | gsl_vector_float; |
| 50 | |
| 51 | typedef struct |
| 52 | { |
| 53 | gsl_vector_float vector; |
| 54 | } _gsl_vector_float_view; |
| 55 | |
| 56 | typedef _gsl_vector_float_view gsl_vector_float_view; |
| 57 | |
| 58 | typedef struct |
| 59 | { |
| 60 | gsl_vector_float vector; |
| 61 | } _gsl_vector_float_const_view; |
| 62 | |
| 63 | typedef const _gsl_vector_float_const_view gsl_vector_float_const_view; |
| 64 | |
| 65 | |
| 66 | /* Allocation */ |
| 67 | |
| 68 | gsl_vector_float *gsl_vector_float_alloc (const size_t n); |
| 69 | gsl_vector_float *gsl_vector_float_calloc (const size_t n); |
| 70 | |
| 71 | gsl_vector_float *gsl_vector_float_alloc_from_block (gsl_block_float * b, |
| 72 | const size_t offset, |
| 73 | const size_t n, |
| 74 | const size_t stride); |
| 75 | |
| 76 | gsl_vector_float *gsl_vector_float_alloc_from_vector (gsl_vector_float * v, |
| 77 | const size_t offset, |
| 78 | const size_t n, |
| 79 | const size_t stride); |
| 80 | |
| 81 | void gsl_vector_float_free (gsl_vector_float * v); |
| 82 | |
| 83 | /* Views */ |
| 84 | |
| 85 | _gsl_vector_float_view |
| 86 | gsl_vector_float_view_array (float *v, size_t n); |
| 87 | |
| 88 | _gsl_vector_float_view |
| 89 | gsl_vector_float_view_array_with_stride (float *base, |
| 90 | size_t stride, |
| 91 | size_t n); |
| 92 | |
| 93 | _gsl_vector_float_const_view |
| 94 | gsl_vector_float_const_view_array (const float *v, size_t n); |
| 95 | |
| 96 | _gsl_vector_float_const_view |
| 97 | gsl_vector_float_const_view_array_with_stride (const float *base, |
| 98 | size_t stride, |
| 99 | size_t n); |
| 100 | |
| 101 | _gsl_vector_float_view |
| 102 | gsl_vector_float_subvector (gsl_vector_float *v, |
| 103 | size_t i, |
| 104 | size_t n); |
| 105 | |
| 106 | _gsl_vector_float_view |
| 107 | gsl_vector_float_subvector_with_stride (gsl_vector_float *v, |
| 108 | size_t i, |
| 109 | size_t stride, |
| 110 | size_t n); |
| 111 | |
| 112 | _gsl_vector_float_const_view |
| 113 | gsl_vector_float_const_subvector (const gsl_vector_float *v, |
| 114 | size_t i, |
| 115 | size_t n); |
| 116 | |
| 117 | _gsl_vector_float_const_view |
| 118 | gsl_vector_float_const_subvector_with_stride (const gsl_vector_float *v, |
| 119 | size_t i, |
| 120 | size_t stride, |
| 121 | size_t n); |
| 122 | |
| 123 | /* Operations */ |
| 124 | |
| 125 | float gsl_vector_float_get (const gsl_vector_float * v, const size_t i); |
| 126 | void gsl_vector_float_set (gsl_vector_float * v, const size_t i, float x); |
| 127 | |
| 128 | float *gsl_vector_float_ptr (gsl_vector_float * v, const size_t i); |
| 129 | const float *gsl_vector_float_const_ptr (const gsl_vector_float * v, const size_t i); |
| 130 | |
| 131 | void gsl_vector_float_set_zero (gsl_vector_float * v); |
| 132 | void gsl_vector_float_set_all (gsl_vector_float * v, float x); |
| 133 | int gsl_vector_float_set_basis (gsl_vector_float * v, size_t i); |
| 134 | |
| 135 | int gsl_vector_float_fread (FILE * stream, gsl_vector_float * v); |
| 136 | int gsl_vector_float_fwrite (FILE * stream, const gsl_vector_float * v); |
| 137 | int gsl_vector_float_fscanf (FILE * stream, gsl_vector_float * v); |
| 138 | int gsl_vector_float_fprintf (FILE * stream, const gsl_vector_float * v, |
| 139 | const char *format); |
| 140 | |
| 141 | int gsl_vector_float_memcpy (gsl_vector_float * dest, const gsl_vector_float * src); |
| 142 | |
| 143 | int gsl_vector_float_reverse (gsl_vector_float * v); |
| 144 | |
| 145 | int gsl_vector_float_swap (gsl_vector_float * v, gsl_vector_float * w); |
| 146 | int gsl_vector_float_swap_elements (gsl_vector_float * v, const size_t i, const size_t j); |
| 147 | |
| 148 | float gsl_vector_float_max (const gsl_vector_float * v); |
| 149 | float gsl_vector_float_min (const gsl_vector_float * v); |
| 150 | void gsl_vector_float_minmax (const gsl_vector_float * v, float * min_out, float * max_out); |
| 151 | |
| 152 | size_t gsl_vector_float_max_index (const gsl_vector_float * v); |
| 153 | size_t gsl_vector_float_min_index (const gsl_vector_float * v); |
| 154 | void gsl_vector_float_minmax_index (const gsl_vector_float * v, size_t * imin, size_t * imax); |
| 155 | |
| 156 | int gsl_vector_float_add (gsl_vector_float * a, const gsl_vector_float * b); |
| 157 | int gsl_vector_float_sub (gsl_vector_float * a, const gsl_vector_float * b); |
| 158 | int gsl_vector_float_mul (gsl_vector_float * a, const gsl_vector_float * b); |
| 159 | int gsl_vector_float_div (gsl_vector_float * a, const gsl_vector_float * b); |
| 160 | int gsl_vector_float_scale (gsl_vector_float * a, const double x); |
| 161 | int gsl_vector_float_add_constant (gsl_vector_float * a, const double x); |
| 162 | |
| 163 | int gsl_vector_float_isnull (const gsl_vector_float * v); |
| 164 | int gsl_vector_float_ispos (const gsl_vector_float * v); |
| 165 | int gsl_vector_float_isneg (const gsl_vector_float * v); |
| 166 | int gsl_vector_float_isnonneg (const gsl_vector_float * v); |
| 167 | |
| 168 | #ifdef HAVE_INLINE |
| 169 | |
| 170 | extern inline |
| 171 | float |
| 172 | gsl_vector_float_get (const gsl_vector_float * v, const size_t i) |
| 173 | { |
| 174 | #if GSL_RANGE_CHECK |
| 175 | if (i >= v->size) |
| 176 | { |
| 177 | GSL_ERROR_VAL ("index out of range", GSL_EINVAL, 0); |
| 178 | } |
| 179 | #endif |
| 180 | return v->data[i * v->stride]; |
| 181 | } |
| 182 | |
| 183 | extern inline |
| 184 | void |
| 185 | gsl_vector_float_set (gsl_vector_float * v, const size_t i, float x) |
| 186 | { |
| 187 | #if GSL_RANGE_CHECK |
| 188 | if (i >= v->size) |
| 189 | { |
| 190 | GSL_ERROR_VOID ("index out of range", GSL_EINVAL); |
| 191 | } |
| 192 | #endif |
| 193 | v->data[i * v->stride] = x; |
| 194 | } |
| 195 | |
| 196 | extern inline |
| 197 | float * |
| 198 | gsl_vector_float_ptr (gsl_vector_float * v, const size_t i) |
| 199 | { |
| 200 | #if GSL_RANGE_CHECK |
| 201 | if (i >= v->size) |
| 202 | { |
| 203 | GSL_ERROR_NULL ("index out of range", GSL_EINVAL); |
| 204 | } |
| 205 | #endif |
| 206 | return (float *) (v->data + i * v->stride); |
| 207 | } |
| 208 | |
| 209 | extern inline |
| 210 | const float * |
| 211 | gsl_vector_float_const_ptr (const gsl_vector_float * v, const size_t i) |
| 212 | { |
| 213 | #if GSL_RANGE_CHECK |
| 214 | if (i >= v->size) |
| 215 | { |
| 216 | GSL_ERROR_NULL ("index out of range", GSL_EINVAL); |
| 217 | } |
| 218 | #endif |
| 219 | return (const float *) (v->data + i * v->stride); |
| 220 | } |
| 221 | |
| 222 | |
| 223 | #endif /* HAVE_INLINE */ |
| 224 | |
| 225 | __END_DECLS |
| 226 | |
| 227 | #endif /* __GSL_VECTOR_FLOAT_H__ */ |
| 228 | |
| 229 |