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

Merge branch 'develop' of gitlab.delpinux.fr:code/pastis into develop

parents 5970b13c 05ded8e9
No related branches found
No related tags found
No related merge requests found
...@@ -160,7 +160,14 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Coverage") ...@@ -160,7 +160,14 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Coverage")
set(GCOVR_EXTRA "--gcov-executable=${LLVM_COV} gcov") set(GCOVR_EXTRA "--gcov-executable=${LLVM_COV} gcov")
endif() endif()
set(GCOVR_OPTIONS --object-directory="${PASTIS_BINARY_DIR}" -r "${PASTIS_SOURCE_DIR}/src" -e "${PASTIS_SOURCE_DIR}/src/experimental" -e "${PASTIS_SOURCE_DIR}/src/main.cpp" ${GCOVR_EXTRA}) set (GCOVR_EXCLUDE
-e "${PASTIS_SOURCE_DIR}/src/experimental"
-e "${PASTIS_SOURCE_DIR}/src/main.cpp"
-e "${PASTIS_SOURCE_DIR}/src/utils/BacktraceManager.cpp"
-e "${PASTIS_SOURCE_DIR}/src/utils/BacktraceManager.hpp"
)
set(GCOVR_OPTIONS --object-directory="${PASTIS_BINARY_DIR}" -r "${PASTIS_SOURCE_DIR}/src" ${GCOVR_EXCLUDE} ${GCOVR_EXTRA})
add_custom_target(run_unit_tests add_custom_target(run_unit_tests
ALL ALL
......
...@@ -99,6 +99,21 @@ public: ...@@ -99,6 +99,21 @@ public:
return os; return os;
} }
KOKKOS_INLINE_FUNCTION
bool operator==(const TinyMatrix& A) const
{
for (size_t i=0; i<N*N; ++i) {
if (m_values[i] != A.m_values[i]) return false;
}
return true;
}
KOKKOS_INLINE_FUNCTION
bool operator!=(const TinyMatrix& A) const
{
return not this->operator==(A);
}
KOKKOS_INLINE_FUNCTION KOKKOS_INLINE_FUNCTION
TinyMatrix operator+(const TinyMatrix& A) const TinyMatrix operator+(const TinyMatrix& A) const
{ {
...@@ -174,7 +189,7 @@ public: ...@@ -174,7 +189,7 @@ public:
} }
KOKKOS_INLINE_FUNCTION KOKKOS_INLINE_FUNCTION
const TinyMatrix& operator=(const TinyMatrix& A) TinyMatrix& operator=(const TinyMatrix& A)
{ {
for (size_t i=0; i<N*N; ++i) { for (size_t i=0; i<N*N; ++i) {
m_values[i] = A.m_values[i]; m_values[i] = A.m_values[i];
...@@ -194,10 +209,7 @@ public: ...@@ -194,10 +209,7 @@ public:
} }
KOKKOS_INLINE_FUNCTION KOKKOS_INLINE_FUNCTION
TinyMatrix() TinyMatrix()=default;
{
;
}
KOKKOS_INLINE_FUNCTION KOKKOS_INLINE_FUNCTION
TinyMatrix(const ZeroType& z) TinyMatrix(const ZeroType& z)
...@@ -231,10 +243,7 @@ public: ...@@ -231,10 +243,7 @@ public:
TinyMatrix(TinyMatrix&& A) = default; TinyMatrix(TinyMatrix&& A) = default;
KOKKOS_INLINE_FUNCTION KOKKOS_INLINE_FUNCTION
~TinyMatrix() ~TinyMatrix()=default;
{
;
}
}; };
template <size_t N, typename T> template <size_t N, typename T>
...@@ -256,17 +265,18 @@ KOKKOS_INLINE_FUNCTION ...@@ -256,17 +265,18 @@ KOKKOS_INLINE_FUNCTION
T det(const TinyMatrix<N,T>& A) T det(const TinyMatrix<N,T>& A)
{ {
static_assert(std::is_arithmetic<T>::value, "determinent is not defined for non arithmetic types"); static_assert(std::is_arithmetic<T>::value, "determinent is not defined for non arithmetic types");
static_assert(std::is_floating_point<T>::value, "determinent for arbitrary dimension N is defined for floating point types only");
TinyMatrix<N,T> M = A; TinyMatrix<N,T> M = A;
TinyVector<N, int> index; TinyVector<N, size_t> index;
for (int i=0; i<N; ++i) index[i]=i; for (size_t i=0; i<N; ++i) index[i]=i;
T determinent = 1; T determinent = 1;
for (int i=0; i<N; ++i) { for (size_t i=0; i<N; ++i) {
for (int j=i; j<N; ++j) { for (size_t j=i; j<N; ++j) {
int l = j; size_t l = j;
const int J = index[j]; const size_t J = index[j];
for (int k=j+1; k<N; ++k) { for (size_t k=j+1; k<N; ++k) {
if (std::abs(M(index[k],i)) > std::abs(M(J,i))) { if (std::abs(M(index[k],i)) > std::abs(M(J,i))) {
l=k; l=k;
} }
...@@ -276,19 +286,19 @@ T det(const TinyMatrix<N,T>& A) ...@@ -276,19 +286,19 @@ T det(const TinyMatrix<N,T>& A)
determinent *= -1; determinent *= -1;
} }
} }
const int I = index[i]; const size_t I = index[i];
if (M(I,i)==0) return 0; if (M(I,i)==0) return 0;
double inv_Mii = 1./M(I,i); const T inv_Mii = 1./M(I,i);
for (int k=i+1; k<N; ++k) { for (size_t k=i+1; k<N; ++k) {
const int K = index[k]; const size_t K = index[k];
const T factor = M(K,i)*inv_Mii; const T factor = M(K,i)*inv_Mii;
for (int l=i+1; l<N; ++l) { for (size_t l=i+1; l<N; ++l) {
M(K,l) -= factor*M(I,l); M(K,l) -= factor*M(I,l);
} }
} }
} }
for (int i=0; i<N; ++i) { for (size_t i=0; i<N; ++i) {
determinent *= M(index[i],i); determinent *= M(index[i],i);
} }
return determinent; return determinent;
......
...@@ -3,7 +3,9 @@ include_directories("${CATCH_INCLUDE_PATH}") ...@@ -3,7 +3,9 @@ include_directories("${CATCH_INCLUDE_PATH}")
set(EXECUTABLE_OUTPUT_PATH ${PASTIS_BINARY_DIR}) set(EXECUTABLE_OUTPUT_PATH ${PASTIS_BINARY_DIR})
add_executable (unit_tests add_executable (unit_tests
test_main.cpp test_main.cpp
test_PastisAssert.cpp
test_RevisionInfo.cpp test_RevisionInfo.cpp
test_TinyMatrix.cpp
test_TinyVector.cpp) test_TinyVector.cpp)
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR}) target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
......
#include <catch.hpp>
#include <PastisAssert.hpp>
#include <string>
TEST_CASE("PastisAssert", "[assert]") {
SECTION("checking for assert error") {
const std::string filename = "filename";
const int line = 10;
const std::string function = "function";
const std::string message = "message";
AssertError assert_error(filename, line, function, message);
REQUIRE(Catch::Detail::stringify(assert_error) == "\n*** Assertion error ***\n at filename:10\n in function\n*** message\n");
}
}
#include <catch.hpp>
#include <TinyMatrix.hpp>
#include <PastisAssert.hpp>
TEST_CASE("TinyMatrix", "[algebra]") {
TinyMatrix<3, int> A(1,2,3,
4,5,6,
7,8,9);
REQUIRE(((A(0,0)==1) and (A(0,1)==2) and (A(0,2)==3) and
(A(1,0)==4) and (A(1,1)==5) and (A(1,2)==6) and
(A(2,0)==7) and (A(2,1)==8) and (A(2,2)==9)));
TinyMatrix<3,int> B(6,5,3,
8,34,6,
35,6,7);
SECTION("checking for equality and difference tests") {
const TinyMatrix<3, int> copy_A = A;
REQUIRE(((copy_A(0,0)==1) and (copy_A(0,1)==2) and (copy_A(0,2)==3) and
(copy_A(1,0)==4) and (copy_A(1,1)==5) and (copy_A(1,2)==6) and
(copy_A(2,0)==7) and (copy_A(2,1)==8) and (copy_A(2,2)==9)));
REQUIRE(copy_A==A);
REQUIRE_FALSE(copy_A!=A);
TinyMatrix<3, int> affected_A; affected_A = A;
REQUIRE(affected_A==A);
REQUIRE_FALSE(affected_A!=A);
REQUIRE(A!=B);
REQUIRE_FALSE(A==B);
}
SECTION("checking for scalar left product") {
const int a = 2;
const TinyMatrix<3, int> aA = a*A;
REQUIRE(aA == TinyMatrix<3,int>(2, 4, 6,
8, 10, 12,
14, 16, 18));
}
SECTION("checking for null matrix management") {
TinyMatrix<3, int> Z = zero;
REQUIRE(Z == TinyMatrix<3, int>(0,0,0,
0,0,0,
0,0,0));
TinyMatrix<3, int> affected_Z; affected_Z = zero;
REQUIRE(affected_Z == Z);
}
SECTION("checking for identity management") {
TinyMatrix<3, int> I = identity;
REQUIRE(I == TinyMatrix<3,int>(1,0,0,
0,1,0,
0,0,1));
TinyMatrix<3, int> affected_I; affected_I=identity;
REQUIRE(affected_I==I);
}
SECTION("checking for matrices sum") {
REQUIRE(A+B == TinyMatrix<3,int>(7,7,6,
12,39,12,
42,14,16));
TinyMatrix<3, int> ApB = A;
ApB += B;
REQUIRE(ApB==A+B);
}
SECTION("checking for matrices difference ") {
REQUIRE(A-B == TinyMatrix<3,int>(-5, -3, 0,
-4, -29, 0,
-28, 2, 2));
TinyMatrix<3, int> AmB = A;
AmB -= B;
REQUIRE(AmB==A-B);
}
SECTION("checking for matrices product") {
REQUIRE(A*B == TinyMatrix<3,int>(127,91,36,
274,226,84,
421,361,132));
}
SECTION("checking for matrix-vector product") {
REQUIRE(A*TinyVector<3,int>(2,-3,5) == TinyVector<3,int>(11,23,35));
}
SECTION("checking for tensor product") {
const TinyVector<3,int> u(1,3,7);
const TinyVector<3,int> v(6,2,-3);
REQUIRE(tensorProduct(u,v)==TinyMatrix<3,int>(6,2,-3,
18,6,-9,
42,14,-21));
}
SECTION("checking for determinant calculations") {
REQUIRE(det(TinyMatrix<1,int>(6))==6);
REQUIRE(det(TinyMatrix<2,int>(3,1,
-3,6))==21);
REQUIRE(det(B)==-1444);
REQUIRE(det(TinyMatrix<4,double> (1,2.3,7,-6.2,
3,4,9,1,
4.1,5,2,-3,
2,27,3,17.5))== Approx(6661.455).epsilon(1E-14));
}
SECTION("checking for matrices output") {
REQUIRE(Catch::Detail::stringify(A) == "[(1,2,3)(4,5,6)(7,8,9)]");
REQUIRE(Catch::Detail::stringify(TinyMatrix<1,int>(7)) == "7");
}
#ifndef NDEBUG
SECTION("checking for bounds vioation") {
REQUIRE_THROWS_AS(A(3,0), AssertError);
REQUIRE_THROWS_AS(A(0,3), AssertError);
const TinyMatrix<3,int>& constA = A;
REQUIRE_THROWS_AS(constA(3,0), AssertError);
REQUIRE_THROWS_AS(constA(0,3), AssertError);
}
#endif // NDEBUG
}
...@@ -5,18 +5,18 @@ ...@@ -5,18 +5,18 @@
TEST_CASE("TinyVector", "[algebra]") { TEST_CASE("TinyVector", "[algebra]") {
TinyVector<3,int> v(1,2,3); TinyVector<3,int> v(1,2,3);
REQUIRE_NOTHROW(((v[0] == 1) and (v[1] == 2) and (v[2] == 3))); REQUIRE(((v[0] == 1) and (v[1] == 2) and (v[2] == 3)));
REQUIRE(v.dimension() == 3); REQUIRE(v.dimension() == 3);
const TinyVector<3,int> z = zero; const TinyVector<3,int> z = zero;
REQUIRE_NOTHROW(((z[0] == 0) and (z[1] == 0) and (z[2] == 0))); REQUIRE(((z[0] == 0) and (z[1] == 0) and (z[2] == 0)));
v = TinyVector<3,int>(3,2,4); v = TinyVector<3,int>(3,2,4);
TinyVector<3,int> w(1,2,6); TinyVector<3,int> w(1,2,6);
REQUIRE((v,w)==31); REQUIRE((v,w)==31);
w = 2*v; w = 2*v;
REQUIRE_NOTHROW(((w[0] == 2*v[0]) and (w[1]==2*v[1]) and (w[2]==2*v[2]))); REQUIRE(((w[0] == 2*v[0]) and (w[1]==2*v[1]) and (w[2]==2*v[2])));
TinyVector<3,int> x = v; TinyVector<3,int> x = v;
REQUIRE(x==v); REQUIRE(x==v);
...@@ -43,7 +43,7 @@ TEST_CASE("TinyVector", "[algebra]") { ...@@ -43,7 +43,7 @@ TEST_CASE("TinyVector", "[algebra]") {
REQUIRE(x==v); REQUIRE(x==v);
TinyVector<3,int> z1; z1 = zero; TinyVector<3,int> z1; z1 = zero;
REQUIRE_NOTHROW(((z1[0] == 0) and (z1[1] == 0) and (z1[2] == 0))); REQUIRE(((z1[0] == 0) and (z1[1] == 0) and (z1[2] == 0)));
REQUIRE(Catch::Detail::stringify(x) == "(3,2,4)"); REQUIRE(Catch::Detail::stringify(x) == "(3,2,4)");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment