mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
bug #1193: fix lpNorm<Infinity> for empty input.
This commit is contained in:
@@ -144,9 +144,21 @@ template<typename MatrixType> void comparisons(const MatrixType& m)
|
||||
template<typename VectorType> void lpNorm(const VectorType& v)
|
||||
{
|
||||
using std::sqrt;
|
||||
typedef typename VectorType::RealScalar RealScalar;
|
||||
VectorType u = VectorType::Random(v.size());
|
||||
|
||||
VERIFY_IS_APPROX(u.template lpNorm<Infinity>(), u.cwiseAbs().maxCoeff());
|
||||
if(v.size()==0)
|
||||
{
|
||||
VERIFY_IS_APPROX(u.template lpNorm<Infinity>(), RealScalar(0));
|
||||
VERIFY_IS_APPROX(u.template lpNorm<1>(), RealScalar(0));
|
||||
VERIFY_IS_APPROX(u.template lpNorm<2>(), RealScalar(0));
|
||||
VERIFY_IS_APPROX(u.template lpNorm<5>(), RealScalar(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
VERIFY_IS_APPROX(u.template lpNorm<Infinity>(), u.cwiseAbs().maxCoeff());
|
||||
}
|
||||
|
||||
VERIFY_IS_APPROX(u.template lpNorm<1>(), u.cwiseAbs().sum());
|
||||
VERIFY_IS_APPROX(u.template lpNorm<2>(), sqrt(u.array().abs().square().sum()));
|
||||
VERIFY_IS_APPROX(numext::pow(u.template lpNorm<5>(), typename VectorType::RealScalar(5)), u.array().abs().pow(5).sum());
|
||||
@@ -255,6 +267,8 @@ void test_array_for_matrix()
|
||||
CALL_SUBTEST_5( lpNorm(VectorXf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
|
||||
CALL_SUBTEST_4( lpNorm(VectorXcf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
|
||||
}
|
||||
CALL_SUBTEST_5( lpNorm(VectorXf(0)) );
|
||||
CALL_SUBTEST_4( lpNorm(VectorXcf(0)) );
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
CALL_SUBTEST_4( resize(MatrixXcf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
|
||||
CALL_SUBTEST_5( resize(MatrixXf(internal::random<int>(1,EIGEN_TEST_MAX_SIZE), internal::random<int>(1,EIGEN_TEST_MAX_SIZE))) );
|
||||
|
||||
Reference in New Issue
Block a user