25 #ifndef ALEXANDRIA_HISTOGRAM_HISTOGRAM_H 26 #define ALEXANDRIA_HISTOGRAM_HISTOGRAM_H 34 #include <type_traits> 48 template<
typename VarType>
79 virtual ssize_t
getBinIndex(VarType value)
const = 0;
87 virtual std::vector<VarType>
getEdges()
const {
88 std::vector<VarType> edges(
m_nbins + 1);
90 std::generate(edges.begin(), edges.end(), [
this, &i]() {
return getEdge(i++); });
109 virtual VarType
getEdge(
size_t e)
const = 0;
123 return (edges.second + edges.first) / 2;
137 template<
typename VarType,
typename WeightType =
float>
141 static_assert(std::is_arithmetic<VarType>::value,
"Histogram only supports numerical types");
142 static_assert(std::is_arithmetic<WeightType>::value,
"Histogram only supports numerical weights");
157 template<typename IterType, typename BinType, typename=typename std::enable_if<std::is_move_constructible<BinType>::value>::type>
158 Histogram(IterType begin, IterType end, BinType&& bin_type) {
159 auto binning_impl = make_unique<ComputationImpl<BinType>>(std::move(bin_type));
185 template<typename IterType, typename WeightIterType, typename BinType, typename=typename std::enable_if<std::is_move_constructible<BinType>::value>::type>
186 Histogram(IterType begin, IterType end, WeightIterType wbegin, WeightIterType wend, BinType&& bin_type) {
187 assert(wend - wbegin == end - begin);
188 auto binning_impl = make_unique<ComputationImpl<BinType>>(std::move(bin_type));
189 binning_impl->computeBins(begin, end, wbegin);
249 std::generate(bins.begin(), bins.end(), [
this, &i]() {
return m_binning_concept->getBinStrategy().getBin(i++); });
270 void clip(VarType min, VarType max) {
289 std::tuple<VarType, VarType, VarType>
getStats()
const {
328 virtual std::unique_ptr<ComputationInterface>
clone()
const = 0;
330 virtual void clip(VarType min, VarType max) = 0;
332 virtual std::tuple<VarType, VarType, VarType>
getStats()
const = 0;
340 template<
typename BinType>
356 std::unique_ptr<ComputationInterface>
clone() const final {
357 return make_unique<ComputationImpl<BinType>>(*this);
373 template<
typename IterType,
typename WeightIterType>
374 void computeBins(IterType begin, IterType end, WeightIterType wbegin);
376 void clip(VarType min, VarType max)
final;
378 std::tuple<VarType, VarType, VarType>
getStats() const final;
387 #include "Histogram/_impl/ComputationImpl.icpp" 389 #endif // ALEXANDRIA_HISTOGRAM_HISTOGRAM_H virtual std::vector< VarType > getEdges() const
std::vector< VarType > getEdges() const
virtual VarType getBin(size_t i) const
std::tuple< VarType, VarType, VarType > getStats() const
virtual ~BinStrategy()=default
virtual std::tuple< VarType, VarType, VarType > getStats() const =0
std::vector< WeightType > getCounts() const
virtual const BinStrategy< VarType > & getBinStrategy() const =0
virtual std::unique_ptr< ComputationInterface > clone() const =0
size_t getBinCount() const
void clip(VarType min, VarType max) final
void clip(VarType min, VarType max)
ComputationImpl(BinType &&bin_type)
Histogram(IterType begin, IterType end, WeightIterType wbegin, WeightIterType wend, BinType &&bin_type)
virtual void clip(VarType min, VarType max)=0
std::unique_ptr< ComputationInterface > clone() const final
const BinStrategy< VarType > & getBinStrategy() const final
std::tuple< VarType, VarType, VarType > getStats() const final
virtual VarType getEdge(size_t e) const =0
Histogram(IterType begin, IterType end, BinType &&bin_type)
virtual ssize_t getBinIndex(VarType value) const =0
std::pair< VarType, VarType > getBinEdges(size_t i) const
ConstantWeight & operator++()
virtual std::pair< VarType, VarType > getBinEdges(size_t i) const
std::vector< VarType > getBins() const
void computeBins(IterType begin, IterType end, WeightIterType wbegin)
std::unique_ptr< ComputationInterface > m_binning_concept
std::shared_ptr< std::vector< WeightType > > m_counts
Histogram & operator=(const Histogram &)=default
WeightType operator*() const
Histogram(const Histogram &other)