// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2010-2011 Jitse Niesen <jitse@maths.leeds.ac.uk> // Copyright (C) 2016 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/.
#include"main.h"
template<typename MatrixType> bool equalsIdentity(const MatrixType& A)
{ typedeftypename MatrixType::Scalar Scalar;
Scalar zero = static_cast<Scalar>(0);
bool offDiagOK = true; for (Index i = 0; i < A.rows(); ++i) { for (Index j = i+1; j < A.cols(); ++j) {
offDiagOK = offDiagOK && (A(i,j) == zero);
}
} for (Index i = 0; i < A.rows(); ++i) { for (Index j = 0; j < (std::min)(i, A.cols()); ++j) {
offDiagOK = offDiagOK && (A(i,j) == zero);
}
}
// 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(size,low,high);
col_vector.setLinSpaced(size,low,high); // when using the extended precision (e.g., FPU) the relative error might exceed 1 bit // when computing the squared sum in isApprox, thus the 2x factor.
VERIFY( row_vector.isApprox(col_vector.transpose(), RealScalar(2)*NumTraits<Scalar>::epsilon()));
// test setUnit() if(m.size()>0)
{ for(Index k=0; k<10; ++k)
{
Index i = internal::random<Index>(0,m.size()-1);
m.setUnit(i);
VERIFY_IS_APPROX( m, VectorType::Unit(m.size(), i) );
} if(VectorType::SizeAtCompileTime==Dynamic)
{
Index i = internal::random<Index>(0,2*m.size()-1);
m.setUnit(2*m.size(),i);
VERIFY_IS_APPROX( m, VectorType::Unit(m.size(),i) );
}
}
}
template<typename MatrixType> void testMatrixType(const MatrixType& m)
{ using std::abs; const Index rows = m.rows(); const Index cols = m.cols(); typedeftypename MatrixType::Scalar Scalar; typedeftypename MatrixType::RealScalar RealScalar;
A = MatrixType::Constant(rows,cols,s1);
Index i = internal::random<Index>(0,rows-1);
Index j = internal::random<Index>(0,cols-1);
VERIFY_IS_APPROX( MatrixType::Constant(rows,cols,s1)(i,j), s1 );
VERIFY_IS_APPROX( MatrixType::Constant(rows,cols,s1).coeff(i,j), s1 );
VERIFY_IS_APPROX( A(i,j), s1 );
}
template<int> void bug79()
{ // Assignment of a RowVectorXd to a MatrixXd (regression test for bug #79).
VERIFY( (MatrixXd(RowVectorXd::LinSpaced(3, 0, 1)) - RowVector3d(0, 0.5, 1)).norm() < std::numeric_limits<double>::epsilon() );
}
// Regression unit test for a weird MSVC bug. // Search "nullary_wrapper_workaround_msvc" in CoreEvaluators.h for the details. // See also traits<Ref>::match.
{
MatrixXf A = MatrixXf::Random(3,3);
Ref<const MatrixXf> R = 2.0*A;
VERIFY_IS_APPROX(R, A+A);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.