| 1 | /* vector/init_source.c |
| 2 | * |
| 3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, 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 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) * |
| 21 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_vector, alloc) (const size_tcxx . . $ size_t# n) |
| 22 | { |
| 23 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_block) * block; |
| 24 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) * v; |
| 25 | |
| 26 | if (n == 0) |
| 27 | { |
| 28 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("vector length n must be positive integer", |
| 29 | GSL_EINVAL, 0); |
| 30 | } |
| 31 | |
| 32 | v = (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector))); |
| 33 | |
| 34 | if (v == 0) |
| 35 | { |
| 36 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for vector struct", |
| 37 | GSL_ENOMEM, 0); |
| 38 | } |
| 39 | |
| 40 | block = FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_block,alloc) (n); |
| 41 | |
| 42 | if (block == 0) |
| 43 | { |
| 44 | freecxx . . $ free(5d22bdacc48458e8). (v) ; |
| 45 | |
| 46 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for block", |
| 47 | GSL_ENOMEM, 0); |
| 48 | } |
| 49 | |
| 50 | v->datacxx . . $ $anonymous_type_34af5c85346b2293_0#data. = block->datacxx . . $ gsl_block_float_struct#data. ; |
| 51 | v->sizecxx . . $ $anonymous_type_34af5c85346b2293_0#size. = n; |
| 52 | v->stridecxx . . $ $anonymous_type_34af5c85346b2293_0#stride. = 1; |
| 53 | v->blockcxx . . $ $anonymous_type_34af5c85346b2293_0#block. = block; |
| 54 | v->ownercxx . . $ $anonymous_type_34af5c85346b2293_0#owner. = 1; |
| 55 | |
| 56 | return v; |
| 57 | } |
| 58 | |
| 59 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) * |
| 60 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_vector, calloc) (const size_tcxx . . $ size_t# n) |
| 61 | { |
| 62 | size_tcxx . . $ size_t# i; |
| 63 | |
| 64 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) * v = FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_vector, alloc) (n); |
| 65 | |
| 66 | if (v == 0) |
| 67 | return 0; |
| 68 | |
| 69 | /* initialize vector to zero */ |
| 70 | |
| 71 | for (i = 0; i < MULTIPLICITYcxx . . $ `./templates_on.h:81:9`! * n; i++) |
| 72 | { |
| 73 | v->datacxx . . $ $anonymous_type_34af5c85346b2293_0#data.[i] = 0; |
| 74 | } |
| 75 | |
| 76 | return v; |
| 77 | } |
| 78 | |
| 79 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) * |
| 80 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_vector, alloc_from_block) (TYPEcxx . . $ `./templates_on.h:234:9`!(gsl_block) * block, |
| 81 | const size_tcxx . . $ size_t# offset, |
| 82 | const size_tcxx . . $ size_t# n, |
| 83 | const size_tcxx . . $ size_t# stride) |
| 84 | { |
| 85 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) * v; |
| 86 | |
| 87 | if (n == 0) |
| 88 | { |
| 89 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("vector length n must be positive integer", |
| 90 | GSL_EINVAL, 0); |
| 91 | } |
| 92 | |
| 93 | if (stride == 0) |
| 94 | { |
| 95 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("stride must be positive integer", GSL_EINVAL, 0); |
| 96 | } |
| 97 | |
| 98 | if (block->sizecxx . . $ gsl_block_float_struct#size. <= offset + (n - 1) * stride) |
| 99 | { |
| 100 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("vector would extend past end of block", GSL_EINVAL, 0); |
| 101 | } |
| 102 | |
| 103 | v = (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector))); |
| 104 | |
| 105 | if (v == 0) |
| 106 | { |
| 107 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for vector struct", |
| 108 | GSL_ENOMEM, 0); |
| 109 | } |
| 110 | |
| 111 | v->datacxx . . $ $anonymous_type_34af5c85346b2293_0#data. = block->datacxx . . $ gsl_block_float_struct#data. + MULTIPLICITYcxx . . $ `./templates_on.h:81:9`! * offset ; |
| 112 | v->sizecxx . . $ $anonymous_type_34af5c85346b2293_0#size. = n; |
| 113 | v->stridecxx . . $ $anonymous_type_34af5c85346b2293_0#stride. = stride; |
| 114 | v->blockcxx . . $ $anonymous_type_34af5c85346b2293_0#block. = block; |
| 115 | v->ownercxx . . $ $anonymous_type_34af5c85346b2293_0#owner. = 0; |
| 116 | |
| 117 | return v; |
| 118 | } |
| 119 | |
| 120 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) * |
| 121 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_vector, alloc_from_vector) (TYPEcxx . . $ `./templates_on.h:234:9`!(gsl_vector) * w, |
| 122 | const size_tcxx . . $ size_t# offset, |
| 123 | const size_tcxx . . $ size_t# n, |
| 124 | const size_tcxx . . $ size_t# stride) |
| 125 | { |
| 126 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) * v; |
| 127 | |
| 128 | if (n == 0) |
| 129 | { |
| 130 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("vector length n must be positive integer", |
| 131 | GSL_EINVAL, 0); |
| 132 | } |
| 133 | |
| 134 | if (stride == 0) |
| 135 | { |
| 136 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("stride must be positive integer", GSL_EINVAL, 0); |
| 137 | } |
| 138 | |
| 139 | if (offset + (n - 1) * stride >= w->sizecxx . . $ $anonymous_type_34af5c85346b2293_0#size.) |
| 140 | { |
| 141 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("vector would extend past end of block", GSL_EINVAL, 0); |
| 142 | } |
| 143 | |
| 144 | v = (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector))); |
| 145 | |
| 146 | if (v == 0) |
| 147 | { |
| 148 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for vector struct", |
| 149 | GSL_ENOMEM, 0); |
| 150 | } |
| 151 | |
| 152 | v->datacxx . . $ $anonymous_type_34af5c85346b2293_0#data. = w->datacxx . . $ $anonymous_type_34af5c85346b2293_0#data. + MULTIPLICITYcxx . . $ `./templates_on.h:81:9`! * w->stridecxx . . $ $anonymous_type_34af5c85346b2293_0#stride. * offset ; |
| 153 | v->sizecxx . . $ $anonymous_type_34af5c85346b2293_0#size. = n; |
| 154 | v->stridecxx . . $ $anonymous_type_34af5c85346b2293_0#stride. = stride * w->stridecxx . . $ $anonymous_type_34af5c85346b2293_0#stride.; |
| 155 | v->blockcxx . . $ $anonymous_type_34af5c85346b2293_0#block. = w->blockcxx . . $ $anonymous_type_34af5c85346b2293_0#block.; |
| 156 | v->ownercxx . . $ $anonymous_type_34af5c85346b2293_0#owner. = 0; |
| 157 | |
| 158 | return v; |
| 159 | } |
| 160 | |
| 161 | |
| 162 | void |
| 163 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_vector, free) (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) * v) |
| 164 | { |
| 165 | if (v->ownercxx . . $ $anonymous_type_34af5c85346b2293_0#owner.) |
| 166 | { |
| 167 | FUNCTIONcxx . . $ `./templates_on.h:233:9`!(gsl_block, free) (v->blockcxx . . $ $anonymous_type_34af5c85346b2293_0#block.) ; |
| 168 | } |
| 169 | freecxx . . $ free(5d22bdacc48458e8). (v); |
| 170 | } |
| 171 | |
| 172 | |
| 173 | void |
| 174 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_vector, set_all) (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) * v, BASEcxx . . $ `./templates_on.h:78:9`! x) |
| 175 | { |
| 176 | ATOMICcxx . . $ `./templates_on.h:80:9`! * const data = v->datacxx . . $ $anonymous_type_34af5c85346b2293_0#data.; |
| 177 | const size_tcxx . . $ size_t# n = v->sizecxx . . $ $anonymous_type_34af5c85346b2293_0#size.; |
| 178 | const size_tcxx . . $ size_t# stride = v->stridecxx . . $ $anonymous_type_34af5c85346b2293_0#stride.; |
| 179 | |
| 180 | size_tcxx . . $ size_t# i; |
| 181 | |
| 182 | for (i = 0; i < n; i++) |
| 183 | { |
| 184 | *(BASEcxx . . $ `./templates_on.h:78:9`! *) (data + MULTIPLICITYcxx . . $ `./templates_on.h:81:9`! * i * stride) = x; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | void |
| 189 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_vector, set_zero) (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) * v) |
| 190 | { |
| 191 | ATOMICcxx . . $ `./templates_on.h:80:9`! * const data = v->datacxx . . $ $anonymous_type_34af5c85346b2293_0#data.; |
| 192 | const size_tcxx . . $ size_t# n = v->sizecxx . . $ $anonymous_type_34af5c85346b2293_0#size.; |
| 193 | const size_tcxx . . $ size_t# stride = v->stridecxx . . $ $anonymous_type_34af5c85346b2293_0#stride.; |
| 194 | const BASEcxx . . $ `./templates_on.h:78:9`! zero = ZEROcxx . . $ `./templates_on.h:86:9`! ; |
| 195 | |
| 196 | size_tcxx . . $ size_t# i; |
| 197 | |
| 198 | for (i = 0; i < n; i++) |
| 199 | { |
| 200 | *(BASEcxx . . $ `./templates_on.h:78:9`! *) (data + MULTIPLICITYcxx . . $ `./templates_on.h:81:9`! * i * stride) = zero; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | int |
| 205 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_vector, set_basis) (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_vector) * v, size_tcxx . . $ size_t# i) |
| 206 | { |
| 207 | ATOMICcxx . . $ `./templates_on.h:80:9`! * const data = v->datacxx . . $ $anonymous_type_34af5c85346b2293_0#data.; |
| 208 | const size_tcxx . . $ size_t# n = v->sizecxx . . $ $anonymous_type_34af5c85346b2293_0#size.; |
| 209 | const size_tcxx . . $ size_t# stride = v->stridecxx . . $ $anonymous_type_34af5c85346b2293_0#stride.; |
| 210 | const BASEcxx . . $ `./templates_on.h:78:9`! zero = ZEROcxx . . $ `./templates_on.h:86:9`! ; |
| 211 | const BASEcxx . . $ `./templates_on.h:78:9`! one = ONEcxx . . $ `./templates_on.h:87:9`!; |
| 212 | |
| 213 | size_tcxx . . $ size_t# k; |
| 214 | |
| 215 | if (i >= n) |
| 216 | { |
| 217 | GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("index out of range", GSL_EINVAL); |
| 218 | } |
| 219 | |
| 220 | for (k = 0; k < n; k++) |
| 221 | { |
| 222 | *(BASEcxx . . $ `./templates_on.h:78:9`! *) (data + MULTIPLICITYcxx . . $ `./templates_on.h:81:9`! * k * stride) = zero; |
| 223 | } |
| 224 | |
| 225 | *(BASEcxx . . $ `./templates_on.h:78:9`! *) (data + MULTIPLICITYcxx . . $ `./templates_on.h:81:9`! * i * stride) = one; |
| 226 | |
| 227 | return GSL_SUCCESScxx . . $ GSL_SUCCESS.; |
| 228 | } |