| 1 |
/* vector/oper_source.c |
| 2 |
* |
| 3 |
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 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 |
|
| 20 |
int |
| 21 |
FUNCTION(gsl_vector, add) (TYPE(gsl_vector) * a, const TYPE(gsl_vector) * b) |
| 22 |
{ |
| 23 |
const size_t N = a->size; |
| 24 |
|
| 25 |
if (b->size != N) |
| 26 |
{ |
| 27 |
GSL_ERROR ("vectors must have same length", GSL_EBADLEN); |
| 28 |
} |
| 29 |
else |
| 30 |
{ |
| 31 |
const size_t stride_a = a->stride; |
| 32 |
const size_t stride_b = b->stride; |
| 33 |
|
| 34 |
size_t i; |
| 35 |
|
| 36 |
for (i = 0; i < N; i++) |
| 37 |
{ |
| 38 |
a->data[i * stride_a] += b->data[i * stride_b]; |
| 39 |
} |
| 40 |
|
| 41 |
return GSL_SUCCESS; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
int |
| 46 |
FUNCTION(gsl_vector, sub) (TYPE(gsl_vector) * a, const TYPE(gsl_vector) * b) |
| 47 |
{ |
| 48 |
const size_t N = a->size; |
| 49 |
|
| 50 |
if (b->size != N) |
| 51 |
{ |
| 52 |
GSL_ERROR ("vectors must have same length", GSL_EBADLEN); |
| 53 |
} |
| 54 |
else |
| 55 |
{ |
| 56 |
const size_t stride_a = a->stride; |
| 57 |
const size_t stride_b = b->stride; |
| 58 |
|
| 59 |
size_t i; |
| 60 |
|
| 61 |
for (i = 0; i < N; i++) |
| 62 |
{ |
| 63 |
a->data[i * stride_a] -= b->data[i * stride_b]; |
| 64 |
} |
| 65 |
|
| 66 |
return GSL_SUCCESS; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
int |
| 71 |
FUNCTION(gsl_vector, mul) (TYPE(gsl_vector) * a, const TYPE(gsl_vector) * b) |
| 72 |
{ |
| 73 |
const size_t N = a->size; |
| 74 |
|
| 75 |
if (b->size != N) |
| 76 |
{ |
| 77 |
GSL_ERROR ("vectors must have same length", GSL_EBADLEN); |
| 78 |
} |
| 79 |
else |
| 80 |
{ |
| 81 |
const size_t stride_a = a->stride; |
| 82 |
const size_t stride_b = b->stride; |
| 83 |
|
| 84 |
size_t i; |
| 85 |
|
| 86 |
for (i = 0; i < N; i++) |
| 87 |
{ |
| 88 |
a->data[i * stride_a] *= b->data[i * stride_b]; |
| 89 |
} |
| 90 |
|
| 91 |
return GSL_SUCCESS; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
int |
| 96 |
FUNCTION(gsl_vector, div) (TYPE(gsl_vector) * a, const TYPE(gsl_vector) * b) |
| 97 |
{ |
| 98 |
const size_t N = a->size; |
| 99 |
|
| 100 |
if (b->size != N) |
| 101 |
{ |
| 102 |
GSL_ERROR ("vectors must have same length", GSL_EBADLEN); |
| 103 |
} |
| 104 |
else |
| 105 |
{ |
| 106 |
const size_t stride_a = a->stride; |
| 107 |
const size_t stride_b = b->stride; |
| 108 |
|
| 109 |
size_t i; |
| 110 |
|
| 111 |
for (i = 0; i < N; i++) |
| 112 |
{ |
| 113 |
a->data[i * stride_a] /= b->data[i * stride_b]; |
| 114 |
} |
| 115 |
|
| 116 |
return GSL_SUCCESS; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
int |
| 121 |
FUNCTION(gsl_vector, scale) (TYPE(gsl_vector) * a, const double x) |
| 122 |
{ |
| 123 |
const size_t N = a->size; |
| 124 |
const size_t stride = a->stride; |
| 125 |
|
| 126 |
size_t i; |
| 127 |
|
| 128 |
for (i = 0; i < N; i++) |
| 129 |
{ |
| 130 |
a->data[i * stride] *= x; |
| 131 |
} |
| 132 |
|
| 133 |
return GSL_SUCCESS; |
| 134 |
} |
| 135 |
|
| 136 |
int |
| 137 |
FUNCTION(gsl_vector, add_constant) (TYPE(gsl_vector) * a, const double x) |
| 138 |
{ |
| 139 |
const size_t N = a->size; |
| 140 |
const size_t stride = a->stride; |
| 141 |
|
| 142 |
size_t i; |
| 143 |
|
| 144 |
for (i = 0; i < N; i++) |
| 145 |
{ |
| 146 |
a->data[i * stride] += x; |
| 147 |
} |
| 148 |
|
| 149 |
return GSL_SUCCESS; |
| 150 |
} |