From 28999ba720844c86447ef4273dfc586b31a72e4e Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Thu, 21 Jun 2018 15:48:59 +0200 Subject: [PATCH] l2Norm(TinyVector) - checks that vector data is floating point - adds unit test --- src/algebra/TinyVector.hpp | 1 + tests/test_TinyVector.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/algebra/TinyVector.hpp b/src/algebra/TinyVector.hpp index 6f09691d1..88f200720 100644 --- a/src/algebra/TinyVector.hpp +++ b/src/algebra/TinyVector.hpp @@ -243,6 +243,7 @@ KOKKOS_INLINE_FUNCTION T l2Norm(const TinyVector<N,T>& x) { static_assert(std::is_arithmetic<T>(),"Cannot compute L2 norm for non-arithmetic types"); + static_assert(std::is_floating_point<T>::value, "L2 norm is defined for floating point types only"); return std::sqrt((x,x)); } diff --git a/tests/test_TinyVector.cpp b/tests/test_TinyVector.cpp index 3dd124cd3..8f10f0127 100644 --- a/tests/test_TinyVector.cpp +++ b/tests/test_TinyVector.cpp @@ -65,6 +65,8 @@ TEST_CASE("TinyVector", "[algebra]") { TinyVector<3,int> z1; z1 = zero; REQUIRE(((z1[0] == 0) and (z1[1] == 0) and (z1[2] == 0))); + REQUIRE(l2Norm(TinyVector<2,double>(3,4)) == Approx(5).epsilon(1E-14)); + #ifndef NDEBUG REQUIRE_THROWS_AS(x[4]=0, AssertError); const TinyVector<3,int>& const_x = x; -- GitLab