|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
zero_matrix iterationHello dears,
I've noticed that zero_matrix is "not iteratable". That is if you iterate a zero_matrix Z either by-row or by-column the condition "Z.begin1() != Z.end1()" or "Z.begin1() != Z.end2()", respectively, is always FALSE (according to how zero_matrix iterators are defined). However if you iterate by using plain row/column indices (instead of iterators) you're successfully able to iterate through a zero_matrix. Is this conceptually right? I mean, in my opinion a zero_matrix(N,M) should be iteratable just like any other ordinary matrix, both with iterators and with simple indices. By preventing iteration (with iterators) it would seem that the matrix has size 0, while it has a precise dimension (NxM) What do you think? Just for curiosity, I've looked at MTL4. It seems MTL4 does not have a zero-matrix type. Rather you assign a scalar 0 to a matrix type or you call the set_to_zero function. The resulting matrix seems to be iteratable. The code below shows an example of what I said above: ---[code]--- #include <boost/numeric/ublas/matrix.hpp> #include <iostream> int main() { typedef double value_type; typedef boost::numeric::ublas::zero_matrix<value_type> matrix_type; matrix_type Z(5,4); std::cout << "Iteration by ITERATORS" << std::endl; for (matrix_type::const_iterator1 row_it = Z.begin1(); row_it != Z.end1(); ++row_it) { std::cout << "Iteration by ITERATORS: never entered" << std::endl; for (matrix_type::const_iterator2 col_it = row_it.begin(); col_it != row_it.end(); ++col_it) { matrix_type::size_type row(col_it.index1()); matrix_type::size_type col(col_it.index2()); std::cout << "Z(" << row << "," << col << ") = " << *col_it << " ==> " << value_type(0) << std::endl; } } std::cout << "Iteration by INDICES" << std::endl; for (matrix_type::size_type row = 0; row < Z.size1(); ++row) { for (matrix_type::size_type col = 0; col < Z.size2(); ++col) { std::cout << "Z(" << row << "," << col << ") = " << Z(row, col) << " ==> " << value_type(0) << std::endl; } } } ---[/code]--- Cheers!! -- Marco _______________________________________________ ublas mailing list ublas@... http://lists.boost.org/mailman/listinfo.cgi/ublas Sent to: lists@... |
|
|
Re: zero_matrix iterationMarco Guazzone schrieb:
> Hello dears, > > I've noticed that zero_matrix is "not iteratable". > That is if you iterate a zero_matrix Z either by-row or by-column the > condition "Z.begin1() != Z.end1()" or "Z.begin1() != Z.end2()", > respectively, is always FALSE (according to how zero_matrix iterators > are defined). > However if you iterate by using plain row/column indices (instead of > iterators) you're successfully able to iterate through a zero_matrix. > > Is this conceptually right? > > iterators may skip matrix/vector elements that are zero. Because the zero_matrix has only zero elements the condition zm.begin1() == zm.end1() is always satisfied. The interator range [(begin1(), end1()) is always empty. mfg Gunter _______________________________________________ ublas mailing list ublas@... http://lists.boost.org/mailman/listinfo.cgi/ublas Sent to: lists@... |
| Free embeddable forum powered by Nabble | Forum Help |