Re: [eigen] AutoDiffScalar

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


Hi

Quoting Björn Piltz <bjornpiltz@xxxxxxxxxxxxxx>:

>> * Your change in realloacate kills performances if, e.g.,
>> Scalar==AutoDiffScalar<VectorXf> because here we really want shallow
>> copies. I agree that using memcpy is unsafe if the Scalar object
>> creates a child-object which itself reference the parent... but
>> recall that here we are designing containers for numerical values,
>> not general containers. So I think it is fine to use memcpy here.
>> Also a memcpy is much faster than simple for loops, and it is very
>> important to provide optimal performances here.
> Ah, this point is key. I really don't care so much about the other
> changes, but this memcpy() caused a nasty crash when doing second
> derivatives. AFAICT memcpy is inherently dangerous on anything but
> POD

Yes. It's undefined.

(By the way, for relatively small sizes (several 100kB), memcpy doesn't
seem to be much faster than ordinary loops. I ran a quick test (GCC
4.4.1, -O3), copying an array of 128.000 floats 100.000 times with
memcpy and a for loop respectively. While memcpy was faster, the
difference was rather small. The loop took around 5.92 seconds, memcpy
around 5.84 seconds (rough average). The difference became significantly
larger when copying 128.000.000 floats 100 times. Memcpy 20s, loop 30s.)

> How about expanding NumTraits to let Eigen know if a Scalar is a POD
> or not. That way we can also make ei_construct_elements_of_array()
> and ei_destruct_elements_of_array() more performant as well by not
> calling placement new and dtor on PODs.

I second this.

Markus




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