[Numpy-discussion] [Feature Suggestion]More comparison functions for floating point numbers

2015-10-19 Thread cy18
I think these would be useful and easy to implement.

greater_close(a, b) = greater_equal(a, b) | isclose(a, b)
less_close(a, b) = less_equal(a, b) | isclose(a, b)
greater_no_close = greater(a, b) & ~isclose(a, b)
less_no_close = less(a, b) & ~isclose(a, b)

The results are element-wise, just like the original functions.

I'm not sure if it is useful enough to be a part of numpy. If so, I will
try to implement them and make a pull request.
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] [Feature Suggestion]More comparison functions for floating point numbers

2015-10-19 Thread Robert Kern
On Mon, Oct 19, 2015 at 9:51 PM, cy18  wrote:
>
> It would be useful when we need to subtracting a bit before comparing by
greater or less. By subtracting a bit, we only have an absolute error
tolerance and with the new functions, we can have both absolute and
relative error tolerance. This is how isclose(a, b) better than
abs(a-b)<=atol.

You just adjust the value by whichever tolerance is greatest in magnitude.

--
Robert Kern
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] [Feature Suggestion]More comparison functions for floating point numbers

2015-10-19 Thread cy18
It would be useful when we need to subtracting a bit before comparing by
greater or less. By subtracting a bit, we only have an absolute error
tolerance and with the new functions, we can have both absolute and
relative error tolerance. This is how isclose(a, b) better than
abs(a-b)<=atol.


2015-10-19 15:46 GMT-04:00 Chris Barker :

>
>
> On Mon, Oct 19, 2015 at 3:06 AM, cy18  wrote:
>
>> I think these would be useful and easy to implement.
>>
>> greater_close(a, b) = greater_equal(a, b) | isclose(a, b)
>> less_close(a, b) = less_equal(a, b) | isclose(a, b)
>> greater_no_close = greater(a, b) & ~isclose(a, b)
>> less_no_close = less(a, b) & ~isclose(a, b)
>>
>
> What's the use-case here? we need is_close because we want to test
> equality, but precision errors are such that two floats may be as close to
> equal as they can be given the computations done. And the assumption is
> that you don't care about the precision to the point you specify.
>
> But for a greater_than (or equiv) comparison, if you the precision is not
> important beyond a certain level, then it's generally not important whether
> you get greater than or less than when it's that close
>
> And this would great a wierd property that some values would be greater
> than, less than, and equal to a target value -- pretty weird!
>
> note that you can get the same effect by subtracting a bit from your
> comparison value for a greater than check...
>
> But maybe there is a common use-case that I'm not thinking of..
>
> -CHB
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR(206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115   (206) 526-6317   main reception
>
> chris.bar...@noaa.gov
>
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] [Feature Suggestion]More comparison functions for floating point numbers

2015-10-19 Thread Chris Barker
On Mon, Oct 19, 2015 at 3:06 AM, cy18  wrote:

> I think these would be useful and easy to implement.
>
> greater_close(a, b) = greater_equal(a, b) | isclose(a, b)
> less_close(a, b) = less_equal(a, b) | isclose(a, b)
> greater_no_close = greater(a, b) & ~isclose(a, b)
> less_no_close = less(a, b) & ~isclose(a, b)
>

What's the use-case here? we need is_close because we want to test
equality, but precision errors are such that two floats may be as close to
equal as they can be given the computations done. And the assumption is
that you don't care about the precision to the point you specify.

But for a greater_than (or equiv) comparison, if you the precision is not
important beyond a certain level, then it's generally not important whether
you get greater than or less than when it's that close

And this would great a wierd property that some values would be greater
than, less than, and equal to a target value -- pretty weird!

note that you can get the same effect by subtracting a bit from your
comparison value for a greater than check...

But maybe there is a common use-case that I'm not thinking of..

-CHB

-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion