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?
Related
Does Eigen allow for spectral decomposition of Quaternionic Matrices? I'm trying to generate matrices from the Gaussian Symplectic Ensemble (Quaternionic Hermitian/Self-Adjoint Matrices) to experiment with the eigenvalue spacings (Wigner Surmise) but after fiddling around for awhile, I'm not sure how to do this.
Do I need to extend the MatrixBase class with the quaternion plugin in order to gain quaternionic matrix support, then feed the matrix into SelfAdjointEigenSolver afterwards?
I currently have only tried using Matrix<Quaternion<double>, Dynamic, Dynamic> and feeding that directly into SelfAdjointEigenSolver. This resulted in clang spitting out a wall of errors, most of which just seem like missing operator complaints.
Error dump:
/usr/include/eigen3/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h:434:11: error: invalid operands to binary expression
('Eigen::SelfAdjointEigenSolver<Eigen::Matrix<Eigen::Quaternion<double, 0>, -1, -1, 0, -1, -1> >::RealScalar'
(aka 'Eigen::Quaternion<double, 0>') and 'Eigen::SelfAdjointEigenSolver<Eigen::Matrix<Eigen::Quaternion<double, 0>, -1, -1, 0, -1,
-1> >::RealScalar')
if(scale==RealScalar(0)) scale = RealScalar(1);
...
/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/8.2.1/../../../../include/c++/8.2.1/bits/stl_algobase.h:224:15: error: invalid operands to
binary expression ('const Eigen::Quaternion<double, 0>' and 'const Eigen::Quaternion<double, 0>')
if (__a < __b)
...
/usr/include/eigen3/Eigen/src/Core/functors/BinaryFunctors.h:361:128: error: invalid operands to binary expression
('const Eigen::Quaternion<double, 0>' and 'const Eigen::Quaternion<double, 0>')
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a / b; }
...
/usr/include/eigen3/Eigen/src/Core/TriangularMatrix.h:769:89: error: no matching conversion for functional-style cast from 'int' to
'Eigen::internal::triangular_dense_assignment_kernel<1, 0, 0,
Eigen::internal::evaluator<Eigen::TriangularView<Eigen::Matrix<Eigen::Quaternion<double, 0>, -1, -1, 0, -1, -1>, 1> >,
Eigen::internal::evaluator<Eigen::CwiseBinaryOp<Eigen::internal::scalar_quotient_op<Eigen::Quaternion<double, 0>,
Eigen::Quaternion<double, 0> >, const Eigen::Matrix<Eigen::Quaternion<double, 0>, -1, -1, 0, -1, -1>, const
Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<Eigen::Quaternion<double, 0> >, const
Eigen::Matrix<Eigen::Quaternion<double, 0>, -1, -1, 0, -1, -1> > > >, Eigen::internal::assign_op<Eigen::Quaternion<double, 0>,
Eigen::Quaternion<double, 0> >, 0>::Scalar' (aka 'Eigen::Quaternion<double, 0>')
if(Mode==UnitDiag && SetOpposite) m_functor.assignCoeff(m_dst.coeffRef(id,id), Scalar(1));
...
/usr/include/eigen3/Eigen/src/Eigenvalues/./Tridiagonalization.h:365:31: error: no viable overloaded '='
matA.col(i).coeffRef(i+1) = 1;
(and then a ton more)
I couldn't seem to find anything from searching. My previous linear algebra library of choice (Armadillo) does not have quaternion support from the looks of it.
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 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
I am currently working on a project which deals with geometric problems. Since this project will be used commercially I cannot use libraries like CGAL.
I am currently using boost::geometry with inexact types but I encountered numeric issues.
I tried to simply use an exact point type from boost::multiprecision but it doesn't compile when I call boost::geometry functions.
I found this page which shows how to use a numeric_adaptor to use boost::geometry with exact number types. However, it seems outdated and I wasn't able to make it work.
Can boost::geometry be used with exact number types ? How ?
#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/segment.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/multiprecision/gmp.hpp>
namespace bg = boost::geometry;
namespace bm = boost::multiprecision;
typedef bg::model::d2::point_xy<bm::mpq_rational> point;
typedef boost::geometry::model::segment<point> segment;
int main(void)
{
point a(0,0);
point b(1,0);
point c(1,1);
point d(0,1);
segment s1(a,c);
segment s2(b,d);
std::vector<point> ip;
bg::intersection(s1, s2, ip); // Doesn't compile
return 0;
}
clang++3.4.2 output:
In file included from boost_geom_intersect.cpp:3:
In file included from /usr/include/boost/geometry.hpp:17:
In file included from /usr/include/boost/geometry/geometry.hpp:36:
In file included from /usr/include/boost/geometry/core/radian_access.hpp:21:
In file included from /usr/include/boost/numeric/conversion/cast.hpp:33:
In file included from /usr/include/boost/numeric/conversion/converter.hpp:14:
/usr/include/boost/numeric/conversion/converter_policies.hpp:187:69: error: cannot convert 'const
boost::multiprecision::detail::expression<boost::multiprecision::detail::divides,
boost::multiprecision::detail::expression<boost::multiprecision::detail::multiply_immediates,
boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
void, void>, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, void, void>' to 'result_type' (aka 'double') without a conversion
operator
static result_type low_level_convert ( argument_type s ) { return static_cast<result_type>(s) ; }
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/boost/numeric/conversion/detail/converter.hpp:524:32: note: in instantiation of member function
'boost::numeric::raw_converter<boost::numeric::conversion_traits<double, boost::multiprecision::detail::expression<boost::multiprecision::detail::divides,
boost::multiprecision::detail::expression<boost::multiprecision::detail::multiply_immediates,
boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
void, void>, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, void, void> > >::low_level_convert' requested here
return RawConverterBase::low_level_convert(s);
^
/usr/include/boost/numeric/conversion/cast.hpp:53:27: note: in instantiation of member function
'boost::numeric::convdetail::non_rounding_converter<boost::numeric::conversion_traits<double,
boost::multiprecision::detail::expression<boost::multiprecision::detail::divides,
boost::multiprecision::detail::expression<boost::multiprecision::detail::multiply_immediates,
boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
void, void>, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, void, void> >,
boost::numeric::convdetail::dummy_range_checker<boost::numeric::conversion_traits<double,
boost::multiprecision::detail::expression<boost::multiprecision::detail::divides,
boost::multiprecision::detail::expression<boost::multiprecision::detail::multiply_immediates,
boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
void, void>, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, void, void> > >,
boost::numeric::raw_converter<boost::numeric::conversion_traits<double, boost::multiprecision::detail::expression<boost::multiprecision::detail::divides,
boost::multiprecision::detail::expression<boost::multiprecision::detail::multiply_immediates,
boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
void, void>, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, void, void> > > >::convert' requested here
return converter::convert(arg);
^
/usr/include/boost/geometry/policies/robustness/segment_ratio.hpp:146:22: note: in instantiation of function template specialization 'boost::numeric_cast<double,
boost::multiprecision::detail::expression<boost::multiprecision::detail::divides,
boost::multiprecision::detail::expression<boost::multiprecision::detail::multiply_immediates,
boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
void, void>, boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, void, void> >' requested here
: boost::numeric_cast<double>
^
/usr/include/boost/geometry/policies/robustness/segment_ratio.hpp:129:9: note: in instantiation of member function
'boost::geometry::segment_ratio<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1> >::initialize' requested here
initialize();
^
/usr/include/boost/geometry/strategies/cartesian/cart_intersect.hpp:207:33: note: in instantiation of member function
'boost::geometry::segment_ratio<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1> >::assign' requested here
sinfo.robust_ra.assign(robust_da, robust_da0);
^
/usr/include/boost/geometry/algorithms/detail/overlay/intersection_insert.hpp:114:47: note: in instantiation of function template specialization
'boost::geometry::strategy::intersection::relate_cartesian_segments<boost::geometry::policies::relate::segments_intersection_points<boost::geometry::segment_intersection_points<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational,
1>, boost::geometry::cs::cartesian>, boost::geometry::segment_ratio<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1> > > >,
void>::apply<boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian> >,
boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian> >, boost::geometry::detail::no_rescale_policy,
boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, boost::geometry::cs::cartesian> >' requested
here
intersection_return_type is = policy::apply(segment1, segment2,
^
/usr/include/boost/geometry/algorithms/intersection.hpp:51:12: note: in instantiation of function template specialization
'boost::geometry::detail::intersection::intersection_segment_segment_point<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational,
1>, boost::geometry::cs::cartesian>
>::apply<boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian> >,
boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian> >, boost::geometry::detail::no_rescale_policy,
std::back_insert_iterator<std::vector<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian>, std::allocator<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational,
1>, boost::geometry::cs::cartesian> > > >, boost::geometry::strategy_intersection<boost::geometry::cartesian_tag,
boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian> >,
boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian> >, boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian>, boost::geometry::detail::no_rescale_policy, void> >' requested here
>::apply(geometry1, geometry2, robust_policy, std::back_inserter(geometry_out), strategy);
^
/usr/include/boost/geometry/algorithms/intersection.hpp:148:12: note: in instantiation of function template specialization
'boost::geometry::dispatch::intersection<boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational,
1>, boost::geometry::cs::cartesian> >,
boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian> >, boost::geometry::segment_tag, boost::geometry::segment_tag, false>::apply<boost::geometry::detail::no_rescale_policy,
std::vector<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>, boost::geometry::cs::cartesian>,
std::allocator<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian> > >, boost::geometry::strategy_intersection<boost::geometry::cartesian_tag,
boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian> >,
boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian> >, boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian>, boost::geometry::detail::no_rescale_policy, void> >' requested here
>::apply(geometry1, geometry2, robust_policy, geometry_out, strategy());
^
/usr/include/boost/geometry/algorithms/intersection.hpp:308:21: note: in instantiation of function template specialization
'boost::geometry::resolve_variant::intersection<boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational,
1>, boost::geometry::cs::cartesian> >,
boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian> >
>::apply<std::vector<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian>, std::allocator<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational,
1>, boost::geometry::cs::cartesian> > > >' requested here
>::template apply
^
boost_geom_intersect.cpp:27:9: note: in instantiation of function template specialization
'boost::geometry::intersection<boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational,
1>, boost::geometry::cs::cartesian> >,
boost::geometry::model::segment<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian> >, std::vector<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational,
1>, boost::geometry::cs::cartesian>,
std::allocator<boost::geometry::model::d2::point_xy<boost::multiprecision::number<boost::multiprecision::backends::gmp_rational, 1>,
boost::geometry::cs::cartesian> > > >' requested here
bg::intersection(s1, s2, ip); // Doesn't compile
^
1 error generated.
Boost Geometry is getting confused by the proxy types returned from expression templates, where it is expecting the concrete numeric results: documentation
The Multiprecision library comes in two distinct parts:
An expression-template-enabled front-end number that handles all the operator overloading, expression evaluation optimization, and code reduction.
A selection of back-ends that implement the actual arithmetic operations, and need conform only to the reduced interface requirements of the front-end.
The meta-programming grinds to a halt there.
Fortunately, you can simply use the mpq_rational modified to disable expressions templates:
typedef bm::number<bm::gmp_rational, bm::et_off> my_rational;
This will compile without problems.
Coliru chokes on it, but here it is: http://coliru.stacked-crooked.com/a/232d98bfbb430468
#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/segment.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/multiprecision/gmp.hpp>
#include <boost/multiprecision/number.hpp>
namespace bg = boost::geometry;
namespace bm = boost::multiprecision;
typedef bm::number<bm::gmp_rational, bm::et_off> my_rational;
typedef bg::model::d2::point_xy<my_rational > point;
typedef boost::geometry::model::segment<point> segment;
int main(void)
{
point a(0,0);
point b(1,0);
point c(1,1);
point d(0,1);
segment s1(a,c);
segment s2(b,d);
std::vector<point> ip;
bg::intersection(s1, s2, ip); // Doesn't compile
return 0;
}