| 1 | /* matrix/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_matrix) * |
| 21 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_matrix, alloc) (const size_t n1, const size_t n2) |
| 22 | { |
| 23 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_block) * block; |
| 24 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) * m; |
| 25 | |
| 26 | if (n1 == 0) |
| 27 | { |
| 28 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("matrix dimension n1 must be positive integer", |
| 29 | GSL_EINVAL, 0); |
| 30 | } |
| 31 | else if (n2 == 0) |
| 32 | { |
| 33 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("matrix dimension n2 must be positive integer", |
| 34 | GSL_EINVAL, 0); |
| 35 | } |
| 36 | |
| 37 | m = (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix))); |
| 38 | |
| 39 | if (m == 0) |
| 40 | { |
| 41 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for matrix struct", |
| 42 | GSL_ENOMEM, 0); |
| 43 | } |
| 44 | |
| 45 | /* FIXME: n1*n2 could overflow for large dimensions */ |
| 46 | |
| 47 | block = FUNCTIONcxx . . $ `./templates_on.h:233:9`!(gsl_block, alloc) (n1 * n2) ; |
| 48 | |
| 49 | if (block == 0) |
| 50 | { |
| 51 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for block", |
| 52 | GSL_ENOMEM, 0); |
| 53 | } |
| 54 | |
| 55 | m->datacxx . . $ $anonymous_type_fb878c6deed39fac_0#data. = block->datacxx . . $ gsl_block_ushort_struct#data.; |
| 56 | m->size1cxx . . $ $anonymous_type_fb878c6deed39fac_0#size1. = n1; |
| 57 | m->size2cxx . . $ $anonymous_type_fb878c6deed39fac_0#size2. = n2; |
| 58 | m->tdacxx . . $ $anonymous_type_fb878c6deed39fac_0#tda. = n2; |
| 59 | m->blockcxx . . $ $anonymous_type_fb878c6deed39fac_0#block. = block; |
| 60 | m->ownercxx . . $ $anonymous_type_fb878c6deed39fac_0#owner. = 1; |
| 61 | |
| 62 | return m; |
| 63 | } |
| 64 | |
| 65 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) * |
| 66 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_matrix, calloc) (const size_t n1, const size_t n2) |
| 67 | { |
| 68 | size_t i; |
| 69 | |
| 70 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) * m = FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_matrix, alloc) (n1, n2); |
| 71 | |
| 72 | if (m == 0) |
| 73 | return 0; |
| 74 | |
| 75 | /* initialize matrix to zero */ |
| 76 | |
| 77 | for (i = 0; i < MULTIPLICITYcxx . . $ `./templates_on.h:140:9`! * n1 * n2; i++) |
| 78 | { |
| 79 | m->datacxx . . $ $anonymous_type_fb878c6deed39fac_0#data.[i] = 0; |
| 80 | } |
| 81 | |
| 82 | return m; |
| 83 | } |
| 84 | |
| 85 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) * |
| 86 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_matrix, alloc_from_block) (TYPEcxx . . $ `./templates_on.h:234:9`!(gsl_block) * block, |
| 87 | const size_t offset, |
| 88 | const size_t n1, |
| 89 | const size_t n2, |
| 90 | const size_t d2) |
| 91 | { |
| 92 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) * m; |
| 93 | |
| 94 | if (n1 == 0) |
| 95 | { |
| 96 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("matrix dimension n1 must be positive integer", |
| 97 | GSL_EINVAL, 0); |
| 98 | } |
| 99 | else if (n2 == 0) |
| 100 | { |
| 101 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("matrix dimension n2 must be positive integer", |
| 102 | GSL_EINVAL, 0); |
| 103 | } |
| 104 | else if (d2 < n2) |
| 105 | { |
| 106 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("matrix dimension d2 must be greater than n2", |
| 107 | GSL_EINVAL, 0); |
| 108 | } |
| 109 | else if (block->sizecxx . . $ gsl_block_ushort_struct#size. < offset + n1 * d2) |
| 110 | { |
| 111 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("matrix size exceeds available block size", |
| 112 | GSL_EINVAL, 0); |
| 113 | } |
| 114 | |
| 115 | m = (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix))); |
| 116 | |
| 117 | if (m == 0) |
| 118 | { |
| 119 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for matrix struct", |
| 120 | GSL_ENOMEM, 0); |
| 121 | } |
| 122 | |
| 123 | m->datacxx . . $ $anonymous_type_fb878c6deed39fac_0#data. = block->datacxx . . $ gsl_block_ushort_struct#data. + MULTIPLICITYcxx . . $ `./templates_on.h:140:9`! * offset; |
| 124 | m->size1cxx . . $ $anonymous_type_fb878c6deed39fac_0#size1. = n1; |
| 125 | m->size2cxx . . $ $anonymous_type_fb878c6deed39fac_0#size2. = n2; |
| 126 | m->tdacxx . . $ $anonymous_type_fb878c6deed39fac_0#tda. = d2; |
| 127 | m->blockcxx . . $ $anonymous_type_fb878c6deed39fac_0#block. = block; |
| 128 | m->ownercxx . . $ $anonymous_type_fb878c6deed39fac_0#owner. = 0; |
| 129 | |
| 130 | return m; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) * |
| 135 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_matrix, alloc_from_matrix) (TYPEcxx . . $ `./templates_on.h:234:9`!(gsl_matrix) * mm, |
| 136 | const size_t k1, |
| 137 | const size_t k2, |
| 138 | const size_t n1, |
| 139 | const size_t n2) |
| 140 | { |
| 141 | TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) * m; |
| 142 | |
| 143 | if (n1 == 0) |
| 144 | { |
| 145 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("matrix dimension n1 must be positive integer", |
| 146 | GSL_EINVAL, 0); |
| 147 | } |
| 148 | else if (n2 == 0) |
| 149 | { |
| 150 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("matrix dimension n2 must be positive integer", |
| 151 | GSL_EINVAL, 0); |
| 152 | } |
| 153 | else if (k1 + n1 > mm->size1cxx . . $ $anonymous_type_fb878c6deed39fac_0#size1.) |
| 154 | { |
| 155 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("submatrix dimension 1 exceeds size of original", |
| 156 | GSL_EINVAL, 0); |
| 157 | } |
| 158 | else if (k2 + n2 > mm->size2cxx . . $ $anonymous_type_fb878c6deed39fac_0#size2.) |
| 159 | { |
| 160 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("submatrix dimension 2 exceeds size of original", |
| 161 | GSL_EINVAL, 0); |
| 162 | } |
| 163 | |
| 164 | m = (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix))); |
| 165 | |
| 166 | if (m == 0) |
| 167 | { |
| 168 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for matrix struct", |
| 169 | GSL_ENOMEM, 0); |
| 170 | } |
| 171 | |
| 172 | m->datacxx . . $ $anonymous_type_fb878c6deed39fac_0#data. = mm->datacxx . . $ $anonymous_type_fb878c6deed39fac_0#data. + k1 * mm->tdacxx . . $ $anonymous_type_fb878c6deed39fac_0#tda. + k2 ; |
| 173 | m->size1cxx . . $ $anonymous_type_fb878c6deed39fac_0#size1. = n1; |
| 174 | m->size2cxx . . $ $anonymous_type_fb878c6deed39fac_0#size2. = n2; |
| 175 | m->tdacxx . . $ $anonymous_type_fb878c6deed39fac_0#tda. = mm->tdacxx . . $ $anonymous_type_fb878c6deed39fac_0#tda.; |
| 176 | m->blockcxx . . $ $anonymous_type_fb878c6deed39fac_0#block. = mm->blockcxx . . $ $anonymous_type_fb878c6deed39fac_0#block.; |
| 177 | m->ownercxx . . $ $anonymous_type_fb878c6deed39fac_0#owner. = 0; |
| 178 | |
| 179 | return m; |
| 180 | } |
| 181 | |
| 182 | void |
| 183 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_matrix, free) (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) * m) |
| 184 | { |
| 185 | if (m->ownercxx . . $ $anonymous_type_fb878c6deed39fac_0#owner.) |
| 186 | { |
| 187 | FUNCTIONcxx . . $ `./templates_on.h:233:9`!(gsl_block, free) (m->blockcxx . . $ $anonymous_type_fb878c6deed39fac_0#block.); |
| 188 | } |
| 189 | |
| 190 | freecxx . . $ free(5d22bdacc48458e8). (m); |
| 191 | } |
| 192 | void |
| 193 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_matrix, set_identity) (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) * m) |
| 194 | { |
| 195 | size_t i, j; |
| 196 | ATOMICcxx . . $ `./templates_on.h:139:9`! * const data = m->datacxx . . $ $anonymous_type_fb878c6deed39fac_0#data.; |
| 197 | const size_t p = m->size1cxx . . $ $anonymous_type_fb878c6deed39fac_0#size1. ; |
| 198 | const size_t q = m->size2cxx . . $ $anonymous_type_fb878c6deed39fac_0#size2. ; |
| 199 | const size_t tda = m->tdacxx . . $ $anonymous_type_fb878c6deed39fac_0#tda. ; |
| 200 | |
| 201 | const BASEcxx . . $ `./templates_on.h:137:9`! zero = ZEROcxx . . $ `./templates_on.h:144:9`!; |
| 202 | const BASEcxx . . $ `./templates_on.h:137:9`! one = ONEcxx . . $ `./templates_on.h:145:9`!; |
| 203 | |
| 204 | for (i = 0; i < p; i++) |
| 205 | { |
| 206 | for (j = 0; j < q; j++) |
| 207 | { |
| 208 | *(BASEcxx . . $ `./templates_on.h:137:9`! *) (data + MULTIPLICITYcxx . . $ `./templates_on.h:140:9`! * (i * tda + j)) = ((i == j) ? one : zero); |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | void |
| 214 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_matrix, set_zero) (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) * m) |
| 215 | { |
| 216 | size_t i, j; |
| 217 | ATOMICcxx . . $ `./templates_on.h:139:9`! * const data = m->datacxx . . $ $anonymous_type_fb878c6deed39fac_0#data.; |
| 218 | const size_t p = m->size1cxx . . $ $anonymous_type_fb878c6deed39fac_0#size1. ; |
| 219 | const size_t q = m->size2cxx . . $ $anonymous_type_fb878c6deed39fac_0#size2. ; |
| 220 | const size_t tda = m->tdacxx . . $ $anonymous_type_fb878c6deed39fac_0#tda. ; |
| 221 | |
| 222 | const BASEcxx . . $ `./templates_on.h:137:9`! zero = ZEROcxx . . $ `./templates_on.h:144:9`!; |
| 223 | |
| 224 | for (i = 0; i < p; i++) |
| 225 | { |
| 226 | for (j = 0; j < q; j++) |
| 227 | { |
| 228 | *(BASEcxx . . $ `./templates_on.h:137:9`! *) (data + MULTIPLICITYcxx . . $ `./templates_on.h:140:9`! * (i * tda + j)) = zero; |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | void |
| 234 | FUNCTIONcxx . . $ `./templates_on.h:233:9`! (gsl_matrix, set_all) (TYPEcxx . . $ `./templates_on.h:234:9`! (gsl_matrix) * m, BASEcxx . . $ `./templates_on.h:137:9`! x) |
| 235 | { |
| 236 | size_t i, j; |
| 237 | ATOMICcxx . . $ `./templates_on.h:139:9`! * const data = m->datacxx . . $ $anonymous_type_fb878c6deed39fac_0#data.; |
| 238 | const size_t p = m->size1cxx . . $ $anonymous_type_fb878c6deed39fac_0#size1. ; |
| 239 | const size_t q = m->size2cxx . . $ $anonymous_type_fb878c6deed39fac_0#size2. ; |
| 240 | const size_t tda = m->tdacxx . . $ $anonymous_type_fb878c6deed39fac_0#tda. ; |
| 241 | |
| 242 | for (i = 0; i < p; i++) |
| 243 | { |
| 244 | for (j = 0; j < q; j++) |
| 245 | { |
| 246 | *(BASEcxx . . $ `./templates_on.h:137:9`! *) (data + MULTIPLICITYcxx . . $ `./templates_on.h:140:9`! * (i * tda + j)) = x; |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 |