|
Ublas : |
Subject: [ublas] Bugs about reverse iterator of matrix_binary
From: Shangtong Zhang (zhangshangtong.cpp_at_[hidden])
Date: 2016-04-02 09:56:38
Hi,
Recently Iâm working on toeplitz matrix. However I find some confusing problems with matrix_binary.
See the following code:
> banded_matrix<int> bm(3, 4, 2, 2);
> bm(0, 0) = 7;
> std::cout << bm(0, 0);
> bm(0, 2) = 9;
> std::cout << bm(0, 2);
> auto row = (bm + bm).begin1();
> std::cout << '\n';
> for (auto it = row.begin(); it < row.end(); ++it) {
> std::cout << *it << ' ';
> }
It works well and outputs â14 0 18 0â as expected.
When I change it to reverse iterator,
> for (auto it = row.rbegin(); it < row.rend(); ++it) {
> std::cout << *it << ' ';
> }
It fails with output â0 0 0 0â.
If I use normal matrix rather than banded matrix, both iterator and reverse iterator work well.
See https://github.com/uBLAS/ublas/blob/master/include/boost/numeric/ublas/matrix_expression.hpp <https://github.com/uBLAS/ublas/blob/master/include/boost/numeric/ublas/matrix_expression.hpp>
There are many condition checks which only make sense for normal iterators, such as Line 2516, Line 2548.
> BOOST_UBLAS_INLINE
> void decrement (packed_random_access_iterator_tag) {
> if (it1_ != it1_end_)
> if (j_ <= it1_.index2 ())
> -- it1_;
> if (it2_ != it2_end_)
> if (j_ <= it2_.index2 ())
> -- it2_;
> -- j_;
> }
However 'dense access specialisationâ(Line 2482) doesnât have these checks, so it works well for reverse iterators.
Iâm not sure how to fix this issue.
Shangtong Zhang,
Senior Student,
School of Computer Science,
Fudan University, PRC.