Implement __eq__ dunder method for MultiIndexSet
Currently, checking equality between two MultiIndexSet
instances falls back to checking whether the two instances share the same identity (basically is
).
What we want, however, checking whether two MultiIndexSet
instances have the same value:
>>> import minterpy as mp
>>> a = mp.MultiIndexSet.from_degree(2, 3, 1)
>>> b = mp.MultiIndexSet.from_degree(2, 3, 1)
>>> a is b
False # As it should be; they are not the same object
>>> a == b
False # Should have been True
To check the equality of value between two MultiIndexSet
instances, we need a custom __eq__()
dunder method.
I propose implementing this method and define that two MultiIndexSet
instances are equal in value iff:
- The sets of exponents are the same
- The
lp_degree
properties are the same
Because the above properties tell us everything about a MultiIndexSet
instance.
Other important properties like spatial_dimension
and polynomial_degree
are actually inferred quantities from the given two above properties; so there's no need of explicitly checking them.
One possible complication from the implementation is checking the equality between two lp_degree
's; they are stored as float
in the instance.
We'll use math.isclose
but who knows what kind of edge cases that may arise from comparing floats with representation errors...
The exponents are stored as NumPy integers so checking the equality won't be complicated.