gsl_matrix__matrix_source.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* matrix/matrix_source.c
  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 HIDE_INLINE_STATIC
  20. BASE
  21. FUNCTION (gsl_matrix, get) (const TYPE (gsl_matrix) * m,
  22. const size_t i, const size_t j)
  23. {
  24. BASE zero = ZERO;
  25. if (gsl_check_range)
  26. {
  27. if (i >= m->size1) /* size_t is unsigned, can't be negative */
  28. {
  29. GSL_ERROR_VAL ("first index out of range", GSL_EINVAL, zero);
  30. }
  31. else if (j >= m->size2) /* size_t is unsigned, can't be negative */
  32. {
  33. GSL_ERROR_VAL ("second index out of range", GSL_EINVAL, zero);
  34. }
  35. }
  36. return *(BASE *) (m->data + MULTIPLICITY * (i * m->tda + j));
  37. }
  38. void
  39. FUNCTION (gsl_matrix, set) (TYPE (gsl_matrix) * m,
  40. const size_t i, const size_t j,
  41. const BASE x)
  42. {
  43. if (gsl_check_range)
  44. {
  45. if (i >= m->size1) /* size_t is unsigned, can't be negative */
  46. {
  47. GSL_ERROR_VOID ("first index out of range", GSL_EINVAL);
  48. }
  49. else if (j >= m->size2) /* size_t is unsigned, can't be negative */
  50. {
  51. GSL_ERROR_VOID ("second index out of range", GSL_EINVAL);
  52. }
  53. }
  54. *(BASE *) (m->data + MULTIPLICITY * (i * m->tda + j)) = x;
  55. }
  56. BASE *
  57. FUNCTION (gsl_matrix, ptr) (TYPE (gsl_matrix) * m,
  58. const size_t i, const size_t j)
  59. {
  60. if (gsl_check_range)
  61. {
  62. if (i >= m->size1) /* size_t is unsigned, can't be negative */
  63. {
  64. GSL_ERROR_NULL ("first index out of range", GSL_EINVAL);
  65. }
  66. else if (j >= m->size2) /* size_t is unsigned, can't be negative */
  67. {
  68. GSL_ERROR_NULL ("second index out of range", GSL_EINVAL);
  69. }
  70. }
  71. return (BASE *) (m->data + MULTIPLICITY * (i * m->tda + j));
  72. }
  73. const BASE *
  74. FUNCTION (gsl_matrix, const_ptr) (const TYPE (gsl_matrix) * m,
  75. const size_t i, const size_t j)
  76. {
  77. if (gsl_check_range)
  78. {
  79. if (i >= m->size1) /* size_t is unsigned, can't be negative */
  80. {
  81. GSL_ERROR_NULL ("first index out of range", GSL_EINVAL);
  82. }
  83. else if (j >= m->size2) /* size_t is unsigned, can't be negative */
  84. {
  85. GSL_ERROR_NULL ("second index out of range", GSL_EINVAL);
  86. }
  87. }
  88. return (const BASE *) (m->data + MULTIPLICITY * (i * m->tda + j));
  89. }
  90. #endif