[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] creating a submatrix from a matrix in a loop

From: Brian Gough
Subject: Re: [Help-gsl] creating a submatrix from a matrix in a loop
Date: Tue, 16 Dec 2008 10:31:27 +0000
User-agent: Wanderlust/2.14.0 (Africa) Emacs/22.2 Mule/5.0 (SAKAKI)

At Thu, 11 Dec 2008 10:36:40 +0100,
George Kalema wrote:
> I have a matrix X of dimension [N by P]. This matrix contains data for
> K subjects
> meaning that there are K submatrices  of dimension [ni by P] in matrix X. I
> would like to take each of these submatrices Xi from X and use it for
> computation in a loop.
> How do I use gsl_matrix to do this?

You need some code like this in the inner loop:

  gsl_matrix_view Xi = gsl_matrix_submatrix (X, begin, 0, ni, P)
  gsl_matrix * work = gsl_matrix_alloc(ni, p);
  gsl_matrix_memcpy (work, &(Xi.matrix));
  /* do calculation on working copy */
  /* copy work back into X, if needed */
  gsl_matrix_memcpy (&(Xi.matrix), work);
  gsl_matrix_free (work)

You'll find many examples of this type of code in the linalg directory
of the GSL source.

Brian Gough

Support freedom by joining the FSF!

reply via email to

[Prev in Thread] Current Thread [Next in Thread]