gsl_vector_float.h 7.1 KB

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