aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2010-07-22 16:29:35 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2010-07-22 16:29:35 +0200
commit7020f30da3ce2b646ddafa535c6564ed00fc762f (patch)
tree5d26ac3fd8b082dfe2d89903d58b760529632d72 /test
parentb9edd6fb85a4930f0291f1b52c7f84cb6684e063 (diff)
parent96ba7cd6557769e01778441cdf7855295542aad0 (diff)
sync with default branch
Diffstat (limited to 'test')
-rw-r--r--test/array_for_matrix.cpp4
-rw-r--r--test/corners.cpp23
-rw-r--r--test/determinant.cpp3
-rw-r--r--test/main.h2
-rw-r--r--test/nullary.cpp12
-rw-r--r--test/product_trmm.cpp9
-rw-r--r--test/redux.cpp11
-rw-r--r--test/sparse_basic.cpp7
8 files changed, 58 insertions, 13 deletions
diff --git a/test/array_for_matrix.cpp b/test/array_for_matrix.cpp
index 01e31d05b..3699b861a 100644
--- a/test/array_for_matrix.cpp
+++ b/test/array_for_matrix.cpp
@@ -72,6 +72,10 @@ template<typename MatrixType> void array_for_matrix(const MatrixType& m)
VERIFY_IS_APPROX(m3.rowwise() += rv1, m1.rowwise() + rv1);
m3 = m1;
VERIFY_IS_APPROX(m3.rowwise() -= rv1, m1.rowwise() - rv1);
+
+ // empty objects
+ VERIFY_IS_APPROX(m1.block(0,0,0,cols).colwise().sum(), RowVectorType::Zero(cols));
+ VERIFY_IS_APPROX(m1.block(0,0,rows,0).rowwise().prod(), ColVectorType::Ones(rows));
}
template<typename MatrixType> void comparisons(const MatrixType& m)
diff --git a/test/corners.cpp b/test/corners.cpp
index 70d12fded..fe2b205d7 100644
--- a/test/corners.cpp
+++ b/test/corners.cpp
@@ -45,13 +45,20 @@ template<typename MatrixType> void corners(const MatrixType& m)
COMPARE_CORNER(bottomLeftCorner(r,c), block(rows-r,0,r,c));
COMPARE_CORNER(bottomRightCorner(r,c), block(rows-r,cols-c,r,c));
+ Index sr = ei_random<Index>(1,rows) - 1;
+ Index nr = ei_random<Index>(1,rows-sr);
+ Index sc = ei_random<Index>(1,cols) - 1;
+ Index nc = ei_random<Index>(1,cols-sc);
+
COMPARE_CORNER(topRows(r), block(0,0,r,cols));
+ COMPARE_CORNER(middleRows(sr,nr), block(sr,0,nr,cols));
COMPARE_CORNER(bottomRows(r), block(rows-r,0,r,cols));
COMPARE_CORNER(leftCols(c), block(0,0,rows,c));
+ COMPARE_CORNER(middleCols(sc,nc), block(0,sc,rows,nc));
COMPARE_CORNER(rightCols(c), block(0,cols-c,rows,c));
}
-template<typename MatrixType, int CRows, int CCols> void corners_fixedsize()
+template<typename MatrixType, int CRows, int CCols, int SRows, int SCols> void corners_fixedsize()
{
MatrixType matrix = MatrixType::Random();
const MatrixType const_matrix = MatrixType::Random();
@@ -60,7 +67,9 @@ template<typename MatrixType, int CRows, int CCols> void corners_fixedsize()
rows = MatrixType::RowsAtCompileTime,
cols = MatrixType::ColsAtCompileTime,
r = CRows,
- c = CCols
+ c = CCols,
+ sr = SRows,
+ sc = SCols
};
VERIFY_IS_EQUAL((matrix.template topLeftCorner<r,c>()), (matrix.template block<r,c>(0,0)));
@@ -69,8 +78,10 @@ template<typename MatrixType, int CRows, int CCols> void corners_fixedsize()
VERIFY_IS_EQUAL((matrix.template bottomRightCorner<r,c>()), (matrix.template block<r,c>(rows-r,cols-c)));
VERIFY_IS_EQUAL((matrix.template topRows<r>()), (matrix.template block<r,cols>(0,0)));
+ VERIFY_IS_EQUAL((matrix.template middleRows<r>(sr)), (matrix.template block<r,cols>(sr,0)));
VERIFY_IS_EQUAL((matrix.template bottomRows<r>()), (matrix.template block<r,cols>(rows-r,0)));
VERIFY_IS_EQUAL((matrix.template leftCols<c>()), (matrix.template block<rows,c>(0,0)));
+ VERIFY_IS_EQUAL((matrix.template middleCols<c>(sc)), (matrix.template block<rows,c>(0,sc)));
VERIFY_IS_EQUAL((matrix.template rightCols<c>()), (matrix.template block<rows,c>(0,cols-c)));
VERIFY_IS_EQUAL((const_matrix.template topLeftCorner<r,c>()), (const_matrix.template block<r,c>(0,0)));
@@ -79,8 +90,10 @@ template<typename MatrixType, int CRows, int CCols> void corners_fixedsize()
VERIFY_IS_EQUAL((const_matrix.template bottomRightCorner<r,c>()), (const_matrix.template block<r,c>(rows-r,cols-c)));
VERIFY_IS_EQUAL((const_matrix.template topRows<r>()), (const_matrix.template block<r,cols>(0,0)));
+ VERIFY_IS_EQUAL((const_matrix.template middleRows<r>(sr)), (const_matrix.template block<r,cols>(sr,0)));
VERIFY_IS_EQUAL((const_matrix.template bottomRows<r>()), (const_matrix.template block<r,cols>(rows-r,0)));
VERIFY_IS_EQUAL((const_matrix.template leftCols<c>()), (const_matrix.template block<rows,c>(0,0)));
+ VERIFY_IS_EQUAL((const_matrix.template middleCols<c>(sc)), (const_matrix.template block<rows,c>(0,sc)));
VERIFY_IS_EQUAL((const_matrix.template rightCols<c>()), (const_matrix.template block<rows,c>(0,cols-c)));
}
@@ -93,8 +106,8 @@ void test_corners()
CALL_SUBTEST_4( corners(MatrixXcf(5, 7)) );
CALL_SUBTEST_5( corners(MatrixXf(21, 20)) );
- CALL_SUBTEST_1(( corners_fixedsize<Matrix<float, 1, 1>, 1, 1>() ));
- CALL_SUBTEST_2(( corners_fixedsize<Matrix4d,2,2>() ));
- CALL_SUBTEST_3(( corners_fixedsize<Matrix<int,10,12>,4,7>() ));
+ CALL_SUBTEST_1(( corners_fixedsize<Matrix<float, 1, 1>, 1, 1, 0, 0>() ));
+ CALL_SUBTEST_2(( corners_fixedsize<Matrix4d,2,2,1,1>() ));
+ CALL_SUBTEST_3(( corners_fixedsize<Matrix<int,10,12>,4,7,5,2>() ));
}
}
diff --git a/test/determinant.cpp b/test/determinant.cpp
index 494fa5eab..8112131b7 100644
--- a/test/determinant.cpp
+++ b/test/determinant.cpp
@@ -61,6 +61,9 @@ template<typename MatrixType> void determinant(const MatrixType& m)
m2 = m1;
m2.row(i) *= x;
VERIFY_IS_APPROX(m2.determinant(), m1.determinant() * x);
+
+ // check empty matrix
+ VERIFY_IS_APPROX(m2.block(0,0,0,0).determinant(), Scalar(1));
}
void test_determinant()
diff --git a/test/main.h b/test/main.h
index 6e1b28cb4..3d277ba61 100644
--- a/test/main.h
+++ b/test/main.h
@@ -283,7 +283,7 @@ namespace Eigen
namespace Eigen {
-template<typename T> inline typename NumTraits<T>::Real test_precision() { return T(0); }
+template<typename T> inline typename NumTraits<T>::Real test_precision() { return NumTraits<T>::dummy_precision(); }
template<> inline float test_precision<float>() { return 1e-3f; }
template<> inline double test_precision<double>() { return 1e-6; }
template<> inline float test_precision<std::complex<float> >() { return test_precision<float>(); }
diff --git a/test/nullary.cpp b/test/nullary.cpp
index c54999580..78d2e9117 100644
--- a/test/nullary.cpp
+++ b/test/nullary.cpp
@@ -59,7 +59,7 @@ void testVectorType(const VectorType& base)
// check whether the result yields what we expect it to do
VectorType m(base);
- m.setLinSpaced(low,high,size);
+ m.setLinSpaced(size,low,high);
VectorType n(size);
for (int i=0; i<size; ++i)
@@ -68,7 +68,7 @@ void testVectorType(const VectorType& base)
VERIFY( (m-n).norm() < std::numeric_limits<Scalar>::epsilon()*10e3 );
// random access version
- m = VectorType::LinSpaced(low,high,size);
+ m = VectorType::LinSpaced(size,low,high);
VERIFY( (m-n).norm() < std::numeric_limits<Scalar>::epsilon()*10e3 );
// These guys sometimes fail! This is not good. Any ideas how to fix them!?
@@ -76,7 +76,7 @@ void testVectorType(const VectorType& base)
//VERIFY( m(0) == low );
// sequential access version
- m = VectorType::LinSpaced(Sequential,low,high,size);
+ m = VectorType::LinSpaced(Sequential,size,low,high);
VERIFY( (m-n).norm() < std::numeric_limits<Scalar>::epsilon()*10e3 );
// These guys sometimes fail! This is not good. Any ideas how to fix them!?
@@ -86,12 +86,12 @@ void testVectorType(const VectorType& base)
// check whether everything works with row and col major vectors
Matrix<Scalar,Dynamic,1> row_vector(size);
Matrix<Scalar,1,Dynamic> col_vector(size);
- row_vector.setLinSpaced(low,high,size);
- col_vector.setLinSpaced(low,high,size);
+ row_vector.setLinSpaced(size,low,high);
+ col_vector.setLinSpaced(size,low,high);
VERIFY( row_vector.isApprox(col_vector.transpose(), NumTraits<Scalar>::epsilon()));
Matrix<Scalar,Dynamic,1> size_changer(size+50);
- size_changer.setLinSpaced(low,high,size);
+ size_changer.setLinSpaced(size,low,high);
VERIFY( size_changer.size() == size );
}
diff --git a/test/product_trmm.cpp b/test/product_trmm.cpp
index e20b408c4..e4790fb66 100644
--- a/test/product_trmm.cpp
+++ b/test/product_trmm.cpp
@@ -35,7 +35,7 @@ template<typename Scalar> void trmm(int size,int /*othersize*/)
DenseIndex cols = ei_random<DenseIndex>(1,size);
MatrixColMaj triV(rows,cols), triH(cols,rows), upTri(cols,rows), loTri(rows,cols),
- unitUpTri(cols,rows), unitLoTri(rows,cols);
+ unitUpTri(cols,rows), unitLoTri(rows,cols), strictlyUpTri(cols,rows), strictlyLoTri(rows,cols);
MatrixColMaj ge1(rows,cols), ge2(cols,rows), ge3;
MatrixRowMaj rge3;
@@ -48,6 +48,8 @@ template<typename Scalar> void trmm(int size,int /*othersize*/)
upTri = triH.template triangularView<Upper>();
unitLoTri = triV.template triangularView<UnitLower>();
unitUpTri = triH.template triangularView<UnitUpper>();
+ strictlyLoTri = triV.template triangularView<StrictlyLower>();
+ strictlyUpTri = triH.template triangularView<StrictlyUpper>();
ge1.setRandom();
ge2.setRandom();
@@ -72,6 +74,11 @@ template<typename Scalar> void trmm(int size,int /*othersize*/)
VERIFY_IS_APPROX( rge3.noalias() = ge2 * triV.template triangularView<UnitLower>(), ge2 * unitLoTri);
VERIFY_IS_APPROX( ge3 = ge2 * triV.template triangularView<UnitLower>(), ge2 * unitLoTri);
VERIFY_IS_APPROX( ge3 = (s1*triV).adjoint().template triangularView<UnitUpper>() * ge2.adjoint(), ei_conj(s1) * unitLoTri.adjoint() * ge2.adjoint());
+
+ VERIFY_IS_APPROX( ge3 = triV.template triangularView<StrictlyLower>() * ge2, strictlyLoTri * ge2);
+ VERIFY_IS_APPROX( rge3.noalias() = ge2 * triV.template triangularView<StrictlyLower>(), ge2 * strictlyLoTri);
+ VERIFY_IS_APPROX( ge3 = ge2 * triV.template triangularView<StrictlyLower>(), ge2 * strictlyLoTri);
+ VERIFY_IS_APPROX( ge3 = (s1*triV).adjoint().template triangularView<StrictlyUpper>() * ge2.adjoint(), ei_conj(s1) * strictlyLoTri.adjoint() * ge2.adjoint());
}
void test_product_trmm()
diff --git a/test/redux.cpp b/test/redux.cpp
index b28252903..9a1df71a8 100644
--- a/test/redux.cpp
+++ b/test/redux.cpp
@@ -64,6 +64,10 @@ template<typename MatrixType> void matrixRedux(const MatrixType& m)
VERIFY_IS_APPROX(m1.block(r0,c0,r1,c1).prod(), m1.block(r0,c0,r1,c1).eval().prod());
VERIFY_IS_APPROX(m1.block(r0,c0,r1,c1).real().minCoeff(), m1.block(r0,c0,r1,c1).real().eval().minCoeff());
VERIFY_IS_APPROX(m1.block(r0,c0,r1,c1).real().maxCoeff(), m1.block(r0,c0,r1,c1).real().eval().maxCoeff());
+
+ // test empty objects
+ VERIFY_IS_APPROX(m1.block(r0,c0,0,0).sum(), Scalar(0));
+ VERIFY_IS_APPROX(m1.block(r0,c0,0,0).prod(), Scalar(1));
}
template<typename VectorType> void vectorRedux(const VectorType& w)
@@ -124,6 +128,13 @@ template<typename VectorType> void vectorRedux(const VectorType& w)
VERIFY_IS_APPROX(minc, v.real().segment(i, size-2*i).minCoeff());
VERIFY_IS_APPROX(maxc, v.real().segment(i, size-2*i).maxCoeff());
}
+
+ // test empty objects
+ VERIFY_IS_APPROX(v.head(0).sum(), Scalar(0));
+ VERIFY_IS_APPROX(v.tail(0).prod(), Scalar(1));
+ VERIFY_RAISES_ASSERT(v.head(0).mean());
+ VERIFY_RAISES_ASSERT(v.head(0).minCoeff());
+ VERIFY_RAISES_ASSERT(v.head(0).maxCoeff());
}
void test_redux()
diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp
index 3ebd59294..8c93909c6 100644
--- a/test/sparse_basic.cpp
+++ b/test/sparse_basic.cpp
@@ -250,6 +250,13 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
VERIFY(countTrueNonZero==m2.nonZeros());
VERIFY_IS_APPROX(m2, refM2);
}
+
+ // test sparseView
+ {
+ DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows);
+ SparseMatrixType m2(rows, rows);
+ VERIFY_IS_APPROX(m2.eval(), refMat2.sparseView().eval());
+ }
}
void test_sparse_basic()