Workaround GCC 5.5 tuple initialisation bug - c++

Consider this code:
std::vector<
std::tuple<std::vector<std::size_t>,
std::vector<std::size_t>,
std::vector<std::size_t>>
> foo = {
{{2, 1, 2, 3}, {1, 2}, {2, 3}},
{{2, 3, 4, 0}, {3}, {2, 3, 4}},
{{2, 3, 4, 0}, {0}, {3, 4, 0}},
};
In Clang, and GCC 6 or later it compiles fine. In GCC 5.5 it gives this error:
In function 'int main()':
:16:4: error: converting to
'std::tuple<std::vector<long unsigned int, std::allocator<long unsigned int> >,
std::vector<long unsigned int, std::allocator<long unsigned int> >,
std::vector<long unsigned int, std::allocator<long unsigned int> > >'
from initializer list would use explicit constructor
'constexpr std::tuple< <template-parameter-1-1> >::tuple(const _Elements& ...)
[with _Elements = {
std::vector<long unsigned int, std::allocator<long unsigned int> >, std::vector<long unsigned int, std::allocator<long unsigned int> >, std::vector<long unsigned int, std::allocator<long unsigned int> >}]'
};
^
Why is this and how can I work around it?

One possible workaround is to call tuple constructor explicitly:
using bar = std::tuple<std::vector<std::size_t>,
std::vector<std::size_t>,
std::vector<std::size_t>>;
std::vector<bar> foo = {
bar{{2, 1, 2, 3}, {1, 2}, {2, 3}},
bar{{2, 3, 4, 0}, {3}, {2, 3, 4}},
bar{{2, 3, 4, 0}, {0}, {3, 4, 0}},
};
(Live demo)

Related

CGAL program compilation error using Eigen3

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?

CppAD with Eigen

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.

Using Eigen in custom tensorflow op

