
Ublas : 
Subject: Re: [ublas] indirect_array<> and resize()
From: Gunter Winkler (guwi17_at_[hidden])
Date: 20080921 07:26:12
Am Sonntag, 21. September 2008 12:11 schrieb Ralf Denzer:
> Ok, but I can do
>
> ublas::matrix<double> M(5,5);
> ublas::indirect_array<> ia(3);
> ia(0) = 1; ia[1] = 2; ia[2] = 4;
> ublas::matrix_indirect<ublas::matrix<double> > Mi(M, ia,ia);
> M.resize(4,4);
> std::cout << "after M.resize() Mi=\n" << Mi << std::endl; // bad
> index "bombs"
This is a general problem of references: They usually are invalid when
the structure of the underlying container changes. (BTW: resize does
not preserve the data, thus M and Mi are useless anyway.)
> The real cause for my question is that I like to initialize something
> like
>
> ublas::vector<ublas::indirect_array<> > vec_ia;
> vec_ia.resize(10);
but why not
ublas::vector<ublas::indirect_array<> > vec_ia;
// ...
vec_ia = ublas::vector<ublas::indirect_array<> >(10);
the constructor is not slower than resize.
> for (unsigned i = 0; i < 10; ++i)
> {
> vec_ia(i).resize( n(i) ); // n(i) are user given unsigned int's
> (size_t's) vec_ia(i)(1:n(i)) = ... // ok, matlab notation
> }
>
> With this data structure I'd like to do the usual
> gathering/scattering process in a finite element code. For element
> "i" the corresponding indices are stored in vec_ia(i) . Sorry, that I
> didn't mentioned this earlier.
I am still not convinced because the number of dof does not change,
right?
But anyway  you can try to add resize() to indirect_array (storage.hpp)
and see how it works. I think an additional member function will not
hurt ...
mfg
Gunter