dilevin / CSC417-a4-cloth-simulation

Cloth simulation using co-rotational linear elasticity
51 stars 14 forks source link

PSA on .data(), .transpose(), and .transposeInPlace() #3

Open mshoe opened 4 years ago

mshoe commented 4 years ago

Say you have a matrix that you want to flatten into a vector. You notice that Eigen is column major by default, so just calling .data() will give you the data in column major order. Since you want your flattened vector to be row major order, you instead call .transpose().data(). But .transpose() doesn't actually modify the data of the original matrix, so you will still get a column major ordered vector. Instead you need to call .transposeInPlace() first, then call .data().

dilevin commented 4 years ago

this is a good point. Eigen operators also have an eval method you can use to force evaluation of commands. Otherwise eigen does lazy evaluation (waiting until you assign the operations to a variable) in order to maximize performance.