1 /* vector/swap_source.c
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
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.
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.
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.
21 FUNCTION (gsl_vector, swap) (TYPE (gsl_vector) * v, TYPE (gsl_vector) * w)
23 ATOMIC * d1 = v->data ;
24 ATOMIC * d2 = w->data ;
25 const size_t size = v->size ;
26 const size_t s1 = MULTIPLICITY * v->stride ;
27 const size_t s2 = MULTIPLICITY * w->stride ;
30 if (v->size != w->size)
32 GSL_ERROR("vector lengths must be equal", GSL_EINVAL);
35 for (i = 0; i < size; i++)
37 for (k = 0; k < MULTIPLICITY; k++)
39 ATOMIC tmp = d1[i*s1 + k];
40 d1[i*s1+k] = d2[i*s2 + k];
49 FUNCTION (gsl_vector, swap_elements) (TYPE (gsl_vector) * v, const size_t i, const size_t j)
51 ATOMIC * data = v->data ;
52 const size_t size = v->size ;
53 const size_t stride = v->stride ;
57 GSL_ERROR("first index is out of range", GSL_EINVAL);
62 GSL_ERROR("second index is out of range", GSL_EINVAL);
67 const size_t s = MULTIPLICITY * stride ;
70 for (k = 0; k < MULTIPLICITY; k++)
72 ATOMIC tmp = data[j*s + k];
73 data[j*s+k] = data[i*s + k];
82 FUNCTION (gsl_vector, reverse) (TYPE (gsl_vector) * v)
84 ATOMIC * data = v->data ;
85 const size_t size = v->size ;
86 const size_t stride = v->stride ;
88 const size_t s = MULTIPLICITY * stride ;
92 for (i = 0 ; i < (size / 2) ; i++)
94 size_t j = size - i - 1 ;
97 for (k = 0; k < MULTIPLICITY; k++)
99 ATOMIC tmp = data[j*s + k];
100 data[j*s+k] = data[i*s + k];