Boost logo

Ublas :

From: Michael Stevens (mail_at_[hidden])
Date: 2006-04-04 15:47:14


On Wednesday, 29. March 2006 21:12, Brad Bell (old) wrote:
> What is the best way to perform matrix element by element operations using
> Ublas matrices; i.e., suppose
> C(i,j) = A(i,j) Op B(i,j)
> where Op is +, -, *, or / ?

Maybe I am misunderstanding the question but Op +, - are
 simply:
        C = A + B; C = A - B;
Op * and / are:
        C = element_prod(A,B);
        C = element_div(A,B);

It is possible to generallise for any Op by using the 'matrix_binary_traits'
type can a user defined functional object.

> Is there a way to use all the elements of a matrix as a vector (in row
> major or column major order) with out copying the elements of the matrix ?

Sadly there is no general vectorisation facility in uBLAS. uBLAS matrices also
onlyhave row/column iterators but no element iterators. Must Matrix classes
have data accessor methods that allow access to the underling Storage types
however.

> If so, perhaps this is the best way; i.e., convert the matrices to
> vector expressions, then perform the element by element operations, then
> convert the vector expression to a resulting matrix ?
>
> Perhaps it is best to store everything as vectors and only convert to
> matrices expressions for matrix operations such as matrix multiplication
> and solving linear equations ?

Michael

-- 
___________________________________
Michael Stevens Systems Engineering
34128 Kassel, Germany
Phone/Fax: +49 561 5218038
Navigation Systems, Estimation  and
                 Bayesian Filtering
    http://bayesclasses.sf.net
___________________________________