This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How to extend MatrixBase with my own methods

Tags: None
(comma "," separated)
p0wertripper
Registered Member
Posts
6
Karma
0
I know that it is described in the manual (http://eigen.tuxfamily.org/dox/TopicCus ... Eigen.html), but I cannot seem to figure it out.

For example, I want to extend the MatrixBase class with one method that looks like this:
Code: Select all
template<typename Derived>
inline double ReturnDoubleValue(const MatrixBase<Derived>& other) const {
   return 20.0;
}


What is it exactly that *.h file with the method should contain, so that I could then call it from the main of the file that contains the following (if it is necessary to add something to this file as well please let me know):

Code: Select all
#include <iostream>
#include <Eigen/Dense>

#include "MatrixBaseAddons.h"//*.h file containing the method

using namespace Eigen;
using namespace std;

int main() {
   MatrixXd A(2,2);
   A << 2,2,
   3,3;
   cout << A.ReturnDoubleValue(A);
   return 0;
}
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Code: Select all
#include <iostream>
#define EIGEN_MATRIXBASE_PLUGIN "MatrixBaseAddons.h"
#include <Eigen/Dense>

using namespace Eigen;
using namespace std;

int main() {
   MatrixXd A(2,2);
   A << 2,2,
   3,3;
   cout << A.ReturnDoubleValue(A);
   return 0;
}



Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]