|
Ublas : |
From: Gunter Winkler (guwi17_at_[hidden])
Date: 2006-12-06 03:49:58
On Tuesday 05 December 2006 19:08, michel schonewille wrote:
> As I am quite new to Boost, please bear with me if this is a "newby
> question"...
>
> I would like to use prod for a matrix vector multiplication, but using only
> a part of the matrix and the vector, so e.g. if the matrix is 10 rows and
> columns and the vector 10 rows, I would like to do a matrix vector
> multiplication on the "submatrix" consisting of the first 5 rows and
> columns, and the "subvector" consisting of the first 5 rows.
You can use project (from matrix_proxy.hpp and vector_proxy.hpp)
MATLAB: x(1:5) = A(1:5,1:5)*y(1:5)
project( x, range(0,5) )
= prod( project( A, range(0,5), range(0,5) ),
project( y, range(0,5) );
note that range specifies a half open interval (as usual in STL). Thus
range(a,b) means index j with a <= j < b
if you further know that the left hand side of the assignment has different
storage location that the right hand side (=lhs does not alias rhs) you can
add the noalias() function which gives ublas the chance to avoid temporaries.
noalias( project( x, range(0,5) ) )
= prod( project( A, range(0,5), range(0,5) ),
project( y, range(0,5) );
You find more details in the "overview" sections of the documentation.
mfg
Gunter