-
Notifications
You must be signed in to change notification settings - Fork 6
fix #488 : added rtol and atol arguments to LArray.equals #582
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
Conversation
>>> arr2 | ||
a a0 a1 | ||
1.0 1.0 | ||
>>> arr1.equals(arr2, atol=5e-5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should first show what happens when you do not specify any *tol argument, and I think the tolerance in the example should be chosen so that the result is True (or one example True and one False)
larray/core/array.py
Outdated
absolute(self - other) <= (atol + rtol * absolute(other)) | ||
|
||
The above equation is not symmetric in self and other, so that equals(self, other) might be different | ||
from equals(other, self) in some rare cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would write it like users are likely to encounter it: array1.equals(array2) might be different from array2.equals(array1)
larray/core/array.py
Outdated
""" | ||
Compares self with another array and returns True if they have the same axes and elements, False otherwise. | ||
|
||
Parameters | ||
---------- | ||
other: LArray-like | ||
Input array. aslarray() is used on a non-LArray input. | ||
rtol : float, optional | ||
The relative tolerance parameter (see Notes). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defaults to 0.
larray/core/array.py
Outdated
rtol : float, optional | ||
The relative tolerance parameter (see Notes). | ||
atol : float, optional | ||
The absolute tolerance parameter (see Notes). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem.
larray/core/array.py
Outdated
@@ -5228,6 +5241,24 @@ def equals(self, other, nan_equals=False): | |||
>>> arr1.equals(arr3) | |||
False | |||
|
|||
Test equality of two floating arrays within a given tolerance range. | |||
Return True if absolute(array1 - array2) <= (atol + rtol * absolute(arr2)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/arr2/array2/
1.0 1.0 | ||
>>> arr1.equals(arr2, atol=5e-5) | ||
False | ||
>>> arr1.equals(arr2, rtol=5e-5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the fact that array2 is 1 makes rtol not very interesting.
I would go for something like:
arr1 = LArray([10, 10], "a=a0,a1")
arr2 = LArray([9.99, 10.01], "a=a0,a1")
larray/core/array.py
Outdated
>>> arr2 = ones("a=a0,a1") | ||
>>> arr2 | ||
a a0 a1 | ||
1.0 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comments as in the release notes
larray/core/array.py
Outdated
""" | ||
Compares self with another array and returns True if they have the same axes and elements, False otherwise. | ||
|
||
Parameters | ||
---------- | ||
other: LArray-like | ||
Input array. aslarray() is used on a non-LArray input. | ||
rtol : float, optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int or float
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int? why int?
When users work with arrays containing big integers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The unit of your arrays could be kg when you only care at the ton level, or whatever.
larray/core/array.py
Outdated
@@ -5211,6 +5215,15 @@ def equals(self, other, nan_equals=False): | |||
bool | |||
Returns True if self is equal to other. | |||
|
|||
Notes | |||
----- | |||
For finite values, equals uses the following equation to test whether two floating point values are equivalent. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not only valid for floating point values (and it makes sense to use atol or rtol on int arrays too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/equivalent/equal/ Otherwise the wording might be ambiguous when we introduce .equiv (#237)
larray/core/array.py
Outdated
@@ -5228,6 +5241,24 @@ def equals(self, other, nan_equals=False): | |||
>>> arr1.equals(arr3) | |||
False | |||
|
|||
Test equality of two floating arrays within a given tolerance range. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not float only
larray/core/array.py
Outdated
@@ -5217,12 +5217,12 @@ def equals(self, other, rtol=0, atol=0, nan_equals=False): | |||
|
|||
Notes | |||
----- | |||
For finite values, equals uses the following equation to test whether two floating point values are equivalent. | |||
For finite values, equals uses the following equation to test whether two float or int values are equal: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/float or int//
False | ||
>>> arr1.equals(arr2, rtol=5e-5, atol=5e-5) | ||
True | ||
These two arguments can used to test the equality between two float or int arrays within a given relative and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/float or int//
larray/core/array.py
Outdated
@@ -5241,22 +5241,22 @@ def equals(self, other, rtol=0, atol=0, nan_equals=False): | |||
>>> arr1.equals(arr3) | |||
False | |||
|
|||
Test equality of two floating arrays within a given tolerance range. | |||
Return True if absolute(array1 - array2) <= (atol + rtol * absolute(arr2)). | |||
Test equality between two float or int arrays within a given tolerance range. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/float or int//
Closes :issue:`548`. | ||
|
||
* added the relative tolerance `rtol` and the absolute tolerance `atol` arguments to the `LArray.equals` method. | ||
These two arguments can used to test the equality between two float or int arrays within a given relative and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/can used/can be used/
…ls in order to test equality between two arrays within a relative or absolute tolerance
4afe0a0
to
4889238
Compare
in order to compare float arrays within a relative and/or absolute tolerance.