
Ublas : 
From: Nico Galoppo (nico_at_[hidden])
Date: 20070612 01:17:36
Sorry about the typo, that should obviously be
matrix_type m(n,n);
matrix_vector_range<matrix_type> diag(m, range (0,n), range (0,n));
double trace = sum(diag);
nico
Nico Galoppo wrote:
> Markus,
>
> 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);
>
> nico
>
> Markus Weimer wrote:
>> Hi,
>>
>> I have some legacy code that computes the inner product between two
>> rowmajor matrices by treating them as long vectors and applying a
>> vector inner product to these vectors. I guess getting a vectorview
>> 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]
>> http://lists.boost.org/mailman/listinfo.cgi/ublas
>
 Nico Galoppo UNCCH PhD. student http://www.ngaloppo.org +19199424388