|
Packit |
67cb25 |
/* matrix/submatrix_source.c
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
67cb25 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
67cb25 |
* the Free Software Foundation; either version 3 of the License, or (at
|
|
Packit |
67cb25 |
* your option) any later version.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* This program is distributed in the hope that it will be useful, but
|
|
Packit |
67cb25 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
67cb25 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
67cb25 |
* General Public License for more details.
|
|
Packit |
67cb25 |
*
|
|
Packit |
67cb25 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
67cb25 |
* along with this program; if not, write to the Free Software
|
|
Packit |
67cb25 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
Packit |
67cb25 |
*/
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
QUALIFIED_VIEW(_gsl_matrix,view)
|
|
Packit |
67cb25 |
FUNCTION (gsl_matrix, submatrix) (QUALIFIED_TYPE(gsl_matrix) * m,
|
|
Packit |
67cb25 |
const size_t i, const size_t j,
|
|
Packit |
67cb25 |
const size_t n1, const size_t n2)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
QUALIFIED_VIEW(_gsl_matrix,view) view = NULL_MATRIX_VIEW;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
if (i >= m->size1)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
GSL_ERROR_VAL ("row index is out of range", GSL_EINVAL, view);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
else if (j >= m->size2)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
GSL_ERROR_VAL ("column index is out of range", GSL_EINVAL, view);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
else if (i + n1 > m->size1)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
GSL_ERROR_VAL ("first dimension overflows matrix", GSL_EINVAL, view);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
else if (j + n2 > m->size2)
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
GSL_ERROR_VAL ("second dimension overflows matrix", GSL_EINVAL, view);
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
{
|
|
Packit |
67cb25 |
TYPE(gsl_matrix) s = NULL_MATRIX;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
s.data = m->data + MULTIPLICITY * (i * m->tda + j);
|
|
Packit |
67cb25 |
s.size1 = n1;
|
|
Packit |
67cb25 |
s.size2 = n2;
|
|
Packit |
67cb25 |
s.tda = m->tda;
|
|
Packit |
67cb25 |
s.block = m->block;
|
|
Packit |
67cb25 |
s.owner = 0;
|
|
Packit |
67cb25 |
|
|
Packit |
67cb25 |
view.matrix = s;
|
|
Packit |
67cb25 |
return view;
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
}
|
|
Packit |
67cb25 |
|