Bugs about reverse iterator of matrix_binary

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Bugs about reverse iterator of matrix_binary

Shangtong Zhang
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.

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.


_______________________________________________
ublas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: [hidden email]