gsl_matrix__rowcol_source.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* matrix/rowcol_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. QUALIFIED_VIEW(_gsl_vector,view)
  20. FUNCTION (gsl_matrix, row) (QUALIFIED_TYPE(gsl_matrix) * m, const size_t i)
  21. {
  22. QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW;
  23. if (i >= m->size1)
  24. {
  25. GSL_ERROR_VAL ("row index is out of range", GSL_EINVAL, view);
  26. }
  27. {
  28. TYPE(gsl_vector) v = NULL_VECTOR;
  29. v.data = m->data + i * MULTIPLICITY * m->tda;
  30. v.size = m->size2;
  31. v.stride = 1;
  32. v.block = m->block;
  33. v.owner = 0;
  34. view.vector = v;
  35. return view;
  36. }
  37. }
  38. QUALIFIED_VIEW(_gsl_vector,view)
  39. FUNCTION (gsl_matrix, column) (QUALIFIED_TYPE(gsl_matrix) * m, const size_t j)
  40. {
  41. QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW;
  42. if (j >= m->size2)
  43. {
  44. GSL_ERROR_VAL ("column index is out of range", GSL_EINVAL, view);
  45. }
  46. {
  47. TYPE(gsl_vector) v = NULL_VECTOR;
  48. v.data = m->data + j * MULTIPLICITY;
  49. v.size = m->size1;
  50. v.stride = m->tda;
  51. v.block = m->block;
  52. v.owner = 0;
  53. view.vector = v;
  54. return view;
  55. }
  56. }
  57. QUALIFIED_VIEW(_gsl_vector,view)
  58. FUNCTION (gsl_matrix, diagonal) (QUALIFIED_TYPE(gsl_matrix) * m)
  59. {
  60. QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW;
  61. TYPE(gsl_vector) v = NULL_VECTOR;
  62. v.data = m->data;
  63. v.size = GSL_MIN(m->size1,m->size2);
  64. v.stride = m->tda + 1;
  65. v.block = m->block;
  66. v.owner = 0;
  67. view.vector = v;
  68. return view;
  69. }
  70. QUALIFIED_VIEW(_gsl_vector,view)
  71. FUNCTION (gsl_matrix, subdiagonal) (QUALIFIED_TYPE(gsl_matrix) * m,
  72. const size_t k)
  73. {
  74. QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW;
  75. if (k >= m->size1)
  76. {
  77. GSL_ERROR_VAL ("subdiagonal index is out of range", GSL_EINVAL, view);
  78. }
  79. {
  80. TYPE(gsl_vector) v = NULL_VECTOR;
  81. v.data = m->data + k * MULTIPLICITY * m->tda;
  82. v.size = GSL_MIN(m->size1 - k, m->size2);
  83. v.stride = m->tda + 1;
  84. v.block = m->block;
  85. v.owner = 0;
  86. view.vector = v;
  87. return view;
  88. }
  89. }
  90. QUALIFIED_VIEW(_gsl_vector,view)
  91. FUNCTION (gsl_matrix, superdiagonal) (QUALIFIED_TYPE(gsl_matrix) * m,
  92. const size_t k)
  93. {
  94. QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW;
  95. if (k >= m->size2)
  96. {
  97. GSL_ERROR_VAL ("column index is out of range", GSL_EINVAL, view);
  98. }
  99. {
  100. TYPE(gsl_vector) v = NULL_VECTOR;
  101. v.data = m->data + k * MULTIPLICITY;
  102. v.size = GSL_MIN(m->size1, m->size2 - k);
  103. v.stride = m->tda + 1;
  104. v.block = m->block;
  105. v.owner = 0;
  106. view.vector = v;
  107. return view;
  108. }
  109. }
  110. QUALIFIED_VIEW(_gsl_vector,view)
  111. FUNCTION (gsl_matrix, subrow) (QUALIFIED_TYPE(gsl_matrix) * m, const size_t i, const size_t offset, const size_t n)
  112. {
  113. QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW;
  114. if (i >= m->size1)
  115. {
  116. GSL_ERROR_VAL ("row index is out of range", GSL_EINVAL, view);
  117. }
  118. else if (n == 0)
  119. {
  120. GSL_ERROR_VAL ("vector length n must be positive integer",
  121. GSL_EINVAL, view);
  122. }
  123. else if (offset + n > m->size1)
  124. {
  125. GSL_ERROR_VAL ("dimension n overflows matrix", GSL_EINVAL, view);
  126. }
  127. {
  128. TYPE(gsl_vector) v = NULL_VECTOR;
  129. v.data = m->data + MULTIPLICITY * (i * m->tda + offset);
  130. v.size = n;
  131. v.stride = 1;
  132. v.block = m->block;
  133. v.owner = 0;
  134. view.vector = v;
  135. return view;
  136. }
  137. }
  138. QUALIFIED_VIEW(_gsl_vector,view)
  139. FUNCTION (gsl_matrix, subcolumn) (QUALIFIED_TYPE(gsl_matrix) * m, const size_t j, const size_t offset, const size_t n)
  140. {
  141. QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW;
  142. if (j >= m->size2)
  143. {
  144. GSL_ERROR_VAL ("column index is out of range", GSL_EINVAL, view);
  145. }
  146. else if (n == 0)
  147. {
  148. GSL_ERROR_VAL ("vector length n must be positive integer",
  149. GSL_EINVAL, view);
  150. }
  151. else if (offset + n > m->size2)
  152. {
  153. GSL_ERROR_VAL ("dimension n overflows matrix", GSL_EINVAL, view);
  154. }
  155. {
  156. TYPE(gsl_vector) v = NULL_VECTOR;
  157. v.data = m->data + MULTIPLICITY * (offset * m->tda + j);
  158. v.size = n;
  159. v.stride = m->tda;
  160. v.block = m->block;
  161. v.owner = 0;
  162. view.vector = v;
  163. return view;
  164. }
  165. }