mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
merge with eigen-tip
This commit is contained in:
@@ -1,9 +1,3 @@
|
||||
|
||||
add_subdirectory(Eigen)
|
||||
|
||||
add_subdirectory(doc)
|
||||
|
||||
if(EIGEN_BUILD_TESTS)
|
||||
add_subdirectory(test)
|
||||
endif(EIGEN_BUILD_TESTS)
|
||||
|
||||
add_subdirectory(doc EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(test EXCLUDE_FROM_ALL)
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
//
|
||||
// This file provides support for adolc's adouble type in forward mode.
|
||||
// ADOL-C is a C++ automatic differentiation library,
|
||||
// see http://www.math.tu-dresden.de/~adol-c/ for more information.
|
||||
// see https://projects.coin-or.org/ADOL-C for more information.
|
||||
//
|
||||
// Note that the maximal number of directions is controlled by
|
||||
// the preprocessor token NUMBER_DIRECTIONS. The default is 2.
|
||||
@@ -63,7 +63,7 @@ namespace Eigen {
|
||||
* \defgroup AdolcForward_Module Adolc forward module
|
||||
* This module provides support for adolc's adouble type in forward mode.
|
||||
* ADOL-C is a C++ automatic differentiation library,
|
||||
* see http://www.math.tu-dresden.de/~adol-c/ for more information.
|
||||
* see https://projects.coin-or.org/ADOL-C for more information.
|
||||
* It mainly consists in:
|
||||
* - a struct Eigen::NumTraits<adtl::adouble> specialization
|
||||
* - overloads of ei_* math function for adtl::adouble type.
|
||||
|
||||
@@ -63,37 +63,37 @@ template<typename _Scalar> class AlignedVector3
|
||||
typedef Matrix<_Scalar,4,1> CoeffType;
|
||||
CoeffType m_coeffs;
|
||||
public:
|
||||
|
||||
|
||||
EIGEN_GENERIC_PUBLIC_INTERFACE(AlignedVector3)
|
||||
using Base::operator*;
|
||||
|
||||
|
||||
inline int rows() const { return 3; }
|
||||
inline int cols() const { return 1; }
|
||||
|
||||
|
||||
inline const Scalar& coeff(int row, int col) const
|
||||
{ return m_coeffs.coeff(row, col); }
|
||||
|
||||
|
||||
inline Scalar& coeffRef(int row, int col)
|
||||
{ return m_coeffs.coeffRef(row, col); }
|
||||
|
||||
|
||||
inline const Scalar& coeff(int index) const
|
||||
{ return m_coeffs.coeff(index); }
|
||||
|
||||
inline Scalar& coeffRef(int index)
|
||||
{ return m_coeffs.coeffRef(index);}
|
||||
|
||||
|
||||
|
||||
|
||||
inline AlignedVector3(const Scalar& x, const Scalar& y, const Scalar& z)
|
||||
: m_coeffs(x, y, z, Scalar(0))
|
||||
{}
|
||||
|
||||
|
||||
inline AlignedVector3(const AlignedVector3& other)
|
||||
: m_coeffs(other.m_coeffs)
|
||||
: Base(), m_coeffs(other.m_coeffs)
|
||||
{}
|
||||
|
||||
|
||||
template<typename XprType, int Size=XprType::SizeAtCompileTime>
|
||||
struct generic_assign_selector {};
|
||||
|
||||
|
||||
template<typename XprType> struct generic_assign_selector<XprType,4>
|
||||
{
|
||||
inline static void run(AlignedVector3& dest, const XprType& src)
|
||||
@@ -101,7 +101,7 @@ template<typename _Scalar> class AlignedVector3
|
||||
dest.m_coeffs = src;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename XprType> struct generic_assign_selector<XprType,3>
|
||||
{
|
||||
inline static void run(AlignedVector3& dest, const XprType& src)
|
||||
@@ -110,44 +110,44 @@ template<typename _Scalar> class AlignedVector3
|
||||
dest.m_coeffs.w() = Scalar(0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename Derived>
|
||||
inline explicit AlignedVector3(const MatrixBase<Derived>& other)
|
||||
{
|
||||
generic_assign_selector<Derived>::run(*this,other.derived());
|
||||
}
|
||||
|
||||
|
||||
inline AlignedVector3& operator=(const AlignedVector3& other)
|
||||
{ m_coeffs = other.m_coeffs; return *this; }
|
||||
|
||||
|
||||
|
||||
|
||||
inline AlignedVector3 operator+(const AlignedVector3& other) const
|
||||
{ return AlignedVector3(m_coeffs + other.m_coeffs); }
|
||||
|
||||
|
||||
inline AlignedVector3& operator+=(const AlignedVector3& other)
|
||||
{ m_coeffs += other.m_coeffs; return *this; }
|
||||
|
||||
|
||||
inline AlignedVector3 operator-(const AlignedVector3& other) const
|
||||
{ return AlignedVector3(m_coeffs - other.m_coeffs); }
|
||||
|
||||
|
||||
inline AlignedVector3 operator-=(const AlignedVector3& other)
|
||||
{ m_coeffs -= other.m_coeffs; return *this; }
|
||||
|
||||
|
||||
inline AlignedVector3 operator*(const Scalar& s) const
|
||||
{ return AlignedVector3(m_coeffs * s); }
|
||||
|
||||
|
||||
inline friend AlignedVector3 operator*(const Scalar& s,const AlignedVector3& vec)
|
||||
{ return AlignedVector3(s * vec.m_coeffs); }
|
||||
|
||||
|
||||
inline AlignedVector3& operator*=(const Scalar& s)
|
||||
{ m_coeffs *= s; return *this; }
|
||||
|
||||
|
||||
inline AlignedVector3 operator/(const Scalar& s) const
|
||||
{ return AlignedVector3(m_coeffs / s); }
|
||||
|
||||
|
||||
inline AlignedVector3& operator/=(const Scalar& s)
|
||||
{ m_coeffs /= s; return *this; }
|
||||
|
||||
|
||||
inline Scalar dot(const AlignedVector3& other) const
|
||||
{
|
||||
ei_assert(m_coeffs.w()==Scalar(0));
|
||||
@@ -164,29 +164,29 @@ template<typename _Scalar> class AlignedVector3
|
||||
{
|
||||
return AlignedVector3(m_coeffs / norm());
|
||||
}
|
||||
|
||||
|
||||
inline Scalar sum() const
|
||||
{
|
||||
ei_assert(m_coeffs.w()==Scalar(0));
|
||||
return m_coeffs.sum();
|
||||
}
|
||||
|
||||
|
||||
inline Scalar squaredNorm() const
|
||||
{
|
||||
ei_assert(m_coeffs.w()==Scalar(0));
|
||||
return m_coeffs.squaredNorm();
|
||||
}
|
||||
|
||||
|
||||
inline Scalar norm() const
|
||||
{
|
||||
return ei_sqrt(squaredNorm());
|
||||
}
|
||||
|
||||
|
||||
inline AlignedVector3 cross(const AlignedVector3& other) const
|
||||
{
|
||||
return AlignedVector3(m_coeffs.cross3(other.m_coeffs));
|
||||
}
|
||||
|
||||
|
||||
template<typename Derived>
|
||||
inline bool isApprox(const MatrixBase<Derived>& other, RealScalar eps=precision<Scalar>()) const
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
typedef Matrix<ActiveScalar, InputsAtCompileTime, 1> ActiveInput;
|
||||
typedef Matrix<ActiveScalar, ValuesAtCompileTime, 1> ActiveValue;
|
||||
|
||||
void operator() (const InputType& x, ValueType* v, JacobianType* _jac) const
|
||||
void operator() (const InputType& x, ValueType* v, JacobianType* _jac=0) const
|
||||
{
|
||||
ei_assert(v!=0);
|
||||
if (!_jac)
|
||||
|
||||
@@ -111,7 +111,7 @@ struct TestFunc1
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Func> void adolc_forward_jacobian(const Func& f)
|
||||
template<typename Func> void forward_jacobian(const Func& f)
|
||||
{
|
||||
typename Func::InputType x = Func::InputType::Random(f.inputs());
|
||||
typename Func::ValueType y(f.values()), yref(f.values());
|
||||
@@ -134,21 +134,29 @@ template<typename Func> void adolc_forward_jacobian(const Func& f)
|
||||
VERIFY_IS_APPROX(j, jref);
|
||||
}
|
||||
|
||||
void test_autodiff()
|
||||
void test_autodiff_scalar()
|
||||
{
|
||||
std::cerr << foo<float>(1,2) << "\n";
|
||||
AutoDiffScalar<Vector2f> ax(1,Vector2f::UnitX());
|
||||
AutoDiffScalar<Vector2f> ay(2,Vector2f::UnitY());
|
||||
std::cerr << foo<AutoDiffScalar<Vector2f> >(ax,ay).value() << " <> "
|
||||
<< foo<AutoDiffScalar<Vector2f> >(ax,ay).derivatives().transpose() << "\n\n";
|
||||
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double,2,2>()) ));
|
||||
CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double,2,3>()) ));
|
||||
CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double,3,2>()) ));
|
||||
CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double,3,3>()) ));
|
||||
CALL_SUBTEST(( adolc_forward_jacobian(TestFunc1<double>(3,3)) ));
|
||||
}
|
||||
|
||||
// exit(1);
|
||||
}
|
||||
|
||||
void test_autodiff_jacobian()
|
||||
{
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
CALL_SUBTEST(( forward_jacobian(TestFunc1<double,2,2>()) ));
|
||||
CALL_SUBTEST(( forward_jacobian(TestFunc1<double,2,3>()) ));
|
||||
CALL_SUBTEST(( forward_jacobian(TestFunc1<double,3,2>()) ));
|
||||
CALL_SUBTEST(( forward_jacobian(TestFunc1<double,3,3>()) ));
|
||||
CALL_SUBTEST(( forward_jacobian(TestFunc1<double>(3,3)) ));
|
||||
}
|
||||
}
|
||||
|
||||
void test_autodiff()
|
||||
{
|
||||
test_autodiff_scalar();
|
||||
test_autodiff_jacobian();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user