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*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Clang issue on MacOS when the set variable is used in the given data*From*: Arnaud BARRE <arnaud.barre@xxxxxxxxx>*Date*: Fri, 19 Apr 2013 13:48:15 +0200*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=PNbx+pZ60jb22uN7LUuRCuJzjL8rOwkmfVliWde3ikw=; b=DN81WRiQKmYC+fSJLKEddttUVbv3tO1ZhkRF0m3OdNb/m7uA6X3pP1Vfm/6+RB4m9G +3YrUWuB1vBKH3hnBRVBZSzGmTrMuMMep+1KMZdr8MjAARvc5VUNluKAiG0iCA2ofVn6 85hKpMSlGjSU+kQQacui8Z84YiHKtQLydjFj6/1idVGs7Xw3fVP1tp93+aDgK5tQx0Oo Y7zlYLrb8TzrfXjDbbFugWSZIjwg8OL2psEoTU/HHWbRWiFFHEiwn1NN8lzkI2kBoQcV CtZvHeMqj1YGeptypovTQZWIyJEHGr1rPNNTdZoW08D2g5/u/pZ8ZvyI2UQnGZEdKlcH sHrw==

To give you the whole code:

// I,J,K are Eigen::Matrix<double,3,1> objectsEigen::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;

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

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 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

Arnaud

On Fri, Apr 19, 2013 at 1:23 PM, Christoph Hertzberg <chtz@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:

On 19.04.2013 13:14, Gael Guennebaud 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

----------------------------------------------

**Follow-Ups**:**Re: [eigen] Clang issue on MacOS when the set variable is used in the given data***From:*Gael Guennebaud

**References**:**[eigen] Clang issue on MacOS when the set variable is used in the given data***From:*Arnaud BARRE

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

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

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

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

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Clang issue on MacOS when the set variable is used in the given data** - Next by Date:
**Re: [eigen] Clang issue on MacOS when the set variable is used in the given data** - Previous by thread:
**Re: [eigen] Clang issue on MacOS when the set variable is used in the given data** - Next by thread:
**Re: [eigen] Clang issue on MacOS when the set variable is used in the given data**

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