|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
MTL: Loop-free submatrix extractionPeter,
Thank you for your detailed response. I'm exploring MTL further. I hope you don't mind if I ask you some questions, the answers to which I couldn't find in the documentation. I need to extract a submatrix of a matrix, in a way similar to: octave:4> a=rand(4),b=a([1,2],[2,4]) a = 0.622575 0.844744 0.424293 0.207615 0.642011 0.102342 0.011919 0.168107 0.774028 0.446422 0.076552 0.759136 0.633285 0.792054 0.738877 0.982645 b = 0.84474 0.20762 0.10234 0.16811 Is there an elegant way of doing this, or I need to write loops? I feel optimistic having read about inserters in your documentation... My matrix is dense for now, but I will probably need to apply this to a sparse matrix as well. Thanks you in advance, Michael. > ----- Original Message ----- > From: "Peter Gottschling" <pgottsch@...> > To: "General Matrix Template Library (MTL) list" <mtl-devel@...>, "Matrix Template Library 4" <mtl4@...> > Subject: Re: MTL: MTL development road > Date: Mon, 03 Dec 2007 10:53:38 +0100 > > -- Want an e-mail address like mine? Get a free e-mail account today at www.mail.com! _______________________________________________ This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/ |
|
|
Re: MTL: Loop-free submatrix extraction
Hi again, Michael,
For dense2D and morton_dense there is a function sub_matrix (shame on me that there is no documentation yet). You can use it like: b= sub_matrix(a, begin_row, end_row, begin_column, end_column); As you see it only supports intervals of rows and columns not arbitrary sets. The reason is that this can be realized efficiently with a view. If you are going to write a function I would do something like (only sketch not tested code): template <typename Matrix, typename RowVector, typename ColVector> Matrix list_sub_matrix(const Matrix& matrix, const RowVector& row_vector, const ColVector& col_vector) { Matrix s(size(row_vector), size(col_vector)); { matrix::inserter<Matrix> ins(s); for (size_t r= 0; r < size(row_vector); r++) for (size_t c= 0; c < size(col_vector); c++) ins(r, c) << matrix[row_vector[r]][col_vector[c]]; } return s; } Returning a matrix is quite expensive at the moment but will be okay once I've implemented move semantics. I hope I haven't overseen a detail otherwise you can asked again. Once you have it done and tested I'd like to put it in the repository. Good luck and Merry Christmas, Peter On Dec 22, 2007, at 8:24 AM, Michael Smolsky wrote:
------------ Peter Gottschling Research Associate Open Systems Laboratory Indiana University 135 Lindley Hall Bloomington, IN 47405 Tel.: +1-812-855-3608 Fax: +1-812-856-0853 http://www.osl.iu.edu/~pgottsch _______________________________________________ This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/ |
|
|
|
|
|
Re: MTL: Loop-free submatrix extraction
Hi Michael,
Thank you for reminding me on that. I thought I already fixed that. Early January I hope finding the time for that. Cheers, Peter On Dec 26, 2007, at 8:44 PM, Michael Smolsky wrote: Peter, ------------ Peter Gottschling Research Associate Open Systems Laboratory Indiana University 135 Lindley Hall Bloomington, IN 47405 Tel.: +1-812-855-3608 Fax: +1-812-856-0853 http://www.osl.iu.edu/~pgottsch _______________________________________________ This list is archived at http://www.osl.iu.edu/MailArchives/mtl-devel/ |
| Free embeddable forum powered by Nabble | Forum Help |