- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我实现了一个比较运算符 operator<
对于 Eigen::VectorXd
,有时,我需要将一个比较函数传递给我的另一个函数,我厌倦了包装 operator<
进入[](const VectorXd& v1, const VectorXd& v2)->bool{return v1 < v2}
,所以我认为 std::less
class 会很有用,因为据我了解,它可以生成 lambda 函数,只要 operator<
已定义。
但是,我发现 std::less<VectorXd>
对我不起作用,例如,下面的代码工作正常:
#include "Eigen/Dense"
#include <iostream>
#include <functional>
using namespace std;
using namespace Eigen;
struct T
{
int x;
};
bool operator<(const T& t1, const T& t2)
{
return t1.x < t2.x;
}
bool operator<(const VectorXd& v1, const VectorXd& v2)
{
return (v1.array() <= v2.array()).all() and (v1 != v2);
}
int main()
{
T t1, t2;
t1.x = 3;
t2.x = 2;
auto ft = std::less<T>();
cout << ft(t1, t2) << endl;
return EXIT_SUCCESS;
}
但是,如果我使用 std::less<VectorXd>
像这样:
#include "Eigen/Dense"
#include <iostream>
#include <functional>
using namespace std;
using namespace Eigen;
struct T
{
int x;
};
bool operator<(const T& t1, const T& t2)
{
return t1.x < t2.x;
}
bool operator<(const VectorXd& v1, const VectorXd& v2)
{
return (v1.array() <= v2.array()).all() and (v1 != v2);
}
int main()
{
T t1, t2;
t1.x = 3;
t2.x = 2;
auto ft = std::less<T>();
cout << ft(t1, t2) << endl;
VectorXd v1(3);
VectorXd v2(3);
v1 << 1, 2, 3;
v2 << 2, 3, 4;
auto fv = std::less<VectorXd>();
cout << fv(v1, v2) << endl;
return EXIT_SUCCESS;
}
代码编译失败,我收到如下错误信息:
In file included from /usr/include/c++/5/string:48:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_function.h: In instantiation of ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Eigen::Matrix<double, -1, 1>]’:
test.cpp:36:26: required from here
/usr/include/c++/5/bits/stl_function.h:387:20: error: no match for ‘operator<’ (operand types are ‘const Eigen::Matrix<double, -1, 1>’ and ‘const Eigen::Matrix<double, -1, 1>’)
{ return __x < __y; }
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:64:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_pair.h:220:5: note: candidate: template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
^
/usr/include/c++/5/bits/stl_pair.h:220:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/string:48:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_function.h:387:20: note: ‘const Eigen::Matrix<double, -1, 1>’ is not derived from ‘const std::pair<_T1, _T2>’
{ return __x < __y; }
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:298:5: note: candidate: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
operator<(const reverse_iterator<_Iterator>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:298:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/string:48:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_function.h:387:20: note: ‘const Eigen::Matrix<double, -1, 1>’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:348:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
operator<(const reverse_iterator<_IteratorL>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:348:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/string:48:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_function.h:387:20: note: ‘const Eigen::Matrix<double, -1, 1>’ is not derived from ‘const std::reverse_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:1089:5: note: candidate: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
operator<(const move_iterator<_IteratorL>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:1089:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/string:48:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_function.h:387:20: note: ‘const Eigen::Matrix<double, -1, 1>’ is not derived from ‘const std::move_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0,
from /usr/include/c++/5/bits/char_traits.h:39,
from /usr/include/c++/5/ios:40,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_iterator.h:1095:5: note: candidate: template<class _Iterator> bool std::operator<(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
operator<(const move_iterator<_Iterator>& __x,
^
/usr/include/c++/5/bits/stl_iterator.h:1095:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/string:48:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_function.h:387:20: note: ‘const Eigen::Matrix<double, -1, 1>’ is not derived from ‘const std::move_iterator<_Iterator>’
{ return __x < __y; }
^
In file included from /usr/include/c++/5/string:52:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/basic_string.h:4987:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/usr/include/c++/5/bits/basic_string.h:4987:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/string:48:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_function.h:387:20: note: ‘const Eigen::Matrix<double, -1, 1>’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/include/c++/5/string:52:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/basic_string.h:4999:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, const _CharT*)
operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
^
/usr/include/c++/5/bits/basic_string.h:4999:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/string:48:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_function.h:387:20: note: ‘const Eigen::Matrix<double, -1, 1>’ is not derived from ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’
{ return __x < __y; }
^
In file included from /usr/include/c++/5/string:52:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/basic_string.h:5011:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> bool std::operator<(const _CharT*, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
operator<(const _CharT* __lhs,
^
/usr/include/c++/5/bits/basic_string.h:5011:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/string:48:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_function.h:387:20: note: mismatched types ‘const _CharT*’ and ‘Eigen::Matrix<double, -1, 1>’
{ return __x < __y; }
^
In file included from /usr/include/c++/5/bits/ios_base.h:46:0,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/system_error:200:3: note: candidate: bool std::operator<(const std::error_code&, const std::error_code&)
operator<(const error_code& __lhs, const error_code& __rhs) noexcept
^
/usr/include/c++/5/system_error:200:3: note: no known conversion for argument 1 from ‘const Eigen::Matrix<double, -1, 1>’ to ‘const std::error_code&’
/usr/include/c++/5/system_error:274:3: note: candidate: bool std::operator<(const std::error_condition&, const std::error_condition&)
operator<(const error_condition& __lhs,
^
/usr/include/c++/5/system_error:274:3: note: no known conversion for argument 1 from ‘const Eigen::Matrix<double, -1, 1>’ to ‘const std::error_condition&’
In file included from /usr/include/c++/5/tuple:39:0,
from /usr/include/c++/5/functional:55,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:262,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/array:250:5: note: candidate: template<class _Tp, long unsigned int _Nm> bool std::operator<(const std::array<_Tp, _Nm>&, const std::array<_Tp, _Nm>&)
operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
^
/usr/include/c++/5/array:250:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/string:48:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_function.h:387:20: note: ‘const Eigen::Matrix<double, -1, 1>’ is not derived from ‘const std::array<_Tp, _Nm>’
{ return __x < __y; }
^
In file included from /usr/include/c++/5/functional:55:0,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:262,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/tuple:928:5: note: candidate: template<class ... _TElements, class ... _UElements> constexpr bool std::operator<(const std::tuple<_Elements ...>&, const std::tuple<_Elements ...>&)
operator<(const tuple<_TElements...>& __t,
^
/usr/include/c++/5/tuple:928:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/string:48:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_function.h:387:20: note: ‘const Eigen::Matrix<double, -1, 1>’ is not derived from ‘const std::tuple<_Elements ...>’
{ return __x < __y; }
^
In file included from /usr/include/c++/5/vector:64:0,
from /usr/include/c++/5/bits/random.h:34,
from /usr/include/c++/5/random:49,
from /usr/include/c++/5/bits/stl_algo.h:66,
from /usr/include/c++/5/algorithm:62,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:269,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_vector.h:1528:5: note: candidate: template<class _Tp, class _Alloc> bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
^
/usr/include/c++/5/bits/stl_vector.h:1528:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5/string:48:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Core:80,
from /home/alaya/.softwares/linear_algebra/eigen3.3/include/eigen3/Eigen/Dense:1,
from test.cpp:1:
/usr/include/c++/5/bits/stl_function.h:387:20: note: ‘const Eigen::Matrix<double, -1, 1>’ is not derived from ‘const std::vector<_Tp, _Alloc>’
{ return __x < __y; }
^
make: *** [try] Error 1
我正在使用 g++ 5.4.0 和 Eigen 3.3
最佳答案
事情是这样的。你的T
不能可靠地重现这种情况。您省略了 namespace ,这非常重要。一个更接近于 Eigen
的例子会是这样的:
namespace Foo {
struct T
{
int x;
};
}
bool operator<(const Foo::T& t1, const Foo::T& t2)
{
return t1.x < t2.x;
}
它会产生完全相同的错误。这是因为模板只会考虑在模板定义(而不是实例化)或通过argument dependent lookup 找到的此运算符的重载。关于操作数的类型。
要使依赖于参数的查找起作用,运算符和类型必须在相同的命名空间中定义,而您的显然不是。
所以这是怎么回事,你包括functional
.定义模板 std::less
在你的翻译单位。那时候没有operator<
对于 Eigen::VectorXd
洞察力。所以后面定义的时候模板定义就不会考虑了。
当您实例化模板时,它会尝试在它意识到的那些重载中寻找合适的重载,然后通过 ADL。由于您的 operator<
不在Eigen
里面命名空间,ADL 也找不到它。
长话短说,为库类型重载运算符是不切实际的。您应该做的是定义一个自定义比较器类型:
struct VectorXdCompare {
bool operator()(const VectorXd& v1, const VectorXd& v2) {
return (v1.array() <= v2.array()).all() and (v1 != v2);
}
};
然后传递 VectorXdCompare
作为类型,只要标准库需要它。
关于c++ - 为什么 std::less<Eigen::VectorXd> 编译失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46811833/
我想了解表达式模板如何在 Eigen 中工作。 我知道两个动态双向量的总和是由如下所示的东西执行的: CwiseBinaryOp, VectorXd const, VectorXd const > o
在本征中,我们可以创建一个矩阵 Matrix3f m; m m(3, 8, 6); // Input after construction m.diagonal() << 3, 8, 6; Diag
我想知道是否有比使用 for 循环更简单的方法来解决我的问题。所以情况是这样的: 一般来说,我想从我的传感器收集数据点(消息类型为 Eigen::Vector3d,我无法更改它,因为它是一个巨大的框架
简而言之,问题是如何通过一个 Eigen::Map 反对一个期待一个函数 Eigen::MatrixXd 对象。 长话短说: 我有这个 C++ 函数声明 void npMatrix(const Eig
考虑以下代码。 const int N = 100; const float alpha = 0.9; Eigen::MatrixXf myVec = Eigen::MatrixXf::Random(
我试图获得两个张量的矩阵乘积,其中一个张量应该在相乘之前转置( At*B )。 到目前为止,我在 eigen documentation 中发现了什么是没有任何转置和两个矩阵都转置的矩阵乘积。 我正在
我的问题很简单,希望也有一个很好的答案:当我构造了 Eigen::MatrixXd 矩阵时,我可以使用多个线程同时填充矩阵中的行吗(如果我可以确保没有行被同时写入),或者我必须在每个线程中创建临时行对
#include #include namespace Eigen { // float op double -> double template struct ScalarBinaryOpTr
我在 Eigen 库的 API 上遇到了一些困难,即用于稀疏矩阵 Cholesky 分解的 SimplicialLLT 类。我需要分解三个矩阵,然后用它们来求解许多方程组(仅更改右侧) - 因此我只想
我正在尝试使用 Eigen 的 JacobiSVD 进行实验。特别是我试图从奇异值分解中重建输入矩阵。 http://eigen.tuxfamily.org/dox/classEigen_1_1Jac
我刚刚阅读了 Structures having static members Eigen 页。后者陈述如下: If you define a structure having members of
我正在使用 C++ 中的 Eigen 库来获取浮点方阵的平方根: MatrixXf gPrime(QUAD_EKF_NUM_STATES, QUAD_EKF_NUM_STATES); gPri
我正在尝试使用 vector 中的相应值来缩放矩阵中的所有列。如果此值为 0,我想用另一个按常数缩放的矩阵中的列替换该列。听起来很复杂,但在 Matlab 中它非常简单(但可能没有完全优化): a(:
使用 Eigen 将仿射变换转换为等距变换(即仅由旋转和平移组成)的最简单方法是什么? 图书馆? 两种变换都是 3D 的。仿射矩阵在左上象限有一个通用的 3x3 矩阵(即旋转、缩放和剪切),而等轴测在
我正在尝试生成 PCL 点云。我所有的点都在以下容器类型中: std::vector > 我想创建一个指向 PCL 点云的指针: pcl::PointCloud::Ptr pc 创建此点云的最有效方法
最近,我编译了 Eigen3 并用它在 Windows 上做一些线性代数任务。 但我想知道为什么 Eigen3 不需要链接额外的 lib 或 DLL(我只需要包含它的头文件) Eigen 是否在编译时
我正在使用特征张量库,在我看来,shuffle() 方法需要一个对象 Eigen::array 作为输入。 在我的实现中,我有一个 std::list 需要传递给 shuffle (当然我只在运行时知
我有两个问题。 Eigen::Affine3f 和 Eigen::Matrix4f 中表示的刚性变换是否相同? 我们如何从 Eigen::Affine3f 转换为 Eigen::Matrix4f,反之
我想用单个 3-D Eigen::Tensor 替换代码中的一系列矩阵。考虑到这一点,我尝试比较张量和矩阵的性能。 下面的函数“tensorContractTest”执行 (n,n,n) 3 阶张量与
如何将 ArrayXXd 数组转换为 MatrixXd?到目前为止,我已经完成了 MatrixXd temp_mat = my_array; 并且隐式转换似乎工作正常,但这是应该完成的方式吗?或者我应
我是一名优秀的程序员,十分优秀!