Skip to content

Commit

Permalink
Add documentation on histogram equality.
Browse files Browse the repository at this point in the history
  • Loading branch information
ynikitenko committed Nov 4, 2021
1 parent ba1e15b commit 7f3f1b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions docs/source/structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@ Structures
Histograms
----------

.. module:: lena.structures
.. module:: lena.structures.histogram
.. _Histogram:

.. autoclass:: histogram
:members:
:inherited-members:

.. automethod:: __eq__

.. autoclass:: Histogram
:members:
:inherited-members:
.. :members: fill, compute, run
.. module:: lena.structures
.. autoclass:: NumpyHistogram
:members:

Expand Down
11 changes: 8 additions & 3 deletions lena/structures/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,16 @@ def __init__(self, edges, bins=None, initial_value=0):
self.nbins = [len(edges)-1]

def __eq__(self, other):
"""Note that in many cases floating numbers should be compared
approximately (isclose).
"""Two histograms are equal, if and only if they have
equal bins and equal edges.
If *other* is not a :class:`.histogram`, return `False`.
Note that floating numbers should be compared
approximately (using :func:`math.isclose`).
"""
if not isinstance(other, histogram):
# in Python comparison between incomparable types is allowed
# in Python comparison between different types is allowed
return False
return self.bins == other.bins and self.edges == other.edges

Expand Down

0 comments on commit 7f3f1b8

Please sign in to comment.