|
Boost Users : |
From: Kresimir Fresl (fresl_at_[hidden])
Date: 2002-11-26 02:36:47
Stephen Crowley wrote:
> Is it possible to define a matrix that is part of a larger matrix, without
> having to create temporaries and copy part of the larger?
>
> /----------\
> | | |
> | SM | |
> |----| LM |
> | |
> \----------/
>
> I need to extract a sub-section of a matrix, multiply it, and then copy it back.
> I am currently using a temporary, but I have a feeling there must be a better way.
I suppose you are using ublas ;o)
`template <typename Matrix> class matrix_range' seems to be
what you are looking for:
==============================================
using namespace boost::numeric::ublas;
matrix<double> LM (10, 10);
// init LM
matrix<double> M1 (4, 4);
// init M1
matrix_range<matrix<double> > SM (LM, range (1, 5), range (2, 6));
LM = prod (M1, LM);
===============================================
matrix_range<> gives you a view of a part (a block) of a
matrix. Note that class `range' follows `convention' of iterator
ranges: `range (1, 5)' is `[1, 5)', i.e. `1, 2, 3, 4'.
There is also function `project()', so there's no need to declare
matrix_range<>:
===============================================
project (M, range (1, 5), range (2, 6))
= prod (M1, project (M, range (1, 5), range (2, 6)));
===============================================
More details on:
http://64.226.201.52/libs/numeric/ublas/doc/matrix_proxy.htm#matrix_range
Hope this help,
fres
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net