Caffe2 - C++ API
A deep learning, cross platform ML framework
dynamic_histogram.h
1 #pragma once
2 
3 #include <memory>
4 #include <vector>
5 
6 namespace dnnlowp {
7 
17 class Histogram {
18  public:
19  Histogram(int nbins, float min, float max)
20  : min_(min), max_(max), histogram_(nbins) {}
21  Histogram(float min, float max, const std::vector<uint64_t>& bins)
22  : min_(min), max_(max), histogram_(bins) {}
23 
24  void Add(float f, uint64_t cnt = 1);
31  void Add(const float* f, int len);
32 
33  float Min() const {
34  return min_;
35  }
36  float Max() const {
37  return max_;
38  }
39 
44  void Finalize();
45 
46  const std::vector<uint64_t>* GetHistogram() const {
47  return &histogram_;
48  }
49 
50  private:
51  float min_, max_;
52  std::vector<uint64_t> histogram_;
53  std::vector<uint64_t> per_thread_histogram_;
54 };
55 
59  public:
60  DynamicHistogram(int nbins);
61 
62  void Add(float f);
63  void Add(const float* f, int len);
64 
67  const Histogram* Finalize();
68 
69  private:
77  std::vector<Histogram> histograms_;
78  int nbins_;
79  float min_, max_;
80 
81  std::unique_ptr<Histogram> final_histogram_;
82 }; // class DynamicHistogram
83 
84 } // namespace dnnlowp
An equi-width histogram where the spread of bins change over time when we see new min or max values...
bin_width = (max - min)/nbins ith bin (zero-based indexing) contains [i*bin_width, (i+1)*bin_width) with an exception that (nbins - 1)th bin contains [(nbins-1)*bin_width, nbins*bin_width]
Definition: OpClasses.h:659
void Finalize()
Reduce per-thread histogram.