Skip to content

Commit

Permalink
Add truncation for quantify::transposition_growth
Browse files Browse the repository at this point in the history
And also coverage for nested::fast_reduce
  • Loading branch information
SSoelvsten committed Feb 12, 2024
1 parent 8cff2c4 commit 719f71c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/adiar/exec_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ namespace adiar
//////////////////////////////////////////////////////////////////////////
class transposition_growth
{
private:
static constexpr float min_val = 0.0f;

public:
/// \brief Minimal value
static constexpr transposition_growth
min()
{
return 0.0f;
return min_val;
}

/// \brief Maximal value
Expand All @@ -144,14 +147,22 @@ namespace adiar
private:
float _value;

/// \brief Convert into a `signed char`
static constexpr float
from_float(float f)
{
// Truncate `f` to be in the interval [0.0f, ...)
return f < min_val ? min_val : f;
}

public:
constexpr transposition_growth()
: _value(1.5f)
{ }

/// \brief Wrap a `float`.
constexpr transposition_growth(float value)
: _value(value)
: _value(from_float(value))
{}

/// \brief Reobtain the wrapped `float`
Expand Down
15 changes: 13 additions & 2 deletions test/adiar/test_exec_policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,25 @@ go_bandit([]() {
AssertThat(default__transposition_growth, Is().GreaterThanOrEqualTo(0.0f));
});

it("'quantify::transposition max' defaults to a non-negative value", [&]() {
AssertThat(default__transposition_max, Is().GreaterThanOrEqualTo(0u));
it("'quantify::transposition growth' truncates negative values to '0.0f'", [&]() {
const exec_policy::quantify::transposition_growth res(-0.5f);
AssertThat(static_cast<float>(res), Is().GreaterThanOrEqualTo(0.0f));
});

it("'nested::fast reduce epsilon' defaults to a value in [-1,1]", [&]() {
AssertThat(default__fast_reduce, Is().GreaterThanOrEqualTo(-1.0f));
AssertThat(default__fast_reduce, Is().LessThanOrEqualTo(1.0f));
});

it("'nested::fast reduce epsilon' truncates negative values to '-1.0f'", [&]() {
const exec_policy::nested::fast_reduce res(-42.0f);
AssertThat(static_cast<float>(res), Is().EqualTo(-1.0f));
});

it("'nested::fast reduce epsilon' truncates positive value to '1.0f'", [&]() {
const exec_policy::nested::fast_reduce res(2.0f);
AssertThat(static_cast<float>(res), Is().EqualTo(1.0f));
});
});

describe("exec_policy(const __ &)", [&]() {
Expand Down

0 comments on commit 719f71c

Please sign in to comment.