Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-constexpr math function #64

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions test/test_span.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "ports-of-call/span.hpp"
#include "ports-of-call/portability.hpp"
#include <type_traits>
#include "ports-of-call/span.hpp"
#include <cmath>
#include <type_traits>

// ========================================================================================
// © (or copyright) 2019-2024. Triad National Security, LLC. All rights
Expand Down Expand Up @@ -564,19 +564,17 @@ TEST_CASE("span portability", "[PortsOfCall::span]") {
constexpr const std::size_t Nb = N * sizeof(Real);
constexpr const Real tol = 1.0E-8;

constexpr const Real pi = std::acos(-1);
constexpr const Real pi = 3.141592653589793238462643383279502884;

Yurlungur marked this conversation as resolved.
Show resolved Hide resolved
constexpr Real d_gp = 2. * pi / static_cast<Real>(N);

std::vector<Real> h_gp(N);
for(auto i = 0; i < N; ++i)
{
for (auto i = 0; i < N; ++i) {
h_gp[i] = -pi + static_cast<Real>(i) * d_gp;
}

Real *p_a = (Real *)PORTABLE_MALLOC(Nb);

Real *p_a = (Real*) PORTABLE_MALLOC(Nb);

// device span, host span
span d_s(p_a, N);
span h_s(h_gp);
Expand All @@ -586,11 +584,13 @@ TEST_CASE("span portability", "[PortsOfCall::span]") {

// integrate cos x dx over [-pi,pi]
Real res_sum{0.0};
portableReduce( "integrate", 0, N, PORTABLE_LAMBDA(const int i, Real& rsum){ rsum += (std::cos(d_s[i])*d_gp) ;}, res_sum);
portableReduce(
"integrate", 0, N,
PORTABLE_LAMBDA(const int i, Real &rsum) { rsum += (std::cos(d_s[i]) * d_gp); },
res_sum);

// require sum < tol
REQUIRE(std::abs(res_sum) < tol);

REQUIRE(std::abs(res_sum) < tol);

PORTABLE_FREE(p_a);
}
Expand Down
Loading