| 1 |
/* matrix/view_source.c |
| 2 |
* |
| 3 |
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 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 |
QUALIFIED_VIEW (_gsl_matrix,view) |
| 21 |
FUNCTION (gsl_matrix, view_array) (QUALIFIER ATOMIC * array, |
| 22 |
const size_t n1, const size_t n2) |
| 23 |
{ |
| 24 |
QUALIFIED_VIEW (_gsl_matrix,view) view = NULL_MATRIX_VIEW; |
| 25 |
|
| 26 |
if (n1 == 0) |
| 27 |
{ |
| 28 |
GSL_ERROR_VAL ("matrix dimension n1 must be positive integer", |
| 29 |
GSL_EINVAL, view); |
| 30 |
} |
| 31 |
else if (n2 == 0) |
| 32 |
{ |
| 33 |
GSL_ERROR_VAL ("matrix dimension n2 must be positive integer", |
| 34 |
GSL_EINVAL, view); |
| 35 |
} |
| 36 |
|
| 37 |
{ |
| 38 |
TYPE(gsl_matrix) m = NULL_MATRIX; |
| 39 |
|
| 40 |
m.data = (ATOMIC *)array; |
| 41 |
m.size1 = n1; |
| 42 |
m.size2 = n2; |
| 43 |
m.tda = n2; |
| 44 |
m.block = 0; |
| 45 |
m.owner = 0; |
| 46 |
|
| 47 |
view.matrix = m; |
| 48 |
return view; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
QUALIFIED_VIEW (_gsl_matrix,view) |
| 53 |
FUNCTION(gsl_matrix, view_array_with_tda) (QUALIFIER ATOMIC * base, |
| 54 |
const size_t n1, |
| 55 |
const size_t n2, |
| 56 |
const size_t tda) |
| 57 |
{ |
| 58 |
QUALIFIED_VIEW (_gsl_matrix,view) view = NULL_MATRIX_VIEW; |
| 59 |
|
| 60 |
if (n1 == 0) |
| 61 |
{ |
| 62 |
GSL_ERROR_VAL ("matrix dimension n1 must be positive integer", |
| 63 |
GSL_EINVAL, view); |
| 64 |
} |
| 65 |
else if (n2 == 0) |
| 66 |
{ |
| 67 |
GSL_ERROR_VAL ("matrix dimension n2 must be positive integer", |
| 68 |
GSL_EINVAL, view); |
| 69 |
} |
| 70 |
else if (n2 > tda) |
| 71 |
{ |
| 72 |
GSL_ERROR_VAL ("matrix dimension n2 must not exceed tda", |
| 73 |
GSL_EINVAL, view); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
{ |
| 78 |
TYPE(gsl_matrix) m = NULL_MATRIX; |
| 79 |
|
| 80 |
m.data = (ATOMIC *)base; |
| 81 |
m.size1 = n1; |
| 82 |
m.size2 = n2; |
| 83 |
m.tda = tda; |
| 84 |
m.block = 0; |
| 85 |
m.owner = 0; |
| 86 |
|
| 87 |
view.matrix = m; |
| 88 |
return view; |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
QUALIFIED_VIEW (_gsl_matrix,view) |
| 93 |
FUNCTION(gsl_matrix, view_vector) (QUALIFIED_TYPE(gsl_vector) * v, |
| 94 |
const size_t n1, |
| 95 |
const size_t n2) |
| 96 |
{ |
| 97 |
QUALIFIED_VIEW (_gsl_matrix,view) view = NULL_MATRIX_VIEW; |
| 98 |
|
| 99 |
if (n1 == 0) |
| 100 |
{ |
| 101 |
GSL_ERROR_VAL ("matrix dimension n1 must be positive integer", |
| 102 |
GSL_EINVAL, view); |
| 103 |
} |
| 104 |
else if (n2 == 0) |
| 105 |
{ |
| 106 |
GSL_ERROR_VAL ("matrix dimension n2 must be positive integer", |
| 107 |
GSL_EINVAL, view); |
| 108 |
} |
| 109 |
else if (v->stride != 1) |
| 110 |
{ |
| 111 |
GSL_ERROR_VAL ("vector must have unit stride", |
| 112 |
GSL_EINVAL, view); |
| 113 |
} |
| 114 |
else if (n1 * n2 > v->size) |
| 115 |
{ |
| 116 |
GSL_ERROR_VAL ("matrix size exceeds size of original", |
| 117 |
GSL_EINVAL, view); |
| 118 |
} |
| 119 |
|
| 120 |
{ |
| 121 |
TYPE(gsl_matrix) m = NULL_MATRIX; |
| 122 |
|
| 123 |
m.data = v->data; |
| 124 |
m.size1 = n1; |
| 125 |
m.size2 = n2; |
| 126 |
m.tda = n2; |
| 127 |
m.block = v->block; |
| 128 |
m.owner = 0; |
| 129 |
|
| 130 |
view.matrix = m; |
| 131 |
return view; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
QUALIFIED_VIEW (_gsl_matrix,view) |
| 137 |
FUNCTION(gsl_matrix, view_vector_with_tda) (QUALIFIED_TYPE(gsl_vector) * v, |
| 138 |
const size_t n1, |
| 139 |
const size_t n2, |
| 140 |
const size_t tda) |
| 141 |
{ |
| 142 |
QUALIFIED_VIEW (_gsl_matrix,view) view = NULL_MATRIX_VIEW; |
| 143 |
|
| 144 |
if (n1 == 0) |
| 145 |
{ |
| 146 |
GSL_ERROR_VAL ("matrix dimension n1 must be positive integer", |
| 147 |
GSL_EINVAL, view); |
| 148 |
} |
| 149 |
else if (n2 == 0) |
| 150 |
{ |
| 151 |
GSL_ERROR_VAL ("matrix dimension n2 must be positive integer", |
| 152 |
GSL_EINVAL, view); |
| 153 |
} |
| 154 |
else if (v->stride != 1) |
| 155 |
{ |
| 156 |
GSL_ERROR_VAL ("vector must have unit stride", |
| 157 |
GSL_EINVAL, view); |
| 158 |
} |
| 159 |
else if (n2 > tda) |
| 160 |
{ |
| 161 |
GSL_ERROR_VAL ("matrix dimension n2 must not exceed tda", |
| 162 |
GSL_EINVAL, view); |
| 163 |
} |
| 164 |
else if (n1 * tda > v->size) |
| 165 |
{ |
| 166 |
GSL_ERROR_VAL ("matrix size exceeds size of original", |
| 167 |
GSL_EINVAL, view); |
| 168 |
} |
| 169 |
|
| 170 |
{ |
| 171 |
TYPE(gsl_matrix) m = NULL_MATRIX; |
| 172 |
|
| 173 |
m.data = v->data; |
| 174 |
m.size1 = n1; |
| 175 |
m.size2 = n2; |
| 176 |
m.tda = tda; |
| 177 |
m.block = v->block; |
| 178 |
m.owner = 0; |
| 179 |
|
| 180 |
view.matrix = m; |
| 181 |
return view; |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
#ifdef JUNK |
| 186 |
int |
| 187 |
FUNCTION (gsl_matrix, view_from_matrix) (TYPE(gsl_matrix) * m, |
| 188 |
TYPE(gsl_matrix) * mm, |
| 189 |
const size_t k1, |
| 190 |
const size_t k2, |
| 191 |
const size_t n1, |
| 192 |
const size_t n2) |
| 193 |
{ |
| 194 |
if (n1 == 0) |
| 195 |
{ |
| 196 |
GSL_ERROR_VAL ("matrix dimension n1 must be positive integer", |
| 197 |
GSL_EINVAL, 0); |
| 198 |
} |
| 199 |
else if (n2 == 0) |
| 200 |
{ |
| 201 |
GSL_ERROR_VAL ("matrix dimension n2 must be positive integer", |
| 202 |
GSL_EINVAL, 0); |
| 203 |
} |
| 204 |
else if (k1 + n1 > mm->size1) |
| 205 |
{ |
| 206 |
GSL_ERROR_VAL ("submatrix dimension 1 exceeds size of original", |
| 207 |
GSL_EINVAL, 0); |
| 208 |
} |
| 209 |
else if (k2 + n2 > mm->size2) |
| 210 |
{ |
| 211 |
GSL_ERROR_VAL ("submatrix dimension 2 exceeds size of original", |
| 212 |
GSL_EINVAL, 0); |
| 213 |
} |
| 214 |
|
| 215 |
m->data = mm->data + k1 * mm->tda + k2 ; |
| 216 |
m->size1 = n1; |
| 217 |
m->size2 = n2; |
| 218 |
m->tda = mm->tda; |
| 219 |
m->block = mm->block; |
| 220 |
m->owner = 0; |
| 221 |
|
| 222 |
return GSL_SUCCESS; |
| 223 |
} |
| 224 |
|
| 225 |
int |
| 226 |
FUNCTION (gsl_vector, view_row_from_matrix) (TYPE(gsl_vector) * v, |
| 227 |
TYPE(gsl_matrix) * m, |
| 228 |
const size_t i) |
| 229 |
{ |
| 230 |
const size_t column_length = m->size1; |
| 231 |
|
| 232 |
if (i >= column_length) |
| 233 |
{ |
| 234 |
GSL_ERROR ("row index is out of range", GSL_EINVAL); |
| 235 |
} |
| 236 |
|
| 237 |
if (v->block != 0) |
| 238 |
{ |
| 239 |
GSL_ERROR ("vector already has memory allocated to it", GSL_ENOMEM); |
| 240 |
} |
| 241 |
|
| 242 |
v->data = m->data + MULTIPLICITY * i * m->tda ; |
| 243 |
v->size = m->size2; |
| 244 |
v->stride = 1; |
| 245 |
|
| 246 |
return GSL_SUCCESS; |
| 247 |
} |
| 248 |
|
| 249 |
int |
| 250 |
FUNCTION (gsl_vector, view_col_from_matrix) (TYPE(gsl_vector) * v, |
| 251 |
TYPE(gsl_matrix) * m, |
| 252 |
const size_t j) |
| 253 |
{ |
| 254 |
const size_t row_length = m->size2; |
| 255 |
|
| 256 |
if (j >= row_length) |
| 257 |
{ |
| 258 |
GSL_ERROR_VAL ("column index is out of range", GSL_EINVAL, 0); |
| 259 |
} |
| 260 |
|
| 261 |
if (v->block != 0) |
| 262 |
{ |
| 263 |
GSL_ERROR ("vector already has memory allocated to it", GSL_ENOMEM); |
| 264 |
} |
| 265 |
|
| 266 |
v->data = m->data + MULTIPLICITY * j ; |
| 267 |
v->size = m->size1; |
| 268 |
v->stride = m->tda; |
| 269 |
|
| 270 |
return GSL_SUCCESS; |
| 271 |
} |
| 272 |
#endif /* JUNK */ |
| 273 |
|