| 1 |
/* matrix/rowcol_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 |
QUALIFIED_VIEW(_gsl_vector,view) |
| 21 |
FUNCTION (gsl_matrix, row) (QUALIFIED_TYPE(gsl_matrix) * m, const size_t i) |
| 22 |
{ |
| 23 |
QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW; |
| 24 |
|
| 25 |
if (i >= m->size1) |
| 26 |
{ |
| 27 |
GSL_ERROR_VAL ("row index is out of range", GSL_EINVAL, view); |
| 28 |
} |
| 29 |
|
| 30 |
{ |
| 31 |
TYPE(gsl_vector) v = NULL_VECTOR; |
| 32 |
|
| 33 |
v.data = m->data + i * MULTIPLICITY * m->tda; |
| 34 |
v.size = m->size2; |
| 35 |
v.stride = 1; |
| 36 |
v.block = m->block; |
| 37 |
v.owner = 0; |
| 38 |
|
| 39 |
view.vector = v; |
| 40 |
return view; |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
QUALIFIED_VIEW(_gsl_vector,view) |
| 45 |
FUNCTION (gsl_matrix, column) (QUALIFIED_TYPE(gsl_matrix) * m, const size_t j) |
| 46 |
{ |
| 47 |
QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW; |
| 48 |
|
| 49 |
if (j >= m->size2) |
| 50 |
{ |
| 51 |
GSL_ERROR_VAL ("column index is out of range", GSL_EINVAL, view); |
| 52 |
} |
| 53 |
|
| 54 |
{ |
| 55 |
TYPE(gsl_vector) v = NULL_VECTOR; |
| 56 |
|
| 57 |
v.data = m->data + j * MULTIPLICITY; |
| 58 |
v.size = m->size1; |
| 59 |
v.stride = m->tda; |
| 60 |
v.block = m->block; |
| 61 |
v.owner = 0; |
| 62 |
|
| 63 |
view.vector = v; |
| 64 |
return view; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
QUALIFIED_VIEW(_gsl_vector,view) |
| 69 |
FUNCTION (gsl_matrix, diagonal) (QUALIFIED_TYPE(gsl_matrix) * m) |
| 70 |
{ |
| 71 |
QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW; |
| 72 |
|
| 73 |
TYPE(gsl_vector) v = NULL_VECTOR; |
| 74 |
v.data = m->data; |
| 75 |
v.size = GSL_MIN(m->size1,m->size2); |
| 76 |
v.stride = m->tda + 1; |
| 77 |
v.block = m->block; |
| 78 |
v.owner = 0; |
| 79 |
|
| 80 |
view.vector = v; |
| 81 |
return view; |
| 82 |
} |
| 83 |
|
| 84 |
QUALIFIED_VIEW(_gsl_vector,view) |
| 85 |
FUNCTION (gsl_matrix, subdiagonal) (QUALIFIED_TYPE(gsl_matrix) * m, |
| 86 |
const size_t k) |
| 87 |
{ |
| 88 |
QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW; |
| 89 |
|
| 90 |
if (k >= m->size1) |
| 91 |
{ |
| 92 |
GSL_ERROR_VAL ("subdiagonal index is out of range", GSL_EINVAL, view); |
| 93 |
} |
| 94 |
|
| 95 |
{ |
| 96 |
TYPE(gsl_vector) v = NULL_VECTOR; |
| 97 |
|
| 98 |
v.data = m->data + k * MULTIPLICITY * m->tda; |
| 99 |
v.size = GSL_MIN(m->size1 - k, m->size2); |
| 100 |
v.stride = m->tda + 1; |
| 101 |
v.block = m->block; |
| 102 |
v.owner = 0; |
| 103 |
|
| 104 |
view.vector = v; |
| 105 |
return view; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
QUALIFIED_VIEW(_gsl_vector,view) |
| 110 |
FUNCTION (gsl_matrix, superdiagonal) (QUALIFIED_TYPE(gsl_matrix) * m, |
| 111 |
const size_t k) |
| 112 |
{ |
| 113 |
QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW; |
| 114 |
|
| 115 |
|
| 116 |
if (k >= m->size2) |
| 117 |
{ |
| 118 |
GSL_ERROR_VAL ("column index is out of range", GSL_EINVAL, view); |
| 119 |
} |
| 120 |
|
| 121 |
{ |
| 122 |
TYPE(gsl_vector) v = NULL_VECTOR; |
| 123 |
|
| 124 |
v.data = m->data + k * MULTIPLICITY; |
| 125 |
v.size = GSL_MIN(m->size1, m->size2 - k); |
| 126 |
v.stride = m->tda + 1; |
| 127 |
v.block = m->block; |
| 128 |
v.owner = 0; |
| 129 |
|
| 130 |
view.vector = v; |
| 131 |
return view; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
QUALIFIED_VIEW(_gsl_vector,view) |
| 136 |
FUNCTION (gsl_matrix, subrow) (QUALIFIED_TYPE(gsl_matrix) * m, const size_t i, const size_t offset, const size_t n) |
| 137 |
{ |
| 138 |
QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW; |
| 139 |
|
| 140 |
if (i >= m->size1) |
| 141 |
{ |
| 142 |
GSL_ERROR_VAL ("row index is out of range", GSL_EINVAL, view); |
| 143 |
} |
| 144 |
else if (n == 0) |
| 145 |
{ |
| 146 |
GSL_ERROR_VAL ("vector length n must be positive integer", |
| 147 |
GSL_EINVAL, view); |
| 148 |
} |
| 149 |
else if (offset + n > m->size1) |
| 150 |
{ |
| 151 |
GSL_ERROR_VAL ("dimension n overflows matrix", GSL_EINVAL, view); |
| 152 |
} |
| 153 |
|
| 154 |
{ |
| 155 |
TYPE(gsl_vector) v = NULL_VECTOR; |
| 156 |
|
| 157 |
v.data = m->data + MULTIPLICITY * (i * m->tda + offset); |
| 158 |
v.size = n; |
| 159 |
v.stride = 1; |
| 160 |
v.block = m->block; |
| 161 |
v.owner = 0; |
| 162 |
|
| 163 |
view.vector = v; |
| 164 |
return view; |
| 165 |
} |
| 166 |
} |
| 167 |
|
| 168 |
QUALIFIED_VIEW(_gsl_vector,view) |
| 169 |
FUNCTION (gsl_matrix, subcolumn) (QUALIFIED_TYPE(gsl_matrix) * m, const size_t j, const size_t offset, const size_t n) |
| 170 |
{ |
| 171 |
QUALIFIED_VIEW(_gsl_vector,view) view = NULL_VECTOR_VIEW; |
| 172 |
|
| 173 |
if (j >= m->size2) |
| 174 |
{ |
| 175 |
GSL_ERROR_VAL ("column index is out of range", GSL_EINVAL, view); |
| 176 |
} |
| 177 |
else if (n == 0) |
| 178 |
{ |
| 179 |
GSL_ERROR_VAL ("vector length n must be positive integer", |
| 180 |
GSL_EINVAL, view); |
| 181 |
} |
| 182 |
else if (offset + n > m->size2) |
| 183 |
{ |
| 184 |
GSL_ERROR_VAL ("dimension n overflows matrix", GSL_EINVAL, view); |
| 185 |
} |
| 186 |
|
| 187 |
{ |
| 188 |
TYPE(gsl_vector) v = NULL_VECTOR; |
| 189 |
|
| 190 |
v.data = m->data + MULTIPLICITY * (offset * m->tda + j); |
| 191 |
v.size = n; |
| 192 |
v.stride = m->tda; |
| 193 |
v.block = m->block; |
| 194 |
v.owner = 0; |
| 195 |
|
| 196 |
view.vector = v; |
| 197 |
return view; |
| 198 |
} |
| 199 |
} |