Skip to content
Draft
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
18 changes: 10 additions & 8 deletions include/boost/histogram/axis/regular.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,18 @@ class regular : public iterator_mixin<regular<Value, Transform, MetaData, Option
return static_cast<index_type>(z * size());
}
} else {
if (z < 1) {
if (z >= 0)
return static_cast<index_type>(z * size());
else
return -1;
}
// Branch-free so that random data does not mispredict. The clamped value
// keeps the conversion to int in range for any input. fmin(NaN, 1) is 1,
// so NaN maps to size(); the order of fmin and fmax matters.
const bool below = z < 0;
const auto zc = std::fmax(std::fmin(z, decltype(z){1}), decltype(z){0});
index_type i = static_cast<index_type>(zc * size());
i = below ? -1 : i;
// upper edge of last bin is inclusive if overflow bin is not present
if (!options_type::test(option::overflow) && z == 1) return size() - 1;
if (!options_type::test(option::overflow)) i = z == 1 ? size() - 1 : i;
return i; // size() if x is NaN
}
return size(); // also returned if x is NaN
return size();
}

/// Returns index and shift (if axis has grown) for the passed argument.
Expand Down
3 changes: 2 additions & 1 deletion include/boost/histogram/detail/fill_n.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ void fill_n_storage(S& s, const Index idx, weight_type<T>&& w, Ts&&... ps) noexc
template <class Index, class S, class A, class T, class... Ts>
void fill_n_nd(const std::size_t offset, S& storage, A& axes, const std::size_t vsize,
const T* values, Ts&&... ts) {
constexpr std::size_t buffer_size = 1ul << 14;
// 32 kB of indices; a larger buffer spills out of L1 and slows the passes below
constexpr std::size_t buffer_size = 1ul << 12;
Index indices[buffer_size];

/*
Expand Down
Loading