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