Skip to content
Snippets Groups Projects
Commit 28999ba7 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

l2Norm(TinyVector)

- checks that vector data is floating point
- adds unit test
parent 5bd71de2
Branches
Tags
No related merge requests found
......@@ -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));
}
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment