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

Implementing log for Matrix object

Tags: None
(comma "," separated)
vkubicki
Registered Member
Posts
14
Karma
0

Implementing log for Matrix object

Tue Jan 27, 2015 12:43 pm
Hi,

I created a plugin file included through EIGEN_MATRIXBASE_PLUGIN. I have been able to implement everything I need so far, except for the log and exp functions. My first naive implementation was to add this to EIGEN_MATRIXBASE_PLUGIN:

Code: Select all
/** Element-wise log computation */
inline const CwiseUnaryOp<internal::scalar_log_op<Scalar>,
                   const Derived>
log() const
{
  return CwiseUnaryOp<internal::scalar_log_op<Scalar>,
                      const Derived>(derived(),
                                     internal::scalar_log_op<Scalar>());
}


However, this trigger the following compilation error:

Code: Select all
../eigen/Eigen/src/Core/MatrixBase.h:459:47: error: ‘const Eigen::MatrixLogarithmReturnValue<Derived> Eigen::MatrixBase<Derived>::log() const’ cannot be overloaded


Which comes from the log() declaration further down MatrixBase.h:

Code: Select all
const MatrixLogarithmReturnValue<Derived> log() const;


Since this class is declared but not defined, I also get the error:

Code: Select all
src/Prog/mcTest.cpp:42:13: error: invalid use of incomplete type ‘const class Eigen::MatrixLogarithmReturnValue<Eigen::Matrix<double, 1, -1> >’


Since the definition is in the "unsupported section" of the code, what are my best options ? I could edit MatrixBase.h to remove the log() declaration, and use my log member function which returns a CwiseUnaryOp. The problem is doing so will alter Eigen, something I am not sure will be an option when deploying my code (neither am I sure that embedding a modified version of Eigen will be).

Or should I include the definition from the unsupported section in my EIGEN_MATRIXBASE_PLUGIN ?

Are there other options ?

Regards,

VK
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Indeed, there is conflict with the matrix logarithm and coefficient-wise logarithm. A workaround would be to define the class MatrixLogarithmReturnValue yourself: it only has to inherit CwiseUnaryOp<internal::scalar_log_op<typename Derived::Scalar>, const Derived>, and implement the respective constructor.


Bookmarks



Who is online

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