Boost logo

Boost Users :

From: jhr.walter_at_[hidden]
Date: 2003-03-10 17:47:23


Hi Roland,

you wrote:

> As I am still on my spline templates, I came on to the following
> beast:
>
> template<class T>
> struct index_vector : public vector<std::pair<T,
> vector<ublas::vector<T>::size_type> > > {};
>
> This should be an index vector that relates to a double (first) a
> vector of indices (second) which happens to be different for
> each 'first'. So far so easy.
>
> I can say:
>
> index_vector<double> IY;
> IY.resize(5);
> IY[0].first = 3.14;
> IY[0].second.reset(vector<double>(3));
> IY[0].second[2] = 1;
>
> But I cannot:
>
> index_vector<double> IZ(IY);
>
> or
>
> index_vector<double> IZ;
> IZ = IY;
>
> or
> IZ.reset(IY);
>
> This compiles, but gives me runtime assertions because of size
> mismatches.

Yes. The following mix of std::vector and ublas::vector seems to work for me
under GCC 3.2.1:
----------
#include <vector>
#include <boost/numeric/ublas/vector.hpp>

using namespace std;
using namespace boost::numeric;

template<class T>
struct index_vector : public vector<std::pair<T,
ublas::vector<typename ublas::vector<T>::size_type> > > {};

int main ()
{
    index_vector<double> IY;
    IY.resize(5);
    IY[0].first = 3.14;
    IY[0].second.reset(ublas::vector<std::size_t>(3));
    IY[0].second[2] = 1;

    index_vector<double> IZ1(IY);
    index_vector<double> IZ2;
    IZ2 = IY;
}

----------

Do you need ublas algorithms for the outer or the inner vector? Otherwise
you could use std::vector instead.

> I think my derived class is not 'copy constructible'
> and 'assignable'.
> Is there a simple way to fix this?

I believe yes: we could drop the requirement that assignments have to be
size conformant. But this requirement is pretty useful when doing basic
linear algebra IMHO. So I'd like to hear other opinions...

> (I am not even sure whether this is a uBLAS matter. So please simple
> tell me, and I will try to learn the missing parts.)

It's definitely an ublas matter: should we increase standard compatibility
or stay with the size conformance restriction.

Best,

Joerg


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net