
Answering myself, without a symmetric type I can just check for a diagonal matrix inside the pinv function and branch, see code below. Are there some recommendations for namespaces for functions like "pinv" ? Inside the loop, shall I use size_type? Thx for your patience, Patrick template <class T> boost::numeric::ublas::banded_matrix<T> pinv(const boost::numeric::ublas::banded_matrix<T>& m) { if (m.lower()==0 && m.upper()==0) // just for reading { boost::numeric::ublas::banded_matrix<T> rm(m.size2(),m.size1()); for (size_t i=0;i<rm.size1();i++) if (m(i,i)!=0) rm(i,i)=1/m(i,i); else rm(i,i)=0; return rm; } else { boost::numeric::ublas::banded_matrix<T> rm(m.size2(),m.size1()); // much missing // perhaps calling pinv(const boost::numeric::ublas::matrix<T>&), casting afterwards?, too much copying? return rm; } } template <class T> boost::numeric::ublas::matrix<T> pinv(const boost::numeric::ublas::matrix<T>& m) { using namespace boost::numeric::ublas; matrix<double> U,V; banded_matrix<double> S; svd(m,U,S,V); return prod(prod(V,pinv(S)),trans(U)); } ----- Original Message ----- From: "Patrick Kowalzick" <yg-boost-users@m.gmane.org> Newsgroups: gmane.comp.lib.boost.user Sent: Wednesday, April 23, 2003 10:14 AM Subject: uBlas - diagonal_matrix
Dear all,
I can use a banded_matrix to represent a diagonal matrix, but while some math for a diagonal matrix is a little bit easier than for a rectangular matrix, it would be nice to have such a type.
In my case:
I use a SVD A = U * S * V.T to calculate the moore-penrose-inverse A+.
Therfore I use A+ = V * S+ * U.T (i do not remember exact, but focus on S+) with S+ as the moore-penrose-inverse of S which is very easy to calculate.
but to use something like pinv(S) , do I need a symmetric_matrix type? Or can I implement a pinv() for a banded_matrix wich must fulfil the constraint of being diagonal?
Thanks a lot Patrick
Info: <http://www.boost.org> Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl> Unsubscribe: <mailto:boost-users-unsubscribe@yahoogroups.com>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/