Boost logo

Ublas :

From: Nico Galoppo (nico_at_[hidden])
Date: 2007-06-12 01:14:23


you can get the diagonal of a square matrix m as a vector expression like this:

matrix_type m(n,n);
matrix_vector_range<matrix_type> diag(m, range (0,n), range (0,n));

Then the trace is just the sum of the elements:

double trace = sum(mvs);


Markus Weimer wrote:
> Hi,
> I have some legacy code that computes the inner product between two
> row-major matrices by treating them as long vectors and applying a
> vector inner product to these vectors. I guess getting a vector-view
> onto a matrix is not possible in uBLAS. Thus, I want to compute the
> inner product between two matrices as follows:
> v = tr(A*B)
> However, I cannot find the trace operation in the documentation. Does
> that mean that there is no trace in uBLAS?
> Thanks in advance,
> Markus
> ------------------------------------------------------------------------
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]

Nico Galoppo        UNC-CH PhD. student