mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
prefix global functions with ei_ as previous solution was rather
fragile. also fix compilation with g++ 4.3.
This commit is contained in:
@@ -51,8 +51,8 @@ template<typename MatrixType> void adjoint(const MatrixType& m)
|
||||
v3 = VectorType::random(rows),
|
||||
vzero = VectorType::zero(rows);
|
||||
|
||||
Scalar s1 = random<Scalar>(),
|
||||
s2 = random<Scalar>();
|
||||
Scalar s1 = ei_random<Scalar>(),
|
||||
s2 = ei_random<Scalar>();
|
||||
|
||||
// check involutivity of adjoint, transpose, conjugate
|
||||
VERIFY_IS_APPROX(m1.transpose().transpose(), m1);
|
||||
@@ -70,18 +70,18 @@ template<typename MatrixType> void adjoint(const MatrixType& m)
|
||||
VERIFY_IS_APPROX((m1.adjoint() * m2).adjoint(), m2.adjoint() * m1);
|
||||
VERIFY_IS_APPROX((m1.transpose() * m2).conjugate(), m1.adjoint() * m2.conjugate());
|
||||
VERIFY_IS_APPROX((s1 * m1).transpose(), s1 * m1.transpose());
|
||||
VERIFY_IS_APPROX((s1 * m1).conjugate(), conj(s1) * m1.conjugate());
|
||||
VERIFY_IS_APPROX((s1 * m1).adjoint(), conj(s1) * m1.adjoint());
|
||||
VERIFY_IS_APPROX((s1 * m1).conjugate(), ei_conj(s1) * m1.conjugate());
|
||||
VERIFY_IS_APPROX((s1 * m1).adjoint(), ei_conj(s1) * m1.adjoint());
|
||||
|
||||
// check basic properties of dot, norm, norm2
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
VERIFY_IS_APPROX((s1 * v1 + s2 * v2).dot(v3), s1 * v1.dot(v3) + s2 * v2.dot(v3));
|
||||
VERIFY_IS_APPROX(v3.dot(s1 * v1 + s2 * v2), conj(s1)*v3.dot(v1)+conj(s2)*v3.dot(v2));
|
||||
VERIFY_IS_APPROX(conj(v1.dot(v2)), v2.dot(v1));
|
||||
VERIFY_IS_APPROX(abs(v1.dot(v1)), v1.norm2());
|
||||
VERIFY_IS_APPROX(v3.dot(s1 * v1 + s2 * v2), ei_conj(s1)*v3.dot(v1)+ei_conj(s2)*v3.dot(v2));
|
||||
VERIFY_IS_APPROX(ei_conj(v1.dot(v2)), v2.dot(v1));
|
||||
VERIFY_IS_APPROX(ei_abs(v1.dot(v1)), v1.norm2());
|
||||
if(NumTraits<Scalar>::HasFloatingPoint)
|
||||
VERIFY_IS_APPROX(v1.norm2(), v1.norm() * v1.norm());
|
||||
VERIFY_IS_MUCH_SMALLER_THAN(abs(vzero.dot(v1)), static_cast<RealScalar>(1));
|
||||
VERIFY_IS_MUCH_SMALLER_THAN(ei_abs(vzero.dot(v1)), static_cast<RealScalar>(1));
|
||||
if(NumTraits<Scalar>::HasFloatingPoint)
|
||||
VERIFY_IS_MUCH_SMALLER_THAN(vzero.norm(), static_cast<RealScalar>(1));
|
||||
|
||||
@@ -89,10 +89,10 @@ template<typename MatrixType> void adjoint(const MatrixType& m)
|
||||
VERIFY_IS_APPROX(v1.dot(square * v2), (square.adjoint() * v1).dot(v2));
|
||||
|
||||
// like in testBasicStuff, test operator() to check const-qualification
|
||||
int r = random<int>(0, rows-1),
|
||||
c = random<int>(0, cols-1);
|
||||
VERIFY_IS_APPROX(m1.conjugate()(r,c), conj(m1(r,c)));
|
||||
VERIFY_IS_APPROX(m1.adjoint()(c,r), conj(m1(r,c)));
|
||||
int r = ei_random<int>(0, rows-1),
|
||||
c = ei_random<int>(0, cols-1);
|
||||
VERIFY_IS_APPROX(m1.conjugate()(r,c), ei_conj(m1(r,c)));
|
||||
VERIFY_IS_APPROX(m1.adjoint()(c,r), ei_conj(m1(r,c)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -49,8 +49,8 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
|
||||
v2 = VectorType::random(rows),
|
||||
vzero = VectorType::zero(rows);
|
||||
|
||||
int r = random<int>(0, rows-1),
|
||||
c = random<int>(0, cols-1);
|
||||
int r = ei_random<int>(0, rows-1),
|
||||
c = ei_random<int>(0, cols-1);
|
||||
|
||||
VERIFY_IS_APPROX( v1, v1);
|
||||
VERIFY_IS_NOT_APPROX( v1, 2*v1);
|
||||
|
||||
@@ -53,11 +53,11 @@ template<typename MatrixType> void linearStructure(const MatrixType& m)
|
||||
v2 = VectorType::random(rows),
|
||||
vzero = VectorType::zero(rows);
|
||||
|
||||
Scalar s1 = random<Scalar>(),
|
||||
s2 = random<Scalar>();
|
||||
Scalar s1 = ei_random<Scalar>(),
|
||||
s2 = ei_random<Scalar>();
|
||||
|
||||
int r = random<int>(0, rows-1),
|
||||
c = random<int>(0, cols-1);
|
||||
int r = ei_random<int>(0, rows-1),
|
||||
c = ei_random<int>(0, cols-1);
|
||||
|
||||
VERIFY_IS_APPROX(-(-m1), m1);
|
||||
VERIFY_IS_APPROX(m1+m1, 2*m1);
|
||||
|
||||
70
test/main.h
70
test/main.h
@@ -38,12 +38,12 @@
|
||||
#define DEFAULT_REPEAT 50
|
||||
|
||||
#define VERIFY(a) QVERIFY(a)
|
||||
#define VERIFY_IS_APPROX(a, b) QVERIFY(test_isApprox(a, b))
|
||||
#define VERIFY_IS_NOT_APPROX(a, b) QVERIFY(!test_isApprox(a, b))
|
||||
#define VERIFY_IS_MUCH_SMALLER_THAN(a, b) QVERIFY(test_isMuchSmallerThan(a, b))
|
||||
#define VERIFY_IS_NOT_MUCH_SMALLER_THAN(a, b) QVERIFY(!test_isMuchSmallerThan(a, b))
|
||||
#define VERIFY_IS_APPROX_OR_LESS_THAN(a, b) QVERIFY(test_isApproxOrLessThan(a, b))
|
||||
#define VERIFY_IS_NOT_APPROX_OR_LESS_THAN(a, b) QVERIFY(!test_isApproxOrLessThan(a, b))
|
||||
#define VERIFY_IS_APPROX(a, b) QVERIFY(test_ei_isApprox(a, b))
|
||||
#define VERIFY_IS_NOT_APPROX(a, b) QVERIFY(!test_ei_isApprox(a, b))
|
||||
#define VERIFY_IS_MUCH_SMALLER_THAN(a, b) QVERIFY(test_ei_isMuchSmallerThan(a, b))
|
||||
#define VERIFY_IS_NOT_MUCH_SMALLER_THAN(a, b) QVERIFY(!test_ei_isMuchSmallerThan(a, b))
|
||||
#define VERIFY_IS_APPROX_OR_LESS_THAN(a, b) QVERIFY(test_ei_isApproxOrLessThan(a, b))
|
||||
#define VERIFY_IS_NOT_APPROX_OR_LESS_THAN(a, b) QVERIFY(!test_ei_isApproxOrLessThan(a, b))
|
||||
|
||||
namespace Eigen {
|
||||
|
||||
@@ -54,53 +54,53 @@ template<> inline double test_precision<double>() { return 1e-5; }
|
||||
template<> inline float test_precision<std::complex<float> >() { return test_precision<float>(); }
|
||||
template<> inline double test_precision<std::complex<double> >() { return test_precision<double>(); }
|
||||
|
||||
inline bool test_isApprox(const int& a, const int& b)
|
||||
{ return isApprox(a, b, test_precision<int>()); }
|
||||
inline bool test_isMuchSmallerThan(const int& a, const int& b)
|
||||
{ return isMuchSmallerThan(a, b, test_precision<int>()); }
|
||||
inline bool test_isApproxOrLessThan(const int& a, const int& b)
|
||||
{ return isApproxOrLessThan(a, b, test_precision<int>()); }
|
||||
inline bool test_ei_isApprox(const int& a, const int& b)
|
||||
{ return ei_isApprox(a, b, test_precision<int>()); }
|
||||
inline bool test_ei_isMuchSmallerThan(const int& a, const int& b)
|
||||
{ return ei_isMuchSmallerThan(a, b, test_precision<int>()); }
|
||||
inline bool test_ei_isApproxOrLessThan(const int& a, const int& b)
|
||||
{ return ei_isApproxOrLessThan(a, b, test_precision<int>()); }
|
||||
|
||||
inline bool test_isApprox(const float& a, const float& b)
|
||||
{ return isApprox(a, b, test_precision<float>()); }
|
||||
inline bool test_isMuchSmallerThan(const float& a, const float& b)
|
||||
{ return isMuchSmallerThan(a, b, test_precision<float>()); }
|
||||
inline bool test_isApproxOrLessThan(const float& a, const float& b)
|
||||
{ return isApproxOrLessThan(a, b, test_precision<float>()); }
|
||||
inline bool test_ei_isApprox(const float& a, const float& b)
|
||||
{ return ei_isApprox(a, b, test_precision<float>()); }
|
||||
inline bool test_ei_isMuchSmallerThan(const float& a, const float& b)
|
||||
{ return ei_isMuchSmallerThan(a, b, test_precision<float>()); }
|
||||
inline bool test_ei_isApproxOrLessThan(const float& a, const float& b)
|
||||
{ return ei_isApproxOrLessThan(a, b, test_precision<float>()); }
|
||||
|
||||
inline bool test_isApprox(const double& a, const double& b)
|
||||
{ return isApprox(a, b, test_precision<double>()); }
|
||||
inline bool test_isMuchSmallerThan(const double& a, const double& b)
|
||||
{ return isMuchSmallerThan(a, b, test_precision<double>()); }
|
||||
inline bool test_isApproxOrLessThan(const double& a, const double& b)
|
||||
{ return isApproxOrLessThan(a, b, test_precision<double>()); }
|
||||
inline bool test_ei_isApprox(const double& a, const double& b)
|
||||
{ return ei_isApprox(a, b, test_precision<double>()); }
|
||||
inline bool test_ei_isMuchSmallerThan(const double& a, const double& b)
|
||||
{ return ei_isMuchSmallerThan(a, b, test_precision<double>()); }
|
||||
inline bool test_ei_isApproxOrLessThan(const double& a, const double& b)
|
||||
{ return ei_isApproxOrLessThan(a, b, test_precision<double>()); }
|
||||
|
||||
inline bool test_isApprox(const std::complex<float>& a, const std::complex<float>& b)
|
||||
{ return isApprox(a, b, test_precision<std::complex<float> >()); }
|
||||
inline bool test_isMuchSmallerThan(const std::complex<float>& a, const std::complex<float>& b)
|
||||
{ return isMuchSmallerThan(a, b, test_precision<std::complex<float> >()); }
|
||||
inline bool test_ei_isApprox(const std::complex<float>& a, const std::complex<float>& b)
|
||||
{ return ei_isApprox(a, b, test_precision<std::complex<float> >()); }
|
||||
inline bool test_ei_isMuchSmallerThan(const std::complex<float>& a, const std::complex<float>& b)
|
||||
{ return ei_isMuchSmallerThan(a, b, test_precision<std::complex<float> >()); }
|
||||
|
||||
inline bool test_isApprox(const std::complex<double>& a, const std::complex<double>& b)
|
||||
{ return isApprox(a, b, test_precision<std::complex<double> >()); }
|
||||
inline bool test_isMuchSmallerThan(const std::complex<double>& a, const std::complex<double>& b)
|
||||
{ return isMuchSmallerThan(a, b, test_precision<std::complex<double> >()); }
|
||||
inline bool test_ei_isApprox(const std::complex<double>& a, const std::complex<double>& b)
|
||||
{ return ei_isApprox(a, b, test_precision<std::complex<double> >()); }
|
||||
inline bool test_ei_isMuchSmallerThan(const std::complex<double>& a, const std::complex<double>& b)
|
||||
{ return ei_isMuchSmallerThan(a, b, test_precision<std::complex<double> >()); }
|
||||
|
||||
template<typename Scalar, typename Derived1, typename Derived2>
|
||||
inline bool test_isApprox(const MatrixBase<Scalar, Derived1>& m1,
|
||||
inline bool test_ei_isApprox(const MatrixBase<Scalar, Derived1>& m1,
|
||||
const MatrixBase<Scalar, Derived2>& m2)
|
||||
{
|
||||
return m1.isApprox(m2, test_precision<Scalar>());
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived1, typename Derived2>
|
||||
inline bool test_isMuchSmallerThan(const MatrixBase<Scalar, Derived1>& m1,
|
||||
inline bool test_ei_isMuchSmallerThan(const MatrixBase<Scalar, Derived1>& m1,
|
||||
const MatrixBase<Scalar, Derived2>& m2)
|
||||
{
|
||||
return m1.isMuchSmallerThan(m2, test_precision<Scalar>());
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
inline bool test_isMuchSmallerThan(const MatrixBase<Scalar, Derived>& m,
|
||||
inline bool test_ei_isMuchSmallerThan(const MatrixBase<Scalar, Derived>& m,
|
||||
const typename NumTraits<Scalar>::Real& s)
|
||||
{
|
||||
return m.isMuchSmallerThan(s, test_precision<Scalar>());
|
||||
|
||||
@@ -39,7 +39,7 @@ template<typename MatrixType> void miscMatrices(const MatrixType& m)
|
||||
int rows = m.rows();
|
||||
int cols = m.cols();
|
||||
|
||||
int r = random<int>(0, rows-1), r2 = random<int>(0, rows-1), c = random<int>(0, cols-1);
|
||||
int r = ei_random<int>(0, rows-1), r2 = ei_random<int>(0, rows-1), c = ei_random<int>(0, cols-1);
|
||||
VERIFY_IS_APPROX(MatrixType::ones(rows,cols)(r,c), static_cast<Scalar>(1));
|
||||
MatrixType m1 = MatrixType::ones(rows,cols);
|
||||
VERIFY_IS_APPROX(m1(r,c), static_cast<Scalar>(1));
|
||||
|
||||
@@ -53,10 +53,10 @@ template<typename MatrixType> void product(const MatrixType& m)
|
||||
v2 = VectorType::random(rows),
|
||||
vzero = VectorType::zero(rows);
|
||||
|
||||
Scalar s1 = random<Scalar>();
|
||||
Scalar s1 = ei_random<Scalar>();
|
||||
|
||||
int r = random<int>(0, rows-1),
|
||||
c = random<int>(0, cols-1);
|
||||
int r = ei_random<int>(0, rows-1),
|
||||
c = ei_random<int>(0, cols-1);
|
||||
|
||||
// begin testing Product.h: only associativity for now
|
||||
// (we use Transpose.h but this doesn't count as a test for it)
|
||||
|
||||
@@ -32,10 +32,10 @@ template<typename Scalar> void smallVectors()
|
||||
typedef Matrix<Scalar, 1, 2> V2;
|
||||
typedef Matrix<Scalar, 3, 1> V3;
|
||||
typedef Matrix<Scalar, 1, 4> V4;
|
||||
Scalar x1 = random<Scalar>(),
|
||||
x2 = random<Scalar>(),
|
||||
x3 = random<Scalar>(),
|
||||
x4 = random<Scalar>();
|
||||
Scalar x1 = ei_random<Scalar>(),
|
||||
x2 = ei_random<Scalar>(),
|
||||
x3 = ei_random<Scalar>(),
|
||||
x4 = ei_random<Scalar>();
|
||||
V2 v2(x1, x2);
|
||||
V3 v3(x1, x2, x3);
|
||||
V4 v4(x1, x2, x3, x4);
|
||||
|
||||
@@ -52,12 +52,12 @@ template<typename MatrixType> void submatrices(const MatrixType& m)
|
||||
v3 = VectorType::random(rows),
|
||||
vzero = VectorType::zero(rows);
|
||||
|
||||
Scalar s1 = random<Scalar>();
|
||||
Scalar s1 = ei_random<Scalar>();
|
||||
|
||||
int r1 = random<int>(0,rows-1);
|
||||
int r2 = random<int>(r1,rows-1);
|
||||
int c1 = random<int>(0,cols-1);
|
||||
int c2 = random<int>(c1,cols-1);
|
||||
int r1 = ei_random<int>(0,rows-1);
|
||||
int r2 = ei_random<int>(r1,rows-1);
|
||||
int c1 = ei_random<int>(0,cols-1);
|
||||
int c2 = ei_random<int>(c1,cols-1);
|
||||
|
||||
//check row() and col()
|
||||
VERIFY_IS_APPROX(m1.col(c1).transpose(), m1.transpose().row(c1));
|
||||
@@ -108,7 +108,7 @@ void EigenTest::testSubmatrices()
|
||||
// being called as a member of a class that is itself a template parameter
|
||||
// (at least as of g++ 4.2)
|
||||
Matrix<float, 6, 8> m = Matrix<float, 6, 8>::random();
|
||||
float s = random<float>();
|
||||
float s = ei_random<float>();
|
||||
// test fixedBlock() as lvalue
|
||||
m.fixedBlock<2,5>(1,1) *= s;
|
||||
// test operator() on fixedBlock() both as constant and non-constant
|
||||
|
||||
Reference in New Issue
Block a user