mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Clean up EIGEN_STATIC_ASSERT to only use standard c++11 static_assert.
This commit is contained in:
@@ -7,8 +7,6 @@
|
||||
// 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 EIGEN_NO_STATIC_ASSERT
|
||||
|
||||
#include "main.h"
|
||||
|
||||
template<bool IsInteger> struct adjoint_specific;
|
||||
|
||||
@@ -7,11 +7,20 @@
|
||||
// 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 EIGEN_NO_STATIC_ASSERT
|
||||
|
||||
#include "main.h"
|
||||
#include "random_without_cast_overflow.h"
|
||||
|
||||
template <typename MatrixType>
|
||||
typename internal::enable_if<(MatrixType::RowsAtCompileTime==1 || MatrixType::ColsAtCompileTime==1),void>::type
|
||||
check_index(const MatrixType& m) {
|
||||
VERIFY_RAISES_ASSERT(m[0]);
|
||||
VERIFY_RAISES_ASSERT((m+m)[0]);
|
||||
}
|
||||
|
||||
template <typename MatrixType>
|
||||
typename internal::enable_if<!(MatrixType::RowsAtCompileTime==1 || MatrixType::ColsAtCompileTime==1),void>::type
|
||||
check_index(const MatrixType& /*unused*/) {}
|
||||
|
||||
template<typename MatrixType> void basicStuff(const MatrixType& m)
|
||||
{
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
@@ -101,8 +110,7 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
|
||||
|
||||
if(cols!=1 && rows!=1)
|
||||
{
|
||||
VERIFY_RAISES_ASSERT(m1[0]);
|
||||
VERIFY_RAISES_ASSERT((m1+m1)[0]);
|
||||
check_index(m1);
|
||||
}
|
||||
|
||||
VERIFY_IS_APPROX(m3 = m1,m1);
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
// 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 EIGEN_NO_STATIC_ASSERT // otherwise we fail at compile time on unused paths
|
||||
#include "main.h"
|
||||
|
||||
template<typename MatrixType, typename Index, typename Scalar>
|
||||
@@ -37,6 +36,20 @@ is_same_block(const T1& a, const T2& b)
|
||||
return a.isApprox(b);
|
||||
}
|
||||
|
||||
template <typename MatrixType>
|
||||
typename internal::enable_if<((MatrixType::Flags&RowMajorBit)==0),void>::type
|
||||
check_left_top(const MatrixType& m, Index r, Index c,
|
||||
Index rows, Index /*unused*/) {
|
||||
VERIFY_IS_EQUAL(m.leftCols(c).coeff(r+c*rows), m(r,c));
|
||||
}
|
||||
|
||||
template <typename MatrixType>
|
||||
typename internal::enable_if<((MatrixType::Flags&RowMajorBit)!=0),void>::type
|
||||
check_left_top(const MatrixType& m, Index r, Index c,
|
||||
Index /*unused*/, Index cols) {
|
||||
VERIFY_IS_EQUAL(m.topRows(r).coeff(c+r*cols), m(r,c));
|
||||
}
|
||||
|
||||
template<typename MatrixType> void block(const MatrixType& m)
|
||||
{
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
@@ -79,7 +92,8 @@ template<typename MatrixType> void block(const MatrixType& m)
|
||||
VERIFY_IS_APPROX(m1.col(c1), m1_copy.col(c1) + s1 * m1_copy.col(c2));
|
||||
m1.col(c1).col(0) += s1 * m1_copy.col(c2);
|
||||
VERIFY_IS_APPROX(m1.col(c1), m1_copy.col(c1) + Scalar(2) * s1 * m1_copy.col(c2));
|
||||
|
||||
|
||||
check_left_top(m1,r1,c1,rows,cols);
|
||||
|
||||
//check block()
|
||||
Matrix<Scalar,Dynamic,Dynamic> b1(1,1); b1(0,0) = m1(r1,c1);
|
||||
@@ -143,11 +157,6 @@ template<typename MatrixType> void block(const MatrixType& m)
|
||||
|
||||
// check that linear acccessors works on blocks
|
||||
m1 = m1_copy;
|
||||
if((MatrixType::Flags&RowMajorBit)==0)
|
||||
VERIFY_IS_EQUAL(m1.leftCols(c1).coeff(r1+c1*rows), m1(r1,c1));
|
||||
else
|
||||
VERIFY_IS_EQUAL(m1.topRows(r1).coeff(c1+r1*cols), m1(r1,c1));
|
||||
|
||||
|
||||
// now test some block-inside-of-block.
|
||||
|
||||
@@ -213,14 +222,6 @@ template<typename MatrixType> void block(const MatrixType& m)
|
||||
VERIFY_IS_EQUAL( ((m1*1).template block<Dynamic,1>(1,0,0,1)), m1.block(1,0,0,1));
|
||||
VERIFY_IS_EQUAL( ((m1*1).template block<1,Dynamic>(0,1,1,0)), m1.block(0,1,1,0));
|
||||
|
||||
if (rows>=2 && cols>=2)
|
||||
{
|
||||
VERIFY_RAISES_ASSERT( m1 += m1.col(0) );
|
||||
VERIFY_RAISES_ASSERT( m1 -= m1.col(0) );
|
||||
VERIFY_RAISES_ASSERT( m1.array() *= m1.col(0).array() );
|
||||
VERIFY_RAISES_ASSERT( m1.array() /= m1.col(0).array() );
|
||||
}
|
||||
|
||||
VERIFY_IS_EQUAL( m1.template subVector<Horizontal>(r1), m1.row(r1) );
|
||||
VERIFY_IS_APPROX( (m1+m1).template subVector<Horizontal>(r1), (m1+m1).row(r1) );
|
||||
VERIFY_IS_EQUAL( m1.template subVector<Vertical>(c1), m1.col(c1) );
|
||||
@@ -240,13 +241,35 @@ template<typename MatrixType> void block(const MatrixType& m)
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename MatrixType>
|
||||
void compare_using_data_and_stride(const MatrixType& m)
|
||||
typename internal::enable_if<MatrixType::IsVectorAtCompileTime,void>::type
|
||||
compare_using_data_and_stride(const MatrixType& m)
|
||||
{
|
||||
Index rows = m.rows();
|
||||
Index cols = m.cols();
|
||||
Index size = m.size();
|
||||
Index innerStride = m.innerStride();
|
||||
Index rowStride = m.rowStride();
|
||||
Index colStride = m.colStride();
|
||||
const typename MatrixType::Scalar* data = m.data();
|
||||
|
||||
for(int j=0;j<cols;++j)
|
||||
for(int i=0;i<rows;++i)
|
||||
VERIFY(m.coeff(i,j) == data[i*rowStride + j*colStride]);
|
||||
|
||||
VERIFY(innerStride == int((&m.coeff(1))-(&m.coeff(0))));
|
||||
for (int i=0;i<size;++i)
|
||||
VERIFY(m.coeff(i) == data[i*innerStride]);
|
||||
}
|
||||
|
||||
template<typename MatrixType>
|
||||
typename internal::enable_if<!MatrixType::IsVectorAtCompileTime,void>::type
|
||||
compare_using_data_and_stride(const MatrixType& m)
|
||||
{
|
||||
Index rows = m.rows();
|
||||
Index cols = m.cols();
|
||||
Index innerStride = m.innerStride();
|
||||
Index outerStride = m.outerStride();
|
||||
Index rowStride = m.rowStride();
|
||||
Index colStride = m.colStride();
|
||||
@@ -256,21 +279,11 @@ void compare_using_data_and_stride(const MatrixType& m)
|
||||
for(int i=0;i<rows;++i)
|
||||
VERIFY(m.coeff(i,j) == data[i*rowStride + j*colStride]);
|
||||
|
||||
if(!MatrixType::IsVectorAtCompileTime)
|
||||
{
|
||||
for(int j=0;j<cols;++j)
|
||||
for(int i=0;i<rows;++i)
|
||||
VERIFY(m.coeff(i,j) == data[(MatrixType::Flags&RowMajorBit)
|
||||
? i*outerStride + j*innerStride
|
||||
: j*outerStride + i*innerStride]);
|
||||
}
|
||||
|
||||
if(MatrixType::IsVectorAtCompileTime)
|
||||
{
|
||||
VERIFY(innerStride == int((&m.coeff(1))-(&m.coeff(0))));
|
||||
for (int i=0;i<size;++i)
|
||||
VERIFY(m.coeff(i) == data[i*innerStride]);
|
||||
}
|
||||
for(int j=0;j<cols;++j)
|
||||
for(int i=0;i<rows;++i)
|
||||
VERIFY(m.coeff(i,j) == data[(MatrixType::Flags&RowMajorBit)
|
||||
? i*outerStride + j*innerStride
|
||||
: j*outerStride + i*innerStride]);
|
||||
}
|
||||
|
||||
template<typename MatrixType>
|
||||
|
||||
@@ -7,32 +7,8 @@
|
||||
// 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 EIGEN_NO_STATIC_ASSERT
|
||||
|
||||
#include "main.h"
|
||||
|
||||
template <typename Scalar>
|
||||
void assertionTest()
|
||||
{
|
||||
typedef DiagonalMatrix<Scalar, 5> DiagMatrix5;
|
||||
typedef DiagonalMatrix<Scalar, 7> DiagMatrix7;
|
||||
typedef DiagonalMatrix<Scalar, Dynamic> DiagMatrixX;
|
||||
|
||||
Scalar raw[6];
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
raw[i] = internal::random<Scalar>();
|
||||
}
|
||||
|
||||
VERIFY_RAISES_ASSERT((DiagMatrix5{raw[0], raw[1], raw[2], raw[3]}));
|
||||
VERIFY_RAISES_ASSERT((DiagMatrix5{raw[0], raw[1], raw[3]}));
|
||||
VERIFY_RAISES_ASSERT((DiagMatrix7{raw[0], raw[1], raw[2], raw[3]}));
|
||||
|
||||
VERIFY_RAISES_ASSERT((DiagMatrixX {
|
||||
{raw[0], raw[1], raw[2]},
|
||||
{raw[3], raw[4], raw[5]}
|
||||
}));
|
||||
}
|
||||
|
||||
#define VERIFY_IMPLICIT_CONVERSION_3(DIAGTYPE, V0, V1, V2) \
|
||||
DIAGTYPE d(V0, V1, V2); \
|
||||
DIAGTYPE::DenseMatrixType Dense = d.toDenseMatrix(); \
|
||||
@@ -167,14 +143,6 @@ void constructorTest<float>()
|
||||
|
||||
EIGEN_DECLARE_TEST(diagonal_matrix_variadic_ctor)
|
||||
{
|
||||
CALL_SUBTEST_1(assertionTest<unsigned char>());
|
||||
CALL_SUBTEST_1(assertionTest<float>());
|
||||
CALL_SUBTEST_1(assertionTest<Index>());
|
||||
CALL_SUBTEST_1(assertionTest<int>());
|
||||
CALL_SUBTEST_1(assertionTest<long int>());
|
||||
CALL_SUBTEST_1(assertionTest<std::ptrdiff_t>());
|
||||
CALL_SUBTEST_1(assertionTest<std::complex<double>>());
|
||||
|
||||
CALL_SUBTEST_2(constructorTest<unsigned char>());
|
||||
CALL_SUBTEST_2(constructorTest<float>());
|
||||
CALL_SUBTEST_2(constructorTest<Index>());
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
// 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 EIGEN_NO_STATIC_ASSERT
|
||||
|
||||
#include "main.h"
|
||||
|
||||
template<typename Scalar, bool is_integer = NumTraits<Scalar>::IsInteger>
|
||||
@@ -320,16 +318,6 @@ template<typename Scalar> void dynamicVectorConstruction()
|
||||
VERIFY(v.cols() == 1);
|
||||
VERIFY_IS_EQUAL(v, (VectorX {{raw[0], raw[1], raw[2], raw[3]}}));
|
||||
}
|
||||
|
||||
{
|
||||
VERIFY_RAISES_ASSERT((VectorX {raw[0], raw[1], raw[2], raw[3]}));
|
||||
}
|
||||
{
|
||||
VERIFY_RAISES_ASSERT((VectorX {
|
||||
{raw[0], raw[1], raw[2], raw[3]},
|
||||
{raw[0], raw[1], raw[2], raw[3]},
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(initializer_list_construction)
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
// 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 EIGEN_NO_STATIC_ASSERT
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#undef VERIFY_IS_APPROX
|
||||
|
||||
27
test/main.h
27
test/main.h
@@ -321,36 +321,10 @@ namespace Eigen
|
||||
#endif // EIGEN_EXCEPTIONS
|
||||
#endif // EIGEN_DEBUG_ASSERTS
|
||||
|
||||
#if defined(TEST_CHECK_STATIC_ASSERTIONS) && defined(EIGEN_EXCEPTIONS)
|
||||
#define EIGEN_STATIC_ASSERT(a,MSG) \
|
||||
if( (!Eigen::internal::copy_bool(a)) && (!no_more_assert) )\
|
||||
{ \
|
||||
Eigen::no_more_assert = true; \
|
||||
if(report_on_cerr_on_assert_failure) \
|
||||
eigen_plain_assert((a) && #MSG); \
|
||||
else \
|
||||
EIGEN_THROW_X(Eigen::eigen_static_assert_exception()); \
|
||||
}
|
||||
#define VERIFY_RAISES_STATIC_ASSERT(a) { \
|
||||
Eigen::no_more_assert = false; \
|
||||
Eigen::report_on_cerr_on_assert_failure = false; \
|
||||
try { \
|
||||
a; \
|
||||
VERIFY(Eigen::should_raise_an_assert && # a); \
|
||||
} \
|
||||
catch (Eigen::eigen_static_assert_exception&) { VERIFY(true); } \
|
||||
Eigen::report_on_cerr_on_assert_failure = true; \
|
||||
}
|
||||
#endif // TEST_CHECK_STATIC_ASSERTIONS
|
||||
|
||||
#ifndef VERIFY_RAISES_ASSERT
|
||||
#define VERIFY_RAISES_ASSERT(a) \
|
||||
std::cout << "Can't VERIFY_RAISES_ASSERT( " #a " ) with exceptions disabled\n";
|
||||
#endif
|
||||
#ifndef VERIFY_RAISES_STATIC_ASSERT
|
||||
#define VERIFY_RAISES_STATIC_ASSERT(a) \
|
||||
std::cout << "Can't VERIFY_RAISES_STATIC_ASSERT( " #a " ) with exceptions disabled\n";
|
||||
#endif
|
||||
|
||||
#if !defined(__CUDACC__) && !defined(__HIPCC__) && !defined(SYCL_DEVICE_ONLY)
|
||||
#define EIGEN_USE_CUSTOM_ASSERT
|
||||
@@ -359,7 +333,6 @@ namespace Eigen
|
||||
#else // EIGEN_NO_ASSERTION_CHECKING
|
||||
|
||||
#define VERIFY_RAISES_ASSERT(a) {}
|
||||
#define VERIFY_RAISES_STATIC_ASSERT(a) {}
|
||||
|
||||
#endif // EIGEN_NO_ASSERTION_CHECKING
|
||||
|
||||
|
||||
@@ -7,10 +7,6 @@
|
||||
// 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/.
|
||||
|
||||
#ifndef EIGEN_NO_STATIC_ASSERT
|
||||
#define EIGEN_NO_STATIC_ASSERT // turn static asserts into runtime asserts in order to check them
|
||||
#endif
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#define EIGEN_TESTMAP_MAX_SIZE 256
|
||||
|
||||
@@ -10,10 +10,6 @@
|
||||
|
||||
#if defined(EIGEN_TEST_PART_7)
|
||||
|
||||
#ifndef EIGEN_NO_STATIC_ASSERT
|
||||
#define EIGEN_NO_STATIC_ASSERT // turn static asserts into runtime asserts in order to check them
|
||||
#endif
|
||||
|
||||
// ignore double-promotion diagnostic for clang and gcc, if we check for static assertion anyway:
|
||||
// TODO do the same for MSVC?
|
||||
#if defined(__clang__)
|
||||
@@ -49,28 +45,6 @@ using namespace std;
|
||||
VERIFY_IS_APPROX(XPR,REF); \
|
||||
VERIFY( g_called && #XPR" not properly optimized");
|
||||
|
||||
template<int SizeAtCompileType>
|
||||
void raise_assertion(Index size = SizeAtCompileType)
|
||||
{
|
||||
// VERIFY_RAISES_ASSERT(mf+md); // does not even compile
|
||||
Matrix<float, SizeAtCompileType, 1> vf; vf.setRandom(size);
|
||||
Matrix<double, SizeAtCompileType, 1> vd; vd.setRandom(size);
|
||||
VERIFY_RAISES_ASSERT(vf=vd);
|
||||
VERIFY_RAISES_ASSERT(vf+=vd);
|
||||
VERIFY_RAISES_ASSERT(vf-=vd);
|
||||
VERIFY_RAISES_ASSERT(vd=vf);
|
||||
VERIFY_RAISES_ASSERT(vd+=vf);
|
||||
VERIFY_RAISES_ASSERT(vd-=vf);
|
||||
|
||||
// vd.asDiagonal() * mf; // does not even compile
|
||||
// vcd.asDiagonal() * mf; // does not even compile
|
||||
|
||||
#if 0 // we get other compilation errors here than just static asserts
|
||||
VERIFY_RAISES_ASSERT(vd.dot(vf));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
template<int SizeAtCompileType> void mixingtypes(int size = SizeAtCompileType)
|
||||
{
|
||||
typedef std::complex<float> CF;
|
||||
@@ -320,10 +294,5 @@ EIGEN_DECLARE_TEST(mixingtypes)
|
||||
CALL_SUBTEST_4(mixingtypes<3>());
|
||||
CALL_SUBTEST_5(mixingtypes<4>());
|
||||
CALL_SUBTEST_6(mixingtypes<Dynamic>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE)));
|
||||
CALL_SUBTEST_7(raise_assertion<Dynamic>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE)));
|
||||
}
|
||||
CALL_SUBTEST_7(raise_assertion<0>());
|
||||
CALL_SUBTEST_7(raise_assertion<3>());
|
||||
CALL_SUBTEST_7(raise_assertion<4>());
|
||||
CALL_SUBTEST_7(raise_assertion<Dynamic>(0));
|
||||
}
|
||||
|
||||
@@ -17,6 +17,17 @@ bool areNotApprox(const MatrixBase<Derived1>& m1, const MatrixBase<Derived2>& m2
|
||||
* (std::max)(m1.cwiseAbs2().maxCoeff(), m2.cwiseAbs2().maxCoeff()));
|
||||
}
|
||||
|
||||
template <typename LhsType, typename RhsType>
|
||||
typename internal::enable_if<RhsType::SizeAtCompileTime==Dynamic,void>::type
|
||||
check_mismatched_product(LhsType& lhs, const RhsType& rhs) {
|
||||
VERIFY_RAISES_ASSERT(lhs = rhs*rhs);
|
||||
}
|
||||
|
||||
template <typename LhsType, typename RhsType>
|
||||
typename internal::enable_if<RhsType::SizeAtCompileTime!=Dynamic,void>::type
|
||||
check_mismatched_product(LhsType& /*unused*/, const RhsType& /*unused*/) {
|
||||
}
|
||||
|
||||
template<typename MatrixType> void product(const MatrixType& m)
|
||||
{
|
||||
/* this test covers the following files:
|
||||
@@ -77,8 +88,9 @@ template<typename MatrixType> void product(const MatrixType& m)
|
||||
// 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);
|
||||
if (rows!=cols) {
|
||||
check_mismatched_product(m3, m1);
|
||||
}
|
||||
|
||||
// test the previous tests were not screwed up because operator* returns 0
|
||||
// (we use the more accurate default epsilon)
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
// 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 EIGEN_NO_STATIC_ASSERT
|
||||
#include "product.h"
|
||||
#include <Eigen/LU>
|
||||
|
||||
|
||||
15
test/ref.cpp
15
test/ref.cpp
@@ -106,9 +106,6 @@ template<typename VectorType> void ref_vector(const VectorType& m)
|
||||
{ RefMat rm0 = v1.block(0,0,size,1); VERIFY_IS_EQUAL(rm0, v1); }
|
||||
{ RefDynMat rv1 = v1; VERIFY_IS_EQUAL(rv1, v1); }
|
||||
{ RefDynMat rv1 = v1.block(0,0,size,1); VERIFY_IS_EQUAL(rv1, v1); }
|
||||
{ VERIFY_RAISES_ASSERT( RefMat rm0 = v1.block(0, 0, size, 0); EIGEN_UNUSED_VARIABLE(rm0); ); }
|
||||
if(VectorType::SizeAtCompileTime!=1)
|
||||
{ VERIFY_RAISES_ASSERT( RefDynMat rv1 = v1.block(0, 0, size, 0); EIGEN_UNUSED_VARIABLE(rv1); ); }
|
||||
|
||||
RefDynMat rv2 = v1.segment(i,bsize);
|
||||
VERIFY_IS_EQUAL(rv2, v1.segment(i,bsize));
|
||||
@@ -320,17 +317,6 @@ void test_ref_overloads()
|
||||
test_ref_ambiguous(A, B);
|
||||
}
|
||||
|
||||
void test_ref_fixed_size_assert()
|
||||
{
|
||||
Vector4f v4 = Vector4f::Random();
|
||||
VectorXf vx = VectorXf::Random(10);
|
||||
VERIFY_RAISES_STATIC_ASSERT( Ref<Vector3f> y = v4; (void)y; );
|
||||
VERIFY_RAISES_STATIC_ASSERT( Ref<Vector3f> y = vx.head<4>(); (void)y; );
|
||||
VERIFY_RAISES_STATIC_ASSERT( Ref<const Vector3f> y = v4; (void)y; );
|
||||
VERIFY_RAISES_STATIC_ASSERT( Ref<const Vector3f> y = vx.head<4>(); (void)y; );
|
||||
VERIFY_RAISES_STATIC_ASSERT( Ref<const Vector3f> y = 2*v4; (void)y; );
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(ref)
|
||||
{
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
@@ -356,5 +342,4 @@ EIGEN_DECLARE_TEST(ref)
|
||||
}
|
||||
|
||||
CALL_SUBTEST_7( test_ref_overloads() );
|
||||
CALL_SUBTEST_7( test_ref_fixed_size_assert() );
|
||||
}
|
||||
|
||||
@@ -45,9 +45,6 @@ template<typename MatrixType> void selfadjoint(const MatrixType& m)
|
||||
m4 = m2;
|
||||
m4 -= m1.template selfadjointView<Lower>();
|
||||
VERIFY_IS_APPROX(m4, m2-m3);
|
||||
|
||||
VERIFY_RAISES_STATIC_ASSERT(m2.template selfadjointView<StrictlyUpper>());
|
||||
VERIFY_RAISES_STATIC_ASSERT(m2.template selfadjointView<UnitLower>());
|
||||
}
|
||||
|
||||
void bug_159()
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
// 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 EIGEN_NO_STATIC_ASSERT
|
||||
#include "main.h"
|
||||
|
||||
template<typename Scalar> void smallVectors()
|
||||
@@ -33,28 +32,11 @@ template<typename Scalar> void smallVectors()
|
||||
VERIFY_IS_APPROX(x3, v4.z());
|
||||
VERIFY_IS_APPROX(x4, v4.w());
|
||||
|
||||
if (!NumTraits<Scalar>::IsInteger)
|
||||
{
|
||||
VERIFY_RAISES_ASSERT(V3(2, 1))
|
||||
VERIFY_RAISES_ASSERT(V3(3, 2))
|
||||
VERIFY_RAISES_ASSERT(V3(Scalar(3), 1))
|
||||
VERIFY_RAISES_ASSERT(V3(3, Scalar(1)))
|
||||
VERIFY_RAISES_ASSERT(V3(Scalar(3), Scalar(1)))
|
||||
VERIFY_RAISES_ASSERT(V3(Scalar(123), Scalar(123)))
|
||||
|
||||
VERIFY_RAISES_ASSERT(V4(1, 3))
|
||||
VERIFY_RAISES_ASSERT(V4(2, 4))
|
||||
VERIFY_RAISES_ASSERT(V4(1, Scalar(4)))
|
||||
VERIFY_RAISES_ASSERT(V4(Scalar(1), 4))
|
||||
VERIFY_RAISES_ASSERT(V4(Scalar(1), Scalar(4)))
|
||||
VERIFY_RAISES_ASSERT(V4(Scalar(123), Scalar(123)))
|
||||
|
||||
VERIFY_RAISES_ASSERT(VX(3, 2))
|
||||
VERIFY_RAISES_ASSERT(VX(Scalar(3), 1))
|
||||
VERIFY_RAISES_ASSERT(VX(3, Scalar(1)))
|
||||
VERIFY_RAISES_ASSERT(VX(Scalar(3), Scalar(1)))
|
||||
VERIFY_RAISES_ASSERT(VX(Scalar(123), Scalar(123)))
|
||||
}
|
||||
VERIFY_RAISES_ASSERT(V3(2, 1))
|
||||
VERIFY_RAISES_ASSERT(V3(3, 2))
|
||||
VERIFY_RAISES_ASSERT(V4(1, 3))
|
||||
VERIFY_RAISES_ASSERT(V4(2, 4))
|
||||
VERIFY_RAISES_ASSERT(VX(3, 2))
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(smallvectors)
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
// 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 EIGEN_NO_STATIC_ASSERT
|
||||
#include "main.h"
|
||||
|
||||
template<typename T>
|
||||
@@ -22,6 +21,20 @@ struct other_matrix_type<Matrix<Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCo
|
||||
typedef Matrix<Scalar_, Rows_, Cols_, Options_^RowMajor, MaxRows_, MaxCols_> type;
|
||||
};
|
||||
|
||||
template <typename MatrixType>
|
||||
typename internal::enable_if<(MatrixType::RowsAtCompileTime==1 || MatrixType::RowsAtCompileTime==Dynamic), void>::type
|
||||
check_row_swap(MatrixType& m1) {
|
||||
// test assertion on mismatching size -- matrix case
|
||||
VERIFY_RAISES_ASSERT(m1.swap(m1.row(0)));
|
||||
// test assertion on mismatching size -- xpr case
|
||||
VERIFY_RAISES_ASSERT(m1.row(0).swap(m1));
|
||||
}
|
||||
|
||||
template <typename MatrixType>
|
||||
typename internal::enable_if<!(MatrixType::RowsAtCompileTime==1 || MatrixType::RowsAtCompileTime==Dynamic), void>::type
|
||||
check_row_swap(MatrixType& /* unused */) {
|
||||
}
|
||||
|
||||
template<typename MatrixType> void swap(const MatrixType& m)
|
||||
{
|
||||
typedef typename other_matrix_type<MatrixType>::type OtherMatrixType;
|
||||
@@ -73,14 +86,8 @@ template<typename MatrixType> void swap(const MatrixType& m)
|
||||
VERIFY_IS_APPROX(m3,m1_copy);
|
||||
m1 = m1_copy;
|
||||
m3 = m3_copy;
|
||||
|
||||
if(m1.rows()>1)
|
||||
{
|
||||
// test assertion on mismatching size -- matrix case
|
||||
VERIFY_RAISES_ASSERT(m1.swap(m1.row(0)));
|
||||
// test assertion on mismatching size -- xpr case
|
||||
VERIFY_RAISES_ASSERT(m1.row(0).swap(m1));
|
||||
}
|
||||
|
||||
check_row_swap(m1);
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(swap)
|
||||
|
||||
@@ -139,7 +139,6 @@ template<typename MatrixType> void triangular_square(const MatrixType& m)
|
||||
m3.setZero();
|
||||
m3.template triangularView<Upper>().setOnes();
|
||||
VERIFY_IS_APPROX(m2,m3);
|
||||
VERIFY_RAISES_STATIC_ASSERT(m1.template triangularView<Eigen::Lower>().swap(m2.template triangularView<Eigen::Upper>()));
|
||||
|
||||
m1.setRandom();
|
||||
m3 = m1.template triangularView<Upper>();
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#define TEST_ENABLE_TEMPORARY_TRACKING
|
||||
#define EIGEN_NO_STATIC_ASSERT
|
||||
|
||||
#include "main.h"
|
||||
|
||||
@@ -32,77 +31,49 @@ template<typename ArrayType> void vectorwiseop_array(const ArrayType& m)
|
||||
RowVectorType rowvec = RowVectorType::Random(cols);
|
||||
|
||||
// test addition
|
||||
|
||||
m2 = m1;
|
||||
m2.colwise() += colvec;
|
||||
VERIFY_IS_APPROX(m2, m1.colwise() + colvec);
|
||||
VERIFY_IS_APPROX(m2.col(c), m1.col(c) + colvec);
|
||||
|
||||
VERIFY_RAISES_ASSERT(m2.colwise() += colvec.transpose());
|
||||
VERIFY_RAISES_ASSERT(m1.colwise() + colvec.transpose());
|
||||
|
||||
m2 = m1;
|
||||
m2.rowwise() += rowvec;
|
||||
VERIFY_IS_APPROX(m2, m1.rowwise() + rowvec);
|
||||
VERIFY_IS_APPROX(m2.row(r), m1.row(r) + rowvec);
|
||||
|
||||
VERIFY_RAISES_ASSERT(m2.rowwise() += rowvec.transpose());
|
||||
VERIFY_RAISES_ASSERT(m1.rowwise() + rowvec.transpose());
|
||||
|
||||
// test substraction
|
||||
|
||||
m2 = m1;
|
||||
m2.colwise() -= colvec;
|
||||
VERIFY_IS_APPROX(m2, m1.colwise() - colvec);
|
||||
VERIFY_IS_APPROX(m2.col(c), m1.col(c) - colvec);
|
||||
|
||||
VERIFY_RAISES_ASSERT(m2.colwise() -= colvec.transpose());
|
||||
VERIFY_RAISES_ASSERT(m1.colwise() - colvec.transpose());
|
||||
|
||||
m2 = m1;
|
||||
m2.rowwise() -= rowvec;
|
||||
VERIFY_IS_APPROX(m2, m1.rowwise() - rowvec);
|
||||
VERIFY_IS_APPROX(m2.row(r), m1.row(r) - rowvec);
|
||||
|
||||
VERIFY_RAISES_ASSERT(m2.rowwise() -= rowvec.transpose());
|
||||
VERIFY_RAISES_ASSERT(m1.rowwise() - rowvec.transpose());
|
||||
|
||||
// test multiplication
|
||||
|
||||
m2 = m1;
|
||||
m2.colwise() *= colvec;
|
||||
VERIFY_IS_APPROX(m2, m1.colwise() * colvec);
|
||||
VERIFY_IS_APPROX(m2.col(c), m1.col(c) * colvec);
|
||||
|
||||
VERIFY_RAISES_ASSERT(m2.colwise() *= colvec.transpose());
|
||||
VERIFY_RAISES_ASSERT(m1.colwise() * colvec.transpose());
|
||||
|
||||
m2 = m1;
|
||||
m2.rowwise() *= rowvec;
|
||||
VERIFY_IS_APPROX(m2, m1.rowwise() * rowvec);
|
||||
VERIFY_IS_APPROX(m2.row(r), m1.row(r) * rowvec);
|
||||
|
||||
VERIFY_RAISES_ASSERT(m2.rowwise() *= rowvec.transpose());
|
||||
VERIFY_RAISES_ASSERT(m1.rowwise() * rowvec.transpose());
|
||||
|
||||
// test quotient
|
||||
|
||||
m2 = m1;
|
||||
m2.colwise() /= colvec;
|
||||
VERIFY_IS_APPROX(m2, m1.colwise() / colvec);
|
||||
VERIFY_IS_APPROX(m2.col(c), m1.col(c) / colvec);
|
||||
|
||||
VERIFY_RAISES_ASSERT(m2.colwise() /= colvec.transpose());
|
||||
VERIFY_RAISES_ASSERT(m1.colwise() / colvec.transpose());
|
||||
|
||||
m2 = m1;
|
||||
m2.rowwise() /= rowvec;
|
||||
VERIFY_IS_APPROX(m2, m1.rowwise() / rowvec);
|
||||
VERIFY_IS_APPROX(m2.row(r), m1.row(r) / rowvec);
|
||||
|
||||
VERIFY_RAISES_ASSERT(m2.rowwise() /= rowvec.transpose());
|
||||
VERIFY_RAISES_ASSERT(m1.rowwise() / rowvec.transpose());
|
||||
|
||||
m2 = m1;
|
||||
// yes, there might be an aliasing issue there but ".rowwise() /="
|
||||
// is supposed to evaluate " m2.colwise().sum()" into a temporary to avoid
|
||||
@@ -158,58 +129,30 @@ template<typename MatrixType> void vectorwiseop_matrix(const MatrixType& m)
|
||||
m2.rowwise() = rowvec;
|
||||
for(Index i=0; i<rows; ++i)
|
||||
VERIFY_IS_APPROX(m2.row(i), rowvec);
|
||||
if(rows>1)
|
||||
VERIFY_RAISES_ASSERT(m2.colwise() = colvec.transpose());
|
||||
if(cols>1)
|
||||
VERIFY_RAISES_ASSERT(m2.rowwise() = rowvec.transpose());
|
||||
|
||||
// test addition
|
||||
|
||||
m2 = m1;
|
||||
m2.colwise() += colvec;
|
||||
VERIFY_IS_APPROX(m2, m1.colwise() + colvec);
|
||||
VERIFY_IS_APPROX(m2.col(c), m1.col(c) + colvec);
|
||||
|
||||
if(rows>1)
|
||||
{
|
||||
VERIFY_RAISES_ASSERT(m2.colwise() += colvec.transpose());
|
||||
VERIFY_RAISES_ASSERT(m1.colwise() + colvec.transpose());
|
||||
}
|
||||
|
||||
m2 = m1;
|
||||
m2.rowwise() += rowvec;
|
||||
VERIFY_IS_APPROX(m2, m1.rowwise() + rowvec);
|
||||
VERIFY_IS_APPROX(m2.row(r), m1.row(r) + rowvec);
|
||||
|
||||
if(cols>1)
|
||||
{
|
||||
VERIFY_RAISES_ASSERT(m2.rowwise() += rowvec.transpose());
|
||||
VERIFY_RAISES_ASSERT(m1.rowwise() + rowvec.transpose());
|
||||
}
|
||||
|
||||
// test substraction
|
||||
|
||||
m2 = m1;
|
||||
m2.colwise() -= colvec;
|
||||
VERIFY_IS_APPROX(m2, m1.colwise() - colvec);
|
||||
VERIFY_IS_APPROX(m2.col(c), m1.col(c) - colvec);
|
||||
|
||||
if(rows>1)
|
||||
{
|
||||
VERIFY_RAISES_ASSERT(m2.colwise() -= colvec.transpose());
|
||||
VERIFY_RAISES_ASSERT(m1.colwise() - colvec.transpose());
|
||||
}
|
||||
|
||||
m2 = m1;
|
||||
m2.rowwise() -= rowvec;
|
||||
VERIFY_IS_APPROX(m2, m1.rowwise() - rowvec);
|
||||
VERIFY_IS_APPROX(m2.row(r), m1.row(r) - rowvec);
|
||||
|
||||
if(cols>1)
|
||||
{
|
||||
VERIFY_RAISES_ASSERT(m2.rowwise() -= rowvec.transpose());
|
||||
VERIFY_RAISES_ASSERT(m1.rowwise() - rowvec.transpose());
|
||||
}
|
||||
|
||||
// ------ partial reductions ------
|
||||
|
||||
@@ -272,11 +215,8 @@ template<typename MatrixType> void vectorwiseop_matrix(const MatrixType& m)
|
||||
VERIFY_IS_APPROX(m1.matrix().middleRows(0,0).colwise().prod().eval(), MatrixX::Ones(1,cols));
|
||||
VERIFY_IS_APPROX(m1.matrix().middleCols(0,fix<0>).rowwise().prod().eval(), MatrixX::Ones(rows,1));
|
||||
VERIFY_IS_APPROX(m1.matrix().middleRows(0,fix<0>).colwise().prod().eval(), MatrixX::Ones(1,cols));
|
||||
|
||||
VERIFY_IS_APPROX(m1.matrix().middleCols(0,0).rowwise().squaredNorm().eval(), MatrixX::Zero(rows,1));
|
||||
|
||||
VERIFY_RAISES_ASSERT(m1.real().middleCols(0,0).rowwise().minCoeff().eval());
|
||||
VERIFY_RAISES_ASSERT(m1.real().middleRows(0,0).colwise().maxCoeff().eval());
|
||||
VERIFY_IS_EQUAL(m1.real().middleRows(0,0).rowwise().maxCoeff().eval().rows(),0);
|
||||
VERIFY_IS_EQUAL(m1.real().middleCols(0,0).colwise().maxCoeff().eval().cols(),0);
|
||||
VERIFY_IS_EQUAL(m1.real().middleRows(0,fix<0>).rowwise().maxCoeff().eval().rows(),0);
|
||||
|
||||
Reference in New Issue
Block a user