diff --git a/Eigen/src/QR/Tridiagonalization.h b/Eigen/src/QR/Tridiagonalization.h index 9ea39be71..69b395fe9 100644 --- a/Eigen/src/QR/Tridiagonalization.h +++ b/Eigen/src/QR/Tridiagonalization.h @@ -293,7 +293,7 @@ void Tridiagonalization::_compute(MatrixType& matA, CoeffVectorType& { int starti = i+1; 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); alignedEnd = alignedStart + ((n-alignedStart)/PacketSize)*PacketSize; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 711660c4a..9cdebb02c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) if(GSL_FOUND AND GSL_VERSION_MINOR LESS 9) @@ -93,12 +97,20 @@ else(CMAKE_COMPILER_IS_GNUCXX) endif(CMAKE_COMPILER_IS_GNUCXX) 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 macro(ei_add_target_property target prop value) 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) @@ -134,13 +146,9 @@ macro(ei_add_test testname) option(EIGEN_DEBUG_ASSERTS "Enable debuging of assertions" OFF) 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) - else(NOT EIGEN_NO_ASSERTION_CHECKING) - - set_target_properties(${targetname} PROPERTIES COMPILE_DEFINITIONS "-DEIGEN_NO_ASSERTION_CHECKING=1") - endif(NOT EIGEN_NO_ASSERTION_CHECKING) if(${ARGC} GREATER 1) @@ -201,7 +209,7 @@ ei_add_test(array) ei_add_test(triangular) ei_add_test(cholesky " " "${GSL_LIBRARIES}") ei_add_test(lu ${EI_OFLAG}) -ei_add_test(determinant) +ei_add_test(determinant ${EI_OFLAG}) ei_add_test(inverse) ei_add_test(qr) ei_add_test(eigensolver " " "${GSL_LIBRARIES}") @@ -216,10 +224,12 @@ ei_add_test(newstdvector) if(QT4_FOUND) ei_add_test(qtvector " " "${QT_QTCORE_LIBRARY}") endif(QT4_FOUND) -ei_add_test(sparse_vector) -ei_add_test(sparse_basic) -ei_add_test(sparse_solvers " " "${SPARSE_LIBS}") -ei_add_test(sparse_product) +if(NOT EIGEN_DEFAULT_TO_ROW_MAJOR) + ei_add_test(sparse_vector) + ei_add_test(sparse_basic) + ei_add_test(sparse_solvers " " "${SPARSE_LIBS}") + ei_add_test(sparse_product) +endif() ei_add_test(swap) ei_add_test(visitor) @@ -268,6 +278,12 @@ else(EIGEN_TEST_NO_EXPLICIT_VECTORIZATION) message("Explicit vec: AUTO") 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}") 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) diff --git a/test/inverse.cpp b/test/inverse.cpp index 54dab489d..9ddc9bb65 100644 --- a/test/inverse.cpp +++ b/test/inverse.cpp @@ -43,11 +43,9 @@ template void inverse(const MatrixType& m) mzero = MatrixType::Zero(rows, cols), identity = MatrixType::Identity(rows, rows); - if (ei_is_same_type::ret) + while(ei_abs(m1.determinant()) < RealScalar(0.1) && rows <= 8) { - // let's build a more stable to inverse matrix - MatrixType a = MatrixType::Random(rows,cols); - m1 += m1 * m1.adjoint() + a * a.adjoint(); + m1 = MatrixType::Random(rows, cols); } m2 = m1.inverse(); diff --git a/test/map.cpp b/test/map.cpp index 5159dffa1..98bc0180e 100644 --- a/test/map.cpp +++ b/test/map.cpp @@ -1,7 +1,7 @@ // 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-2008 Benoit Jacob +// Copyright (C) 2007-2010 Benoit Jacob // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -24,7 +24,7 @@ #include "main.h" -template void map_class(const VectorType& m) +template void map_class_vector(const VectorType& m) { typedef typename VectorType::Scalar Scalar; @@ -50,6 +50,34 @@ template void map_class(const VectorType& m) delete[] array3; } +template 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(size); + for(int i = 0; i < size; i++) array1[i] = Scalar(1); + Scalar* array2 = ei_aligned_new(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(array1, rows, cols) = MatrixType::Ones(rows,cols); + Map(array2, rows, cols) = Map(array1, rows, cols); + Map(array3unaligned, rows, cols) = Map(array1, rows, cols); + MatrixType ma1 = Map(array1, rows, cols); + MatrixType ma2 = Map(array2, rows, cols); + VERIFY_IS_APPROX(ma1, ma2); + MatrixType ma3 = Map(array3unaligned, rows, cols); + VERIFY_IS_APPROX(ma1, ma3); + + ei_aligned_delete(array1, size); + ei_aligned_delete(array2, size); + delete[] array3; +} + template void map_static_methods(const VectorType& m) { typedef typename VectorType::Scalar Scalar; @@ -80,11 +108,17 @@ template void map_static_methods(const VectorType& m) void test_map() { for(int i = 0; i < g_repeat; i++) { - CALL_SUBTEST( map_class(Matrix()) ); - CALL_SUBTEST( map_class(Vector4d()) ); - CALL_SUBTEST( map_class(RowVector4f()) ); - CALL_SUBTEST( map_class(VectorXcf(8)) ); - CALL_SUBTEST( map_class(VectorXi(12)) ); + CALL_SUBTEST( map_class_vector(Matrix()) ); + CALL_SUBTEST( map_class_vector(Vector4d()) ); + CALL_SUBTEST( map_class_vector(RowVector4f()) ); + CALL_SUBTEST( map_class_vector(VectorXcf(8)) ); + CALL_SUBTEST( map_class_vector(VectorXi(12)) ); + + CALL_SUBTEST( map_class_matrix(Matrix()) ); + CALL_SUBTEST( map_class_matrix(Matrix4d()) ); + CALL_SUBTEST( map_class_matrix(Matrix()) ); + CALL_SUBTEST( map_class_matrix(MatrixXcf(ei_random(1,10),ei_random(1,10))) ); + CALL_SUBTEST( map_class_matrix(MatrixXi(ei_random(1,10),ei_random(1,10))) ); CALL_SUBTEST( map_static_methods(Matrix()) ); CALL_SUBTEST( map_static_methods(Vector3f()) ); diff --git a/test/product.h b/test/product.h index 2a32958ce..4f4aeb965 100644 --- a/test/product.h +++ b/test/product.h @@ -46,7 +46,7 @@ template void product(const MatrixType& m) typedef Matrix RowSquareMatrixType; typedef Matrix ColSquareMatrixType; typedef Matrix OtherMajorMatrixType; + MatrixType::Options^RowMajor> OtherMajorMatrixType; int rows = m.rows(); int cols = m.cols(); @@ -137,6 +137,7 @@ template void product(const MatrixType& m) res2 = square2; res2 += (m1.transpose() * m2).lazy(); VERIFY_IS_APPROX(res2, square2 + m1.transpose() * m2); + if (NumTraits::HasFloatingPoint && std::min(rows,cols)>1) { VERIFY(areNotApprox(res2,square2 + m2.transpose() * m1)); diff --git a/test/vectorization_logic.cpp b/test/vectorization_logic.cpp index d1b5b4916..fcbcbfb75 100644 --- a/test/vectorization_logic.cpp +++ b/test/vectorization_logic.cpp @@ -44,12 +44,21 @@ void test_vectorization_logic() #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(), InnerVectorization,CompleteUnrolling)); VERIFY(test_assign(Vector4f(),Vector4f()+Vector4f(), InnerVectorization,CompleteUnrolling)); VERIFY(test_assign(Vector4f(),Vector4f().cwise() * Vector4f(), InnerVectorization,CompleteUnrolling)); +#endif VERIFY(test_assign(Matrix4f(),Matrix4f(), InnerVectorization,CompleteUnrolling)); @@ -92,8 +101,10 @@ void test_vectorization_logic() VERIFY(test_sum(Matrix().block<4,4>(1,2), NoVectorization,CompleteUnrolling)); +#ifndef EIGEN_DEFAULT_TO_ROW_MAJOR VERIFY(test_sum(Matrix().block<8,1>(1,2), LinearVectorization,CompleteUnrolling)); +#endif VERIFY(test_sum(Matrix(), NoVectorization,CompleteUnrolling));