0
votes

What I am currently trying to do is get the data from my variable input, convert it into and Eigen matrix, do some computation and then map the result back to an c++ array.

       void RBM::reconstruct(double *input, double *w) 
       {

              double *data = input;
              mexPrintf("\n");

           for (int j = 0; j < 6; j++){
             mexPrintf("%f", data[j]);
           }
                mexPrintf("\n");

            Map<MatrixXd> XX(data,6,6);
            MatrixXd resultEigen;
            double *result;

           Map<MatrixXd>( result, 6, 6 ) =   XX;
           resultEigen = XX.transpose();

           Map<MatrixXd>( result, resultEigen.rows(), resultEigen.cols() ) = resultEigen;
         }

The above code compiles but i get (run Time error) probably link to an access violation and i can't really figure out where the problem is. Thanks for any hint.

2
result is not allocated.akakatak
Hallo akakatak, i thought the allocation would be done Dynamically. i am not that familiar with Eigen Library.JNW
Here is a reference about Eigen::Map. It says 'A matrix or vector expression mapping an existing array of data.' expression means this object does not hold any data in rum-time. it's only a wrapper. existing means you have to prepare an array because this object is only a expression.akakatak
I don't think this has nothing to do with MATLAB!Ander Biguri
If I am not wrong, you should be able to fix the issue by double *result[6*6];Ander Biguri

2 Answers

2
votes

You misunderstand what a Eigen::Map is. The map wraps an existing memory block and allows you to use Eigens functionality on that block. With a Eigen::Map Eigen does handle any of the memory allocations. This allow you to manipulate the data in objects from other libraries without copying back and forth. As mentioned in the comments, if you allocate the result array as double result[36]; the program should run fine.

0
votes
#include <Eigen/Dense>
#include <kdl/jntarray.hpp>

Eigen::MatrixXd mat_1, mat_2;
KDL::JntArray arr;

mat_1 = arr.data.matrix() - mat_2 ;

Here, array is converted to matrix