* Added support for a comma initializer: mat.block(i,j,2,2) << 1, 2, 3, 4;

If the number of coefficients does not match the matrix size, then an assertion is raised.
  No support for xpr on the right side for the moment.

* Added support for assertion checking. This allows to test that an assertion is indeed raised
  when it should be.

* Fixed a mistake in the CwiseUnary example.
This commit is contained in:
Gael Guennebaud
2008-03-08 19:02:24 +00:00
parent 138aad0ed0
commit 721626dfc5
13 changed files with 259 additions and 67 deletions

View File

@@ -1,11 +1,12 @@
IF(BUILD_TESTS)
OPTION(EIGEN_NO_ASSERTION_CHECKING "Disable checking of assertions" OFF)
ENABLE_TESTING()
FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} )
SET(test_SRCS
cwiseop.cpp
main.cpp
basicstuff.cpp
linearstructure.cpp
@@ -15,11 +16,25 @@ SET(test_SRCS
miscmatrices.cpp
smallvectors.cpp
map.cpp
cwiseop.cpp
)
QT4_AUTOMOC(${test_SRCS})
ADD_EXECUTABLE(test ${test_SRCS})
TARGET_LINK_LIBRARIES(test ${QT_QTCORE_LIBRARY} ${QT_QTTEST_LIBRARY})
IF(NOT EIGEN_NO_ASSERTION_CHECKING)
SET_TARGET_PROPERTIES(test PROPERTIES COMPILE_FLAGS "-fexceptions")
OPTION(EIGEN_DEBUG_ASSERTS "Enable debuging of assertions" OFF)
IF(EIGEN_DEBUG_ASSERTS)
ADD_DEFINITIONS(-DEIGEN_DEBUG_ASSERTS=1)
ENDIF(EIGEN_DEBUG_ASSERTS)
ELSE(NOT EIGEN_NO_ASSERTION_CHECKING)
ADD_DEFINITIONS(-DEIGEN_NO_ASSERTION_CHECKING=1)
ENDIF(NOT EIGEN_NO_ASSERTION_CHECKING)
ADD_TEST(Eigen test)

View File

@@ -79,6 +79,11 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
rv = square.col(r);
cv = square.row(r);
VERIFY_IS_APPROX(rv, cv.transpose());
if(cols!=1 && rows!=1 && MatrixType::Traits::SizeAtCompileTime!=Dynamic)
{
VERIFY_RAISES_ASSERT(m1 = (m2.block(0,0, rows-1, cols-1)));
}
}
void EigenTest::testBasicStuff()
@@ -91,6 +96,19 @@ void EigenTest::testBasicStuff()
basicStuff(MatrixXcd(20, 20));
basicStuff(Matrix<float, 100, 100>());
}
// some additional basic tests
{
Matrix3d m3;
Matrix4d m4;
VERIFY_RAISES_ASSERT(m4 = m3);
VERIFY_RAISES_ASSERT( (m3 << 1, 2, 3, 4, 5, 6, 7, 8) );
VERIFY_RAISES_ASSERT( (m3 << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) );
m3 << 1, 2, 3, 4, 5, 6, 7, 8, 9;
double data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
VERIFY_IS_APPROX(m3, (Matrix<double,3,3,RowMajor>::map(data)) );
}
}
} // namespace Eigen

View File

@@ -5,12 +5,12 @@
//
// Eigen is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// Alternatively, 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 of
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
@@ -18,7 +18,7 @@
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// You should have received a copy of the GNU Lesser General Public
// License and a copy of the GNU General Public License along with
// Eigen. If not, see <http://www.gnu.org/licenses/>.
@@ -27,15 +27,80 @@
#include <QtTest/QtTest>
//#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER RowMajor
#define EIGEN_INTERNAL_DEBUGGING
#include <Eigen/Core>
#include <cstdlib>
#include <ctime>
#define DEFAULT_REPEAT 50
#ifndef EIGEN_NO_ASSERTION_CHECKING
namespace Eigen
{
struct ei_assert_exception
{};
static const bool should_raise_an_assert = false;
}
#define EI_PP_MAKE_STRING2(S) #S
#define EI_PP_MAKE_STRING(S) EI_PP_MAKE_STRING2(S)
#ifdef assert
#undef assert
#endif
// If EIGEN_DEBUG_ASSERTS is defined and if no assertion is raised while
// one should have been, then the list of excecuted assertions is printed out.
//
// EIGEN_DEBUG_ASSERTS is not enabled by default as it
// significantly increases the compilation time
// and might even introduce side effects that would hide
// some memory errors.
#ifdef EIGEN_DEBUG_ASSERTS
namespace Eigen
{
static bool ei_push_assert = false;
static std::vector<std::string> ei_assert_list;
}
#define assert(a) if (!(a)) { throw Eigen::ei_assert_exception();} \
else if (Eigen::ei_push_assert) {ei_assert_list.push_back( std::string(EI_PP_MAKE_STRING(__FILE__)) + " (" + EI_PP_MAKE_STRING(__LINE__) + ") : " + #a );}
#define VERIFY_RAISES_ASSERT(a) {\
try { \
Eigen::ei_assert_list.clear(); \
Eigen::ei_push_assert = true; \
a; \
Eigen::ei_push_assert = false; \
std::cout << "One of the following asserts should have been raised:\n"; \
for (uint ai=0 ; ai<ei_assert_list.size() ; ++ai) \
std::cout << " " << ei_assert_list[ai] << "\n"; \
QVERIFY(Eigen::should_raise_an_assert && # a); \
} catch (Eigen::ei_assert_exception e) { Eigen::ei_push_assert = false; QVERIFY(true);} }
#else // EIGEN_DEBUG_ASSERTS
#define assert(a) if (!(a)) { throw Eigen::ei_assert_exception();}
#define VERIFY_RAISES_ASSERT(a) {\
try {a; QVERIFY(Eigen::should_raise_an_assert && # a); } \
catch (Eigen::ei_assert_exception e) { QVERIFY(true);} }
#endif // EIGEN_DEBUG_ASSERTS
#define EIGEN_CUSTOM_ASSERT
#else // EIGEN_NO_ASSERTION_CHECKING
#define VERIFY_RAISES_ASSERT(a) {}
#endif // EIGEN_NO_ASSERTION_CHECKING
//#define EIGEN_DEFAULT_MATRIX_STORAGE_ORDER RowMajor
#define EIGEN_INTERNAL_DEBUGGING
#include <Eigen/Core>
#define VERIFY(a) QVERIFY(a)
#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))

View File

@@ -83,6 +83,9 @@ template<typename MatrixType> void product(const MatrixType& m)
VERIFY_IS_APPROX(v1, identity*v1);
// again, test operator() to check const-qualification
VERIFY_IS_APPROX(MatrixType::identity(rows, cols)(r,c), static_cast<Scalar>(r==c));
if (rows!=cols)
VERIFY_RAISES_ASSERT(m3 = m1*m1);
}
void EigenTest::testProduct()