* Introduce EIGEN_DEFAULT_TO_ROW_MAJOR tests option

---> Now only product_large fails with EIGEN_DEFAULT_TO_ROW_MAJOR.
* Fix EIGEN_NO_ASSERTION_CHECKING tests option
* Fix a crash in Tridiagonalization on row-major matrices + SSE
* Fix inverse test (numeric stability noise)
* Extend map test (see previous fixes in MapBase)
* Fix vectorization_logic test for row-major
* Disable sparse tests with EIGEN_DEFAULT_TO_ROW_MAJOR
This commit is contained in:
Benoit Jacob 2010-01-25 14:00:02 -05:00
parent 55c0707b1d
commit d209120180
6 changed files with 84 additions and 24 deletions

View File

@ -293,7 +293,7 @@ void Tridiagonalization<MatrixType>::_compute(MatrixType& matA, CoeffVectorType&
{ {
int starti = i+1; int starti = i+1;
int alignedEnd = starti; int alignedEnd = starti;
if (PacketSize>1) if (PacketSize>1 && (int(MatrixType::Flags)&RowMajor) == 0)
{ {
int alignedStart = (starti) + ei_alignmentOffset(&matA.coeffRef(starti,j1), n-starti); int alignedStart = (starti) + ei_alignmentOffset(&matA.coeffRef(starti,j1), n-starti);
alignedEnd = alignedStart + ((n-alignedStart)/PacketSize)*PacketSize; alignedEnd = alignedStart + ((n-alignedStart)/PacketSize)*PacketSize;

View File

@ -1,3 +1,7 @@
option(EIGEN_DEFAULT_TO_ROW_MAJOR "Use row-major as default matrix storage order" OFF)
if(EIGEN_DEFAULT_TO_ROW_MAJOR)
add_definitions("-DEIGEN_DEFAULT_TO_ROW_MAJOR")
endif()
find_package(GSL) find_package(GSL)
if(GSL_FOUND AND GSL_VERSION_MINOR LESS 9) if(GSL_FOUND AND GSL_VERSION_MINOR LESS 9)
@ -93,12 +97,20 @@ else(CMAKE_COMPILER_IS_GNUCXX)
endif(CMAKE_COMPILER_IS_GNUCXX) endif(CMAKE_COMPILER_IS_GNUCXX)
option(EIGEN_NO_ASSERTION_CHECKING "Disable checking of assertions" OFF) option(EIGEN_NO_ASSERTION_CHECKING "Disable checking of assertions" OFF)
if(EIGEN_NO_ASSERTION_CHECKING)
add_definitions("-DEIGEN_NO_ASSERTION_CHECKING=1")
endif()
# similar to set_target_properties but append the property instead of overwriting it # similar to set_target_properties but append the property instead of overwriting it
macro(ei_add_target_property target prop value) macro(ei_add_target_property target prop value)
get_target_property(previous ${target} ${prop}) get_target_property(previous ${target} ${prop})
set_target_properties(${target} PROPERTIES ${prop} "${previous} ${value}") if(previous MATCHES "NOTFOUND")
set_target_properties(${target} PROPERTIES ${prop} "${value}")
else()
set_target_properties(${target} PROPERTIES ${prop} "${previous} ${value}")
endif()
endmacro(ei_add_target_property) endmacro(ei_add_target_property)
@ -134,13 +146,9 @@ macro(ei_add_test testname)
option(EIGEN_DEBUG_ASSERTS "Enable debuging of assertions" OFF) option(EIGEN_DEBUG_ASSERTS "Enable debuging of assertions" OFF)
if(EIGEN_DEBUG_ASSERTS) if(EIGEN_DEBUG_ASSERTS)
set_target_properties(${targetname} PROPERTIES COMPILE_DEFINITIONS "-DEIGEN_DEBUG_ASSERTS=1") set_target_properties(${targetname} PROPERTIES COMPILE_DEFINITIONS "EIGEN_DEBUG_ASSERTS=1")
endif(EIGEN_DEBUG_ASSERTS) endif(EIGEN_DEBUG_ASSERTS)
else(NOT EIGEN_NO_ASSERTION_CHECKING)
set_target_properties(${targetname} PROPERTIES COMPILE_DEFINITIONS "-DEIGEN_NO_ASSERTION_CHECKING=1")
endif(NOT EIGEN_NO_ASSERTION_CHECKING) endif(NOT EIGEN_NO_ASSERTION_CHECKING)
if(${ARGC} GREATER 1) if(${ARGC} GREATER 1)
@ -201,7 +209,7 @@ ei_add_test(array)
ei_add_test(triangular) ei_add_test(triangular)
ei_add_test(cholesky " " "${GSL_LIBRARIES}") ei_add_test(cholesky " " "${GSL_LIBRARIES}")
ei_add_test(lu ${EI_OFLAG}) ei_add_test(lu ${EI_OFLAG})
ei_add_test(determinant) ei_add_test(determinant ${EI_OFLAG})
ei_add_test(inverse) ei_add_test(inverse)
ei_add_test(qr) ei_add_test(qr)
ei_add_test(eigensolver " " "${GSL_LIBRARIES}") ei_add_test(eigensolver " " "${GSL_LIBRARIES}")
@ -216,10 +224,12 @@ ei_add_test(newstdvector)
if(QT4_FOUND) if(QT4_FOUND)
ei_add_test(qtvector " " "${QT_QTCORE_LIBRARY}") ei_add_test(qtvector " " "${QT_QTCORE_LIBRARY}")
endif(QT4_FOUND) endif(QT4_FOUND)
ei_add_test(sparse_vector) if(NOT EIGEN_DEFAULT_TO_ROW_MAJOR)
ei_add_test(sparse_basic) ei_add_test(sparse_vector)
ei_add_test(sparse_solvers " " "${SPARSE_LIBS}") ei_add_test(sparse_basic)
ei_add_test(sparse_product) ei_add_test(sparse_solvers " " "${SPARSE_LIBS}")
ei_add_test(sparse_product)
endif()
ei_add_test(swap) ei_add_test(swap)
ei_add_test(visitor) ei_add_test(visitor)
@ -268,6 +278,12 @@ else(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
message("Explicit vec: AUTO") message("Explicit vec: AUTO")
endif(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION) endif(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION)
if(EIGEN_DEFAULT_TO_ROW_MAJOR)
message("Default order: Row-major")
else()
message("Default order: Column-major")
endif()
message("CXX: ${CMAKE_CXX_COMPILER}") message("CXX: ${CMAKE_CXX_COMPILER}")
if(CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCXX)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version COMMAND head -n 1 OUTPUT_VARIABLE EIGEN_CXX_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version COMMAND head -n 1 OUTPUT_VARIABLE EIGEN_CXX_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE)

View File

@ -43,11 +43,9 @@ template<typename MatrixType> void inverse(const MatrixType& m)
mzero = MatrixType::Zero(rows, cols), mzero = MatrixType::Zero(rows, cols),
identity = MatrixType::Identity(rows, rows); identity = MatrixType::Identity(rows, rows);
if (ei_is_same_type<RealScalar,float>::ret) while(ei_abs(m1.determinant()) < RealScalar(0.1) && rows <= 8)
{ {
// let's build a more stable to inverse matrix m1 = MatrixType::Random(rows, cols);
MatrixType a = MatrixType::Random(rows,cols);
m1 += m1 * m1.adjoint() + a * a.adjoint();
} }
m2 = m1.inverse(); m2 = m1.inverse();

View File

@ -1,7 +1,7 @@
// This file is part of Eigen, a lightweight C++ template library // This file is part of Eigen, a lightweight C++ template library
// for linear algebra. Eigen itself is part of the KDE project. // for linear algebra. Eigen itself is part of the KDE project.
// //
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> // Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
// //
// Eigen is free software; you can redistribute it and/or // Eigen is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public // modify it under the terms of the GNU Lesser General Public
@ -24,7 +24,7 @@
#include "main.h" #include "main.h"
template<typename VectorType> void map_class(const VectorType& m) template<typename VectorType> void map_class_vector(const VectorType& m)
{ {
typedef typename VectorType::Scalar Scalar; typedef typename VectorType::Scalar Scalar;
@ -50,6 +50,34 @@ template<typename VectorType> void map_class(const VectorType& m)
delete[] array3; delete[] array3;
} }
template<typename MatrixType> void map_class_matrix(const MatrixType& m)
{
typedef typename MatrixType::Scalar Scalar;
int rows = m.rows(), cols = m.cols(), size = rows*cols;
// test Map.h
Scalar* array1 = ei_aligned_new<Scalar>(size);
for(int i = 0; i < size; i++) array1[i] = Scalar(1);
Scalar* array2 = ei_aligned_new<Scalar>(size);
for(int i = 0; i < size; i++) array2[i] = Scalar(1);
Scalar* array3 = new Scalar[size+1];
for(int i = 0; i < size+1; i++) array3[i] = Scalar(1);
Scalar* array3unaligned = size_t(array3)%16 == 0 ? array3+1 : array3;
Map<MatrixType, Aligned>(array1, rows, cols) = MatrixType::Ones(rows,cols);
Map<MatrixType>(array2, rows, cols) = Map<MatrixType>(array1, rows, cols);
Map<MatrixType>(array3unaligned, rows, cols) = Map<MatrixType>(array1, rows, cols);
MatrixType ma1 = Map<MatrixType>(array1, rows, cols);
MatrixType ma2 = Map<MatrixType, Aligned>(array2, rows, cols);
VERIFY_IS_APPROX(ma1, ma2);
MatrixType ma3 = Map<MatrixType>(array3unaligned, rows, cols);
VERIFY_IS_APPROX(ma1, ma3);
ei_aligned_delete(array1, size);
ei_aligned_delete(array2, size);
delete[] array3;
}
template<typename VectorType> void map_static_methods(const VectorType& m) template<typename VectorType> void map_static_methods(const VectorType& m)
{ {
typedef typename VectorType::Scalar Scalar; typedef typename VectorType::Scalar Scalar;
@ -80,11 +108,17 @@ template<typename VectorType> void map_static_methods(const VectorType& m)
void test_map() void test_map()
{ {
for(int i = 0; i < g_repeat; i++) { for(int i = 0; i < g_repeat; i++) {
CALL_SUBTEST( map_class(Matrix<float, 1, 1>()) ); CALL_SUBTEST( map_class_vector(Matrix<float, 1, 1>()) );
CALL_SUBTEST( map_class(Vector4d()) ); CALL_SUBTEST( map_class_vector(Vector4d()) );
CALL_SUBTEST( map_class(RowVector4f()) ); CALL_SUBTEST( map_class_vector(RowVector4f()) );
CALL_SUBTEST( map_class(VectorXcf(8)) ); CALL_SUBTEST( map_class_vector(VectorXcf(8)) );
CALL_SUBTEST( map_class(VectorXi(12)) ); CALL_SUBTEST( map_class_vector(VectorXi(12)) );
CALL_SUBTEST( map_class_matrix(Matrix<float, 1, 1>()) );
CALL_SUBTEST( map_class_matrix(Matrix4d()) );
CALL_SUBTEST( map_class_matrix(Matrix<float,3,5>()) );
CALL_SUBTEST( map_class_matrix(MatrixXcf(ei_random<int>(1,10),ei_random<int>(1,10))) );
CALL_SUBTEST( map_class_matrix(MatrixXi(ei_random<int>(1,10),ei_random<int>(1,10))) );
CALL_SUBTEST( map_static_methods(Matrix<double, 1, 1>()) ); CALL_SUBTEST( map_static_methods(Matrix<double, 1, 1>()) );
CALL_SUBTEST( map_static_methods(Vector3f()) ); CALL_SUBTEST( map_static_methods(Vector3f()) );

View File

@ -46,7 +46,7 @@ template<typename MatrixType> void product(const MatrixType& m)
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> RowSquareMatrixType; typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> RowSquareMatrixType;
typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, MatrixType::ColsAtCompileTime> ColSquareMatrixType; typedef Matrix<Scalar, MatrixType::ColsAtCompileTime, MatrixType::ColsAtCompileTime> ColSquareMatrixType;
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime, typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime,
MatrixType::Flags&RowMajorBit> OtherMajorMatrixType; MatrixType::Options^RowMajor> OtherMajorMatrixType;
int rows = m.rows(); int rows = m.rows();
int cols = m.cols(); int cols = m.cols();
@ -137,6 +137,7 @@ template<typename MatrixType> void product(const MatrixType& m)
res2 = square2; res2 = square2;
res2 += (m1.transpose() * m2).lazy(); res2 += (m1.transpose() * m2).lazy();
VERIFY_IS_APPROX(res2, square2 + m1.transpose() * m2); VERIFY_IS_APPROX(res2, square2 + m1.transpose() * m2);
if (NumTraits<Scalar>::HasFloatingPoint && std::min(rows,cols)>1) if (NumTraits<Scalar>::HasFloatingPoint && std::min(rows,cols)>1)
{ {
VERIFY(areNotApprox(res2,square2 + m2.transpose() * m1)); VERIFY(areNotApprox(res2,square2 + m2.transpose() * m1));

View File

@ -44,12 +44,21 @@ void test_vectorization_logic()
#ifdef EIGEN_VECTORIZE #ifdef EIGEN_VECTORIZE
#ifdef EIGEN_DEFAULT_TO_ROW_MAJOR
VERIFY(test_assign(Vector4f(),Vector4f(),
LinearVectorization,CompleteUnrolling));
VERIFY(test_assign(Vector4f(),Vector4f()+Vector4f(),
LinearVectorization,CompleteUnrolling));
VERIFY(test_assign(Vector4f(),Vector4f().cwise() * Vector4f(),
LinearVectorization,CompleteUnrolling));
#else
VERIFY(test_assign(Vector4f(),Vector4f(), VERIFY(test_assign(Vector4f(),Vector4f(),
InnerVectorization,CompleteUnrolling)); InnerVectorization,CompleteUnrolling));
VERIFY(test_assign(Vector4f(),Vector4f()+Vector4f(), VERIFY(test_assign(Vector4f(),Vector4f()+Vector4f(),
InnerVectorization,CompleteUnrolling)); InnerVectorization,CompleteUnrolling));
VERIFY(test_assign(Vector4f(),Vector4f().cwise() * Vector4f(), VERIFY(test_assign(Vector4f(),Vector4f().cwise() * Vector4f(),
InnerVectorization,CompleteUnrolling)); InnerVectorization,CompleteUnrolling));
#endif
VERIFY(test_assign(Matrix4f(),Matrix4f(), VERIFY(test_assign(Matrix4f(),Matrix4f(),
InnerVectorization,CompleteUnrolling)); InnerVectorization,CompleteUnrolling));
@ -92,8 +101,10 @@ void test_vectorization_logic()
VERIFY(test_sum(Matrix<float,16,16>().block<4,4>(1,2), VERIFY(test_sum(Matrix<float,16,16>().block<4,4>(1,2),
NoVectorization,CompleteUnrolling)); NoVectorization,CompleteUnrolling));
#ifndef EIGEN_DEFAULT_TO_ROW_MAJOR
VERIFY(test_sum(Matrix<float,16,16>().block<8,1>(1,2), VERIFY(test_sum(Matrix<float,16,16>().block<8,1>(1,2),
LinearVectorization,CompleteUnrolling)); LinearVectorization,CompleteUnrolling));
#endif
VERIFY(test_sum(Matrix<double,7,3>(), VERIFY(test_sum(Matrix<double,7,3>(),
NoVectorization,CompleteUnrolling)); NoVectorization,CompleteUnrolling));