I need to perform A*v in Eigen where v is a vector of size p with t ones in random positions and p-t zeros, for more details look this question.
My first question is: there is any way to do it in Eigen? If you know how to do it, please answer this question.
My second question is: in the first linked question I found a time and memory efficient method via std::vector<bool>, then it would be pretty easy to use it through Eigen::Map.
The problem is that I tried to do the following (just for testing purpose):
Eigen::Matrix<bool,2,1> v;
Eigen::Matrix<float,2,2> A;
v<<1,0;
A<<1,2,3,4;
A*v;
But I get a compile error (find it at the end of the question). How can I do it? A simple workaround could be declaring Eigen::Matrix<float,2,1> v; but this could be really memory inefficient (especially considering that v could be big).
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h: In instantiation of ‘struct Eigen::internal::traits<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >’:
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:41:34: required from ‘class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >’
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:48:34: required from ‘class Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >’
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:114:7: required from ‘class Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>’
../Math.hpp:83:7: required from ‘static void Math::createHashTable(const cv::Mat&, cv::Mat&, cv::Mat&, int, int) [with T = float]’
../CloudCache.cpp:155:58: required from here
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:43:112: error: no type named ‘ReturnType’ in ‘struct Eigen::internal::scalar_product_traits<float, bool>’
typedef typename scalar_product_traits<typename _LhsNested::Scalar, typename _RhsNested::Scalar>::ReturnType Scalar;
^
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:69:51: error: no type named ‘ReturnType’ in ‘struct Eigen::internal::scalar_product_traits<float, bool>’
|| ( (ColsAtCompileTime % packet_traits<Scalar>::size) == 0
^
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:76:51: error: no type named ‘ReturnType’ in ‘struct Eigen::internal::scalar_product_traits<float, bool>’
|| ( (RowsAtCompileTime % packet_traits<Scalar>::size) == 0
^
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:94:63: error: no type named ‘ReturnType’ in ‘struct Eigen::internal::scalar_product_traits<float, bool>’
: InnerSize * (NumTraits<Scalar>::MulCost + LhsCoeffReadCost + RhsCoeffReadCost)
^
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:95:41: error: no type named ‘ReturnType’ in ‘struct Eigen::internal::scalar_product_traits<float, bool>’
+ (InnerSize - 1) * NumTraits<Scalar>::AddCost,
^
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:107:41: error: no type named ‘ReturnType’ in ‘struct Eigen::internal::scalar_product_traits<float, bool>’
&& (InnerSize % packet_traits<Scalar>::size == 0)
^
In file included from /usr/local/include/eigen3/Eigen/Core:278:0,
from ../Math.hpp:13,
from ../CloudCache.cpp:15:
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h: In instantiation of ‘class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >’:
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:48:34: required from ‘class Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >’
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:114:7: required from ‘class Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>’
../Math.hpp:83:7: required from ‘static void Math::createHashTable(const cv::Mat&, cv::Mat&, cv::Mat&, int, int) [with T = float]’
../CloudCache.cpp:155:58: required from here
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:67:25: error: using-declaration for non-member at class scope
using Base::operator*;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:68:17: error: using-declaration for non-member at class scope
using Base::derived;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:69:17: error: using-declaration for non-member at class scope
using Base::const_cast_derived;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:70:17: error: using-declaration for non-member at class scope
using Base::rows;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:71:17: error: using-declaration for non-member at class scope
using Base::cols;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:72:17: error: using-declaration for non-member at class scope
using Base::size;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:73:17: error: using-declaration for non-member at class scope
using Base::rowIndexByOuterInner;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:74:17: error: using-declaration for non-member at class scope
using Base::colIndexByOuterInner;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:75:17: error: using-declaration for non-member at class scope
using Base::coeff;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:76:17: error: using-declaration for non-member at class scope
using Base::coeffByOuterInner;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:77:17: error: using-declaration for non-member at class scope
using Base::packet;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:78:17: error: using-declaration for non-member at class scope
using Base::packetByOuterInner;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:79:17: error: using-declaration for non-member at class scope
using Base::writePacket;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:80:17: error: using-declaration for non-member at class scope
using Base::writePacketByOuterInner;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:81:17: error: using-declaration for non-member at class scope
using Base::coeffRef;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:82:17: error: using-declaration for non-member at class scope
using Base::coeffRefByOuterInner;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:83:17: error: using-declaration for non-member at class scope
using Base::copyCoeff;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:84:17: error: using-declaration for non-member at class scope
using Base::copyCoeffByOuterInner;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:85:17: error: using-declaration for non-member at class scope
using Base::copyPacket;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:86:17: error: using-declaration for non-member at class scope
using Base::copyPacketByOuterInner;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:87:26: error: using-declaration for non-member at class scope
using Base::operator();
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:88:26: error: using-declaration for non-member at class scope
using Base::operator[];
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:89:17: error: using-declaration for non-member at class scope
using Base::x;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:90:17: error: using-declaration for non-member at class scope
using Base::y;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:91:17: error: using-declaration for non-member at class scope
using Base::z;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:92:17: error: using-declaration for non-member at class scope
using Base::w;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:93:17: error: using-declaration for non-member at class scope
using Base::stride;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:94:17: error: using-declaration for non-member at class scope
using Base::innerStride;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:95:17: error: using-declaration for non-member at class scope
using Base::outerStride;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:96:17: error: using-declaration for non-member at class scope
using Base::rowStride;
^
/usr/local/include/eigen3/Eigen/src/Core/DenseBase.h:97:17: error: using-declaration for non-member at class scope
using Base::colStride;
^
In file included from /usr/local/include/eigen3/Eigen/Core:279:0,
from ../Math.hpp:13,
from ../CloudCache.cpp:15:
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h: In instantiation of ‘class Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >’:
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:114:7: required from ‘class Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>’
../Math.hpp:83:7: required from ‘static void Math::createHashTable(const cv::Mat&, cv::Mat&, cv::Mat&, int, int) [with T = float]’
../CloudCache.cpp:155:58: required from here
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:71:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::derived’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
using Base::derived;
^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:72:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::const_cast_derived’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
using Base::const_cast_derived;
^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:73:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::rows’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
using Base::rows;
^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:74:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::cols’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
using Base::cols;
^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:75:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::size’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
using Base::size;
^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:76:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::coeff’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
using Base::coeff;
^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:77:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::coeffRef’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
using Base::coeffRef;
^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:79:17: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::eval’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
using Base::eval;
^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:82:25: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::operator*=’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
using Base::operator*=;
^
/usr/local/include/eigen3/Eigen/src/Core/MatrixBase.h:83:25: error: no members matching ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::operator/=’ in ‘Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >::Base {aka class Eigen::DenseBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
using Base::operator/=;
^
In file included from /usr/local/include/eigen3/Eigen/Core:20:0,
from ../Math.hpp:13,
from ../CloudCache.cpp:15:
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h: In instantiation of ‘class Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>’:
../Math.hpp:83:7: required from ‘static void Math::createHashTable(const cv::Mat&, cv::Mat&, cv::Mat&, int, int) [with T = float]’
../CloudCache.cpp:155:58: required from here
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:121:5: error: no members matching ‘Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>::Base {aka Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::derived’ in ‘Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>::Base {aka class Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
EIGEN_DENSE_PUBLIC_INTERFACE(CoeffBasedProduct)
^
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:121:5: error: no members matching ‘Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>::Base {aka Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}::const_cast_derived’ in ‘Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>::Base {aka class Eigen::MatrixBase<Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6> >}’
EIGEN_DENSE_PUBLIC_INTERFACE(CoeffBasedProduct)
^
In file included from /usr/local/include/eigen3/Eigen/Core:254:0,
from ../Math.hpp:13,
from ../CloudCache.cpp:15:
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h: In instantiation of ‘Eigen::CoeffBasedProduct<Lhs, Rhs, NestingFlags>::CoeffBasedProduct(const Lhs&, const Rhs&) [with Lhs = Eigen::Matrix<float, 2, 2>; Rhs = Eigen::Matrix<bool, 2, 1>; LhsNested = const Eigen::Matrix<float, 2, 2>&; RhsNested = const Eigen::Matrix<bool, 2, 1>&; int NestingFlags = 6]’:
/usr/local/include/eigen3/Eigen/src/Core/GeneralProduct.h:598:91: required from ‘const typename Eigen::ProductReturnType<Derived, OtherDerived>::Type Eigen::MatrixBase<Derived>::operator*(const Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived = Eigen::Matrix<bool, 2, 1>; Derived = Eigen::Matrix<float, 2, 2>; typename Eigen::ProductReturnType<Derived, OtherDerived>::Type = Eigen::CoeffBasedProduct<const Eigen::Matrix<float, 2, 2>&, const Eigen::Matrix<bool, 2, 1>&, 6>]’
../Math.hpp:83:7: required from ‘static void Math::createHashTable(const cv::Mat&, cv::Mat&, cv::Mat&, int, int) [with T = float]’
../CloudCache.cpp:155:58: required from here
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:154:7: error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
EIGEN_STATIC_ASSERT((internal::scalar_product_traits<typename Lhs::RealScalar, typename Rhs::RealScalar>::Defined),
^
subdir.mk:30: recipe for target 'CloudCache.o' failed
make: *** [CloudCache.o] Error 1
You need to cast to the relevant type. Eigen doesn't support implicit type casting so you'd have to write:
A*v.cast<float>();
There was a hint to this in the error output:
/usr/local/include/eigen3/Eigen/src/Core/products/CoeffBasedProduct.h:154:7: error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
Related
I want to use CGAL wrapper for OpenGR to register two point clouds(reference.ply and 1.ply), and I wrote the following simple program (basically copying from the CGAL OpenGR example):
#include <CGAL/Simple_cartesian.h>
#include <CGAL/IO/read_ply_points.h>
#include <CGAL/IO/write_ply_points.h>
#include <CGAL/property_map.h>
#include <CGAL/Aff_transformation_3.h>
#include <CGAL/OpenGR/compute_registration_transformation.h>
#include <fstream>
#include <iostream>
#include <utility>
#include <vector>
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_3 Point_3;
typedef K::Vector_3 Vector_3;
typedef std::pair<Point_3, Vector_3> Pwn;
typedef CGAL::First_of_pair_property_map<Pwn> Point_map;
typedef CGAL::Second_of_pair_property_map<Pwn> Normal_map;
namespace params = CGAL::parameters;
int main(int argc, const char** argv) {
const char* fname1 = "data/reference.ply";
const char* fname2 = "data/1.ply";
std::vector<Pwn> pwns1, pwns2;
std::ifstream input(fname1);
if (!input ||
!CGAL::read_ply_points(input, std::back_inserter(pwns1),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<Pwn>()).
normal_map(Normal_map())))
{
std::cerr << "Error: cannot read file " << fname1 << std::endl;
return EXIT_FAILURE;
}
input.close();
input.open(fname2);
if (!input ||
!CGAL::read_ply_points(input, std::back_inserter(pwns2),
CGAL::parameters::point_map(Point_map()).
normal_map(Normal_map())))
{
std::cerr << "Error: cannot read file " << fname2 << std::endl;
return EXIT_FAILURE;
}
input.close();
std::cerr << "Computing registration transformation using OpenGR Super4PCS.." << std::endl;
// First, compute registration transformation using OpenGR Super4PCS
K::Aff_transformation_3 res =
std::get<0>( // get first of pair, which is the transformation
CGAL::OpenGR::compute_registration_transformation
(pwns1, pwns2,
params::point_map(Point_map()).normal_map(Normal_map()),
params::point_map(Point_map()).normal_map(Normal_map()))
);
return EXIT_SUCCESS;
}
The error occurs when I compile the program using Makefile created by cmake, and there are a lot of errors that involves the Eigen library (The error is pretty long):
senyangjiang#senyangjiang-MS-7A38:~/Desktop/dev_compare/cgal_compare/build$ make
Scanning dependencies of target compare
[ 50%] Building CXX object CMakeFiles/compare.dir/compare.cpp.o
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/Product.h:29:127: error: no type named ‘ReturnType’ in ‘struct Eigen::ScalarBinaryOpTraits<float, double, Eigen::internal::scalar_product_op<float, double> >’
29 | typedef typename ScalarBinaryOpTraits<typename traits<LhsCleaned>::Scalar, typename traits<RhsCleaned>::Scalar>::ReturnType Scalar;
| ^~~~~~
home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:83:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::coeff’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
83 | using Base::coeff;
| ^~~~~
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:84:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::coeffByOuterInner’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
84 | using Base::coeffByOuterInner;
| ^~~~~~~~~~~~~~~~~
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:85:26: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::operator()’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
85 | using Base::operator();
| ^
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:86:26: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::operator[]’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
86 | using Base::operator[];
| ^
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:87:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::x’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
87 | using Base::x;
| ^
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:88:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::y’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
88 | using Base::y;
| ^
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:89:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::z’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
89 | using Base::z;
| ^
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:90:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::w’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
90 | using Base::w;
| ^
... more errors like this
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/AssignEvaluator.h:834:3: error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
834 | EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/compare.dir/build.make:63: CMakeFiles/compare.dir/compare.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/compare.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I can solve the error by changing my code from
typedef CGAL::Simple_cartesian<double> K;
to
typedef CGAL::Simple_cartesian<float> K;
in other words, changing double to float. But I prefer using double due to higher precision, is there any other way to resolve the error?
I want to use "reshape()" fuction in Eigen unsupported tensor, but my source code cannot be compiled.
The compilation was done as follows.
g++ -std=c++14 -I (path to Eigen) eigen_practice.cpp -o eigen_practice
and here is my source code.
# include "unsupported/Eigen/CXX11/Tensor"
using namespace Eigen;
int main(){
Tensor<float, 2> input(7, 11);
Eigen::array<int, 3> three_dims{{7, 11, 1}};
Tensor<float, 3> result = input.reshape(three_dims);
return 0;
}
And here is the error messeage.
In file included from eigen_practice.cpp:12:
In file included from /Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/Tensor:145:
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:397:7: error:
no matching member function for call to 'resize'
resize(TensorEvaluator<const Assign, DefaultDevice>(assign, Defaul...
^~~~~~
eigen_practice.cpp:63:28: note: in instantiation of function template
specialization 'Eigen::Tensor<float, 3, 0,
long>::Tensor<Eigen::TensorReshapingOp<const std::__1::array<int, 3>,
Eigen::Tensor<float, 2, 0, long> > >' requested here
Tensor<float, 3> result = input.reshape(three_dims);
^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:423:10: note:
candidate function template not viable: no known conversion from 'const
Eigen::TensorEvaluator<const Eigen::TensorAssignOp<Eigen::Tensor<float, 3,
0, long>, const Eigen::TensorReshapingOp<const std::__1::array<int, 3>,
Eigen::Tensor<float, 2, 0, long> > >, Eigen::DefaultDevice>::Dimensions'
(aka 'const std::__1::array<int, 3>') to 'Eigen::Tensor<float, 3, 0,
long>::Index' (aka 'long') for 1st argument
void resize(Index firstDimension, IndexTypes... otherDimensions)
^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:432:28: note:
candidate function not viable: no known conversion from
'array<int, [...]>' to 'const array<long, [...]>' for 1st argument
EIGEN_DEVICE_FUNC void resize(const array<Index, NumIndices>& dimensions)
^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:450:28: note:
candidate function not viable: no known conversion from 'const
Eigen::TensorEvaluator<const Eigen::TensorAssignOp<Eigen::Tensor<float, 3,
0, long>, const Eigen::TensorReshapingOp<const std::__1::array<int, 3>,
Eigen::Tensor<float, 2, 0, long> > >, Eigen::DefaultDevice>::Dimensions'
(aka 'const std::__1::array<int, 3>') to 'const
DSizes<Eigen::Tensor<float, 3, 0, long>::Index, NumIndices>' (aka 'const
DSizes<long, NumIndices>') for 1st argument
EIGEN_DEVICE_FUNC void resize(const DSizes<Index, NumIndices>& dimensions) {
^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:479:10: note:
candidate template ignored: could not match 'Sizes' against 'array'
void resize(const Sizes<Indices...>& dimensions) {
^
/Users/yamamototatsuto/Dropbox/include_for_C++/eigen/unsupported/Eigen/CXX11/src/Tensor/Tensor.h:459:10: note:
candidate function not viable: requires 0 arguments, but 1 was provided
void resize()
^
1 error generated.
This source code is just a copy of what is in the documentation.
(https://eigen.tuxfamily.org/dox/unsupported/eigen_tensors.html)
So it should compile, but it doesn't.
How can I solve it?
And why the error message mentions about "resize()" function?
I have the following function that is throwing an error. I can isolate the problem to the line
A.template triangularView<Lower>().solveInPlace(MatrixXd::Identity(p,p)); // the problem line
But I am having trouble figuring out how what the problem is an how to fix it.
template <typename T, typename RNG>
inline void rInvWishRevCholesky_thread_inplace(Eigen::MatrixBase<T>& A,
const int v,
const Eigen::Ref<const Eigen::MatrixXd>& Psi,
RNG& rng){
int p = Psi.rows();
MatrixXd PsiInv = Psi.llt().solve(MatrixXd::Identity(p,p));
if (v <= p-1)
Rcpp::stop("v must be > Psi.rows - 1");
VectorXd z(p*(p-1)/2);
fillUnitNormal_thread(z, rng);
MatrixXd X = MatrixXd::Zero(p, p);
for (int i=0; i<p; i++){
boost::random::chi_squared_distribution<> rchisq(v-i);
X(i,i) = sqrt(rchisq(rng));
}
int pos = 0;
for (int i=1; i<p; i++){
for (int j=0; j<i; j++){
X(i,j) = z(pos);
pos++;
}
}
A.template noalias() = PsiInv.llt().matrixL()*X;
A.template triangularView<Lower>().solveInPlace(MatrixXd::Identity(p,p)); // the problem line
A.template transposeInPlace();
}
Here is the error message:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:496:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/SolveTriangular.h: In instantiation of 'void Eigen::TriangularViewImpl<_MatrixType, _Mode, Eigen::Dense>::solveInPlace(const Eigen::MatrixBase<OtherDerived>&) const [with int Side = 1; OtherDerived = Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >; _MatrixType = Eigen::Matrix<double, -1, -1>; unsigned int _Mode = 1]':
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/TriangularMatrix.h:511:37: required from 'void Eigen::TriangularViewImpl<_MatrixType, _Mode, Eigen::Dense>::solveInPlace(const Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived = Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >; _MatrixType = Eigen::Matrix<double, -1, -1>; unsigned int _Mode = 1]'
../inst/include/MatDist_thread.h:153:3: required from 'void rInvWishRevCholesky_thread_inplace(Eigen::MatrixBase<Derived>&, int, const Eigen::Ref<const Eigen::Matrix<double, -1, -1> >&, RNG&) [with T = Eigen::Matrix<double, -1, -1>; RNG = boost::random::mersenne_twister_engine<unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>]'
MongrelCollapsed_Uncollapse.cpp:162:72: required from here
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/SolveTriangular.h:182:11: error: use of deleted function 'Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >& Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >::operator=(const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >&)'
other = otherCopy;
~~~~~~^~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:463:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/CwiseNullaryOp.h:60:7: note: 'Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >& Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >::operator=(const Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >&)' is implicitly deleted because the default definition would be ill-formed:
class CwiseNullaryOp : public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
^~~~~~~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/CwiseNullaryOp.h:60:7: error: 'Eigen::internal::no_assignment_operator& Eigen::internal::no_assignment_operator::operator=(const Eigen::internal::no_assignment_operator&)' is private within this context
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:367:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/util/XprHelper.h:92:29: note: declared private here
no_assignment_operator& operator=(const no_assignment_operator&);
^~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:463:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/CwiseNullaryOp.h:60:7: error: passing 'const Eigen::internal::variable_if_dynamic<long int, -1>' as 'this' argument discards qualifiers [-fpermissive]
class CwiseNullaryOp : public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
^~~~~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:367:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/util/XprHelper.h:115:28: note: in call to 'Eigen::internal::variable_if_dynamic<long int, -1>& Eigen::internal::variable_if_dynamic<long int, -1>::operator=(const Eigen::internal::variable_if_dynamic<long int, -1>&)'
template<typename T> class variable_if_dynamic<T, Dynamic>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:463:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/CwiseNullaryOp.h:60:7: error: passing 'const Eigen::internal::variable_if_dynamic<long int, -1>' as 'this' argument discards qualifiers [-fpermissive]
class CwiseNullaryOp : public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
^~~~~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:367:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/util/XprHelper.h:115:28: note: in call to 'Eigen::internal::variable_if_dynamic<long int, -1>& Eigen::internal::variable_if_dynamic<long int, -1>::operator=(const Eigen::internal::variable_if_dynamic<long int, -1>&)'
template<typename T> class variable_if_dynamic<T, Dynamic>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:463:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/CwiseNullaryOp.h:60:7: error: passing 'const Eigen::internal::scalar_identity_op<double>' as 'this' argument discards qualifiers [-fpermissive]
class CwiseNullaryOp : public internal::dense_xpr_base< CwiseNullaryOp<NullaryOp, PlainObjectType> >::type, internal::no_assignment_operator
^~~~~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:425:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/functors/NullaryFunctors.h:31:34: note: in call to 'Eigen::internal::scalar_identity_op<double>& Eigen::internal::scalar_identity_op<double>::operator=(const Eigen::internal::scalar_identity_op<double>&)'
template<typename Scalar> struct scalar_identity_op {
^~~~~~~~~~~~~~~~~~
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:496:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/SolveTriangular.h: In instantiation of 'static void Eigen::internal::triangular_solver_selector<Lhs, Rhs, Side, Mode, 0, -1>::run(const Lhs&, Rhs&) [with Lhs = Eigen::Matrix<double, -1, -1>; Rhs = Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >; int Side = 1; int Mode = 1]':
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/SolveTriangular.h:179:21: required from 'void Eigen::TriangularViewImpl<_MatrixType, _Mode, Eigen::Dense>::solveInPlace(const Eigen::MatrixBase<OtherDerived>&) const [with int Side = 1; OtherDerived = Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >; _MatrixType = Eigen::Matrix<double, -1, -1>; unsigned int _Mode = 1]'
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/TriangularMatrix.h:511:37: required from 'void Eigen::TriangularViewImpl<_MatrixType, _Mode, Eigen::Dense>::solveInPlace(const Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived = Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >; _MatrixType = Eigen::Matrix<double, -1, -1>; unsigned int _Mode = 1]'
../inst/include/MatDist_thread.h:153:3: required from 'void rInvWishRevCholesky_thread_inplace(Eigen::MatrixBase<Derived>&, int, const Eigen::Ref<const Eigen::Matrix<double, -1, -1> >&, RNG&) [with T = Eigen::Matrix<double, -1, -1>; RNG = boost::random::mersenne_twister_engine<unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>]'
MongrelCollapsed_Uncollapse.cpp:162:72: required from here
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/SolveTriangular.h:102:81: error: no matching function for call to 'Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >::coeffRef(int, int)'
::run(size, othersize, &actualLhs.coeffRef(0,0), actualLhs.outerStride(), &rhs.coeffRef(0,0), rhs.outerStride(), blocking);
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Core:434:0,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/Dense:1,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigenForward.h:30,
from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/RcppEigen.h:25,
from ../inst/include/MatrixAlgebra.h:4,
from ../inst/include/mongrel.h:17,
from MongrelCollapsed_Uncollapse.cpp:1:
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:273:10: note: candidate: void Eigen::DenseCoeffsBase<Derived, 0>::coeffRef() [with Derived = Eigen::CwiseNullaryOp<Eigen::internal::scalar_identity_op<double>, Eigen::Matrix<double, -1, -1> >]
void coeffRef();
^~~~~~~~
/Library/Frameworks/R.framework/Versions/3.5/Resources/library/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:273:10: note: candidate expects 0 arguments, 2 provided
make: *** [MongrelCollapsed_Uncollapse.o] Error 1
ERROR: compilation failed for package ‘mongrel’
* removing ‘/private/var/folders/x1/9_lpy_fs0kvg0p88td6_df200000gq/T/Rtmp7seVyi/devtools_install_1385330e7ebb0/mongrel’
Error: Command failed (1)
Any advice would be much appreciated!
solveInPlace requires its argument to be writable, MatrixXd::Identity(p,p) is a read-only expression. (Where would you expect to get the result from that function?)
Maybe what you want is this?
A.noalias() = (PsiInv.llt().matrixL()*X).transpose()
.template triangularView<Upper>().solve(MatrixXd::Identity(p,p));
I can't seem to find any great documentation on how to use Eigen with CppAD. The specific problem that I would like to see addressed is how to multiply a matrix of doubles with a matrix of CppAD::AD<double>. Here is a MWE that does not compile:
#include "cppad/example/cppad_eigen.hpp"
#include "Eigen/Dense"
int main() {
using ADdouble= CppAD::AD<double>;
const int n = 3;
Eigen::Matrix<double, n, n> A = Eigen::Matrix<double, n, n>::Zero();
Eigen::Matrix<ADdouble, n, n> B = Eigen::Matrix<ADdouble, n, n>::Zero();
Eigen::Matrix<ADdouble, n, n> C = A * B;
return 0;
}
I was under the impression that I simply needed to include
#include "cppad/example/cppad_eigen.hpp"
and that that would take care of these issues.
EDIT
Upon further inspection, the documentation provides two examples:
https://www.coin-or.org/CppAD/Doc/eigen_array.cpp.htm
https://www.coin-or.org/CppAD/Doc/eigen_det.cpp.htm
But neither show how to mix types.
EDIT
Here is the full error message
C:\Users\matth\.CLion2018.1\system\cygwin_cmake\bin\cmake.exe --build /cygdrive/c/Dropbox/android/TrajectoryOptimization/app/src/main/cpp/cmake-build-debug --target tester -- -j 4
Scanning dependencies of target tester
[ 50%] Building CXX object CMakeFiles/tester.dir/test.cpp.o
In file included from /cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/Core:463:0,
from /cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/cppad/example/cppad_eigen.hpp:73,
from /cygdrive/c/Dropbox/android/TrajectoryOptimization/app/src/main/cpp/test.cpp:1:
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/Product.h: In instantiation of 'struct Eigen::internal::traits<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >':
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/Product.h:115:7: required from 'class Eigen::internal::dense_product_base<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0, 3>'
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/Product.h:147:7: required from 'class Eigen::ProductImpl<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0, Eigen::Dense>'
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/Product.h:71:7: required from 'class Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>'
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/src/main/cpp/test.cpp:11:43: required from here
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/Product.h:29:127: error: no type named 'ReturnType' in 'struct Eigen::ScalarBinaryOpTraits<double, CppAD::AD<double>, Eigen::internal::scalar_product_op<double, CppAD::AD<double> > >'
typedef typename ScalarBinaryOpTraits<typename traits<LhsCleaned>::Scalar, typename traits<RhsCleaned>::Scalar>::ReturnType Scalar;
^~~~~~
In file included from /cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/Core:459:0,
from /cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/cppad/example/cppad_eigen.hpp:73,
from /cygdrive/c/Dropbox/android/TrajectoryOptimization/app/src/main/cpp/test.cpp:1:
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/DenseBase.h: In instantiation of 'class Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >':
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/MatrixBase.h:48:34: required from 'class Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >'
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/Product.h:115:7: required from 'class Eigen::internal::dense_product_base<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0, 3>'
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/Product.h:147:7: required from 'class Eigen::ProductImpl<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0, Eigen::Dense>'
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/Product.h:71:7: required from 'class Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>'
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/src/main/cpp/test.cpp:11:43: required from here
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/DenseBase.h:83:17: error: no members matching 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}::coeff' in 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}'
using Base::coeff;
^~~~~
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/DenseBase.h:84:17: error: no members matching 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}::coeffByOuterInner' in 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}'
using Base::coeffByOuterInner;
^~~~~~~~~~~~~~~~~
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/DenseBase.h:85:26: error: no members matching 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}::operator()' in 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}'
using Base::operator();
^
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/DenseBase.h:86:26: error: no members matching 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}::operator[]' in 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}'
using Base::operator[];
^
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/DenseBase.h:87:17: error: no members matching 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}::x' in 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}'
using Base::x;
^
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/DenseBase.h:88:17: error: no members matching 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}::y' in 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}'
using Base::y;
^
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/DenseBase.h:89:17: error: no members matching 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}::z' in 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}'
using Base::z;
^
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/DenseBase.h:90:17: error: no members matching 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}::w' in 'Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>, 0>}'
using Base::w;
^
In file included from /cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/Core:460:0,
from /cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/cppad/example/cppad_eigen.hpp:73,
from /cygdrive/c/Dropbox/android/TrajectoryOptimization/app/src/main/cpp/test.cpp:1:
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/MatrixBase.h: In instantiation of 'class Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >':
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/Product.h:115:7: required from 'class Eigen::internal::dense_product_base<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0, 3>'
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/Product.h:147:7: required from 'class Eigen::ProductImpl<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0, Eigen::Dense>'
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/Product.h:71:7: required from 'class Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0>'
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/src/main/cpp/test.cpp:11:43: required from here
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/MatrixBase.h:75:17: error: no members matching 'Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >}::coeff' in 'Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka class Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >}'
using Base::coeff;
^~~~~
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/MatrixBase.h:78:17: error: no members matching 'Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >}::eval' in 'Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka class Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >}'
using Base::eval;
^~~~
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/MatrixBase.h:79:25: error: no members matching 'Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >}::operator-' in 'Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka class Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >}'
using Base::operator-;
^
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/MatrixBase.h:82:25: error: no members matching 'Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >}::operator*=' in 'Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka class Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >}'
using Base::operator*=;
^~
/cygdrive/c/Dropbox/android/TrajectoryOptimization/app/libs/include/Eigen/src/Core/MatrixBase.h:83:25: error: no members matching 'Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >}::operator/=' in 'Eigen::MatrixBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >::Base {aka class Eigen::DenseBase<Eigen::Product<Eigen::Matrix<double, 3, 3>, Eigen::Matrix<CppAD::AD<double>, 3, 3>, 0> >}'
using Base::operator/=;
^~
make[3]: *** [CMakeFiles/tester.dir/build.make:63: CMakeFiles/tester.dir/test.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/tester.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/tester.dir/rule] Error 2
make: *** [Makefile:118: tester] Error 2
EDIT
As per the suggested answers, I created the header mixed_types.h:
#ifndef MIXED_TYPES_HEADER
#define MIXED_TYPES_HEADER
#include <Eigen/Core>
#include <cppad/cppad.hpp>
namespace Eigen {
template<typename S, typename BinOp>
struct ScalarBinaryOpTraits<CppAD::AD<S>, S, BinOp> {
typedef CppAD::AD<S> ReturnType;
};
template<typename S, typename BinOp>
struct ScalarBinaryOpTraits<S, CppAD::AD<S>, BinOp> {
typedef CppAD::AD<S> ReturnType;
};
}
#endif /* MIXED_TYPES_HEADER */
and I tried using this in a product of the form
A = B * C
where the Scalar type of A and B is CppAD::AD<double>, and the Scalar type of C is double. However, this generates a very long compiler error of the form:
In file included from ../src\main\cpp/mixed_types.h:4:
In file included from ../../../../libs/include\Eigen/Core:516:
../../../../libs/include\Eigen/src/Core/products/GeneralBlockPanelKernel.h:999:13: error: no matching member function for call to 'madd'
EIGEN_GEBP_ONESTEP(0);
^~~~~~~~~~~~~~~~~~~~~
../../../../libs/include\Eigen/src/Core/products/GeneralBlockPanelKernel.h:980:22: note: expanded from macro 'EIGEN_GEBP_ONESTEP'
traits.madd(A0, B_0, C0, T0); \
~~~~~~~^~~~
../../../../libs/include\Eigen/src/Core/products/GeneralMatrixMatrix.h:194:11: note: in instantiation of member function 'Eigen::internal::gebp_kernel<CppAD::AD<double>, double, long, Eigen::internal::blas_data_mapper<CppAD::AD<double>, long, 0, 0>, 2, 4, false, false>::operator()' requested here
gebp(res.getSubMapper(i2, j2), blockA, blockB, actual_mc, actual_kc, actual_nc, alpha);
^
../../../../libs/include\Eigen/src/Core/products/GeneralMatrixMatrix.h:226:11: note: in instantiation of member function 'Eigen::internal::general_matrix_matrix_product<long, CppAD::AD<double>, 0, false, double, 0, false, 0>::run' requested here
Gemm::run(rows, cols, m_lhs.cols(),
Can't verify right now, but it seems the code you need is in eigen_mat_mul.hpp.
Have a look a the file here.
Hmmm. Surprisingly, a cast up from the raw type double to CppAD::AD<double> seems to do the trick. For example, this code
#include <iostream>
#include <cppad/cppad.hpp>
#include <cppad/example/cppad_eigen.hpp>
#include <Eigen/Dense>
template<typename T>
using Vector = Eigen::Matrix<T, Eigen::Dynamic, 1>;
int main() {
/* Types and sizes */
using ADdouble = CppAD::AD<double>;
const int rows = 5;
const int cols = 3;
/* Define the independent variable that we will be differentiating with respect to */
Vector<ADdouble> X = Vector<ADdouble>::Ones(cols);
CppAD::Independent(X);
/* Now define the function. The function is simply a matrix multiplication */
Eigen::Matrix<double, rows, cols> A = Eigen::Matrix<double, rows, cols>::Random();
Vector<ADdouble> Y = A.cast<ADdouble>() * X;
CppAD::ADFun<double> f(X, Y);
/* Now define the value of X that we want to evaluate the jacobian at */
Vector<double> x = Vector<double>::Random(cols);
/* Compute the jacobian and compare to the know value */
Vector<double> jac = f.Jacobian(x);
/* We are going to map the jacobian back to a matrix so that it is easier to visualize.
* Note that CppAD seems to use row major format, while Eigen defaults to
* column major */
Eigen::Map<Eigen::Matrix<double, rows, cols, Eigen::RowMajor>> Jac(jac.data());
std::cout << "CppAD Jacobian: " << std::endl << Jac << std::endl << std::endl;
/* Now compare to the know jacobian, which is simply "A" */
std::cout << "Known Jacobian: " << std::endl << A << std::endl << std::endl;
return 0;
}
produces:
CppAD Jacobian:
0.380002 -0.484536 -0.862444
0.0108368 -0.585236 -0.180186
0.182981 0.252524 0.759988
0.10957 -0.319746 -0.361039
-0.243142 0.687704 0.961136
Known Jacobian:
0.380002 -0.484536 -0.862444
0.0108368 -0.585236 -0.180186
0.182981 0.252524 0.759988
0.10957 -0.319746 -0.361039
-0.243142 0.687704 0.961136
However, I am not sure if this will always work. It seems suspect to me because the case must be initializing some properties for the constant matrices of type double. I would guess that there is technically some undefined behavior here. It would be great if an Eigen/CppAD dev could comment.
The right solution is to specialize ScalarBinaryOpTraits:
namespace Eigen{
template<typename S, typename BinOp>
struct ScalarBinaryOpTraits<CppAD::AD<S>,S,BinOp>
{ typedef CppAD::AD<S> ReturnType; };
template<typename S, typename BinOp>
struct ScalarBinaryOpTraits<S,CppAD::AD<S>,BinOp>
{ typedef CppAD::AD<S> ReturnType; };
}
Of course, this only works if there are implementations for operator*(double,CppAD::AD<double>) and operator*(CppAD::AD<double>,double).
Casting the double matrix to CppAD::AD<double> works as well, but requires to make a more expensive CppAD::AD<double>*CppAD::AD<double> product instead of a double*CppAD::AD<double> product every time.
I'm trying to convert a Matrix3d rotation to a Quaternion<double>, but I got only weird compiler errors so far. The code I'm using is:
Quaternion<double> getQuaternionFromRotationMatrix(const Matrix3d& mat)
{
AngleAxisd aa;
aa = mat;
Quaternion<double> q = aa;// conversion error
return q;
}
And the compiler errors:
path/src/Utils.cpp: In function ‘Eigen::Quaternion<double> Utils::getQuaternionFromRotationMatrix(const Matrix3d&)’:
path/src/Utils.cpp:55:26: error: conversion from ‘Eigen::AngleAxisd {aka Eigen::AngleAxis<double>}’ to non-scalar type ‘Eigen::Quaternion<double>’ requested
In file included from /usr/local/include/eigen3/Eigen/Core:283:0,
from /usr/local/include/eigen3/Eigen/Dense:1,
from path/include/Utils.h:4,
from path/src/Utils.cpp:1:
/usr/local/include/eigen3/Eigen/src/Core/Assign.h: In member function ‘Derived& Eigen::DenseBase<Derived>::lazyAssign(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<double, 3, 1>, Derived = Eigen::Block<Eigen::Matrix<double, 4, 4>, 4, -0x00000000000000001, true, true>]’:
/usr/local/include/eigen3/Eigen/src/Core/Assign.h:534:123: instantiated from ‘static Derived& Eigen::internal::assign_selector<Derived, OtherDerived, false, false>::run(Derived&, const OtherDerived&) [with Derived = Eigen::Block<Eigen::Matrix<double, 4, 4>, 4, -0x00000000000000001, true, true>, OtherDerived = Eigen::Matrix<double, 3, 1>]’
/usr/local/include/eigen3/Eigen/src/Core/Assign.h:574:89: instantiated from ‘Derived& Eigen::MatrixBase<Derived>::operator=(const Eigen::DenseBase<OtherDerived>&) [with OtherDerived = Eigen::Matrix<double, 3, 1>, Derived = Eigen::Block<Eigen::Matrix<double, 4, 4>, 4, -0x00000000000000001, true, true>]’
path/src/Utils.cpp:34:20: instantiated from here
/usr/local/include/eigen3/Eigen/src/Core/Assign.h:504:3: error: static assertion failed: "YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES"
Does someone know how to convert between both representations?
The constructors from an AngleAxis or Matrix are explicit meaning you have to write the conversion as follow:
Matrix3f mat;
Quaternionf q(mat);
or
Quaternionf q;
q = mat;
Same for AngleAxis.