Related
I am trying to implement some auto-differentation jacobians for verification of analytical jacobians. These are the functions in question being tested. When I compile them with g++ I get the following error:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__functional/perfect_forward.h:14:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/tuple:1546:5: error: no matching function for call to '__apply_tuple_impl'
_VSTD::__apply_tuple_impl(
^~~~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__config:858:15: note: expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_ABI_NAMESPACE
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/tuple:1530:79: note: expanded from macro '_LIBCPP_NOEXCEPT_RETURN'
#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
^~~~~~~~~~~
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/derivative.hpp:161:19: note: in instantiation of function template specialization 'std::apply<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> (Cantera::Reactor::*const &)(Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &), const std::tuple<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &>' requested here
auto u = std::apply(f, at.args);
^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:138:13: note: in instantiation of function template specialization 'autodiff::detail::eval<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> (Cantera::Reactor::*)(Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &), Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &, autodiff::detail::Real<1, double> &>' requested here
F = eval(f, at, detail::wrt(xi)); // evaluate F with xi seeded so that dF/dxi is also computed
^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:75:21: note: in instantiation of function template specialization 'autodiff::detail::jacobian(Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> (Cantera::Reactor::*const &)(Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &), const Wrt<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &, const At<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &, Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &, Eigen::Matrix<double, -1, -1, 0> &)::(anonymous class)::operator()<int, autodiff::detail::Real<1, double> &>' requested here
f(i++, item[j]);
^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:138:9: note: in instantiation of function template specialization 'autodiff::detail::ForEachWrtVar(const Wrt<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &, (lambda at /Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:136:24) &&)::(anonymous class)::operator()<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0>>' requested here
f(std::get<i>(tuple));
^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:94:9: note: in instantiation of function template specialization 'autodiff::detail::ForEach(const std::tuple<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &, (lambda at /Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:67:23) &&)::(anonymous class)::operator()<autodiff::detail::Index<0>>' requested here
f(Index<i>{});
^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:102:5: note: (skipping 1 context in backtrace; use -ftemplate-backtrace-limit=0 to see all)
AuxFor<ibegin, ibegin, iend>(std::forward<Function>(f));
^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:108:5: note: in instantiation of function template specialization 'autodiff::detail::For<0UL, 1UL, (lambda at /Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:137:12)>' requested here
For<0, iend>(std::forward<Function>(f));
^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:137:5: note: in instantiation of function template specialization 'autodiff::detail::For<1UL, (lambda at /Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/common/meta.hpp:137:12)>' requested here
For<N>([&](auto i) constexpr {
^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:67:5: note: in instantiation of function template specialization 'autodiff::detail::ForEach<const std::tuple<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &, (lambda at /Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:67:23)>' requested here
ForEach(wrt.args, [&](auto& item) constexpr
^
/Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:136:5: note: in instantiation of function template specialization 'autodiff::detail::ForEachWrtVar<(lambda at /Users/walkerant/mambaforge3/envs/ct-build/include/autodiff/forward/utils/gradient.hpp:136:24), Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &>' requested here
ForEachWrtVar(wrt, [&](auto&& i, auto&& xi) constexpr {
^
src/zeroD/Reactor.cpp:569:15: note: in instantiation of function template specialization 'autodiff::detail::jacobian<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> (Cantera::Reactor::*)(Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &), Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &, Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &, Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0>, Eigen::Matrix<double, -1, -1, 0>>' requested here
autodiff::jacobian(&Reactor::_autodiffEval, autodiff::wrt(yV), autodiff::at(yV), ydot, jac);
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/tuple:1534:26: note: candidate template ignored: substitution failure [with _Fn = Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> (Cantera::Reactor::*const &)(Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &), _Tuple = const std::tuple<Eigen::Matrix<autodiff::detail::Real<1, double>, -1, 1, 0> &> &, _Id = <0>]
constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
^
3 errors generated.
scons: *** [build/src/zeroD/Reactor.os] Error 1
scons: building terminated because of errors.
I have checked out deleted functions but the code is not explicitly deleting any functions. This issue only arises with the call of autodiff::jacobian, if I comment that line out and recompile, everything runs just fine. Is there a way I can try to track down why the compiler is saying these functions are deleted? I am using this auto-differentiation package called autodiff.
The code in question is:
#include <autodiff/forward/real.hpp>
#include <autodiff/forward/real/eigen.hpp>
Eigen::SparseMatrix<double> Reactor::autodiffJacobian()
{
double y[m_nv];
getState(y);
autodiff::VectorXreal yV(Eigen::Map<Eigen::VectorXd>(y, m_nv));
Eigen::MatrixXd jac(m_nv, m_nv);
autodiff::VectorXreal ydot;
autodiff::jacobian(&Reactor::_autodiffEval, autodiff::wrt(yV), autodiff::at(yV), ydot, jac);
return jac.sparseView();
// return jac;
}
autodiff::VectorXreal Reactor::_autodiffEval(autodiff::VectorXreal& y)
{
vector_fp yT(m_nv);
for (size_t i = 0; i < m_nv; i++) {
yT[i] = y[i].val();
}
updateState(yT.data());
vector_fp lhs(m_nv, 1);
vector_fp rhs(m_nv, 0);
eval(0, lhs.data(), rhs.data());
autodiff::VectorXreal ydot(m_nv);
for (size_t i = 0; i < m_nv; i++) {
ydot[i] = rhs[i]/lhs[i];
}
return ydot;
}
The code is compiled with:
g++ -o build/src/zeroD/Reactor.os -c --std=c++17 -I/ext/eigen/Eigen -I/ext/eigen -O3 -Wno-inline -g -Wall -include src/pch/system.h -fPIC -DNDEBUG -Iinclude -I/ext -Ibuild/src -Ict-build/include src/zeroD/Reactor.cpp
Edit
The error has to something to do with it being in a class. I created a very simple example to replicate the process from an accepted example in autodiff.
// C++ includes
#include <iostream>
// autodiff include
#include <autodiff/forward/real.hpp>
#include <autodiff/forward/real/eigen.hpp>
using namespace autodiff;
VectorXreal ft(const VectorXreal& x, const VectorXreal& p, const real& q)
{
return x * p.sum() * exp(q);
}
class scratch
{
private:
/* data */
public:
scratch(/* args */);
~scratch();
VectorXreal f(const VectorXreal& x, const VectorXreal& p,
const real& q);
Eigen::MatrixXd jac();
};
VectorXreal scratch::f(const VectorXreal& x, const VectorXreal& p, const real& q)
{
return x * p.sum() * exp(q);
}
Eigen::MatrixXd scratch::jac()
{
VectorXreal x(5); // the input vector x with 5 variables
x << 1, 2, 3, 4, 5; // x = [1, 2, 3, 4, 5]
VectorXreal p(3);
p << 1, 2, 3; // p = [1, 2, 3]
real q = -2;
VectorXreal F;
Eigen::MatrixXd Jqpx = jacobian(ft, wrt(q, p, x), at(x, p, q), F);
return Jqpx;
}
int main()
{
scratch sobj;
Eigen::MatrixXd Jqpx = sobj.jac();
std::cout << "Jqpx = \n" << Jqpx << std::endl;
}
I want to use CGAL wrapper for OpenGR to register two point clouds(reference.ply and 1.ply), and I wrote the following simple program (basically copying from the CGAL OpenGR example):
#include <CGAL/Simple_cartesian.h>
#include <CGAL/IO/read_ply_points.h>
#include <CGAL/IO/write_ply_points.h>
#include <CGAL/property_map.h>
#include <CGAL/Aff_transformation_3.h>
#include <CGAL/OpenGR/compute_registration_transformation.h>
#include <fstream>
#include <iostream>
#include <utility>
#include <vector>
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_3 Point_3;
typedef K::Vector_3 Vector_3;
typedef std::pair<Point_3, Vector_3> Pwn;
typedef CGAL::First_of_pair_property_map<Pwn> Point_map;
typedef CGAL::Second_of_pair_property_map<Pwn> Normal_map;
namespace params = CGAL::parameters;
int main(int argc, const char** argv) {
const char* fname1 = "data/reference.ply";
const char* fname2 = "data/1.ply";
std::vector<Pwn> pwns1, pwns2;
std::ifstream input(fname1);
if (!input ||
!CGAL::read_ply_points(input, std::back_inserter(pwns1),
CGAL::parameters::point_map(CGAL::First_of_pair_property_map<Pwn>()).
normal_map(Normal_map())))
{
std::cerr << "Error: cannot read file " << fname1 << std::endl;
return EXIT_FAILURE;
}
input.close();
input.open(fname2);
if (!input ||
!CGAL::read_ply_points(input, std::back_inserter(pwns2),
CGAL::parameters::point_map(Point_map()).
normal_map(Normal_map())))
{
std::cerr << "Error: cannot read file " << fname2 << std::endl;
return EXIT_FAILURE;
}
input.close();
std::cerr << "Computing registration transformation using OpenGR Super4PCS.." << std::endl;
// First, compute registration transformation using OpenGR Super4PCS
K::Aff_transformation_3 res =
std::get<0>( // get first of pair, which is the transformation
CGAL::OpenGR::compute_registration_transformation
(pwns1, pwns2,
params::point_map(Point_map()).normal_map(Normal_map()),
params::point_map(Point_map()).normal_map(Normal_map()))
);
return EXIT_SUCCESS;
}
The error occurs when I compile the program using Makefile created by cmake, and there are a lot of errors that involves the Eigen library (The error is pretty long):
senyangjiang#senyangjiang-MS-7A38:~/Desktop/dev_compare/cgal_compare/build$ make
Scanning dependencies of target compare
[ 50%] Building CXX object CMakeFiles/compare.dir/compare.cpp.o
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/Product.h:29:127: error: no type named ‘ReturnType’ in ‘struct Eigen::ScalarBinaryOpTraits<float, double, Eigen::internal::scalar_product_op<float, double> >’
29 | typedef typename ScalarBinaryOpTraits<typename traits<LhsCleaned>::Scalar, typename traits<RhsCleaned>::Scalar>::ReturnType Scalar;
| ^~~~~~
home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:83:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::coeff’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
83 | using Base::coeff;
| ^~~~~
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:84:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::coeffByOuterInner’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
84 | using Base::coeffByOuterInner;
| ^~~~~~~~~~~~~~~~~
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:85:26: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::operator()’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
85 | using Base::operator();
| ^
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:86:26: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::operator[]’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
86 | using Base::operator[];
| ^
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:87:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::x’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
87 | using Base::x;
| ^
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:88:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::y’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
88 | using Base::y;
| ^
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:89:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::z’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
89 | using Base::z;
| ^
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/DenseBase.h:90:17: error: no members matching ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base {aka Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>}::w’ in ‘Eigen::DenseBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0> >::Base’ {aka ‘class Eigen::DenseCoeffsBase<Eigen::Product<Eigen::Ref<const Eigen::Matrix<float, -1, -1> >, Eigen::Homogeneous<Eigen::Matrix<double, 3, 1>, 0>, 0>, 0>’}
90 | using Base::w;
| ^
... more errors like this
/home/senyangjiang/Desktop/dev_compare/OpenGR/3rdparty/Eigen/Eigen/src/Core/AssignEvaluator.h:834:3: error: static assertion failed: YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY
834 | EIGEN_CHECK_BINARY_COMPATIBILIY(Func,typename ActualDstTypeCleaned::Scalar,typename Src::Scalar);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/compare.dir/build.make:63: CMakeFiles/compare.dir/compare.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/compare.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I can solve the error by changing my code from
typedef CGAL::Simple_cartesian<double> K;
to
typedef CGAL::Simple_cartesian<float> K;
in other words, changing double to float. But I prefer using double due to higher precision, is there any other way to resolve the error?
I 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 am trying to compile the Eigen3 PartialPivLU example
MatrixXd A(2,2);
A << 2, -1, 1, 3;
PartialPivLU >> lu(A);
but I get compiler errors (see below).
If I remove the "Ref<> it compiles OK. Does anyone know how to use PartialPivLU with Ref<>?
Thanks
Steve
In file included from /apps/eigen/3.2.8/include/eigen3/Eigen/LU:23:0,
from /apps/eigen/3.2.8/include/eigen3/Eigen/Dense:2,
from test3.cc:2:
/apps/eigen/3.2.8/include/eigen3/Eigen/src/LU/PartialPivLU.h: In instantiation of 'class Eigen::PartialPivLU<Eigen::Ref<Eigen::Matrix<double, -1, -1> > >':
test3.cc:9:36: required from here
/apps/eigen/3.2.8/include/eigen3/Eigen/src/LU/PartialPivLU.h:52:10: error: 'Options' is not a member of 'Eigen::PartialPivLU<Eigen::Ref<Eigen::Matrix<double, -1, -1> > >::MatrixType {aka Eigen::Ref<Eigen::Matrix<double, -1, -1> >}'
/apps/eigen/3.2.8/include/eigen3/Eigen/src/LU/PartialPivLU.h: In instantiation of 'Eigen::PartialPivLU<MatrixType>::PartialPivLU(const MatrixType&) [with _MatrixType = Eigen::Ref<Eigen::Matrix<double, -1, -1> >; Eigen::PartialPivLU<MatrixType>::MatrixType = Eigen::Ref<Eigen::Matrix<double, -1, -1> >]':
test3.cc:9:36: required from here
/apps/eigen/3.2.8/include/eigen3/Eigen/src/LU/PartialPivLU.h:213:26: error: no matching function for call to 'Eigen::Ref<Eigen::Matrix<double, -1, -1> >::Ref(Eigen::MapBase<Eigen::Ref<Eigen::Matrix<double, -1, -1> >, 0>::Index, Eigen::MapBase<Eigen::Ref<Eigen::Matrix<double, -1, -1> >, 0>::Index)'
/apps/eigen/3.2.8/include/eigen3/Eigen/src/LU/PartialPivLU.h:213:26: note: candidates are:
In file included from /apps/eigen/3.2.8/include/eigen3/Eigen/Core:308:0,
from /apps/eigen/3.2.8/include/eigen3/Eigen/Dense:1,
from test3.cc:2:
/apps/eigen/3.2.8/include/eigen3/Eigen/src/Core/Ref.h:211:12: note: template<class Derived> Eigen::Ref::Ref(const Eigen::DenseBase<OtherDerived>&, typename Eigen::internal::enable_if<(bool)(typename Eigen::internal::traits<Eigen::Ref<_PlainObjectType, _Options, _StrideType> >::match<Derived>::MatchAtCompileTime), Derived>::type*)
/apps/eigen/3.2.8/include/eigen3/Eigen/src/Core/Ref.h:211:12: note: template argument deduction/substitution failed:
In file included from /apps/eigen/3.2.8/include/eigen3/Eigen/LU:23:0,
from /apps/eigen/3.2.8/include/eigen3/Eigen/Dense:2,
from test3.cc:2:
/apps/eigen/3.2.8/include/eigen3/Eigen/src/LU/PartialPivLU.h:213:26: note: mismatched types 'const Eigen::DenseBase<Derived>' and 'Eigen::MapBase<Eigen::Ref<Eigen::Matrix<double, -1, -1> >, 0>::Index {aka long int}'
In file included from /apps/eigen/3.2.8/include/eigen3/Eigen/Core:308:0,
from /apps/eigen/3.2.8/include/eigen3/Eigen/Dense:1,
from test3.cc:2:
/apps/eigen/3.2.8/include/eigen3/Eigen/src/Core/Ref.h:204:12: note: template<class Derived> Eigen::Ref::Ref(Eigen::PlainObjectBase<OtherDerived>&, typename Eigen::internal::enable_if<(bool)(typename Eigen::internal::traits<Eigen::Ref<_PlainObjectType, _Options, _StrideType> >::match<Derived>::MatchAtCompileTime), Derived>::type*)
/apps/eigen/3.2.8/include/eigen3/Eigen/src/Core/Ref.h:204:12: note: template argument deduction/substitution failed:
In file included from /apps/eigen/3.2.8/include/eigen3/Eigen/LU:23:0,
from /apps/eigen/3.2.8/include/eigen3/Eigen/Dense:2,
from test3.cc:2:
/apps/eigen/3.2.8/include/eigen3/Eigen/src/LU/PartialPivLU.h:213:26: note: mismatched types 'Eigen::PlainObjectBase<OtherDerived>' and 'Eigen::MapBase<Eigen::Ref<Eigen::Matrix<double, -1, -1> >, 0>::Index {aka long int}'
In file included from /apps/eigen/3.2.8/include/eigen3/Eigen/Core:308:0,
from /apps/eigen/3.2.8/include/eigen3/Eigen/Dense:1,
from test3.cc:2:
/apps/eigen/3.2.8/include/eigen3/Eigen/src/Core/Ref.h:194:12: note: template<class Derived> Eigen::Ref::Ref(const Eigen::PlainObjectBase<OtherDerived>&, typename Eigen::internal::enable_if<(bool)(typename Eigen::internal::traits<Eigen::Ref<_PlainObjectType, _Options, _StrideType> >::match<Derived>::MatchAtCompileTime), Derived>::type*)
/apps/eigen/3.2.8/include/eigen3/Eigen/src/Core/Ref.h:194:12: note: template argument deduction/substitution failed:
In file included from /apps/eigen/3.2.8/include/eigen3/Eigen/LU:23:0,
from /apps/eigen/3.2.8/include/eigen3/Eigen/Dense:2,
from test3.cc:2:
/apps/eigen/3.2.8/include/eigen3/Eigen/src/LU/PartialPivLU.h:213:26: note: mismatched types 'const Eigen::PlainObjectBase<OtherDerived>' and 'Eigen::MapBase<Eigen::Ref<Eigen::Matrix<double, -1, -1> >, 0>::Index {aka long int}'
In file included from /apps/eigen/3.2.8/include/eigen3/Eigen/Core:308:0,
from /apps/eigen/3.2.8/include/eigen3/Eigen/Dense:1,
from test3.cc:2:
/apps/eigen/3.2.8/include/eigen3/Eigen/src/Core/Ref.h:188:76: note: Eigen::Ref<Eigen::Matrix<double, -1, -1> >::Ref(const Eigen::Ref<Eigen::Matrix<double, -1, -1> >&)
/apps/eigen/3.2.8/include/eigen3/Eigen/src/Core/Ref.h:188:76: note: candidate expects 1 argument, 2 provided
As chtz noted, the problem was the version of Eigen I was using. You need to use Eigen 3.3 or above.
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.