Open andreacortis opened 3 years ago
this makes a lot more sense.
how would you go about overloading __eq__
? overwrite the method in Base
i have not seen anything like this in the literature (i might be reading the wrong textbooks). could a check be implemented to first compare the uncertainties between two quantities... and then proceed with the assertion for quantity equality only if the uncertainties are equivalent?
something like (look before you leap):
if mass_a.uncertainty == mass_b.uncertainty:
if mass_a.quantity == mass_b.quantity:
print("equal")
else:
print("not equal")
else:
print("uncertainties don't align... equality not possible")
let's keep on looking for definitions in literature. Maybe we need to think if the eq as overloading an approximate equality?
So, to comment on the code review by Matt (@mlr07), what does it mean for two quantities to be equal?
Clearly, if the quantities do not have any uncertainties to them, then we can compare magnitudes up to tolerance. From the help function of
numpy allclose
But what if the quantities have some uncertainties to them? say we three define
mass
quantitiescan we assert that
m1==m2
? Or can we assert thatm2==m3
because the distribution form3
is contained within the distribution form2
?In other words, we would need to agree on equality for quantities, (maybe there is a definition in literature?) and only then overload the
__eq__
method. This is why I commented out that line asuse sparingly!!