Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Histogram Comparison (Public Facing) #778

Draft
wants to merge 31 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e929fe2
Update BoostHistogramHandsOn.ipynb
gohil-jay Jun 23, 2022
4700409
Merge branch 'scikit-hep:develop' into develop
gohil-jay Jun 27, 2022
c26aa03
Merge branch 'scikit-hep:develop' into develop
gohil-jay Jun 27, 2022
7d8252a
Updated all numpy.testing asserts to pytest.approx
gohil-jay Jun 27, 2022
a063d37
Updated all numpy.testing asserts to pytest.approx
gohil-jay Jun 27, 2022
65f0a1c
Updated all numpy.testing asserts to pytest.approx
gohil-jay Jun 27, 2022
b877ee5
style: pre-commit fixes
pre-commit-ci[bot] Jun 29, 2022
190e6ce
Wrapping this assert to remove test failing
gohil-jay Jun 30, 2022
b69b165
Merge branch 'scikit-hep:develop' into issue157
gohil-jay Jul 1, 2022
b6b0003
Added histograms comparison function
gohil-jay Jul 1, 2022
ebe0cff
Added 'compare' operation
gohil-jay Jul 1, 2022
772104c
style: pre-commit fixes
pre-commit-ci[bot] Jul 1, 2022
220c1ca
Tweaked the comparison function
gohil-jay Jul 1, 2022
246cc2f
style: pre-commit fixes
pre-commit-ci[bot] Jul 1, 2022
8a61023
Added type annotation
gohil-jay Jul 1, 2022
c2994e2
Updated function return from bool to colorized str
gohil-jay Jul 1, 2022
d1f5797
Updated annotation type and syntax
gohil-jay Jul 1, 2022
fb5af1e
style: pre-commit fixes
pre-commit-ci[bot] Jul 1, 2022
bae1ecd
Updated function with linear checks & f"str return
gohil-jay Jul 1, 2022
e6a3a2a
style: pre-commit fixes
pre-commit-ci[bot] Jul 1, 2022
8a36fe8
Fixed a typo
gohil-jay Jul 1, 2022
e0c2f5a
Removed colorized return text
gohil-jay Jul 1, 2022
b7096bd
Solved few pylint issues
gohil-jay Jul 1, 2022
fd2bcec
style: pre-commit fixes
pre-commit-ci[bot] Jul 1, 2022
69ab6dc
Redefined storage check & removed variance check
gohil-jay Jul 3, 2022
8df3ff6
Added histogram storage type operation
gohil-jay Jul 3, 2022
e9c1bd8
Tiny changes for pylint
gohil-jay Jul 3, 2022
9e79f51
Merge branch 'scikit-hep:develop' into issue157-2
gohil-jay Jul 14, 2022
9f5ebb9
Updated comparison function and mapped np.allclose
gohil-jay Jul 14, 2022
ceef764
Operation rename (compare -> allclose)
gohil-jay Jul 14, 2022
c132c1c
style: pre-commit fixes
pre-commit-ci[bot] Aug 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ histograms can be plotted via any compatible library, such as [mplhep][].
* `.kind`: Either `bh.Kind.COUNT` or `bh.Kind.MEAN`, depending on storage
* `.sum(flow=False)`: The total count of all bins
* `.project(ax1, ax2, ...)`: Project down to listed axis (numbers). Can also reorder axes.
* `.allclose(second_hist)`: Compare the histogram with another histogram
* `.to_numpy(flow=False, view=False)`: Convert to a NumPy style tuple (with or without under/overflow bins)
* `.view(flow=False)`: Get a view on the bin contents (with or without under/overflow bins)
* `.values(flow=False)`: Get a view on the values (counts or means, depending on storage)
Expand Down
23 changes: 23 additions & 0 deletions src/boost_histogram/_internal/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,32 @@ def view(
"""
return _to_view(self._hist.view(flow))

def allclose(self: "Histogram", hist2: "Histogram", **kwargs) -> str:
if not np.allclose(self.view().shape, hist2.view().shape, **kwargs):
return f"The histogram dimensions [{self.view().shape} and {hist2.view().shape}] are not equal."
if not np.allclose(self.view(), hist2.view(), **kwargs):
return f"The histogram contents : {self.view()} and {hist2.view()} are not equal."
if not np.allclose(self.to_numpy()[1], hist2.to_numpy()[1], **kwargs):
return f"The edges : {self.to_numpy()[1]} and {hist2.to_numpy()[1]} are not equal."
if self._storage_type != hist2._storage_type:
return f"The storage types ({str(self._storage_type).split('.')[-1][:-2]} and {str(hist2._storage_type).split('.')[-1][:-2]}) are not equal."
if list(self.axes) != list(hist2.axes):
return f"The axes : {list(self.axes)} and {list(hist2.axes)} are not equal."
return ""

def __array__(self) -> "np.typing.NDArray[Any]":
return self.view(False)

def __array_function__(
self,
ufunc: typing.Any,
*inputs: typing.Any,
**kwargs: typing.Any,
) -> typing.Any:
if ufunc is np.allclose:
return inputs[1][0].allclose(inputs[1][1], **kwargs)
return NotImplemented

def __eq__(self, other: Any) -> bool:
return hasattr(other, "_hist") and self._hist == other._hist

Expand Down