mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
bug #1223: fix compilation of AutoDiffScalar's min/max operators, and add regression unit test.
This commit is contained in:
parent
448d9d943c
commit
1fbfab27a9
@ -548,13 +548,25 @@ inline const AutoDiffScalar<DerType>& real(const AutoDiffScalar<DerType>& x) {
|
|||||||
template<typename DerType>
|
template<typename DerType>
|
||||||
inline typename DerType::Scalar imag(const AutoDiffScalar<DerType>&) { return 0.; }
|
inline typename DerType::Scalar imag(const AutoDiffScalar<DerType>&) { return 0.; }
|
||||||
template<typename DerType, typename T>
|
template<typename DerType, typename T>
|
||||||
inline AutoDiffScalar<DerType> (min)(const AutoDiffScalar<DerType>& x, const T& y) { return (x <= y ? x : y); }
|
inline AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject> (min)(const AutoDiffScalar<DerType>& x, const T& y) {
|
||||||
|
typedef AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject> ADS;
|
||||||
|
return (x <= y ? ADS(x) : ADS(y));
|
||||||
|
}
|
||||||
template<typename DerType, typename T>
|
template<typename DerType, typename T>
|
||||||
inline AutoDiffScalar<DerType> (max)(const AutoDiffScalar<DerType>& x, const T& y) { return (x >= y ? x : y); }
|
inline AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject> (max)(const AutoDiffScalar<DerType>& x, const T& y) {
|
||||||
|
typedef AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject> ADS;
|
||||||
|
return (x >= y ? ADS(x) : ADS(y));
|
||||||
|
}
|
||||||
template<typename DerType, typename T>
|
template<typename DerType, typename T>
|
||||||
inline AutoDiffScalar<DerType> (min)(const T& x, const AutoDiffScalar<DerType>& y) { return (x < y ? x : y); }
|
inline AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject> (min)(const T& x, const AutoDiffScalar<DerType>& y) {
|
||||||
|
typedef AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject> ADS;
|
||||||
|
return (x < y ? ADS(x) : ADS(y));
|
||||||
|
}
|
||||||
template<typename DerType, typename T>
|
template<typename DerType, typename T>
|
||||||
inline AutoDiffScalar<DerType> (max)(const T& x, const AutoDiffScalar<DerType>& y) { return (x > y ? x : y); }
|
inline AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject> (max)(const T& x, const AutoDiffScalar<DerType>& y) {
|
||||||
|
typedef AutoDiffScalar<typename Eigen::internal::remove_all<DerType>::type::PlainObject> ADS;
|
||||||
|
return (x > y ? ADS(x) : ADS(y));
|
||||||
|
}
|
||||||
|
|
||||||
EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs,
|
EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs,
|
||||||
using std::abs;
|
using std::abs;
|
||||||
|
@ -216,6 +216,24 @@ double bug_1222() {
|
|||||||
return denom.value();
|
return denom.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double bug_1223() {
|
||||||
|
using std::min;
|
||||||
|
typedef Eigen::AutoDiffScalar<Eigen::Vector3d> AD;
|
||||||
|
|
||||||
|
const double _cv1_3 = 1.0;
|
||||||
|
const AD chi_3 = 1.0;
|
||||||
|
const AD denom = 1.0;
|
||||||
|
|
||||||
|
// failed because implementation of min attempts to construct ADS<DerType&> via constructor AutoDiffScalar(const Real& value)
|
||||||
|
// without initializing m_derivatives (which is a reference in this case)
|
||||||
|
#define EIGEN_TEST_SPACE
|
||||||
|
const AD t = min EIGEN_TEST_SPACE (denom / chi_3, 1.0);
|
||||||
|
|
||||||
|
const AD t2 = min EIGEN_TEST_SPACE (denom / (chi_3 * _cv1_3), 1.0);
|
||||||
|
|
||||||
|
return t.value() + t2.value();
|
||||||
|
}
|
||||||
|
|
||||||
void test_autodiff()
|
void test_autodiff()
|
||||||
{
|
{
|
||||||
for(int i = 0; i < g_repeat; i++) {
|
for(int i = 0; i < g_repeat; i++) {
|
||||||
@ -226,5 +244,6 @@ void test_autodiff()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bug_1222();
|
bug_1222();
|
||||||
|
bug_1223();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user