aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2008-11-03 22:47:00 +0000
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2008-11-03 22:47:00 +0000
commite80099932a0fafed4b6473dec5e8d83deac44799 (patch)
tree14cae6ad67cc2e8a61fcf579fcc2e8915c722bbf /test
parenta0ec0fca5ae4469e516b15910c80af5a46073cbe (diff)
add lpNorm<p>() method to MatrixBase, implemented in Array module, with
specializations for cases p=1,2,Eigen::Infinity.
Diffstat (limited to 'test')
-rw-r--r--test/array.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/array.cpp b/test/array.cpp
index 977449365..e1047489d 100644
--- a/test/array.cpp
+++ b/test/array.cpp
@@ -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)) );
+ }
}