mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-02-17 18:09:55 +08:00
implement the first _real_ unit-tests, testing the results for correctness instead
of just checking compilation. Fix the many issues discovered by these unit-tests, by the way fixing a performance bug.
This commit is contained in:
parent
31061557a5
commit
e445f5085a
@ -7,24 +7,20 @@ using namespace std;
|
||||
template<typename Scalar, typename Derived>
|
||||
void foo(const Eigen::Object<Scalar, Derived>& m)
|
||||
{
|
||||
cout << "Here's m:" << endl << m << endl;
|
||||
cout << "Here's m:" << endl << m << endl;
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Eigen::ScalarMultiple<Derived>
|
||||
twice(const Eigen::Object<Scalar, Derived>& m)
|
||||
{
|
||||
return 2 * m;
|
||||
return 2 * m;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
Matrix2d m;
|
||||
m(0,0)= 1;
|
||||
m(1,0)= 2;
|
||||
m(0,1)= 3;
|
||||
m(1,1)= 4;
|
||||
foo(m);
|
||||
foo(twice(m));
|
||||
return 0;
|
||||
Matrix2d m = Matrix2d::random();
|
||||
foo(m);
|
||||
foo(twice(m));
|
||||
return 0;
|
||||
}
|
||||
|
@ -27,5 +27,6 @@ namespace Eigen {
|
||||
#include "Core/Trace.h"
|
||||
#include "Core/Dot.h"
|
||||
#include "Core/Random.h"
|
||||
#include "Core/Fuzzy.h"
|
||||
|
||||
} // namespace Eigen
|
||||
|
@ -75,9 +75,9 @@ template<typename MatrixType> class Column
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Column<Derived>
|
||||
Object<Scalar, Derived>::col(int i)
|
||||
Object<Scalar, Derived>::col(int i) const
|
||||
{
|
||||
return Column<Derived>(static_cast<Derived*>(this)->ref(), i);
|
||||
return Column<Derived>(static_cast<Derived*>(const_cast<Object*>(this))->ref(), i);
|
||||
}
|
||||
|
||||
#endif // EI_COLUMN_H
|
||||
|
@ -40,7 +40,7 @@ template<int UnrollCount, int Rows> struct CopyHelperUnroller
|
||||
}
|
||||
};
|
||||
|
||||
template<int Rows> struct CopyHelperUnroller<0, Rows>
|
||||
template<int Rows> struct CopyHelperUnroller<1, Rows>
|
||||
{
|
||||
template <typename Derived1, typename Derived2>
|
||||
static void run(Derived1 &dst, const Derived2 &src)
|
||||
|
@ -32,7 +32,7 @@ struct DotUnroller
|
||||
static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot)
|
||||
{
|
||||
DotUnroller<Index-1, Size, Derived1, Derived2>::run(v1, v2, dot);
|
||||
dot += v1[Index] * Conj(v2[Index]);
|
||||
dot += v1[Index] * NumTraits<typename Derived1::Scalar>::conj(v2[Index]);
|
||||
}
|
||||
};
|
||||
|
||||
@ -41,7 +41,7 @@ struct DotUnroller<0, Size, Derived1, Derived2>
|
||||
{
|
||||
static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot)
|
||||
{
|
||||
dot = v1[0] * Conj(v2[0]);
|
||||
dot = v1[0] * NumTraits<typename Derived1::Scalar>::conj(v2[0]);
|
||||
}
|
||||
};
|
||||
|
||||
@ -67,9 +67,9 @@ Scalar Object<Scalar, Derived>::dot(const OtherDerived& other) const
|
||||
::run(*static_cast<const Derived*>(this), other, res);
|
||||
else
|
||||
{
|
||||
res = (*this)[0] * Conj(other[0]);
|
||||
res = (*this)[0] * NumTraits<Scalar>::conj(other[0]);
|
||||
for(int i = 1; i < size(); i++)
|
||||
res += (*this)[i]* Conj(other[i]);
|
||||
res += (*this)[i]* NumTraits<Scalar>::conj(other[i]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@ -78,7 +78,7 @@ template<typename Scalar, typename Derived>
|
||||
typename NumTraits<Scalar>::Real Object<Scalar, Derived>::norm2() const
|
||||
{
|
||||
assert(IsVector);
|
||||
return Real(dot(*this));
|
||||
return NumTraits<Scalar>::real(dot(*this));
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
|
@ -40,7 +40,8 @@ bool Object<Scalar, Derived>::isApprox(
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < cols(); i++)
|
||||
if(!col(i).isApprox(other.col(i), prec))
|
||||
if((col(i) - other.col(i)).norm2()
|
||||
> std::min(col(i).norm2(), other.col(i).norm2()) * prec * prec)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@ -59,7 +60,7 @@ bool Object<Scalar, Derived>::isMuchSmallerThan(
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < cols(); i++)
|
||||
if(!col(i).isMuchSmallerThan(other, prec))
|
||||
if(col(i).norm2() > NumTraits<Scalar>::abs2(other) * prec * prec)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@ -79,10 +80,10 @@ bool Object<Scalar, Derived>::isMuchSmallerThan(
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < cols(); i++)
|
||||
if(!col(i).isMuchSmallerThan(other.col(i), prec))
|
||||
if(col(i).norm2() > other.col(i).norm2() * prec * prec)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // EI_FUZZY_H
|
||||
#endif // EI_FUZZY_H
|
||||
|
@ -45,10 +45,10 @@ template<> struct NumTraits<int>
|
||||
static double sqrt(const int& x) { return std::sqrt(static_cast<double>(x)); }
|
||||
static int abs(const int& x) { return std::abs(x); }
|
||||
static int abs2(const int& x) { return x*x; }
|
||||
static int rand()
|
||||
static int random()
|
||||
{
|
||||
// "rand() % n" is bad, they say, because the low-order bits are not random enough.
|
||||
// However here, 21 is odd, so rand() % 21 uses the high-order bits
|
||||
// "random() % n" is bad, they say, because the low-order bits are not random enough.
|
||||
// However here, 21 is odd, so random() % 21 uses the high-order bits
|
||||
// as well, so there's no problem.
|
||||
return (std::rand() % 21) - 10;
|
||||
}
|
||||
@ -86,7 +86,7 @@ template<> struct NumTraits<float>
|
||||
static float sqrt(const float& x) { return std::sqrt(x); }
|
||||
static float abs(const float& x) { return std::abs(x); }
|
||||
static float abs2(const float& x) { return x*x; }
|
||||
static float rand()
|
||||
static float random()
|
||||
{
|
||||
return std::rand() / (RAND_MAX/20.0f) - 10.0f;
|
||||
}
|
||||
@ -120,7 +120,7 @@ template<> struct NumTraits<double>
|
||||
static double sqrt(const double& x) { return std::sqrt(x); }
|
||||
static double abs(const double& x) { return std::abs(x); }
|
||||
static double abs2(const double& x) { return x*x; }
|
||||
static double rand()
|
||||
static double random()
|
||||
{
|
||||
return std::rand() / (RAND_MAX/20.0) - 10.0;
|
||||
}
|
||||
@ -158,9 +158,9 @@ template<typename _Real> struct NumTraits<std::complex<_Real> >
|
||||
{ return std::abs(static_cast<FloatingPoint>(x)); }
|
||||
static Real abs2(const Complex& x)
|
||||
{ return std::real(x) * std::real(x) + std::imag(x) * std::imag(x); }
|
||||
static Complex rand()
|
||||
static Complex random()
|
||||
{
|
||||
return Complex(NumTraits<Real>::rand(), NumTraits<Real>::rand());
|
||||
return Complex(NumTraits<Real>::random(), NumTraits<Real>::random());
|
||||
}
|
||||
static bool isMuchSmallerThan(const Complex& a, const Complex& b, const Real& prec = precision())
|
||||
{
|
||||
|
@ -34,6 +34,20 @@ template<typename Scalar, typename Derived> class Object
|
||||
template<typename OtherDerived>
|
||||
void _copy_helper(const Object<Scalar, OtherDerived>& other);
|
||||
|
||||
template<typename OtherDerived>
|
||||
bool _isApprox_helper(
|
||||
const OtherDerived& other,
|
||||
const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::precision()
|
||||
) const;
|
||||
bool _isMuchSmallerThan_helper(
|
||||
const Scalar& other,
|
||||
const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::precision()
|
||||
) const;
|
||||
template<typename OtherDerived>
|
||||
bool _isMuchSmallerThan_helper(
|
||||
const Object<Scalar, OtherDerived>& other,
|
||||
const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::precision()
|
||||
) const;
|
||||
public:
|
||||
static const int SizeAtCompileTime
|
||||
= RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic
|
||||
@ -81,8 +95,8 @@ template<typename Scalar, typename Derived> class Object
|
||||
return *static_cast<Derived*>(this);
|
||||
}
|
||||
|
||||
Row<Derived> row(int i);
|
||||
Column<Derived> col(int i);
|
||||
Row<Derived> row(int i) const;
|
||||
Column<Derived> col(int i) const;
|
||||
Minor<Derived> minor(int row, int col);
|
||||
Block<Derived> block(int startRow, int endRow, int startCol, int endCol);
|
||||
Transpose<Derived> transpose();
|
||||
@ -111,7 +125,7 @@ template<typename Scalar, typename Derived> class Object
|
||||
) const;
|
||||
template<typename OtherDerived>
|
||||
bool isMuchSmallerThan(
|
||||
const OtherDerived& other,
|
||||
const Object<Scalar, OtherDerived>& other,
|
||||
const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::precision()
|
||||
) const;
|
||||
|
||||
|
@ -51,7 +51,7 @@ template<typename MatrixType> class Random
|
||||
{
|
||||
EI_UNUSED(row);
|
||||
EI_UNUSED(col);
|
||||
return NumTraits<Scalar>::rand();
|
||||
return NumTraits<Scalar>::random();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -80,9 +80,9 @@ template<typename MatrixType> class Row
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
Row<Derived>
|
||||
Object<Scalar, Derived>::row(int i)
|
||||
Object<Scalar, Derived>::row(int i) const
|
||||
{
|
||||
return Row<Derived>(static_cast<Derived*>(this)->ref(), i);
|
||||
return Row<Derived>(static_cast<Derived*>(const_cast<Object*>(this))->ref(), i);
|
||||
}
|
||||
|
||||
#endif // EI_ROW_H
|
||||
|
@ -6,9 +6,7 @@ INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} )
|
||||
|
||||
SET(test_SRCS
|
||||
main.cpp
|
||||
vectorops.cpp
|
||||
matrixops.cpp
|
||||
matrixmanip.cpp
|
||||
basicstuff.cpp
|
||||
)
|
||||
QT4_AUTOMOC(${test_SRCS})
|
||||
|
||||
|
83
test/basicstuff.cpp
Normal file
83
test/basicstuff.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 or (at your option) any later version.
|
||||
//
|
||||
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
|
||||
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// As a special exception, if other files instantiate templates or use macros
|
||||
// or functions from this file, or you compile this file and link it
|
||||
// with other works to produce a work based on this file, this file does not
|
||||
// by itself cause the resulting work to be covered by the GNU General Public
|
||||
// License. This exception does not invalidate any other reasons why a work
|
||||
// based on this file might be covered by the GNU General Public License.
|
||||
|
||||
#include "main.h"
|
||||
|
||||
template<typename MatrixType> void basicStuff(const MatrixType& m)
|
||||
{
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
|
||||
int rows = m.rows();
|
||||
int cols = m.cols();
|
||||
|
||||
MatrixType m1 = MatrixType::random(rows, cols),
|
||||
m2 = MatrixType::random(rows, cols),
|
||||
m3;
|
||||
VectorType v1 = VectorType::random(rows, 1),
|
||||
v2 = VectorType::random(rows, 1);
|
||||
|
||||
Scalar s1 = NumTraits<Scalar>::random(),
|
||||
s2 = NumTraits<Scalar>::random();
|
||||
|
||||
QVERIFY(v1.isApprox(v1));
|
||||
QVERIFY((v1-v1).isMuchSmallerThan(v1));
|
||||
QVERIFY((v1-v1).isMuchSmallerThan(v1.norm()));
|
||||
QVERIFY(m1.isApprox(m1));
|
||||
QVERIFY((m1-m1).isMuchSmallerThan(m1));
|
||||
|
||||
QVERIFY((m1+m1).isApprox(2 * m1));
|
||||
QVERIFY((m1 * s1).isApprox(s1 * m1));
|
||||
QVERIFY(((m1 + m2) * s1).isApprox(s1 * m1 + s1 * m2));
|
||||
QVERIFY(((s1 + s2) * m1).isApprox(m1 * s1 + m1 * s2));
|
||||
|
||||
|
||||
|
||||
m3 = m2;
|
||||
QVERIFY((m3 += m1).isApprox(m1 + m2));
|
||||
m3 = m2;
|
||||
QVERIFY((m3 -= m1).isApprox(-m1 + m2));
|
||||
m3 = m2;
|
||||
QVERIFY((m3 *= s1).isApprox(s1 * m2));
|
||||
m3 = m2;
|
||||
if(NumTraits<Scalar>::HasFloatingPoint
|
||||
&& s1 != static_cast<Scalar>(0))
|
||||
QVERIFY((m3 /= s1).isApprox(m2 / s1));
|
||||
|
||||
QVERIFY(((m1 * m1.transpose()) * m2).isApprox(m1 * (m1.transpose() * m2)));
|
||||
m3 = m1;
|
||||
m3 *= (m1.transpose() * m2);
|
||||
QVERIFY(m3.isApprox(m1 * (m1.transpose() * m2)));
|
||||
QVERIFY(m3.isApprox(m1.lazyProduct(m1.transpose() * m2)));
|
||||
}
|
||||
|
||||
void EigenTest::testBasicStuff()
|
||||
{
|
||||
basicStuff(Matrix<float, 1, 1>());
|
||||
basicStuff(Matrix<complex<int>, 2, 5>());
|
||||
basicStuff(Matrix<complex<double>, 4, 4>());
|
||||
basicStuff(MatrixXcf(3, 3));
|
||||
basicStuff(MatrixXi(8, 12));
|
||||
basicStuff(MatrixXd(20, 20));
|
||||
}
|
55
test/main.h
55
test/main.h
@ -44,60 +44,7 @@ class EigenTest : public QObject
|
||||
EigenTest();
|
||||
|
||||
private slots:
|
||||
void testVectorOps();
|
||||
void testMatrixOps();
|
||||
void testMatrixManip();
|
||||
void testBasicStuff();
|
||||
};
|
||||
|
||||
template<typename T> inline typename Eigen::NumTraits<T>::Real TestEpsilon();
|
||||
template<> inline int TestEpsilon<int>() { return 0; }
|
||||
template<> inline float TestEpsilon<float>() { return 1e-2f; }
|
||||
template<> inline double TestEpsilon<double>() { return 1e-4; }
|
||||
template<> inline int TestEpsilon<std::complex<int> >() { return TestEpsilon<int>(); }
|
||||
template<> inline float TestEpsilon<std::complex<float> >() { return TestEpsilon<float>(); }
|
||||
template<> inline double TestEpsilon<std::complex<double> >() { return TestEpsilon<double>(); }
|
||||
|
||||
template<typename T> bool TestMuchSmallerThan(const T& a, const T& b)
|
||||
{
|
||||
return NumTraits<T>::isMuchSmallerThan(a, b, TestEpsilon<T>());
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived, typename OtherDerived>
|
||||
bool TestMuchSmallerThan(
|
||||
const Object<Scalar, Derived>& a,
|
||||
const Object<Scalar, OtherDerived>& b)
|
||||
{
|
||||
return a.isMuchSmallerThan(b, TestEpsilon<Scalar>());
|
||||
}
|
||||
|
||||
template<typename T> bool TestApprox(const T& a, const T& b)
|
||||
{
|
||||
return NumTraits<T>::isApprox(a, b, TestEpsilon<T>());
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived, typename OtherDerived>
|
||||
bool TestApprox(
|
||||
const Object<Scalar, Derived>& a,
|
||||
const Object<Scalar, OtherDerived>& b)
|
||||
{
|
||||
return a.isApprox(b, TestEpsilon<Scalar>());
|
||||
}
|
||||
|
||||
template<typename T> bool TestApproxOrLessThan(const T& a, const T& b)
|
||||
{
|
||||
return NumTraits<T>::isApproxOrLessThan(a, b, TestEpsilon<T>());
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived, typename OtherDerived>
|
||||
bool TestApproxOrLessThan(
|
||||
const Object<Scalar, Derived>& a,
|
||||
const Object<Scalar, OtherDerived>& b)
|
||||
{
|
||||
return a.isApproxOrLessThan(b, TestEpsilon<Scalar>());
|
||||
}
|
||||
|
||||
#define QVERIFY_MUCH_SMALLER_THAN(a, b) QVERIFY(TestMuchSmallerThan(a, b))
|
||||
#define QVERIFY_APPROX(a, b) QVERIFY(TestApprox(a, b))
|
||||
#define QVERIFY_APPROX_OR_LESS_THAN(a, b) QVERIFY(TestApproxOrLessThan(a, b))
|
||||
|
||||
#endif // EI_TEST_MAIN_H
|
||||
|
@ -1,53 +0,0 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 or (at your option) any later version.
|
||||
//
|
||||
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
|
||||
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// As a special exception, if other files instantiate templates or use macros
|
||||
// or functions from this file, or you compile this file and link it
|
||||
// with other works to produce a work based on this file, this file does not
|
||||
// by itself cause the resulting work to be covered by the GNU General Public
|
||||
// License. This exception does not invalidate any other reasons why a work
|
||||
// based on this file might be covered by the GNU General Public License.
|
||||
|
||||
#include "main.h"
|
||||
|
||||
template<typename MatrixType> void matrixManip(const MatrixType& m)
|
||||
{
|
||||
int rows = m.rows(), cols = m.cols();
|
||||
int i = rand()%rows, j = rand()%cols;
|
||||
|
||||
MatrixType a(rows, cols), b(rows, cols);
|
||||
a.row(i);
|
||||
a.col(j);
|
||||
a.minor(i, j);
|
||||
a.block(1, rows-1, 1, cols-1);
|
||||
a.row(i) = b.row(i);
|
||||
a.row(i) += b.row(i);
|
||||
a.col(j) *= 2;
|
||||
a.minor(i, j) = b.block(1, rows-1, 1, cols-1);
|
||||
a.minor(i, j) -= a.block(1, rows-1, 1, cols-1).eval();
|
||||
}
|
||||
|
||||
void EigenTest::testMatrixManip()
|
||||
{
|
||||
matrixManip(Matrix<int, 2, 3>());
|
||||
matrixManip(Matrix<double, 3, 3>());
|
||||
matrixManip(Matrix<complex<float>, 4,3>());
|
||||
matrixManip(MatrixXi(2, 2));
|
||||
matrixManip(MatrixXd(3, 5));
|
||||
matrixManip(MatrixXcf(4, 4));
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 or (at your option) any later version.
|
||||
//
|
||||
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
|
||||
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// As a special exception, if other files instantiate templates or use macros
|
||||
// or functions from this file, or you compile this file and link it
|
||||
// with other works to produce a work based on this file, this file does not
|
||||
// by itself cause the resulting work to be covered by the GNU General Public
|
||||
// License. This exception does not invalidate any other reasons why a work
|
||||
// based on this file might be covered by the GNU General Public License.
|
||||
|
||||
#include "main.h"
|
||||
|
||||
template<typename MatrixType1,
|
||||
typename MatrixType2> void matrixOps(const MatrixType1& m1, const MatrixType2& m2)
|
||||
{
|
||||
typedef typename MatrixType1::Scalar Scalar;
|
||||
int rows1 = m1.rows(), cols1 = m1.cols();
|
||||
int rows2 = m2.rows(), cols2 = m2.cols();
|
||||
|
||||
MatrixType1 a(rows1, cols1), b(rows1, cols1), c(b);
|
||||
Scalar s;
|
||||
a * s;
|
||||
s * a;
|
||||
a + b;
|
||||
a - b;
|
||||
(a + b) * s;
|
||||
s * (a + b);
|
||||
a + b + c;
|
||||
a = b;
|
||||
a = b + c;
|
||||
a = s * (b - c);
|
||||
a = (a + b).eval();
|
||||
a += b;
|
||||
a -= b + b;
|
||||
a *= s;
|
||||
if(rows1 == cols1)
|
||||
{
|
||||
a *= b;
|
||||
a.lazyProduct(b);
|
||||
}
|
||||
|
||||
MatrixType1 d(rows1, cols1);
|
||||
MatrixType2 e(rows2, cols2);
|
||||
QVERIFY( (d * e).rows() == rows1 && (d * e).cols() == cols2 );
|
||||
}
|
||||
|
||||
void EigenTest::testMatrixOps()
|
||||
{
|
||||
matrixOps(Matrix<float, 1, 1>(), Matrix<float, 1, 1>());
|
||||
matrixOps(Matrix<int, 2, 3>(), Matrix<int, 3, 1>());
|
||||
matrixOps(Matrix<double, 3, 3>(), Matrix<double, 3, 3>());
|
||||
matrixOps(Matrix<complex<float>, 4,3>(), Matrix<complex<float>, 3,4>());
|
||||
matrixOps(MatrixXf(1, 1), MatrixXf(1, 3));
|
||||
matrixOps(MatrixXi(2, 2), MatrixXi(2, 2));
|
||||
matrixOps(MatrixXd(3, 5), MatrixXd(5, 1));
|
||||
matrixOps(MatrixXcf(4, 4), MatrixXcf(4, 4));
|
||||
matrixOps(MatrixXd(3, 5), Matrix<double, 5, 1>());
|
||||
matrixOps(Matrix4cf(), MatrixXcf(4, 4));
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
//
|
||||
// Eigen is free software; you can redistribute it and/or modify it under the
|
||||
// terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation; either version 2 or (at your option) any later version.
|
||||
//
|
||||
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
// details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along
|
||||
// with Eigen; if not, write to the Free Software Foundation, Inc., 51
|
||||
// Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
//
|
||||
// As a special exception, if other files instantiate templates or use macros
|
||||
// or functions from this file, or you compile this file and link it
|
||||
// with other works to produce a work based on this file, this file does not
|
||||
// by itself cause the resulting work to be covered by the GNU General Public
|
||||
// License. This exception does not invalidate any other reasons why a work
|
||||
// based on this file might be covered by the GNU General Public License.
|
||||
|
||||
#include "main.h"
|
||||
|
||||
template<typename VectorType> void vectorOps(const VectorType& v)
|
||||
{
|
||||
typedef typename VectorType::Scalar Scalar;
|
||||
int size = v.size();
|
||||
|
||||
VectorType a(size), b(size), c(b);
|
||||
Scalar s;
|
||||
a * s;
|
||||
s * a;
|
||||
a + b;
|
||||
a - b;
|
||||
(a + b) * s;
|
||||
s * (a + b);
|
||||
a + b + c;
|
||||
a = b;
|
||||
a = b + c;
|
||||
a = s * (b - c);
|
||||
a = (s * (b - c)).eval();
|
||||
|
||||
a += b;
|
||||
a -= b + b;
|
||||
a *= s;
|
||||
a += (a + a).eval();
|
||||
}
|
||||
|
||||
void EigenTest::testVectorOps()
|
||||
{
|
||||
vectorOps(Vector2i());
|
||||
vectorOps(Vector3d());
|
||||
vectorOps(Vector4cf());
|
||||
vectorOps(VectorXf(1));
|
||||
vectorOps(VectorXi(2));
|
||||
vectorOps(VectorXd(3));
|
||||
vectorOps(VectorXcf(4));
|
||||
}
|
Loading…
Reference in New Issue
Block a user