This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Matrix/Vector: Docu typo, feature request, & code
- From: Hans Ekkehard Plesser <hans dot plesser at itf dot nlh dot no>
- To: gsl-discuss at sources dot redhat dot com
- Date: Fri, 1 Mar 2002 14:57:16 +0100 (CET)
- Subject: Matrix/Vector: Docu typo, feature request, & code
- Reply-to: hans dot plesser at itf dot nlh dot no
Hi!
First, a tiny bug in the Matrix documentation. In the documentation
of gsl_matrix_submatrix the function prototype is given as
gsl_matrix_view gsl_matrix_submatrix (gsl_matrix * m, size_t i, size_t j, size_t n1, size_t n2)
but subsequent text talks about indices k1 and k2; obviously one
should replace i:=k1, j:=k2.
Now a feature request: I would like to see functions to copy a
(contiguous) part of a matrix/vector into an arbitrary position of
another matrix/vector. I append some code for double
matrices/vectors, implementing this functionality based on gsl
highlevel functions. Maybe someone with more experiences could
re-code this in a more "direct" manner and generalize it to all data
types (I found the vector/matrix code a bit too confusing to mess with
it directly).
Best regards,
Hans
/*******************************************************************/
int copy_submatrix(gsl_matrix *dest, const size_t doff1, const size_t doff2,
const gsl_matrix *src, const size_t soff1, const size_t soff2,
const size_t n1, const size_t n2)
/* Copy rows soff1 ... soff1+n1, columns soff2 ... soff2+n2 of matrix src
to rows doff1 ... doff1+n1, columns doff2 ... doff2+n2 of matrix dest
The source and destination submatrices have to fit into src and dest,
respectively.
(C) Hans E. Plesser, 2002-03-01 (hans dot plesser at itf dot nlh dot no)
This code is copyright under the GNU Public License 2
*/
{
int status;
gsl_matrix_view
dview = gsl_matrix_submatrix(dest, doff1, doff2, n1, n2);
gsl_matrix_const_view
sview = gsl_matrix_const_submatrix(src, soff1, soff2, n1, n2);
if ( !dview.matrix.data || !sview.matrix.data )
GSL_ERROR("could not create matrix views", GSL_EBADLEN);
status = gsl_matrix_memcpy(&dview.matrix, &sview.matrix);
/* no need to handle error here: if error handler is on,
it will be called from gsl_matrix_memcpy */
return status;
}
/*******************************************************************/
int copy_subvector(gsl_vector *dest, const size_t doff,
const gsl_vector *src, const size_t soff,
const size_t n)
/* Copy entries soff ... soff+n of vector src
to entries doff ... doff+n of vector dest
The source and destination subvectors have to fit into src and dest,
respectively.
(C) Hans E. Plesser, 2002-03-01 (hans dot plesser at itf dot nlh dot no)
This code is copyright under the GNU Public License 2
*/
{
int status;
gsl_vector_view
dview = gsl_vector_subvector(dest, doff, n);
gsl_vector_const_view
sview = gsl_vector_const_subvector(src, soff, n);
if ( !dview.vector.data || !sview.vector.data )
GSL_ERROR("could not create vector views", GSL_EBADLEN);
status = gsl_vector_memcpy(&dview.vector, &sview.vector);
/* no need to handle error here: if error handler is on,
it will be called from gsl_vector_memcpy */
return status;
}
/*******************************************************************/