-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: restore regular_numpy, without a way to create it
Signed-off-by: Henry Schreiner <[email protected]>
- Loading branch information
Showing
3 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2018-2019 Henry Schreiner and Hans Dembinski | ||
// | ||
// Distributed under the 3-Clause BSD License. See accompanying | ||
// file LICENSE or https://github.com/scikit-hep/boost-histogram for details. | ||
|
||
#pragma once | ||
|
||
#include <bh_python/metadata.hpp> | ||
|
||
#include <boost/core/nvp.hpp> | ||
#include <boost/histogram/axis/regular.hpp> | ||
|
||
namespace bh = boost::histogram; | ||
|
||
namespace axis { | ||
|
||
using index_type = boost::histogram::axis::index_type; | ||
|
||
/// Mimics the numpy behavior for the upper bin; required for auto range. | ||
class regular_numpy : public bh::axis::regular<double, bh::use_default, metadata_t> { | ||
using value_type = double; | ||
double stop_{0}; | ||
|
||
public: | ||
regular_numpy(unsigned n, value_type start, value_type stop, metadata_t meta = {}) | ||
: regular(n, start, stop, meta) | ||
, stop_(stop) {} | ||
|
||
regular_numpy(const regular_numpy& a, index_type i, index_type j, unsigned n) | ||
: regular(a, i, j, n) | ||
, stop_(a.stop_) {} | ||
|
||
regular_numpy() | ||
: regular() {} | ||
|
||
bh::axis::index_type index(value_type v) const { | ||
return v <= stop_ ? std::min(regular::index(v), size() - 1) : regular::index(v); | ||
} | ||
|
||
template <class Archive> | ||
void serialize(Archive& ar, unsigned version) { | ||
regular::serialize(ar, version); | ||
ar& boost::make_nvp("stop", stop_); | ||
} | ||
}; | ||
|
||
} // namespace axis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters