Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions hist/histv7/benchmark/hist_benchmark_axes.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <benchmark/benchmark.h>

#include <cstddef>
#include <random>
#include <tuple>
#include <vector>
Expand All @@ -19,7 +20,7 @@ struct RAxes_Regular1 : public benchmark::Fixture {
{
std::mt19937 gen;
std::uniform_real_distribution<> dis;
fNumbers.resize(state.range(0));
fNumbers.resize(static_cast<std::size_t>(state.range(0)));
for (std::size_t i = 0; i < fNumbers.size(); i++) {
fNumbers[i] = dis(gen);
}
Expand Down Expand Up @@ -49,7 +50,7 @@ struct RAxes_Regular2 : public benchmark::Fixture {
{
std::mt19937 gen;
std::uniform_real_distribution<> dis;
fNumbers.resize(2 * state.range(0));
fNumbers.resize(2 * static_cast<std::size_t>(state.range(0)));
for (std::size_t i = 0; i < fNumbers.size(); i++) {
fNumbers[i] = dis(gen);
}
Expand Down
13 changes: 7 additions & 6 deletions hist/histv7/benchmark/hist_benchmark_engine.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <benchmark/benchmark.h>

#include <cstddef>
#include <random>
#include <vector>

Expand All @@ -21,7 +22,7 @@ struct RHistEngine_int_Regular1 : public benchmark::Fixture {
{
std::mt19937 gen;
std::uniform_real_distribution<> dis;
fNumbers.resize(state.range(0));
fNumbers.resize(static_cast<std::size_t>(state.range(0)));
for (std::size_t i = 0; i < fNumbers.size(); i++) {
fNumbers[i] = dis(gen);
}
Expand Down Expand Up @@ -51,7 +52,7 @@ struct RHistEngine_int_Regular2 : public benchmark::Fixture {
{
std::mt19937 gen;
std::uniform_real_distribution<> dis;
fNumbers.resize(2 * state.range(0));
fNumbers.resize(2 * static_cast<std::size_t>(state.range(0)));
for (std::size_t i = 0; i < fNumbers.size(); i++) {
fNumbers[i] = dis(gen);
}
Expand Down Expand Up @@ -81,7 +82,7 @@ struct RHistEngine_float_Regular1 : public benchmark::Fixture {
{
std::mt19937 gen;
std::uniform_real_distribution<> dis;
fNumbers.resize(state.range(0));
fNumbers.resize(static_cast<std::size_t>(state.range(0)));
for (std::size_t i = 0; i < fNumbers.size(); i++) {
fNumbers[i] = dis(gen);
}
Expand Down Expand Up @@ -121,7 +122,7 @@ struct RHistEngine_float_Regular2 : public benchmark::Fixture {
{
std::mt19937 gen;
std::uniform_real_distribution<> dis;
fNumbers.resize(2 * state.range(0));
fNumbers.resize(2 * static_cast<std::size_t>(state.range(0)));
for (std::size_t i = 0; i < fNumbers.size(); i++) {
fNumbers[i] = dis(gen);
}
Expand Down Expand Up @@ -161,7 +162,7 @@ struct RHistEngine_RBinWithError_Regular1 : public benchmark::Fixture {
{
std::mt19937 gen;
std::uniform_real_distribution<> dis;
fNumbers.resize(state.range(0));
fNumbers.resize(static_cast<std::size_t>(state.range(0)));
for (std::size_t i = 0; i < fNumbers.size(); i++) {
fNumbers[i] = dis(gen);
}
Expand Down Expand Up @@ -201,7 +202,7 @@ struct RHistEngine_RBinWithError_Regular2 : public benchmark::Fixture {
{
std::mt19937 gen;
std::uniform_real_distribution<> dis;
fNumbers.resize(2 * state.range(0));
fNumbers.resize(2 * static_cast<std::size_t>(state.range(0)));
for (std::size_t i = 0; i < fNumbers.size(); i++) {
fNumbers[i] = dis(gen);
}
Expand Down
3 changes: 2 additions & 1 deletion hist/histv7/benchmark/hist_benchmark_regular.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <benchmark/benchmark.h>

#include <cstddef>
#include <random>
#include <vector>

Expand All @@ -17,7 +18,7 @@ struct RRegularAxis : public benchmark::Fixture {
{
std::mt19937 gen;
std::uniform_real_distribution<> dis;
fNumbers.resize(state.range(0));
fNumbers.resize(static_cast<std::size_t>(state.range(0)));
for (std::size_t i = 0; i < fNumbers.size(); i++) {
fNumbers[i] = dis(gen);
}
Expand Down
5 changes: 3 additions & 2 deletions hist/histv7/benchmark/hist_benchmark_stats.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <benchmark/benchmark.h>

#include <cstddef>
#include <random>
#include <vector>

Expand All @@ -18,7 +19,7 @@ struct RHistStats1 : public benchmark::Fixture {
{
std::mt19937 gen;
std::uniform_real_distribution<> dis;
fNumbers.resize(state.range(0));
fNumbers.resize(static_cast<std::size_t>(state.range(0)));
for (std::size_t i = 0; i < fNumbers.size(); i++) {
fNumbers[i] = dis(gen);
}
Expand Down Expand Up @@ -57,7 +58,7 @@ struct RHistStats2 : public benchmark::Fixture {
{
std::mt19937 gen;
std::uniform_real_distribution<> dis;
fNumbers.resize(2 * state.range(0));
fNumbers.resize(2 * static_cast<std::size_t>(state.range(0)));
for (std::size_t i = 0; i < fNumbers.size(); i++) {
fNumbers[i] = dis(gen);
}
Expand Down
28 changes: 14 additions & 14 deletions hist/histv7/inc/ROOT/RBinIndex.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ Objects of this type should be passed by value.
Feedback is welcome!
*/
class RBinIndex final {
static constexpr std::uint64_t UnderflowIndex = -3;
static constexpr std::uint64_t OverflowIndex = -2;
static constexpr std::uint64_t InvalidIndex = -1;
static constexpr auto kUnderflowIndex = static_cast<std::uint64_t>(-3);
static constexpr auto kOverflowIndex = static_cast<std::uint64_t>(-2);
static constexpr auto kInvalidIndex = static_cast<std::uint64_t>(-1);

// We use std::uint64_t instead of std::size_t for the index because for sparse histograms, not all bins have to be
// allocated in memory. However, we require that the index has at least that size.
static_assert(sizeof(std::uint64_t) >= sizeof(std::size_t), "index type not large enough to address all bins");

std::uint64_t fIndex = InvalidIndex;
std::uint64_t fIndex = kInvalidIndex;

public:
/// Construct an invalid bin index.
Expand All @@ -48,22 +48,22 @@ public:
/// A bin index is normal iff it is not one of the special values.
///
/// Note that a normal bin index may not actually be valid for a given axis if it is outside its range.
bool IsNormal() const { return fIndex < UnderflowIndex; }
bool IsUnderflow() const { return fIndex == UnderflowIndex; }
bool IsOverflow() const { return fIndex == OverflowIndex; }
bool IsInvalid() const { return fIndex == InvalidIndex; }
bool IsNormal() const { return fIndex < kUnderflowIndex; }
bool IsUnderflow() const { return fIndex == kUnderflowIndex; }
bool IsOverflow() const { return fIndex == kOverflowIndex; }
bool IsInvalid() const { return fIndex == kInvalidIndex; }

RBinIndex &operator+=(std::uint64_t a)
{
if (!IsNormal()) {
// Arithmetic operations on special values go to InvalidIndex.
fIndex = InvalidIndex;
fIndex = kInvalidIndex;
} else {
std::uint64_t old = fIndex;
fIndex += a;
if (fIndex < old || !IsNormal()) {
// The addition wrapped around, go to InvalidIndex.
fIndex = InvalidIndex;
fIndex = kInvalidIndex;
}
}
return *this;
Expand Down Expand Up @@ -93,12 +93,12 @@ public:
{
if (!IsNormal()) {
// Arithmetic operations on special values go to InvalidIndex.
fIndex = InvalidIndex;
fIndex = kInvalidIndex;
} else if (fIndex >= a) {
fIndex -= a;
} else {
// The operation would wrap around, go to InvalidIndex.
fIndex = InvalidIndex;
fIndex = kInvalidIndex;
}
return *this;
}
Expand Down Expand Up @@ -147,14 +147,14 @@ public:
static RBinIndex Underflow()
{
RBinIndex underflow;
underflow.fIndex = UnderflowIndex;
underflow.fIndex = kUnderflowIndex;
return underflow;
}

static RBinIndex Overflow()
{
RBinIndex overflow;
overflow.fIndex = OverflowIndex;
overflow.fIndex = kOverflowIndex;
return overflow;
}
};
Expand Down
2 changes: 1 addition & 1 deletion hist/histv7/test/hist_index.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ TEST(RBinIndex, Plus)
}

// Matches RBinIndex::UnderflowIndex
static constexpr std::uint64_t UnderflowIndex = -3;
static constexpr auto UnderflowIndex = static_cast<std::uint64_t>(-3);
EXPECT_TRUE((RBinIndex(0) + UnderflowIndex).IsInvalid());
EXPECT_TRUE((RBinIndex(3) + UnderflowIndex).IsInvalid());
}
Expand Down
Loading