mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Much more convenient, less over-engineered NumTraits. Done during this KDE-Edu weekend.
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "main.h"
|
||||
|
||||
namespace Eigen {
|
||||
|
||||
template<typename MatrixType> void adjoint(const MatrixType& m)
|
||||
{
|
||||
/* this test covers the following files:
|
||||
@@ -49,8 +51,8 @@ template<typename MatrixType> void adjoint(const MatrixType& m)
|
||||
v3 = VectorType::random(rows),
|
||||
vzero = VectorType::zero(rows);
|
||||
|
||||
Scalar s1 = NumTraits<Scalar>::random(),
|
||||
s2 = NumTraits<Scalar>::random();
|
||||
Scalar s1 = random<Scalar>(),
|
||||
s2 = random<Scalar>();
|
||||
|
||||
// check involutivity of adjoint, transpose, conjugate
|
||||
QVERIFY(m1.transpose().transpose().isApprox(m1));
|
||||
@@ -67,28 +69,32 @@ template<typename MatrixType> void adjoint(const MatrixType& m)
|
||||
QVERIFY((m1.adjoint() * m2).adjoint().isApprox(m2.adjoint() * m1));
|
||||
QVERIFY((m1.transpose() * m2).conjugate().isApprox(m1.adjoint() * m2.conjugate()));
|
||||
QVERIFY((s1 * m1).transpose().isApprox(s1 * m1.transpose()));
|
||||
QVERIFY((s1 * m1).conjugate().isApprox(NumTraits<Scalar>::conj(s1) * m1.conjugate()));
|
||||
QVERIFY((s1 * m1).adjoint().isApprox(NumTraits<Scalar>::conj(s1) * m1.adjoint()));
|
||||
QVERIFY((s1 * m1).conjugate().isApprox(conj(s1) * m1.conjugate()));
|
||||
QVERIFY((s1 * m1).adjoint().isApprox(conj(s1) * m1.adjoint()));
|
||||
|
||||
// check basic properties of dot, norm, norm2
|
||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||
QVERIFY(NumTraits<Scalar>::isApprox((s1 * v1 + s2 * v2).dot(v3), s1 * v1.dot(v3) + s2 * v2.dot(v3)));
|
||||
QVERIFY(NumTraits<Scalar>::isApprox(v3.dot(s1 * v1 + s2 * v2), NumTraits<Scalar>::conj(s1) * v3.dot(v1) + NumTraits<Scalar>::conj(s2) * v3.dot(v2)));
|
||||
QVERIFY(NumTraits<Scalar>::isApprox(NumTraits<Scalar>::conj(v1.dot(v2)), v2.dot(v1)));
|
||||
QVERIFY(NumTraits<RealScalar>::isApprox(abs(v1.dot(v1)), v1.norm2()));
|
||||
if(NumTraits<Scalar>::HasFloatingPoint) QVERIFY(NumTraits<RealScalar>::isApprox(v1.norm2(), v1.norm() * v1.norm()));
|
||||
QVERIFY(NumTraits<RealScalar>::isMuchSmallerThan(abs(vzero.dot(v1)), 1));
|
||||
QVERIFY(NumTraits<RealScalar>::isMuchSmallerThan(vzero.norm(), 1));
|
||||
QVERIFY(isApprox((s1 * v1 + s2 * v2).dot(v3), s1 * v1.dot(v3) + s2 * v2.dot(v3)));
|
||||
QVERIFY(isApprox(v3.dot(s1 * v1 + s2 * v2), conj(s1) * v3.dot(v1) + conj(s2) * v3.dot(v2)));
|
||||
QVERIFY(isApprox(conj(v1.dot(v2)), v2.dot(v1)));
|
||||
QVERIFY(isApprox(abs(v1.dot(v1)), v1.norm2()));
|
||||
if(NumTraits<Scalar>::HasFloatingPoint)
|
||||
QVERIFY(isApprox(v1.norm2(), v1.norm() * v1.norm()));
|
||||
QVERIFY(isMuchSmallerThan(abs(vzero.dot(v1)), static_cast<RealScalar>(1)));
|
||||
if(NumTraits<Scalar>::HasFloatingPoint)
|
||||
QVERIFY(isMuchSmallerThan(vzero.norm(), static_cast<RealScalar>(1)));
|
||||
|
||||
// check compatibility of dot and adjoint
|
||||
QVERIFY(NumTraits<Scalar>::isApprox(v1.dot(square * v2), (square.adjoint() * v1).dot(v2)));
|
||||
QVERIFY(isApprox(v1.dot(square * v2), (square.adjoint() * v1).dot(v2)));
|
||||
}
|
||||
|
||||
void EigenTest::testAdjoint()
|
||||
{
|
||||
adjoint(Matrix<float, 1, 1>());
|
||||
adjoint(Matrix<complex<double>, 4, 4>());
|
||||
adjoint(Matrix4cd());
|
||||
adjoint(MatrixXcf(3, 3));
|
||||
adjoint(MatrixXi(8, 12));
|
||||
adjoint(MatrixXd(20, 20));
|
||||
}
|
||||
|
||||
} // namespace Eigen
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#include "main.h"
|
||||
|
||||
namespace Eigen {
|
||||
|
||||
template<typename MatrixType> void basicStuff(const MatrixType& m)
|
||||
{
|
||||
/* this test covers the following files:
|
||||
@@ -56,14 +58,15 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
|
||||
v2 = VectorType::random(rows),
|
||||
vzero = VectorType::zero(rows);
|
||||
|
||||
Scalar s1 = NumTraits<Scalar>::random(),
|
||||
s2 = NumTraits<Scalar>::random();
|
||||
Scalar s1 = random<Scalar>(),
|
||||
s2 = random<Scalar>();
|
||||
|
||||
// test Fuzzy.h and Zero.h.
|
||||
QVERIFY(v1.isApprox(v1));
|
||||
QVERIFY(!v1.isApprox(2*v1));
|
||||
QVERIFY(vzero.isMuchSmallerThan(v1));
|
||||
QVERIFY(vzero.isMuchSmallerThan(v1.norm()));
|
||||
if(NumTraits<Scalar>::HasFloatingPoint)
|
||||
QVERIFY(vzero.isMuchSmallerThan(v1.norm()));
|
||||
QVERIFY(!v1.isMuchSmallerThan(v1));
|
||||
QVERIFY(vzero.isApprox(v1-v1));
|
||||
QVERIFY(m1.isApprox(m1));
|
||||
@@ -134,8 +137,10 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
|
||||
void EigenTest::testBasicStuff()
|
||||
{
|
||||
basicStuff(Matrix<float, 1, 1>());
|
||||
basicStuff(Matrix<complex<double>, 4, 4>());
|
||||
basicStuff(Matrix4cd());
|
||||
basicStuff(MatrixXcf(3, 3));
|
||||
basicStuff(MatrixXi(8, 12));
|
||||
basicStuff(MatrixXd(20, 20));
|
||||
}
|
||||
|
||||
} // namespace Eigen
|
||||
|
||||
@@ -25,13 +25,14 @@
|
||||
|
||||
#include "main.h"
|
||||
|
||||
EigenTest::EigenTest()
|
||||
Eigen::EigenTest::EigenTest()
|
||||
{
|
||||
unsigned int t = (unsigned int) time( NULL );
|
||||
unsigned int t = (unsigned int) time(NULL);
|
||||
qDebug() << "Initializing random number generator with seed"
|
||||
<< t;
|
||||
srand(t);
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN( EigenTest )
|
||||
QTEST_APPLESS_MAIN(Eigen::EigenTest)
|
||||
|
||||
#include "main.moc"
|
||||
|
||||
@@ -29,12 +29,10 @@
|
||||
#include <QtTest/QtTest>
|
||||
#include "../src/Core.h"
|
||||
|
||||
using namespace Eigen;
|
||||
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
using namespace std;
|
||||
namespace Eigen {
|
||||
|
||||
class EigenTest : public QObject
|
||||
{
|
||||
@@ -48,4 +46,6 @@ class EigenTest : public QObject
|
||||
void testAdjoint();
|
||||
};
|
||||
|
||||
} // end namespace Eigen
|
||||
|
||||
#endif // EIGEN_TEST_MAIN_H
|
||||
|
||||
Reference in New Issue
Block a user