Boost logo

Ublas :

From: Vardan Akopian (vakopian_at_[hidden])
Date: 2005-06-24 15:52:13


On 6/24/05, Gunter Winkler <guwi17_at_[hidden]> wrote:
> On Friday 24 June 2005 00:13, Vardan Akopian wrote:
> >>> Interestingly, when NDEBUG is off, ublas's internal runtime check
> >>> catches the problem with an assertion failure:
> >>> Assertion failed in file
> >>> ../../../../boost_1_32_0/boost/numeric/ublas/matrix_assign.hpp at line
> >>> 797:
> >>> equals (m, cm)
> >>> terminate called after throwing an instance of
> >>> 'boost::numeric::ublas::external_logic'
> >>> what(): external logic
> >>> Aborted
> >>
> >> That means, that ublas internal checks work perfectly and inform the user
> >> about a broken algorithm.
>
> I tracked the bug down until matrix_expression.hpp:2121-2131 where
> matrix_binary::const_iterator1::operator += ( n )
> is defined as
> const_iterator1 &operator += (difference_type n) {
> i_ += n, it1_ += n, it2_ += n;
> return *this;
> }
> which may move the iterator (far) behind the end if n is too large. I suggest
> changing this to n times calling operator ++ () which already checks the
> bounds (depending on the iterator type.) Or it may move the iterator if the
> index is already larger than i_.

Wouldn't it be too inefficient though, to do the check n times?
I would think, we might wonna do the other way around, i.e. have a function
 increment(tag, differnece_type n), which does the appropriate check
for each iterator type in the general case, then call this from
operator+= and operator++.

-Vardan