1 /* vector/oper_source.c
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 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, add) (TYPE(gsl_vector) * a, const TYPE(gsl_vector) * b)
23 const size_t N = a->size;
27 GSL_ERROR ("vectors must have same length", GSL_EBADLEN);
31 const size_t stride_a = a->stride;
32 const size_t stride_b = b->stride;
36 for (i = 0; i < N; i++)
38 a->data[i * stride_a] += b->data[i * stride_b];
46 FUNCTION(gsl_vector, sub) (TYPE(gsl_vector) * a, const TYPE(gsl_vector) * b)
48 const size_t N = a->size;
52 GSL_ERROR ("vectors must have same length", GSL_EBADLEN);
56 const size_t stride_a = a->stride;
57 const size_t stride_b = b->stride;
61 for (i = 0; i < N; i++)
63 a->data[i * stride_a] -= b->data[i * stride_b];
71 FUNCTION(gsl_vector, mul) (TYPE(gsl_vector) * a, const TYPE(gsl_vector) * b)
73 const size_t N = a->size;
77 GSL_ERROR ("vectors must have same length", GSL_EBADLEN);
81 const size_t stride_a = a->stride;
82 const size_t stride_b = b->stride;
86 for (i = 0; i < N; i++)
88 a->data[i * stride_a] *= b->data[i * stride_b];
96 FUNCTION(gsl_vector, div) (TYPE(gsl_vector) * a, const TYPE(gsl_vector) * b)
98 const size_t N = a->size;
102 GSL_ERROR ("vectors must have same length", GSL_EBADLEN);
106 const size_t stride_a = a->stride;
107 const size_t stride_b = b->stride;
111 for (i = 0; i < N; i++)
113 a->data[i * stride_a] /= b->data[i * stride_b];
121 FUNCTION(gsl_vector, scale) (TYPE(gsl_vector) * a, const double x)
123 const size_t N = a->size;
124 const size_t stride = a->stride;
128 for (i = 0; i < N; i++)
130 a->data[i * stride] *= x;
137 FUNCTION(gsl_vector, add_constant) (TYPE(gsl_vector) * a, const double x)
139 const size_t N = a->size;
140 const size_t stride = a->stride;
144 for (i = 0; i < N; i++)
146 a->data[i * stride] += x;