Boost logo

Ublas :

From: Michael Stevens (mail_at_[hidden])
Date: 2005-06-02 14:09:24


Hi Jon,

> The current implementation of ublas::indirect_array appears to implicity
> treat an empty index set as "the set of all indices".
>
> In the following implementation of indirect_array::preprocess(), the
> call to indirect_array::all() returns a static, default-constructed
> instance, hence which has an empty set of indirection indices:
>
> [ublas/storage.hpp line 1554]
> BOOST_UBLAS_INLINE
> indirect_array preprocess (size_type size) const {
> if (*this != all ())
> return *this;
> indirect_array ia (size);
> for (size_type i = 0; i < size; ++ i)
> ia (i) = i;
> return ia;
> }
>
> It appears to me that this definition results in an inconsistency.
> Introducing some variable names...
>
> typedef ublas ublas::vector<double> vector_type;
> vector_type v(100);
> ublas::indirect_array< > indices1 = ... , indices2 = ... ;
> ublas::vector_indirect<vector_type> view1(v, indices1), view2(v,
> indices2);
>
> ... IMHO the following would make a sensible invariant:
> "[indices1.size() < indices2.size()] implies [view1.size() <
> view2.size()]"
>
> Currently, this relationship does not necessarily hold if
> 0==size(indices1).

I see. That this invariant fails is rather uggly.

> I would be grateful for any comments. In particular
> * Does anyone else see this as a problem?
> * Would it be a good idea to modify the current implementation? (Does
> anyone currently rely on the default behaviour, such that they would be
> affected by a change)

I think a change would be reasonable. I certainly don't rely on this
behaviour.

We could effect such a by using:
        if (this != &all_)

In this case only the explicit use of all() would break your invariant.

Michael

-- 
___________________________________
Michael Stevens Systems Engineering
Navigation Systems, Estimation  and
                 Bayesian Filtering
    http://bayesclasses.sf.net
___________________________________