mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
add lpNorm<p>() method to MatrixBase, implemented in Array module, with
specializations for cases p=1,2,Eigen::Infinity.
This commit is contained in:
@@ -113,6 +113,16 @@ template<typename MatrixType> void comparisons(const MatrixType& m)
|
||||
VERIFY_IS_APPROX( (m1.cwise().abs().cwise()<mid).select(0,m1), m3);
|
||||
}
|
||||
|
||||
template<typename VectorType> void lpNorm(const VectorType& v)
|
||||
{
|
||||
VectorType u = VectorType::Random(v.size());
|
||||
|
||||
VERIFY_IS_APPROX(u.template lpNorm<Infinity>(), u.cwise().abs().maxCoeff());
|
||||
VERIFY_IS_APPROX(u.template lpNorm<1>(), u.cwise().abs().sum());
|
||||
VERIFY_IS_APPROX(u.template lpNorm<2>(), ei_sqrt(u.cwise().abs().cwise().square().sum()));
|
||||
VERIFY_IS_APPROX(ei_pow(u.template lpNorm<5>(), typename VectorType::RealScalar(5)), u.cwise().abs().cwise().pow(5).sum());
|
||||
}
|
||||
|
||||
void test_array()
|
||||
{
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
@@ -130,4 +140,12 @@ void test_array()
|
||||
CALL_SUBTEST( comparisons(MatrixXf(8, 12)) );
|
||||
CALL_SUBTEST( comparisons(MatrixXi(8, 12)) );
|
||||
}
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
CALL_SUBTEST( lpNorm(Matrix<float, 1, 1>()) );
|
||||
CALL_SUBTEST( lpNorm(Vector2f()) );
|
||||
CALL_SUBTEST( lpNorm(Vector3d()) );
|
||||
CALL_SUBTEST( lpNorm(Vector4f()) );
|
||||
CALL_SUBTEST( lpNorm(VectorXf(16)) );
|
||||
CALL_SUBTEST( lpNorm(VectorXcd(10)) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user