Skip to content

Commit

Permalink
Merge pull request #56 from histogrammar/num_bins_fix
Browse files Browse the repository at this point in the history
Num bins fix
  • Loading branch information
mbaak authored Jun 15, 2022
2 parents dcbf220 + 06ba23b commit 5c98f72
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Release notes
=============

Version 1.0.29, June 2022
-------------------------
* Fix for machine-level rounding error, which can show up on in num_bins() call of Bin histogram.

Version 1.0.28, June 2022
-------------------------
* Multiple performance updates, to Bin, SparselyBin and Categorize histograms.
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ PyCUDA is available, they can also be filled from Numpy arrays by JIT-compiling

This Python implementation of histogrammar been tested to guarantee compatibility with its Scala implementation.

Latest Python release: v1.0.28 (June 2022).
Latest Python release: v1.0.29 (June 2022).

Announcements
=============
Expand Down
7 changes: 4 additions & 3 deletions histogrammar/primitives/bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,8 +1004,8 @@ def num_bins(self, low=None, high=None):
if np.isclose(high, self.low + self.bin_width() * maxBin):
maxBin -= 1
high = self.low + self.bin_width() * (maxBin + 1)
# number of bins
num_bins = int((high - low) / self.bin_width())
# number of bins. use np.round to correct for machine level rounding errors
num_bins = int(np.round((high - low) / self.bin_width()))
return num_bins

def bin_width(self):
Expand Down Expand Up @@ -1096,7 +1096,8 @@ def bin_edges(self, low=None, high=None):
if np.isclose(high, self.low + self.bin_width() * maxBin):
maxBin -= 1
high = self.low + self.bin_width() * (maxBin + 1)

# new low and high values reset, so redo num_bins
num_bins = self.num_bins(low, high)
edges = np.linspace(low, high, num_bins + 1)
return edges

Expand Down
4 changes: 2 additions & 2 deletions histogrammar/primitives/sparselybin.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,6 @@ def bin_edges(self, low=None, high=None):
elif low is not None and high is not None:
if low > high:
raise RuntimeError('low {low} greater than high {high}'.format(low=low, high=high))
# number of bins, before low/high adjustments
num_bins = self.num_bins(low, high)
# lowest edge
if low is None:
low = self.low
Expand All @@ -752,6 +750,8 @@ def bin_edges(self, low=None, high=None):
if np.isclose(high, self.origin + self.bin_width() * maxBin):
maxBin -= 1
high = self.origin + self.bin_width() * (maxBin + 1)
# number of bins, after low/high adjustments
num_bins = self.num_bins(low, high)
edges = np.linspace(low, high, num_bins + 1)
return edges

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

MAJOR = 1
REVISION = 0
PATCH = 28
PATCH = 29
DEV = False
# NOTE: also update version at: README.rst

Expand Down

0 comments on commit 5c98f72

Please sign in to comment.