How would one go about using Eigen's internal functions like Eigen::internal::scalar_product_op in a custom Tensorflow op? After going through the Tensorflow codebase, like cwise_ops_common.h and cwise_ops.h, I came up with the following (barebones) implementation:
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/shape_inference.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
#include "tensorflow/core/framework/numeric_types.h"
#include "tensorflow/core/framework/tensor_types.h"
#include "tensorflow/core/platform/types.h"
using namespace tensorflow;
typedef Eigen::ThreadPoolDevice CPUDevice;
REGISTER_OP("CustomMul")
.Input("to_zero: int8")
.Output("zeroed: int8")
.SetShapeFn([](::tensorflow::shape_inference::InferenceContext* c) {
c->set_output(0, c->input(0));
return Status::OK();
});
class CustomMulOp : public OpKernel {
public:
explicit CustomMulOp(OpKernelConstruction* context) : OpKernel(context) {}
void Compute(OpKernelContext* context) override {
// Grab the input tensor
const Tensor& a_tensor = context->input(0);
const Tensor& b_tensor = context->input(0);
auto a = a_tensor.flat<int8>();
auto b = b_tensor.flat<int8>();
// Create an output tensor
Tensor* output_tensor = NULL;
OP_REQUIRES_OK(context, context->allocate_output(0, b_tensor.shape(),
&output_tensor));
auto output = output_tensor->flat<int8>();
const CPUDevice& d = context->eigen_device<CPUDevice>();
// Multiply the tensors
To32Bit(output).device(d) =
To32Bit(a).binaryExpr(b, typename Eigen::internal::scalar_product_op<int8>());
}
};
REGISTER_KERNEL_BUILDER(Name("CustomMul").Device(DEVICE_CPU), CustomMulOp);
Compiling the above code with
TF_INC=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())')
g++ -std=c++11 -shared custom_mul.cc -o custom_mul.so -fPIC -I $TF_INC -O2
produces the following error:
In file included from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/Tensor:112:0,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:4,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/partial_tensor_shape.h:21,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/attr_value_util.h:22,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/node_def_util.h:23,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/shape_inference.h:21,
from custom_mul.cc:2:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h: In instantiation of ‘bool Eigen::TensorEvaluator<Derived, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<Derived, Device>::CoeffReturnType*) [with Derived = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<Derived, Device>::CoeffReturnType = signed char]’:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h:123:5: required from ‘bool Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar*) [with LeftArgType = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; RightArgType = const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> >; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar = signed char]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h:35:66: required from ‘static void Eigen::internal::TensorExecutor<Expression, Device, Vectorizable>::run(const Expression&, const Device&) [with Expression = const Eigen::TensorAssignOp<Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> > >; Device = Eigen::ThreadPoolDevice; bool Vectorizable = false]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorDevice.h:35:62: required from ‘Eigen::TensorDevice<ExpressionType, DeviceType>& Eigen::TensorDevice<ExpressionType, DeviceType>::operator=(const OtherDerived&) [with OtherDerived = Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> >; ExpressionType = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; DeviceType = Eigen::ThreadPoolDevice]’
custom_mul.cc:41:85: required from here
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h:59:16: error: invalid use of incomplete type ‘const struct Eigen::ThreadPoolDevice’
m_device.memcpy((void*)dest, m_data, sizeof(Scalar) * m_dims.TotalSize());
~~~~~~~~~^~~~~~
In file included from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/Tensor:92:0,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:4,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/partial_tensor_shape.h:21,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/attr_value_util.h:22,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/node_def_util.h:23,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/shape_inference.h:21,
from custom_mul.cc:2:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h:84:8: note: forward declaration of ‘struct Eigen::ThreadPoolDevice’
struct ThreadPoolDevice;
^~~~~~~~~~~~~~~~
In file included from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/Tensor:112:0,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:4,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/partial_tensor_shape.h:21,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/attr_value_util.h:22,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/node_def_util.h:23,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/shape_inference.h:21,
from custom_mul.cc:2:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h: In instantiation of ‘bool Eigen::TensorEvaluator<const Derived, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Derived, Device>::CoeffReturnType*) [with Derived = Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Derived, Device>::CoeffReturnType = const signed char]’:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h:404:5: required from ‘bool Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::CoeffReturnType*) [with BinaryOp = Eigen::internal::scalar_product_op<signed char, signed char>; LeftArgType = const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>; RightArgType = const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer>; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::CoeffReturnType = signed char]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h:128:62: required from ‘bool Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar*) [with LeftArgType = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; RightArgType = const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> >; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar = signed char]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h:35:66: required from ‘static void Eigen::internal::TensorExecutor<Expression, Device, Vectorizable>::run(const Expression&, const Device&) [with Expression = const Eigen::TensorAssignOp<Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> > >; Device = Eigen::ThreadPoolDevice; bool Vectorizable = false]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorDevice.h:35:62: required from ‘Eigen::TensorDevice<ExpressionType, DeviceType>& Eigen::TensorDevice<ExpressionType, DeviceType>::operator=(const OtherDerived&) [with OtherDerived = Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> >; ExpressionType = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; DeviceType = Eigen::ThreadPoolDevice]’
custom_mul.cc:41:85: required from here
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h:186:16: error: invalid use of incomplete type ‘const struct Eigen::ThreadPoolDevice’
m_device.memcpy((void*)data, m_data, m_dims.TotalSize() * sizeof(Scalar));
~~~~~~~~~^~~~~~
In file included from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/Tensor:92:0,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:4,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/partial_tensor_shape.h:21,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/attr_value_util.h:22,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/node_def_util.h:23,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/shape_inference.h:21,
from custom_mul.cc:2:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h:84:8: note: forward declaration of ‘struct Eigen::ThreadPoolDevice’
struct ThreadPoolDevice;
^~~~~~~~~~~~~~~~
In file included from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/Tensor:112:0,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:4,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/partial_tensor_shape.h:21,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/attr_value_util.h:22,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/node_def_util.h:23,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/shape_inference.h:21,
from custom_mul.cc:2:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h: In instantiation of ‘bool Eigen::TensorEvaluator<const Derived, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Derived, Device>::CoeffReturnType*) [with Derived = Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer>; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Derived, Device>::CoeffReturnType = const signed char]’:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h:405:5: required from ‘bool Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::CoeffReturnType*) [with BinaryOp = Eigen::internal::scalar_product_op<signed char, signed char>; LeftArgType = const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>; RightArgType = const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer>; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Eigen::TensorCwiseBinaryOp<BinaryOp, LeftArgType, RightArgType>, Device>::CoeffReturnType = signed char]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorAssign.h:128:62: required from ‘bool Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::evalSubExprsIfNeeded(Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar*) [with LeftArgType = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; RightArgType = const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> >; Device = Eigen::ThreadPoolDevice; Eigen::TensorEvaluator<const Eigen::TensorAssignOp<LhsXprType, RhsXprType>, Device>::Scalar = signed char]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorExecutor.h:35:66: required from ‘static void Eigen::internal::TensorExecutor<Expression, Device, Vectorizable>::run(const Expression&, const Device&) [with Expression = const Eigen::TensorAssignOp<Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> > >; Device = Eigen::ThreadPoolDevice; bool Vectorizable = false]’
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorDevice.h:35:62: required from ‘Eigen::TensorDevice<ExpressionType, DeviceType>& Eigen::TensorDevice<ExpressionType, DeviceType>::operator=(const OtherDerived&) [with OtherDerived = Eigen::TensorCwiseBinaryOp<Eigen::internal::scalar_product_op<signed char, signed char>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, int>, 16, Eigen::MakePointer>, const Eigen::TensorMap<Eigen::Tensor<const signed char, 1, 1, long int>, 16, Eigen::MakePointer> >; ExpressionType = Eigen::TensorMap<Eigen::Tensor<signed char, 1, 1, int>, 16, Eigen::MakePointer>; DeviceType = Eigen::ThreadPoolDevice]’
custom_mul.cc:41:85: required from here
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h:186:16: error: invalid use of incomplete type ‘const struct Eigen::ThreadPoolDevice’
m_device.memcpy((void*)data, m_data, m_dims.TotalSize() * sizeof(Scalar));
~~~~~~~~~^~~~~~
In file included from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/Tensor:92:0,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:4,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/partial_tensor_shape.h:21,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/attr_value_util.h:22,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/node_def_util.h:23,
from /home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/tensorflow/core/framework/shape_inference.h:21,
from custom_mul.cc:2:
/home/user123/miniconda3/envs/ml/lib/python2.7/site-packages/tensorflow/include/unsupported/Eigen/CXX11/src/Tensor/TensorForwardDeclarations.h:84:8: note: forward declaration of ‘struct Eigen::ThreadPoolDevice’
struct ThreadPoolDevice;
I'm using TensorFlow v.1.0.1 and GCC 6.3.1.
You need to add #define EIGEN_USE_THREADS before including third_party/eigen3/unsupported/Eigen/CXX11/Tensor, otherwise the ThreadPoolDevice will not be available.
struct ThreadPoolDevice is only forward-declared initially (at custom_mul.cc:2) but it must be fully defined. This means you miss some include. Move this include
#include <third_party/eigen3/unsupported/Eigen/CXX11/Tensor>
up to the beginning of your code. I think that should fully define ThreadPoolDevice.

Eigen: multiply a float matrix by a bool vector

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

Eigen: convert Matrix3d rotation to Quaternion

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.