Re: [eigen] Appending items in VectorXfs |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Appending items in VectorXfs
- From: Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx>
- Date: Thu, 10 Sep 2009 18:54:50 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=PdElgH04eaHryDN/y29ncGgyeCNRJkB7uOtRxuEyA4w=; b=DUDN3nF0nbcvuCUizYoBt1ufFGhaZaphaydwO/r5b89UtWpsWIXLnYlakdfnRkRCmE lrbze1sFTAQUkuJCAAMJBg9wul0IufXlJsh3L6dk5vAANrxxqy79eezIIMEtdkp3Nc4Y 81lFlpxOhrY1GQO2srmJ9Wt+taZ8J0KZjPyiU=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=MpbhYdDcwd3IGTAJGWgaIxLw5V0idfS6h67+SOtlTo132LxuPkaKBt3fMSgfSYFV1D S0WDK73fMNxwtaG2fm4eGGjhA/29xb0CjKmMsAc4C1gLxxAcze2WwFIIDC/VZtKO89yS IYI4vQ53aJptD7KMV8KCUTjoUNZhX8J5XQqoc=
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
>
>
>