PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/gsl/gsl_matrix_uchar.h

https://github.com/mantidproject/3rdpartyincludes
C Header | 358 lines | 268 code | 64 blank | 26 comment | 17 complexity | 9e9cc824713260b9a463a24b22d6347a MD5 | raw file
  1. /* matrix/gsl_matrix_uchar.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_MATRIX_UCHAR_H__
  20. #define __GSL_MATRIX_UCHAR_H__
  21. #if !defined( GSL_FUN )
  22. # if !defined( GSL_DLL )
  23. # define GSL_FUN extern
  24. # elif defined( BUILD_GSL_DLL )
  25. # define GSL_FUN extern __declspec(dllexport)
  26. # else
  27. # define GSL_FUN extern __declspec(dllimport)
  28. # endif
  29. #endif
  30. #include <stdlib.h>
  31. #include <gsl/gsl_types.h>
  32. #include <gsl/gsl_errno.h>
  33. #include <gsl/gsl_inline.h>
  34. #include <gsl/gsl_check_range.h>
  35. #include <gsl/gsl_vector_uchar.h>
  36. #undef __BEGIN_DECLS
  37. #undef __END_DECLS
  38. #ifdef __cplusplus
  39. # define __BEGIN_DECLS extern "C" {
  40. # define __END_DECLS }
  41. #else
  42. # define __BEGIN_DECLS /* empty */
  43. # define __END_DECLS /* empty */
  44. #endif
  45. __BEGIN_DECLS
  46. typedef struct
  47. {
  48. size_t size1;
  49. size_t size2;
  50. size_t tda;
  51. unsigned char * data;
  52. gsl_block_uchar * block;
  53. int owner;
  54. } gsl_matrix_uchar;
  55. typedef struct
  56. {
  57. gsl_matrix_uchar matrix;
  58. } _gsl_matrix_uchar_view;
  59. typedef _gsl_matrix_uchar_view gsl_matrix_uchar_view;
  60. typedef struct
  61. {
  62. gsl_matrix_uchar matrix;
  63. } _gsl_matrix_uchar_const_view;
  64. typedef const _gsl_matrix_uchar_const_view gsl_matrix_uchar_const_view;
  65. /* Allocation */
  66. GSL_FUN gsl_matrix_uchar *
  67. gsl_matrix_uchar_alloc (const size_t n1, const size_t n2);
  68. GSL_FUN gsl_matrix_uchar *
  69. gsl_matrix_uchar_calloc (const size_t n1, const size_t n2);
  70. GSL_FUN gsl_matrix_uchar *
  71. gsl_matrix_uchar_alloc_from_block (gsl_block_uchar * b,
  72. const size_t offset,
  73. const size_t n1,
  74. const size_t n2,
  75. const size_t d2);
  76. GSL_FUN gsl_matrix_uchar *
  77. gsl_matrix_uchar_alloc_from_matrix (gsl_matrix_uchar * m,
  78. const size_t k1,
  79. const size_t k2,
  80. const size_t n1,
  81. const size_t n2);
  82. GSL_FUN gsl_vector_uchar *
  83. gsl_vector_uchar_alloc_row_from_matrix (gsl_matrix_uchar * m,
  84. const size_t i);
  85. GSL_FUN gsl_vector_uchar *
  86. gsl_vector_uchar_alloc_col_from_matrix (gsl_matrix_uchar * m,
  87. const size_t j);
  88. GSL_FUN void gsl_matrix_uchar_free (gsl_matrix_uchar * m);
  89. /* Views */
  90. GSL_FUN _gsl_matrix_uchar_view
  91. gsl_matrix_uchar_submatrix (gsl_matrix_uchar * m,
  92. const size_t i, const size_t j,
  93. const size_t n1, const size_t n2);
  94. GSL_FUN _gsl_vector_uchar_view
  95. gsl_matrix_uchar_row (gsl_matrix_uchar * m, const size_t i);
  96. GSL_FUN _gsl_vector_uchar_view
  97. gsl_matrix_uchar_column (gsl_matrix_uchar * m, const size_t j);
  98. GSL_FUN _gsl_vector_uchar_view
  99. gsl_matrix_uchar_diagonal (gsl_matrix_uchar * m);
  100. GSL_FUN _gsl_vector_uchar_view
  101. gsl_matrix_uchar_subdiagonal (gsl_matrix_uchar * m, const size_t k);
  102. GSL_FUN _gsl_vector_uchar_view
  103. gsl_matrix_uchar_superdiagonal (gsl_matrix_uchar * m, const size_t k);
  104. GSL_FUN _gsl_vector_uchar_view
  105. gsl_matrix_uchar_subrow (gsl_matrix_uchar * m, const size_t i,
  106. const size_t offset, const size_t n);
  107. GSL_FUN _gsl_vector_uchar_view
  108. gsl_matrix_uchar_subcolumn (gsl_matrix_uchar * m, const size_t j,
  109. const size_t offset, const size_t n);
  110. GSL_FUN _gsl_matrix_uchar_view
  111. gsl_matrix_uchar_view_array (unsigned char * base,
  112. const size_t n1,
  113. const size_t n2);
  114. GSL_FUN _gsl_matrix_uchar_view
  115. gsl_matrix_uchar_view_array_with_tda (unsigned char * base,
  116. const size_t n1,
  117. const size_t n2,
  118. const size_t tda);
  119. GSL_FUN _gsl_matrix_uchar_view
  120. gsl_matrix_uchar_view_vector (gsl_vector_uchar * v,
  121. const size_t n1,
  122. const size_t n2);
  123. GSL_FUN _gsl_matrix_uchar_view
  124. gsl_matrix_uchar_view_vector_with_tda (gsl_vector_uchar * v,
  125. const size_t n1,
  126. const size_t n2,
  127. const size_t tda);
  128. GSL_FUN _gsl_matrix_uchar_const_view
  129. gsl_matrix_uchar_const_submatrix (const gsl_matrix_uchar * m,
  130. const size_t i, const size_t j,
  131. const size_t n1, const size_t n2);
  132. GSL_FUN _gsl_vector_uchar_const_view
  133. gsl_matrix_uchar_const_row (const gsl_matrix_uchar * m,
  134. const size_t i);
  135. GSL_FUN _gsl_vector_uchar_const_view
  136. gsl_matrix_uchar_const_column (const gsl_matrix_uchar * m,
  137. const size_t j);
  138. GSL_FUN _gsl_vector_uchar_const_view
  139. gsl_matrix_uchar_const_diagonal (const gsl_matrix_uchar * m);
  140. GSL_FUN _gsl_vector_uchar_const_view
  141. gsl_matrix_uchar_const_subdiagonal (const gsl_matrix_uchar * m,
  142. const size_t k);
  143. GSL_FUN _gsl_vector_uchar_const_view
  144. gsl_matrix_uchar_const_superdiagonal (const gsl_matrix_uchar * m,
  145. const size_t k);
  146. GSL_FUN _gsl_vector_uchar_const_view
  147. gsl_matrix_uchar_const_subrow (const gsl_matrix_uchar * m, const size_t i,
  148. const size_t offset, const size_t n);
  149. GSL_FUN _gsl_vector_uchar_const_view
  150. gsl_matrix_uchar_const_subcolumn (const gsl_matrix_uchar * m, const size_t j,
  151. const size_t offset, const size_t n);
  152. GSL_FUN _gsl_matrix_uchar_const_view
  153. gsl_matrix_uchar_const_view_array (const unsigned char * base,
  154. const size_t n1,
  155. const size_t n2);
  156. GSL_FUN _gsl_matrix_uchar_const_view
  157. gsl_matrix_uchar_const_view_array_with_tda (const unsigned char * base,
  158. const size_t n1,
  159. const size_t n2,
  160. const size_t tda);
  161. GSL_FUN _gsl_matrix_uchar_const_view
  162. gsl_matrix_uchar_const_view_vector (const gsl_vector_uchar * v,
  163. const size_t n1,
  164. const size_t n2);
  165. GSL_FUN _gsl_matrix_uchar_const_view
  166. gsl_matrix_uchar_const_view_vector_with_tda (const gsl_vector_uchar * v,
  167. const size_t n1,
  168. const size_t n2,
  169. const size_t tda);
  170. /* Operations */
  171. GSL_FUN void gsl_matrix_uchar_set_zero (gsl_matrix_uchar * m);
  172. GSL_FUN void gsl_matrix_uchar_set_identity (gsl_matrix_uchar * m);
  173. GSL_FUN void gsl_matrix_uchar_set_all (gsl_matrix_uchar * m, unsigned char x);
  174. GSL_FUN int gsl_matrix_uchar_fread (FILE * stream, gsl_matrix_uchar * m) ;
  175. GSL_FUN int gsl_matrix_uchar_fwrite (FILE * stream, const gsl_matrix_uchar * m) ;
  176. GSL_FUN int gsl_matrix_uchar_fscanf (FILE * stream, gsl_matrix_uchar * m);
  177. GSL_FUN int gsl_matrix_uchar_fprintf (FILE * stream, const gsl_matrix_uchar * m, const char * format);
  178. GSL_FUN int gsl_matrix_uchar_memcpy(gsl_matrix_uchar * dest, const gsl_matrix_uchar * src);
  179. GSL_FUN int gsl_matrix_uchar_swap(gsl_matrix_uchar * m1, gsl_matrix_uchar * m2);
  180. GSL_FUN int gsl_matrix_uchar_swap_rows(gsl_matrix_uchar * m, const size_t i, const size_t j);
  181. GSL_FUN int gsl_matrix_uchar_swap_columns(gsl_matrix_uchar * m, const size_t i, const size_t j);
  182. GSL_FUN int gsl_matrix_uchar_swap_rowcol(gsl_matrix_uchar * m, const size_t i, const size_t j);
  183. GSL_FUN int gsl_matrix_uchar_transpose (gsl_matrix_uchar * m);
  184. GSL_FUN int gsl_matrix_uchar_transpose_memcpy (gsl_matrix_uchar * dest, const gsl_matrix_uchar * src);
  185. GSL_FUN unsigned char gsl_matrix_uchar_max (const gsl_matrix_uchar * m);
  186. GSL_FUN unsigned char gsl_matrix_uchar_min (const gsl_matrix_uchar * m);
  187. GSL_FUN void gsl_matrix_uchar_minmax (const gsl_matrix_uchar * m, unsigned char * min_out, unsigned char * max_out);
  188. GSL_FUN void gsl_matrix_uchar_max_index (const gsl_matrix_uchar * m, size_t * imax, size_t *jmax);
  189. GSL_FUN void gsl_matrix_uchar_min_index (const gsl_matrix_uchar * m, size_t * imin, size_t *jmin);
  190. GSL_FUN void gsl_matrix_uchar_minmax_index (const gsl_matrix_uchar * m, size_t * imin, size_t * jmin, size_t * imax, size_t * jmax);
  191. GSL_FUN int gsl_matrix_uchar_isnull (const gsl_matrix_uchar * m);
  192. GSL_FUN int gsl_matrix_uchar_ispos (const gsl_matrix_uchar * m);
  193. GSL_FUN int gsl_matrix_uchar_isneg (const gsl_matrix_uchar * m);
  194. GSL_FUN int gsl_matrix_uchar_isnonneg (const gsl_matrix_uchar * m);
  195. GSL_FUN int gsl_matrix_uchar_add (gsl_matrix_uchar * a, const gsl_matrix_uchar * b);
  196. GSL_FUN int gsl_matrix_uchar_sub (gsl_matrix_uchar * a, const gsl_matrix_uchar * b);
  197. GSL_FUN int gsl_matrix_uchar_mul_elements (gsl_matrix_uchar * a, const gsl_matrix_uchar * b);
  198. GSL_FUN int gsl_matrix_uchar_div_elements (gsl_matrix_uchar * a, const gsl_matrix_uchar * b);
  199. GSL_FUN int gsl_matrix_uchar_scale (gsl_matrix_uchar * a, const double x);
  200. GSL_FUN int gsl_matrix_uchar_add_constant (gsl_matrix_uchar * a, const double x);
  201. GSL_FUN int gsl_matrix_uchar_add_diagonal (gsl_matrix_uchar * a, const double x);
  202. /***********************************************************************/
  203. /* The functions below are obsolete */
  204. /***********************************************************************/
  205. GSL_FUN int gsl_matrix_uchar_get_row(gsl_vector_uchar * v, const gsl_matrix_uchar * m, const size_t i);
  206. GSL_FUN int gsl_matrix_uchar_get_col(gsl_vector_uchar * v, const gsl_matrix_uchar * m, const size_t j);
  207. GSL_FUN int gsl_matrix_uchar_set_row(gsl_matrix_uchar * m, const size_t i, const gsl_vector_uchar * v);
  208. GSL_FUN int gsl_matrix_uchar_set_col(gsl_matrix_uchar * m, const size_t j, const gsl_vector_uchar * v);
  209. /***********************************************************************/
  210. /* inline functions if you are using GCC */
  211. GSL_FUN INLINE_DECL unsigned char gsl_matrix_uchar_get(const gsl_matrix_uchar * m, const size_t i, const size_t j);
  212. GSL_FUN INLINE_DECL void gsl_matrix_uchar_set(gsl_matrix_uchar * m, const size_t i, const size_t j, const unsigned char x);
  213. GSL_FUN INLINE_DECL unsigned char * gsl_matrix_uchar_ptr(gsl_matrix_uchar * m, const size_t i, const size_t j);
  214. GSL_FUN INLINE_DECL const unsigned char * gsl_matrix_uchar_const_ptr(const gsl_matrix_uchar * m, const size_t i, const size_t j);
  215. #ifdef HAVE_INLINE
  216. INLINE_FUN
  217. unsigned char
  218. gsl_matrix_uchar_get(const gsl_matrix_uchar * m, const size_t i, const size_t j)
  219. {
  220. #if GSL_RANGE_CHECK
  221. if (GSL_RANGE_COND(1))
  222. {
  223. if (i >= m->size1)
  224. {
  225. GSL_ERROR_VAL("first index out of range", GSL_EINVAL, 0) ;
  226. }
  227. else if (j >= m->size2)
  228. {
  229. GSL_ERROR_VAL("second index out of range", GSL_EINVAL, 0) ;
  230. }
  231. }
  232. #endif
  233. return m->data[i * m->tda + j] ;
  234. }
  235. INLINE_FUN
  236. void
  237. gsl_matrix_uchar_set(gsl_matrix_uchar * m, const size_t i, const size_t j, const unsigned char x)
  238. {
  239. #if GSL_RANGE_CHECK
  240. if (GSL_RANGE_COND(1))
  241. {
  242. if (i >= m->size1)
  243. {
  244. GSL_ERROR_VOID("first index out of range", GSL_EINVAL) ;
  245. }
  246. else if (j >= m->size2)
  247. {
  248. GSL_ERROR_VOID("second index out of range", GSL_EINVAL) ;
  249. }
  250. }
  251. #endif
  252. m->data[i * m->tda + j] = x ;
  253. }
  254. INLINE_FUN
  255. unsigned char *
  256. gsl_matrix_uchar_ptr(gsl_matrix_uchar * m, const size_t i, const size_t j)
  257. {
  258. #if GSL_RANGE_CHECK
  259. if (GSL_RANGE_COND(1))
  260. {
  261. if (i >= m->size1)
  262. {
  263. GSL_ERROR_NULL("first index out of range", GSL_EINVAL) ;
  264. }
  265. else if (j >= m->size2)
  266. {
  267. GSL_ERROR_NULL("second index out of range", GSL_EINVAL) ;
  268. }
  269. }
  270. #endif
  271. return (unsigned char *) (m->data + (i * m->tda + j)) ;
  272. }
  273. INLINE_FUN
  274. const unsigned char *
  275. gsl_matrix_uchar_const_ptr(const gsl_matrix_uchar * m, const size_t i, const size_t j)
  276. {
  277. #if GSL_RANGE_CHECK
  278. if (GSL_RANGE_COND(1))
  279. {
  280. if (i >= m->size1)
  281. {
  282. GSL_ERROR_NULL("first index out of range", GSL_EINVAL) ;
  283. }
  284. else if (j >= m->size2)
  285. {
  286. GSL_ERROR_NULL("second index out of range", GSL_EINVAL) ;
  287. }
  288. }
  289. #endif
  290. return (const unsigned char *) (m->data + (i * m->tda + j)) ;
  291. }
  292. #endif
  293. __END_DECLS
  294. #endif /* __GSL_MATRIX_UCHAR_H__ */