2090: Add matrix trace and transposition.

https://svn.lrde.epita.fr/svn/oln/trunk/milena Index: ChangeLog from Ugo Jardonnet <ugo.jardonnet@lrde.epita.fr> Add matrix trace and transposition. * mln/algebra/mat.hh (transpose,trace): Add. mat.hh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) Index: mln/algebra/mat.hh --- mln/algebra/mat.hh (revision 2089) +++ mln/algebra/mat.hh (working copy) @@ -256,6 +256,16 @@ std::ostream& operator<<(std::ostream& ostr, const mat<n,m,T>& v); + // transpose + + template<unsigned n, unsigned m, typename T> + mat<m,n,T> + trans(const mat<n,m,T>& matrix); + + // trace + + template<unsigned n, typename T> inline + float tr(const mat<n,n,T>& m); # ifndef MLN_INCLUDE_ONLY @@ -489,6 +499,27 @@ return ostr; } + + template<unsigned n, unsigned m, typename T> + mat<m,n,T> + trans(const mat<n,m,T>& matrix) + { + mat<m,n,T> tmp; + for (unsigned i = 0; i < n; ++i) + for (unsigned j = 0; j < m; ++j) + tmp(j,i) = matrix(i,j); + return tmp; + } + + template<unsigned n, typename T> inline + float tr(const mat<n,n,T>& m) + { + float f = 0.f; + for (unsigned i = 0; i < n; ++i) + f += m(i,i); + return f; + } + # endif // ! MLN_INCLUDE_ONLY } // end of namespace mln::algebra
participants (1)
-
Ugo Jardonnet