eigen3

performance of coefficient-wise array operations of the eigen library with mkl backend

懵懂的女人 提交于 2019-12-24 04:33:07
问题 I am porting a Matlab algorithm with lots of coefficient-wise array operations to C++, which look like this example, but are often much more complex: Eigen::Array<double, Dynamic, 1> tx2(12); tx2 << 1,2,3,4,5,6; Eigen::Array<double, Dynamic, 1> tx1(12); tx1 << 7,8,9,10,11,12; Eigen::Array<double, Dynamic, 1> x = (tx1 + tx2) / 2; The C++ code turned out to be significantly slower than Matlab (around 20%). So in a next step I tried to turn on the Intel MKL implementation of Eigen, which did

Fixed Sized Eigen types as parameters

青春壹個敷衍的年華 提交于 2019-12-24 00:58:00
问题 I am trying to write a function that takes fixed size Eigen Types (but templated on Scalar type e.g. float/double). I have read http://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html but I am not able to make it work perfectly. Here is the function definition: template <typename T> inline Matrix<T, 3, 3> makeSkewSymmetric(const Matrix<T, 3, 1>& v) { Matrix<T, 3, 3> out; out << 0, -v[2], v[1], v[2], 0, -v[0], -v[1], v[0], 0; return out; } Now I am using this as following: Vector3d a

how to use Eigen for B-Splines for noisy sequence data

馋奶兔 提交于 2019-12-23 20:26:04
问题 In the below picture, the spap2 function is used in Matlab to smooth noisy data. The result is very good. Eigen library supports this functionality Splines. I'm looking for an example in Eigen to obtain similar results. For the Matlab, I've used spap2(4, 4, time, noisyY); Data is provided in this format time noisyData 1.766 6.61202 1.767 11.4159 1.768 8.29416 1.769 8.29416 1.77 8.29416 1.771 6.02606 1.772 4.37819 1.773 4.37819 1.774 4.37819 1.775 3.18094 1.776 2.31109 1.777 1.67911 1.778 1

How to get rank of a matrix in Eigen library?

佐手、 提交于 2019-12-23 16:42:25
问题 How to get rank of a matrix in eigen? 回答1: You need to convert your matrix to a rank-revealing decomposition. For instance FullPivLU . If you have a matrix3f it looks like this : FullPivLU<Matrix3f> lu_decomp(your_matrix); auto rank = lu_decomp.rank(); Edit Decomposing the matrix is the most common way to get the rank. Although, LU is not the most reliable way to achieve it for floating values as explained on the rank article on wikipedia When applied to floating point computations on

Re-use Eigen::SimplicialLLT's symbolic decomposition

為{幸葍}努か 提交于 2019-12-23 16:13:49
问题 I am struggling a bit with the API of the Eigen Library, namely the SimplicialLLT class for Cholesky factorization of sparse matrices. I have three matrices that I need to factor and later use to solve many equation systems (changing only the right side) - therefore I would like to factor these matrices only once and then just re-use them. Moreover, they all have the same sparcity pattern, so I would like to do the symbolic decomposition only once and then use it for the numerical

Convert Eigen Affine3d to Affine2d

我与影子孤独终老i 提交于 2019-12-22 18:22:21
问题 I have an affine transform in 3D and I wish to discard any z-axis information from. Is there a convenient way to convert from an Affine3d to and Affine2d ? 回答1: Try following: Affine2d S2d = Translation2d(S3d.translation().topRows<2>()) * S3d.linear().topLeftCorner<2,2>(); Demo: #include <Eigen/Dense> #include <iostream> #include <string> int main() { using namespace Eigen; using namespace std; Vector3d p3d(1.,2.,3.); cout << p3d << endl << endl; Affine3d S3d = Translation3d(2.,2.,2.)*Scaling

using several eigen matrices as statetypes in boost/odeint

可紊 提交于 2019-12-22 12:14:25
问题 I am working on a physics problem for which I have to evolve parameters according to ODEs. From time to time they have to manipulated so that I would like to have a data type that can be used with routines such as diagonalisation,... Therefore, I implemented a class with eigen::Matrix as members and want to perform the integration with odeint. For a single eigen::matrix this worked fine. I made a minimal example: #include <iostream> #include <fstream> #include <cmath> #include <string>

How to write/read an Eigen matrix from binary file

可紊 提交于 2019-12-21 05:06:37
问题 To write Eigen::Matrix to file I really like to use the following: typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> Matrix_MxN; Matrix_MxN J = Matrix_MxN::Zeros(10,10); std::ofstream("matrix.txt") << J; But unfortunately, something that can do the opposite is not defined: std::ifstream("matrix.txt") >> J; To circumvent this problem, how can you read/write an Eigen::Matrix to binary file instead ? 回答1: You can define these methods: namespace Eigen{ template<class Matrix> void

Issue casting C++ Eigen::Matrix types via templates

怎甘沉沦 提交于 2019-12-19 03:17:02
问题 I'm writing a C++ function that is templated on type (either float or double ), and uses Eigen::Matrix internally. The function will be using a combination of float , double , and templated type Eigen:Matrix objects. Eigen::Matrix<>::cast() works just fine for double and float , though I'm hitting an odd issue when using it with templated types. See code below: #include "Eigen/Core" // Version 3.2.4 (eigen-eigen-10219c95fe65) template <typename Scalar> void Foo() { Eigen::Matrix<double, 3, 1>

Issue casting C++ Eigen::Matrix types via templates

允我心安 提交于 2019-12-19 03:16:22
问题 I'm writing a C++ function that is templated on type (either float or double ), and uses Eigen::Matrix internally. The function will be using a combination of float , double , and templated type Eigen:Matrix objects. Eigen::Matrix<>::cast() works just fine for double and float , though I'm hitting an odd issue when using it with templated types. See code below: #include "Eigen/Core" // Version 3.2.4 (eigen-eigen-10219c95fe65) template <typename Scalar> void Foo() { Eigen::Matrix<double, 3, 1>