aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2017-02-26 10:02:14 -0800
committerGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2017-02-26 10:02:14 -0800
commite0bd6f5738b94e8d7a4b17b61bf9cb6418685f28 (patch)
tree91c22b0751640a02596c63c4a9315fc44cbc9d43 /test
parent2fa2b617a97ba254343c7c1635a9b6d617a100e8 (diff)
parent76687f385c80a4d576d4fadeb271a94d9783b194 (diff)
Merged eigen/eigen into default
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt1
-rw-r--r--test/constructor.cpp84
-rw-r--r--test/jacobisvd.cpp6
-rw-r--r--test/main.h3
-rw-r--r--test/permutationmatrices.cpp13
-rw-r--r--test/redux.cpp6
-rw-r--r--test/vectorwiseop.cpp4
7 files changed, 106 insertions, 11 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 84a21b3df..d337594f5 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -151,6 +151,7 @@ ei_add_test(packetmath "-DEIGEN_FAST_MATH=1")
ei_add_test(unalignedassert)
ei_add_test(vectorization_logic)
ei_add_test(basicstuff)
+ei_add_test(constructor)
ei_add_test(linearstructure)
ei_add_test(integer_types)
ei_add_test(unalignedcount)
diff --git a/test/constructor.cpp b/test/constructor.cpp
new file mode 100644
index 000000000..eec9e2192
--- /dev/null
+++ b/test/constructor.cpp
@@ -0,0 +1,84 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra.
+//
+// Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
+//
+// This Source Code Form is subject to the terms of the Mozilla
+// Public License v. 2.0. If a copy of the MPL was not distributed
+// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+
+#define TEST_ENABLE_TEMPORARY_TRACKING
+
+#include "main.h"
+
+template<typename MatrixType> struct Wrapper
+{
+ MatrixType m_mat;
+ inline Wrapper(const MatrixType &x) : m_mat(x) {}
+ inline operator const MatrixType& () const { return m_mat; }
+ inline operator MatrixType& () { return m_mat; }
+};
+
+template<typename MatrixType> void ctor_init1(const MatrixType& m)
+{
+ // Check logic in PlainObjectBase::_init1
+ Index rows = m.rows();
+ Index cols = m.cols();
+
+ MatrixType m0 = MatrixType::Random(rows,cols);
+
+ VERIFY_EVALUATION_COUNT( MatrixType m1(m0), 1);
+ VERIFY_EVALUATION_COUNT( MatrixType m2(m0+m0), 1);
+ VERIFY_EVALUATION_COUNT( MatrixType m2(m0.block(0,0,rows,cols)) , 1);
+
+ Wrapper<MatrixType> wrapper(m0);
+ VERIFY_EVALUATION_COUNT( MatrixType m3(wrapper) , 1);
+}
+
+
+void test_constructor()
+{
+ for(int i = 0; i < g_repeat; i++) {
+ CALL_SUBTEST_1( ctor_init1(Matrix<float, 1, 1>()) );
+ CALL_SUBTEST_1( ctor_init1(Matrix4d()) );
+ CALL_SUBTEST_1( ctor_init1(MatrixXcf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
+ CALL_SUBTEST_1( ctor_init1(MatrixXi(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
+ }
+ {
+ Matrix<Index,1,1> a(123);
+ VERIFY_IS_EQUAL(a[0], 123);
+ }
+ {
+ Matrix<Index,1,1> a(123.0);
+ VERIFY_IS_EQUAL(a[0], 123);
+ }
+ {
+ Matrix<float,1,1> a(123);
+ VERIFY_IS_EQUAL(a[0], 123.f);
+ }
+ {
+ Array<Index,1,1> a(123);
+ VERIFY_IS_EQUAL(a[0], 123);
+ }
+ {
+ Array<Index,1,1> a(123.0);
+ VERIFY_IS_EQUAL(a[0], 123);
+ }
+ {
+ Array<float,1,1> a(123);
+ VERIFY_IS_EQUAL(a[0], 123.f);
+ }
+ {
+ Array<Index,3,3> a(123);
+ VERIFY_IS_EQUAL(a(4), 123);
+ }
+ {
+ Array<Index,3,3> a(123.0);
+ VERIFY_IS_EQUAL(a(4), 123);
+ }
+ {
+ Array<float,3,3> a(123);
+ VERIFY_IS_EQUAL(a(4), 123.f);
+ }
+}
diff --git a/test/jacobisvd.cpp b/test/jacobisvd.cpp
index 3d8d0203d..7f5f71562 100644
--- a/test/jacobisvd.cpp
+++ b/test/jacobisvd.cpp
@@ -101,6 +101,12 @@ void test_jacobisvd()
// Test on inf/nan matrix
CALL_SUBTEST_7( (svd_inf_nan<JacobiSVD<MatrixXf>, MatrixXf>()) );
CALL_SUBTEST_10( (svd_inf_nan<JacobiSVD<MatrixXd>, MatrixXd>()) );
+
+ // bug1395 test compile-time vectors as input
+ CALL_SUBTEST_13(( jacobisvd_verify_assert(Matrix<double,6,1>()) ));
+ CALL_SUBTEST_13(( jacobisvd_verify_assert(Matrix<double,1,6>()) ));
+ CALL_SUBTEST_13(( jacobisvd_verify_assert(Matrix<double,Dynamic,1>(r)) ));
+ CALL_SUBTEST_13(( jacobisvd_verify_assert(Matrix<double,1,Dynamic>(c)) ));
}
CALL_SUBTEST_7(( jacobisvd<MatrixXf>(MatrixXf(internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2), internal::random<int>(EIGEN_TEST_MAX_SIZE/4, EIGEN_TEST_MAX_SIZE/2))) ));
diff --git a/test/main.h b/test/main.h
index 1d5bdc1c4..25d2dcf43 100644
--- a/test/main.h
+++ b/test/main.h
@@ -41,6 +41,7 @@
#include <complex>
#include <deque>
#include <queue>
+#include <cassert>
#include <list>
#if __cplusplus >= 201103L
#include <random>
@@ -79,10 +80,12 @@
#ifdef TEST_ENABLE_TEMPORARY_TRACKING
static long int nb_temporaries;
+static long int nb_temporaries_on_assert = -1;
inline void on_temporary_creation(long int size) {
// here's a great place to set a breakpoint when debugging failures in this test!
if(size!=0) nb_temporaries++;
+ if(nb_temporaries_on_assert>0) assert(nb_temporaries<nb_temporaries_on_assert);
}
#define EIGEN_DENSE_STORAGE_CTOR_PLUGIN { on_temporary_creation(size); }
diff --git a/test/permutationmatrices.cpp b/test/permutationmatrices.cpp
index 70b469ebc..db1266579 100644
--- a/test/permutationmatrices.cpp
+++ b/test/permutationmatrices.cpp
@@ -37,8 +37,7 @@ template<typename MatrixType> void permutationmatrices(const MatrixType& m)
RightPermutationType rp(rv);
MatrixType m_permuted = MatrixType::Random(rows,cols);
- const int one_if_dynamic = MatrixType::SizeAtCompileTime==Dynamic ? 1 : 0;
- VERIFY_EVALUATION_COUNT(m_permuted = lp * m_original * rp, one_if_dynamic); // 1 temp for sub expression "lp * m_original"
+ VERIFY_EVALUATION_COUNT(m_permuted = lp * m_original * rp, 1); // 1 temp for sub expression "lp * m_original"
for (int i=0; i<rows; i++)
for (int j=0; j<cols; j++)
@@ -50,7 +49,7 @@ template<typename MatrixType> void permutationmatrices(const MatrixType& m)
VERIFY_IS_APPROX(m_permuted, lm*m_original*rm);
m_permuted = m_original;
- VERIFY_EVALUATION_COUNT(m_permuted = lp * m_permuted * rp, one_if_dynamic);
+ VERIFY_EVALUATION_COUNT(m_permuted = lp * m_permuted * rp, 1);
VERIFY_IS_APPROX(m_permuted, lm*m_original*rm);
VERIFY_IS_APPROX(lp.inverse()*m_permuted*rp.inverse(), m_original);
@@ -75,19 +74,19 @@ template<typename MatrixType> void permutationmatrices(const MatrixType& m)
// check inplace permutations
m_permuted = m_original;
- VERIFY_EVALUATION_COUNT(m_permuted.noalias()= lp.inverse() * m_permuted, one_if_dynamic); // 1 temp to allocate the mask
+ VERIFY_EVALUATION_COUNT(m_permuted.noalias()= lp.inverse() * m_permuted, 1); // 1 temp to allocate the mask
VERIFY_IS_APPROX(m_permuted, lp.inverse()*m_original);
m_permuted = m_original;
- VERIFY_EVALUATION_COUNT(m_permuted.noalias() = m_permuted * rp.inverse(), one_if_dynamic); // 1 temp to allocate the mask
+ VERIFY_EVALUATION_COUNT(m_permuted.noalias() = m_permuted * rp.inverse(), 1); // 1 temp to allocate the mask
VERIFY_IS_APPROX(m_permuted, m_original*rp.inverse());
m_permuted = m_original;
- VERIFY_EVALUATION_COUNT(m_permuted.noalias() = lp * m_permuted, one_if_dynamic); // 1 temp to allocate the mask
+ VERIFY_EVALUATION_COUNT(m_permuted.noalias() = lp * m_permuted, 1); // 1 temp to allocate the mask
VERIFY_IS_APPROX(m_permuted, lp*m_original);
m_permuted = m_original;
- VERIFY_EVALUATION_COUNT(m_permuted.noalias() = m_permuted * rp, one_if_dynamic); // 1 temp to allocate the mask
+ VERIFY_EVALUATION_COUNT(m_permuted.noalias() = m_permuted * rp, 1); // 1 temp to allocate the mask
VERIFY_IS_APPROX(m_permuted, m_original*rp);
if(rows>1 && cols>1)
diff --git a/test/redux.cpp b/test/redux.cpp
index 6ddc59c18..989e1057b 100644
--- a/test/redux.cpp
+++ b/test/redux.cpp
@@ -70,10 +70,10 @@ template<typename MatrixType> void matrixRedux(const MatrixType& m)
VERIFY_IS_APPROX(m1.block(r0,c0,0,0).prod(), Scalar(1));
// test nesting complex expression
- VERIFY_EVALUATION_COUNT( (m1.matrix()*m1.matrix().transpose()).sum(), (MatrixType::SizeAtCompileTime==Dynamic ? 1 : 0) );
+ VERIFY_EVALUATION_COUNT( (m1.matrix()*m1.matrix().transpose()).sum(), (MatrixType::IsVectorAtCompileTime && MatrixType::SizeAtCompileTime!=1 ? 0 : 1) );
Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> m2(rows,rows);
m2.setRandom();
- VERIFY_EVALUATION_COUNT( ((m1.matrix()*m1.matrix().transpose())+m2).sum(), (MatrixType::SizeAtCompileTime==Dynamic ? 1 : 0) );
+ VERIFY_EVALUATION_COUNT( ((m1.matrix()*m1.matrix().transpose())+m2).sum(),(MatrixType::IsVectorAtCompileTime && MatrixType::SizeAtCompileTime!=1 ? 0 : 1));
}
template<typename VectorType> void vectorRedux(const VectorType& w)
@@ -156,8 +156,10 @@ void test_redux()
CALL_SUBTEST_1( matrixRedux(Array<float, 1, 1>()) );
CALL_SUBTEST_2( matrixRedux(Matrix2f()) );
CALL_SUBTEST_2( matrixRedux(Array2f()) );
+ CALL_SUBTEST_2( matrixRedux(Array22f()) );
CALL_SUBTEST_3( matrixRedux(Matrix4d()) );
CALL_SUBTEST_3( matrixRedux(Array4d()) );
+ CALL_SUBTEST_3( matrixRedux(Array44d()) );
CALL_SUBTEST_4( matrixRedux(MatrixXcf(internal::random<int>(1,maxsize), internal::random<int>(1,maxsize))) );
CALL_SUBTEST_4( matrixRedux(ArrayXXcf(internal::random<int>(1,maxsize), internal::random<int>(1,maxsize))) );
CALL_SUBTEST_5( matrixRedux(MatrixXd (internal::random<int>(1,maxsize), internal::random<int>(1,maxsize))) );
diff --git a/test/vectorwiseop.cpp b/test/vectorwiseop.cpp
index 739eacaf3..f3ab561ee 100644
--- a/test/vectorwiseop.cpp
+++ b/test/vectorwiseop.cpp
@@ -231,12 +231,12 @@ template<typename MatrixType> void vectorwiseop_matrix(const MatrixType& m)
Matrix<Scalar,MatrixType::RowsAtCompileTime,MatrixType::RowsAtCompileTime> m1m1 = m1 * m1.transpose();
VERIFY_IS_APPROX( (m1 * m1.transpose()).colwise().sum(), m1m1.colwise().sum());
Matrix<Scalar,1,MatrixType::RowsAtCompileTime> tmp(rows);
- VERIFY_EVALUATION_COUNT( tmp = (m1 * m1.transpose()).colwise().sum(), (MatrixType::RowsAtCompileTime==Dynamic ? 1 : 0));
+ VERIFY_EVALUATION_COUNT( tmp = (m1 * m1.transpose()).colwise().sum(), 1);
m2 = m1.rowwise() - (m1.colwise().sum()/RealScalar(m1.rows())).eval();
m1 = m1.rowwise() - (m1.colwise().sum()/RealScalar(m1.rows()));
VERIFY_IS_APPROX( m1, m2 );
- VERIFY_EVALUATION_COUNT( m2 = (m1.rowwise() - m1.colwise().sum()/RealScalar(m1.rows())), (MatrixType::RowsAtCompileTime==Dynamic && MatrixType::ColsAtCompileTime!=1 ? 1 : 0) );
+ VERIFY_EVALUATION_COUNT( m2 = (m1.rowwise() - m1.colwise().sum()/RealScalar(m1.rows())), (MatrixType::RowsAtCompileTime!=1 ? 1 : 0) );
}
void test_vectorwiseop()