1 /* matrix/view_source.c
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2007 Gerard Jungman, Brian Gough
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.
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.
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.
20 QUALIFIED_VIEW (_gsl_matrix,view)
21 FUNCTION (gsl_matrix, view_array) (QUALIFIER ATOMIC * array,
22 const size_t n1, const size_t n2)
24 QUALIFIED_VIEW (_gsl_matrix,view) view = NULL_MATRIX_VIEW;
28 GSL_ERROR_VAL ("matrix dimension n1 must be positive integer",
33 GSL_ERROR_VAL ("matrix dimension n2 must be positive integer",
38 TYPE(gsl_matrix) m = NULL_MATRIX;
40 m.data = (ATOMIC *)array;
52 QUALIFIED_VIEW (_gsl_matrix,view)
53 FUNCTION(gsl_matrix, view_array_with_tda) (QUALIFIER ATOMIC * base,
58 QUALIFIED_VIEW (_gsl_matrix,view) view = NULL_MATRIX_VIEW;
62 GSL_ERROR_VAL ("matrix dimension n1 must be positive integer",
67 GSL_ERROR_VAL ("matrix dimension n2 must be positive integer",
72 GSL_ERROR_VAL ("matrix dimension n2 must not exceed tda",
78 TYPE(gsl_matrix) m = NULL_MATRIX;
80 m.data = (ATOMIC *)base;
92 QUALIFIED_VIEW (_gsl_matrix,view)
93 FUNCTION(gsl_matrix, view_vector) (QUALIFIED_TYPE(gsl_vector) * v,
97 QUALIFIED_VIEW (_gsl_matrix,view) view = NULL_MATRIX_VIEW;
101 GSL_ERROR_VAL ("matrix dimension n1 must be positive integer",
106 GSL_ERROR_VAL ("matrix dimension n2 must be positive integer",
109 else if (v->stride != 1)
111 GSL_ERROR_VAL ("vector must have unit stride",
114 else if (n1 * n2 > v->size)
116 GSL_ERROR_VAL ("matrix size exceeds size of original",
121 TYPE(gsl_matrix) m = NULL_MATRIX;
136 QUALIFIED_VIEW (_gsl_matrix,view)
137 FUNCTION(gsl_matrix, view_vector_with_tda) (QUALIFIED_TYPE(gsl_vector) * v,
142 QUALIFIED_VIEW (_gsl_matrix,view) view = NULL_MATRIX_VIEW;
146 GSL_ERROR_VAL ("matrix dimension n1 must be positive integer",
151 GSL_ERROR_VAL ("matrix dimension n2 must be positive integer",
154 else if (v->stride != 1)
156 GSL_ERROR_VAL ("vector must have unit stride",
161 GSL_ERROR_VAL ("matrix dimension n2 must not exceed tda",
164 else if (n1 * tda > v->size)
166 GSL_ERROR_VAL ("matrix size exceeds size of original",
171 TYPE(gsl_matrix) m = NULL_MATRIX;
187 FUNCTION (gsl_matrix, view_from_matrix) (TYPE(gsl_matrix) * m,
188 TYPE(gsl_matrix) * mm,
196 GSL_ERROR_VAL ("matrix dimension n1 must be positive integer",
201 GSL_ERROR_VAL ("matrix dimension n2 must be positive integer",
204 else if (k1 + n1 > mm->size1)
206 GSL_ERROR_VAL ("submatrix dimension 1 exceeds size of original",
209 else if (k2 + n2 > mm->size2)
211 GSL_ERROR_VAL ("submatrix dimension 2 exceeds size of original",
215 m->data = mm->data + k1 * mm->tda + k2 ;
219 m->block = mm->block;
226 FUNCTION (gsl_vector, view_row_from_matrix) (TYPE(gsl_vector) * v,
227 TYPE(gsl_matrix) * m,
230 const size_t column_length = m->size1;
232 if (i >= column_length)
234 GSL_ERROR ("row index is out of range", GSL_EINVAL);
239 GSL_ERROR ("vector already has memory allocated to it", GSL_ENOMEM);
242 v->data = m->data + MULTIPLICITY * i * m->tda ;
250 FUNCTION (gsl_vector, view_col_from_matrix) (TYPE(gsl_vector) * v,
251 TYPE(gsl_matrix) * m,
254 const size_t row_length = m->size2;
258 GSL_ERROR_VAL ("column index is out of range", GSL_EINVAL, 0);
263 GSL_ERROR ("vector already has memory allocated to it", GSL_ENOMEM);
266 v->data = m->data + MULTIPLICITY * j ;