symmetric_matrix operation
I am very new to the whole Ublas library. I have two symmetric matrices and I need to divide each element of the first matrix to the element in the second matrix. I am now doing smth like this: int _matrixsize; symmetric_matrix<double> mfirst(_matrixsize); symmetric_matrix<double> msecond(_matrixsize); symmetric_matrix<double> ratio (_matrixsize); for (int ifirst = 0; ifirst < _matrixsize; ifirst++) for (int isecond = 0; isecond < _matrixsize; isecond++) ratio(ifirst, isecond) = mfirst(ifirst, isecond) / msecond (ifirst, isecond); My questions are: 1. Can I use iterators (begin1, begin2) and if yes, then how? Examples in the doc use above method of iterating through elements, without using iterators. 2. I did not find built-in operators in the symmetric_matrix to do this division, but may be I overlooked smth or did not understand the docs? 3. If matrix "msecond" contains zeros - what is the "boost-way" to deal with this?
Hi Archie14, hth: # include <boost/numeric/ublas/symmetric.hpp> # include <boost/numeric/ublas/io.hpp> # include <boost/spirit/include/phoenix.hpp> # include <vector> # include <algorithm> using namespace boost::phoenix; using namespace boost::phoenix::arg_names; using namespace boost::numeric::ublas; int main () { symmetric_matrix<double,lower> m(3, 3), n(3,3), u(3,3); generate(arg1, lambda[val(1.0)] )(m.data()); generate(arg1, lambda[val(2.0)] )(n.data()); transform(arg1,n.data().begin(),u.data().begin(),lambda[arg1/arg2])(m.data()); std::cout << u << std::endl; } Best regards, Kim Archie14 schrieb:
My questions are: 1. Can I use iterators (begin1, begin2) and if yes, then how? Examples in the doc use above method of iterating through elements, without using iterators. 2. I did not find built-in operators in the symmetric_matrix to do this division, but may be I overlooked smth or did not understand the docs? 3. If matrix "msecond" contains zeros - what is the "boost-way" to deal with this?
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Archie14
-
Kim Kuen Tang