Re: [eigen] Clang issue on MacOS when the set variable is used in the given data

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


To give you the whole code:

// I,J,K are Eigen::Matrix<double,3,1> objects
// JC is a pointer to an Eigen::Matrix<double,3,1> object
Eigen::Matrix<double,4,4> local, inv;
Eigen::Matrix<double,3,1> y = (J - I).normalized();
Eigen::Matrix<double,3,1> x = y.cross(K - I).normalized();
local << x, y, x.cross(y), (J + I) / 2.0, 0.0, 0.0, 0.0, 1.0;

// I Don't use Inverse as I assume the following code is faster
inv = Eigen::Matrix<double,4,4>::Identity();
Eigen::Matrix<double,3,3> Rinv = local.block(0,0,3,3).transpose();
inv.block(0,0,3,3) = Rinv;
inv.block(0,3,3,1) = -(Rinv * local.block(0,3,3,1));

double d = (I - J).norm(); // cannot be 0
double theta = std::asin(offset / d) * 2.0;
Eigen::Matrix<double,2,2> rot;
rot << std::cos(theta), -1.0 * std::sin(theta), std::sin(theta), std::cos(theta);
Eigen::Matrix<double,4,1> foo;
foo << I, 1.0;
foo = inv * foo; // Don't inline this code in the next line. There is an issue between Eigen 3.1.2 and Clang.
foo << 0.0, rot * foo.block(1,0,2,1), 1.0;
*JC = (local * foo).block(0,0,3,1);
// End code

This code is a direct translation of old Eigen2 code. So I don't know that some "homogeneous()" method exist. I should check that.

I reused the variable here to limit the amount of memory needed. I know it is only a 3x1 vector, but I tried to apply this everywhere in my code. We work with quit big time series data, so the less amount of memory we used, the best it is. In this idea also, I tried to reduce the number of temporary variable.

I know I can use the methods "tail", or "segment" instead of "block", but the difference is only in the simplicity of writting the code. There is no optimisation in these two methods compared to "block", is there?

Regarding, the use of Transform. Long time ago (i..e. more than three years), I contacted Gael on IRC about the possibility to compute a 4x4 matrix with 3x1. At that time, it was not possible, but it seems It is now. Let me check how it works.

So It seems I have to rewrite all of this code :-)

Have you also some other advice to better write this code? This only a fery small subset of all the function used to compute data in a biomechanical model.

Thanks a lot,

Arnaud






On Fri, Apr 19, 2013 at 1:23 PM, Christoph Hertzberg <chtz@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
On 19.04.2013 13:14, Gael Guennebaud wrote:
On Fri, Apr 19, 2013 at 12:53 PM, Christoph Hertzberg
<chtz@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I always assumed that
   foo << A, B, C;
is basically the same as
   foo.segment<dim_A>(0          ) = A;
   foo.segment<dim_B>(dim_A      ) = B;
   foo.segment<dim_C>(dim_A+dim_B) = C;

yes, in theory it's what happen in that order. but in that case
Arnaud's 1st example should fail regardless on the compiler. So there
might a c++ subtlety I'm missing.

I assume the compiler does some over-optimization here, i.e., loads values of foo and starts evaluating the product before beginning to write to foo. I don't know if that kind of optimization is allowed by the C++ standard (it would not surprise me if it was).


Christoph



--
----------------------------------------------
Dipl.-Inf., Dipl.-Math. Christoph Hertzberg
Cartesium 0.049
Universität Bremen
Enrique-Schmidt-Straße 5
28359 Bremen

Tel: +49 (421) 218-64252
----------------------------------------------





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