20 #ifndef __TRACE_UBLAS_HPP__ 21 #define __TRACE_UBLAS_HPP__ 23 #include <boost/numeric/ublas/matrix.hpp> 24 #include <boost/numeric/ublas/matrix_proxy.hpp> 32 typename E::value_type trace(
const E &A)
34 const size_t n = (std::min)(A.size1(),A.size2());
35 typename E::value_type sum = 0;
36 for (
size_t i=0; i<n; ++i)
43 typename E::value_type log_trace(
const E &A)
45 const size_t n = (std::min)(A.size1(),A.size2());
46 typename E::value_type sum = 0;
47 for (
size_t i=0; i<n; ++i)
48 sum += std::log(A(i,i));
54 template<
class E1,
class E2>
55 typename E1::value_type trace_prod(
const E1 & A,
const E2 & B )
57 namespace ublas = boost::numeric::ublas;
59 const size_t n = (std::min)(A.size1(),B.size2());
60 typename E1::value_type sum = 0;
61 for (
size_t i=0; i<n; ++i)
62 sum += ublas::inner_prod(ublas::row(A,i),ublas::column(B,i));
Namespace of the library interface.