49 iterator(
size_t begin1,
size_t end1,
size_t begin2)
86 std::vector<size_t> result;
87 result.reserve(this->
size());
88 for (
size_t idx : *
this) {
89 result.push_back(idx);
102 template <AxisBoundaryType bdt>
116 m_width((xmax - xmin) / nBins),
142 return neighborHoodIndices(idx, std::make_pair(size, size));
156 std::enable_if_t<T == AxisBoundaryType::Open, int> = 0>
158 std::pair<size_t, size_t> sizes = {
160 constexpr
int min = 0;
161 const int max = getNBins() + 1;
162 const int itmin =
std::max(min,
int(idx - sizes.first));
163 const int itmax =
std::min(max,
int(idx + sizes.second));
177 std::enable_if_t<T == AxisBoundaryType::Bound, int> = 0>
179 std::pair<size_t, size_t> sizes = {
181 if (idx <= 0 || idx >= (getNBins() + 1)) {
184 constexpr
int min = 1;
185 const int max = getNBins();
186 const int itmin =
std::max(min,
int(idx - sizes.first));
187 const int itmax =
std::min(max,
int(idx + sizes.second));
201 std::enable_if_t<T == AxisBoundaryType::Closed, int> = 0>
203 std::pair<size_t, size_t> sizes = {
206 if (idx <= 0 || idx >= (getNBins() + 1)) {
212 sizes.first %= getNBins();
213 sizes.second %= getNBins();
214 if (sizes.first + sizes.second + 1 > getNBins()) {
215 sizes.second -= (sizes.first + sizes.second + 1) - getNBins();
225 const int itmin = idx - sizes.first;
226 const int itmax = idx + sizes.second;
227 const size_t itfirst = wrapBin(itmin);
228 const size_t itlast = wrapBin(itmax);
229 if (itfirst <= itlast) {
230 return NeighborHoodIndices(itfirst, itlast + 1);
232 return NeighborHoodIndices(itfirst, getNBins() + 1, 1, itlast + 1);
243 std::enable_if_t<T == AxisBoundaryType::Open, int> = 0>
255 std::enable_if_t<T == AxisBoundaryType::Bound, int> = 0>
267 std::enable_if_t<T == AxisBoundaryType::Closed, int> = 0>
269 const int w = getNBins();
270 return 1 + (w + ((bin - 1) % w)) % w;
285 return wrapBin(std::floor((x - getMin()) / getBinWidth()) + 1);
304 return getMin() + (bin - 1) * getBinWidth();
318 return getMin() + bin * getBinWidth();
329 return getMin() + (bin - 0.5) * getBinWidth();
335 double getMax()
const override {
return m_max; }
340 double getMin()
const override {
return m_min; }
345 size_t getNBins()
const override {
return m_bins; }
354 bool isInside(
double x)
const {
return (m_min <= x) && (x < m_max); }
359 std::vector<double> binEdges;
360 for (
size_t i = 1; i <= m_bins; i++) {
361 binEdges.push_back(getBinLowerBound(i));
363 binEdges.push_back(getBinUpperBound(m_bins));
382 template <AxisBoundaryType bdt>
394 Axis(std::vector<double> binEdges) : m_binEdges(std::move(binEdges)) {}
419 return neighborHoodIndices(idx, std::make_pair(size, size));
433 std::enable_if_t<T == AxisBoundaryType::Open, int> = 0>
435 std::pair<size_t, size_t> sizes = {
437 constexpr
int min = 0;
438 const int max = getNBins() + 1;
439 const int itmin =
std::max(min,
int(idx - sizes.first));
440 const int itmax =
std::min(max,
int(idx + sizes.second));
454 std::enable_if_t<T == AxisBoundaryType::Bound, int> = 0>
456 std::pair<size_t, size_t> sizes = {
458 if (idx <= 0 || idx >= (getNBins() + 1)) {
461 constexpr
int min = 1;
462 const int max = getNBins();
463 const int itmin =
std::max(min,
int(idx - sizes.first));
464 const int itmax =
std::min(max,
int(idx + sizes.second));
478 std::enable_if_t<T == AxisBoundaryType::Closed, int> = 0>
480 std::pair<size_t, size_t> sizes = {
483 if (idx <= 0 || idx >= (getNBins() + 1)) {
489 sizes.first %= getNBins();
490 sizes.second %= getNBins();
491 if (sizes.first + sizes.second + 1 > getNBins()) {
492 sizes.second -= (sizes.first + sizes.second + 1) - getNBins();
502 const int itmin = idx - sizes.first;
503 const int itmax = idx + sizes.second;
504 const size_t itfirst = wrapBin(itmin);
505 const size_t itlast = wrapBin(itmax);
506 if (itfirst <= itlast) {
507 return NeighborHoodIndices(itfirst, itlast + 1);
509 return NeighborHoodIndices(itfirst, getNBins() + 1, 1, itlast + 1);
520 std::enable_if_t<T == AxisBoundaryType::Open, int> = 0>
532 std::enable_if_t<T == AxisBoundaryType::Bound, int> = 0>
544 std::enable_if_t<T == AxisBoundaryType::Closed, int> = 0>
546 const int w = getNBins();
547 return 1 + (w + ((bin - 1) % w)) % w;
563 std::upper_bound(std::begin(m_binEdges), std::end(m_binEdges), x);
564 return wrapBin(std::distance(std::begin(m_binEdges),
it));
575 return m_binEdges.at(bin) - m_binEdges.at(bin - 1);
610 return 0.5 * (getBinLowerBound(bin) + getBinUpperBound(bin));
616 double getMax()
const override {
return m_binEdges.back(); }
621 double getMin()
const override {
return m_binEdges.front(); }
626 size_t getNBins()
const override {
return m_binEdges.size() - 1; }
636 return (m_binEdges.front() <=
x) && (x < m_binEdges.back());
641 std::vector<double>
getBinEdges()
const override {
return m_binEdges; }