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

Added comparison function as histogram operation (with colorized + info based string return) #763

Draft
wants to merge 28 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ histograms can be plotted via any compatible library, such as [mplhep][].
* `*=`: Multiply by a scaler (not all storages) (`hist * scalar` and `scalar * hist` supported too)
* `/=`: Divide by a scaler (not all storages) (`hist / scalar` supported too)
* `.kind`: Either `bh.Kind.COUNT` or `bh.Kind.MEAN`, depending on storage
* `._storage_type`: Fetch histogram storage type class
* `.sum(flow=False)`: The total count of all bins
* `.project(ax1, ax2, ...)`: Project down to listed axis (numbers). Can also reorder axes.
* `.compare(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
11 changes: 11 additions & 0 deletions src/boost_histogram/_internal/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,17 @@ def ndim(self) -> int:
"""
return self._hist.rank()

def compare(self, hist2: "Histogram") -> str:
if not np.allclose(self.view().shape, hist2.view().shape):
return f"The histogram dimensions [{self.view().shape} and {hist2.view().shape}] are not equal."
if not np.allclose(self.view(), hist2.view()):
return f"The histogram contents :\n {self.view()} \nand\n {hist2.view()} \nare not equal."
if self._storage_type != hist2._storage_type:
return f"The storage types ({str(self._storage_type).rsplit('.', maxsplit=1)[-1][:-2]} and {str(hist2._storage_type).rsplit('.', maxsplit=1)[-1][:-2]}) are not equal."
if list(self.axes) != list(hist2.axes):
return f"The axes :\n {list(self.axes)} \nand\n {list(hist2.axes)} \nare not equal."
return ""

def view(
self, flow: bool = False
) -> Union["np.typing.NDArray[Any]", WeightedSumView, WeightedMeanView, MeanView]:
Expand Down