gsl_matrix__getset_source.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /**********************************************************************/
  2. /* The functions below are obsolete */
  3. /**********************************************************************/
  4. int
  5. FUNCTION (gsl_matrix, get_row) (TYPE (gsl_vector) * v,
  6. const TYPE (gsl_matrix) * m,
  7. const size_t i)
  8. {
  9. const size_t M = m->size1;
  10. const size_t N = m->size2;
  11. const size_t tda = m->tda;
  12. if (i >= M)
  13. {
  14. GSL_ERROR ("row index is out of range", GSL_EINVAL);
  15. }
  16. if (v->size != N)
  17. {
  18. GSL_ERROR ("matrix row size and vector length are not equal",
  19. GSL_EBADLEN);
  20. }
  21. {
  22. ATOMIC *v_data = v->data;
  23. const ATOMIC *row_data = m->data + MULTIPLICITY * i * tda;
  24. const size_t stride = v->stride ;
  25. size_t j;
  26. for (j = 0; j < N; j++)
  27. {
  28. unsigned int k;
  29. for (k = 0; k < MULTIPLICITY; k++)
  30. {
  31. v_data[MULTIPLICITY * stride * j + k]
  32. = row_data[MULTIPLICITY * j + k];
  33. }
  34. }
  35. }
  36. return GSL_SUCCESS;
  37. }
  38. int
  39. FUNCTION (gsl_matrix, get_col) (TYPE (gsl_vector) * v,
  40. const TYPE (gsl_matrix) * m,
  41. const size_t j)
  42. {
  43. const size_t M = m->size1;
  44. const size_t N = m->size2;
  45. const size_t tda = m->tda;
  46. if (j >= N)
  47. {
  48. GSL_ERROR ("column index is out of range", GSL_EINVAL);
  49. }
  50. if (v->size != M)
  51. {
  52. GSL_ERROR ("matrix column size and vector length are not equal",
  53. GSL_EBADLEN);
  54. }
  55. {
  56. ATOMIC *v_data = v->data;
  57. const ATOMIC *column_data = m->data + MULTIPLICITY * j;
  58. const size_t stride = v->stride ;
  59. size_t i;
  60. for (i = 0; i < M; i++)
  61. {
  62. unsigned int k;
  63. for (k = 0; k < MULTIPLICITY; k++)
  64. {
  65. v_data[stride * MULTIPLICITY * i + k] =
  66. column_data[MULTIPLICITY * i * tda + k];
  67. }
  68. }
  69. }
  70. return GSL_SUCCESS;
  71. }
  72. int
  73. FUNCTION (gsl_matrix, set_row) (TYPE (gsl_matrix) * m,
  74. const size_t i,
  75. const TYPE (gsl_vector) * v)
  76. {
  77. const size_t M = m->size1;
  78. const size_t N = m->size2;
  79. const size_t tda = m->tda;
  80. if (i >= M)
  81. {
  82. GSL_ERROR ("row index is out of range", GSL_EINVAL);
  83. }
  84. if (v->size != N)
  85. {
  86. GSL_ERROR ("matrix row size and vector length are not equal",
  87. GSL_EBADLEN);
  88. }
  89. {
  90. const ATOMIC *v_data = v->data;
  91. ATOMIC *row_data = m->data + MULTIPLICITY * i * tda;
  92. const size_t stride = v->stride ;
  93. size_t j;
  94. for (j = 0; j < N; j++)
  95. {
  96. unsigned int k;
  97. for (k = 0; k < MULTIPLICITY; k++)
  98. {
  99. row_data[MULTIPLICITY*j + k]
  100. = v_data[MULTIPLICITY * stride * j + k];
  101. }
  102. }
  103. }
  104. return GSL_SUCCESS;
  105. }
  106. int
  107. FUNCTION (gsl_matrix, set_col) (TYPE (gsl_matrix) * m,
  108. const size_t j,
  109. const TYPE (gsl_vector) * v)
  110. {
  111. const size_t M = m->size1;
  112. const size_t N = m->size2;
  113. const size_t tda = m->tda;
  114. if (j >= N)
  115. {
  116. GSL_ERROR ("column index is out of range", GSL_EINVAL);
  117. }
  118. if (v->size != M)
  119. {
  120. GSL_ERROR ("matrix column size and vector length are not equal",
  121. GSL_EBADLEN);
  122. }
  123. {
  124. const ATOMIC *v_data = v->data;
  125. ATOMIC *column_data = m->data + MULTIPLICITY * j;
  126. const size_t stride = v->stride ;
  127. size_t i;
  128. for (i = 0; i < M; i++)
  129. {
  130. unsigned int k;
  131. for (k = 0; k < MULTIPLICITY; k++)
  132. {
  133. column_data[MULTIPLICITY * i * tda + k]
  134. = v_data[MULTIPLICITY * stride * i + k];
  135. }
  136. }
  137. }
  138. return GSL_SUCCESS;
  139. }
  140. TYPE (gsl_vector) *
  141. FUNCTION (gsl_vector, alloc_row_from_matrix) (TYPE(gsl_matrix) * m,
  142. const size_t i)
  143. {
  144. TYPE (gsl_vector) * v;
  145. const size_t M = m->size1;
  146. if (i >= M)
  147. {
  148. GSL_ERROR_VAL ("row index is out of range", GSL_EINVAL, 0);
  149. }
  150. v = (TYPE (gsl_vector) *) malloc (sizeof (TYPE (gsl_vector)));
  151. if (v == 0)
  152. {
  153. GSL_ERROR_VAL ("failed to allocate space for vector struct",
  154. GSL_ENOMEM, 0);
  155. }
  156. v->data = m->data + MULTIPLICITY * i * m->tda ;
  157. v->size = m->size2;
  158. v->stride = 1;
  159. v->block = 0;
  160. return v;
  161. }
  162. TYPE (gsl_vector) *
  163. FUNCTION (gsl_vector, alloc_col_from_matrix) (TYPE(gsl_matrix) * m,
  164. const size_t j)
  165. {
  166. TYPE (gsl_vector) * v;
  167. const size_t N = m->size2;
  168. if (j >= N)
  169. {
  170. GSL_ERROR_VAL ("column index is out of range", GSL_EINVAL, 0);
  171. }
  172. v = (TYPE (gsl_vector) *) malloc (sizeof (TYPE (gsl_vector)));
  173. if (v == 0)
  174. {
  175. GSL_ERROR_VAL ("failed to allocate space for vector struct",
  176. GSL_ENOMEM, 0);
  177. }
  178. v->data = m->data + MULTIPLICITY * j ;
  179. v->size = m->size1;
  180. v->stride = m->tda;
  181. v->block = 0;
  182. return v;
  183. }