[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] more than one submatrix of the same matrix?
From: |
Eduardo Zacarías B. |
Subject: |
[Help-gsl] more than one submatrix of the same matrix? |
Date: |
Thu, 29 Jan 2004 23:19:07 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 |
Hi!
I have come across some very particular problem:
I need to manipulate different rows of a matrix and I made two pointers
pointing to the address of the matrix part of some views, created by the
submatrix function. Curiously enough, the view seems to be overwritten
by a newly created view, even if they point to different rows. I have
looked at the documentation and didn't find anything saying that I
couldn't create two independent views of the same matrix. That, or I'm
really blind...
However, I have not tried to create vector views.
The following code illustrates the problem. The original annoyances
happened with complex matrices
Platform is Slackware Linux 9 with locally compiled GSL 1.3 (gcc 3.2.2)
Any light on is highly appreciated. It's been several hours trying to
figure out this.
Thank you very much!
Eduardo
code follows:
---------------------------------------------------
#include "all_the_includes.h"
int showMat(gsl_matrix *mat);
int main() {
gsl_matrix *mat = gsl_matrix_calloc(3,2);
gsl_matrix_set(mat,0,0,1);
gsl_matrix_set(mat,0,1,2);
gsl_matrix_set(mat,1,0,3);
gsl_matrix_set(mat,1,1,4);
gsl_matrix_set(mat,2,0,5);
gsl_matrix_set(mat,2,1,6);
std::cout << "Original matrix:\n\n";
showMat(mat);
std::cout << "Slicing second row\n";
gsl_matrix *secondRow = &gsl_matrix_submatrix(mat,1,0,1,mat->size2).matrix;
showMat(secondRow);
std::cout << "Slicing third row\n";
gsl_matrix *thirdRow = &gsl_matrix_submatrix(mat,2,0,1,mat->size2).matrix;
showMat(thirdRow);
std::cout << "Showing slice of the second row again:\n";
showMat(secondRow);
}
int showMat(gsl_matrix *mat) {
for (int row = 0; row < mat->size1; ++row) {
for (int col = 0; col < mat->size2; ++col) {
std::cout << gsl_matrix_get(mat,row,col) << " ";
}
std::cout << "\n";
}
std::cout << "\n";
}
---------------------------------------------------
And the output is:
---------------------------------------------------
Original matrix:
1 2
3 4
5 6
Slicing second row
3 4
Slicing third row
5 6
Showing slice of the second row again:
5 6
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-gsl] more than one submatrix of the same matrix?,
Eduardo Zacarías B. <=