Re: [eigen] Appending items in VectorXfs

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hm, feel kind of stupid about this, Eigen appears to have a method resize() for those types, that works great. For some reason it is not mentioned in the core documentation, or I couldn't find it anyway. Still, thanks everybody for the answers :)
take care

On Thu, Sep 10, 2009 at 6:54 PM, Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx> wrote:
Hi Panos,

With the default (development) branch you can do something like this
(untested)...

VectorXd x;
const int old_size = x.size();
// x.conservativeResize(old_size+10); // this is much (!) better...
for i=1:10
  x.conservativeResize(old_size+1); // not so good...
  x(old_size+i-1) = i;
end

It is obviously much better to do the resizing just once in case you
know how many elements you will be appending...

- Hauke

On 9/10/09, Rohit Garg <rpg.314@xxxxxxxxx> wrote:
>> It can be done by allocating a tmp of size x.size()+1 in each loops and
>> copying there, adding the element and copying back to x, but is nowhere
>> near
>> optimal so I wonder if it can be done with an Eigen function or in a
>> better/faster way?
> I doubt that. :(
>
>
> --
> Rohit Garg
>
> http://rpg-314.blogspot.com/
>
> Senior Undergraduate
> Department of Physics
> Indian Institute of Technology
> Bombay
>
>
>





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/