comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: VALUE_LOCATE and NaNs
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: VALUE_LOCATE and NaNs [message #81813] Thu, 25 October 2012 08:07
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
On 10/25/2012 05:01 PM, wlandsman wrote:
> Indeed the VALUE_LOCATE documentation says about the input vector
>
>
> "A vector of monotonically increasing or decreasing values. Vector
> may be of type string, or any numeric type except complex, and may
> not contain the value NaN (not-a-number)"
>
> --Wayne

Yes, but the Value array contains NaNs, not the vector. Anyway, I got
the lesson and I will check for NaNs before using value_locate. Thanks!
Re: VALUE_LOCATE and NaNs [message #81815 is a reply to message #81813] Thu, 25 October 2012 08:05 Go to previous message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On 10/25/12 9:48 AM, Fab wrote:
> On 10/25/2012 03:41 PM, Kai Muehlbauer wrote:
>>
>> I can confirm:
>>
>> IDL> print, !VERSION
>> { x86_64 linux unix linux 7.1.1 Aug 21 2009 64 64}
>>
>> IDL> data = FINDGEN(10) & data[0] = !VALUES.F_NAN
>> IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
>> -1
>> % Program caused arithmetic error: Floating illegal operand
>> IDL>
>>
>> Cheers,
>> Kai
>>
>
> At least the answer is right, but the warning is there ;-)
> So three different behaviours of value locate with three input types:
>
> IDL> data = FINDGEN(10) & data[0] = !VALUES.F_NAN
> IDL> p = VALUE_LOCATE(INDGEN(10), data) & print, p[0]
> 0
> % Program caused arithmetic error: Floating illegal operand
> IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
> -1
> % Program caused arithmetic error: Floating illegal operand
> IDL> p = VALUE_LOCATE(FINDGEN(10), data) & print, p[0]
> -1
>
>

I agree with Craig - there is no well-defined answer for what
VALUE_LOCATE should return when faced with a NaN. But it also shouldn't
give different answers depending on the type of location array.

-Jeremy.
Re: VALUE_LOCATE and NaNs [message #81816 is a reply to message #81815] Thu, 25 October 2012 08:01 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Thursday, October 25, 2012 10:30:22 AM UTC-4, Craig Markwardt wrote:

>
> The lesson is: you can't use NAN's with VALUE_LOCATE().
>
Indeed the VALUE_LOCATE documentation says about the input vector


"A vector of monotonically increasing or decreasing values. Vector may be of type string, or any numeric type except complex, and may not contain the value NaN (not-a-number)"

--Wayne
Re: VALUE_LOCATE and NaNs [message #81817 is a reply to message #81816] Thu, 25 October 2012 07:59 Go to previous message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
Le jeudi 25 octobre 2012 16:30:22 UTC+2, Craig Markwardt a écrit :
> On Thursday, October 25, 2012 5:14:47 AM UTC-4, Fab wrote:
>
>> Dear IDLers,
>
>>
>
>> I am quite an adept of using NaNs as missing values for my data, because
>
>> many IDL routines go along with them. However, some of the routines are
>
>> not really documented about how they handle NaNs.
>
>>
>
>> See the following example:
>
>> IDL> data = FINDGEN(10) & data[0] = !VALUES.F_NAN
>
>> IDL> p = VALUE_LOCATE(FINDGEN(10), data) & print, p[0]
>
>> -1
>
>> IDL> p = VALUE_LOCATE(INDGEN(10), data) & print, p[0]
>
>> 0
>
>> % Program caused arithmetic error: Floating illegal operand
>
>>
>
>>
>
>>
>
>> Which is quite dangerous! If I didn't debug my code to find the origin
>
>> of the Floating illegal operand warning, value_locate's output would be
>
>> wrong.
>
>>
>
>>
>
>>
>
>> Someone else than me thinking of this as a bug?
>
>
>
> NAN is neither greater than or less than any other finite number. For the purposes of VALUE_LOCATE(), there is no way to indicate "complete failure" other than the message you saw. I think the results of VALUE_LOCATE() are undefined, but this should be documented more explicitly in the reference documentation.
>
>
>
> The lesson is: you can't use NAN's with VALUE_LOCATE().
>
>
>
> Craig

In addition, there is one more inconsistency: 'value_locate' is considering NAN as the smallest value, while 'sort' is doing the opposite. Both being wrong as Craig said.
In IDL 8.2.1 and Win7, no warning/error messages are provided.
IDL> data=findgen(10) & data[1] = !Values.F_NAN
IDL> print,value_locate(findgen(10),data)
0 -1 2 3 4 5 6 7 8 9
IDL> print,sort(data)
0 2 3 4 5 6 7 8 9 1
alx.
Re: VALUE_LOCATE and NaNs [message #81819 is a reply to message #81817] Thu, 25 October 2012 07:30 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Thursday, October 25, 2012 5:14:47 AM UTC-4, Fab wrote:
> Dear IDLers,
>
> I am quite an adept of using NaNs as missing values for my data, because
> many IDL routines go along with them. However, some of the routines are
> not really documented about how they handle NaNs.
>
> See the following example:
> IDL> data = FINDGEN(10) & data[0] = !VALUES.F_NAN
> IDL> p = VALUE_LOCATE(FINDGEN(10), data) & print, p[0]
> -1
> IDL> p = VALUE_LOCATE(INDGEN(10), data) & print, p[0]
> 0
> % Program caused arithmetic error: Floating illegal operand
>
>
>
> Which is quite dangerous! If I didn't debug my code to find the origin
> of the Floating illegal operand warning, value_locate's output would be
> wrong.
>
>
>
> Someone else than me thinking of this as a bug?

NAN is neither greater than or less than any other finite number. For the purposes of VALUE_LOCATE(), there is no way to indicate "complete failure" other than the message you saw. I think the results of VALUE_LOCATE() are undefined, but this should be documented more explicitly in the reference documentation.

The lesson is: you can't use NAN's with VALUE_LOCATE().

Craig
Re: VALUE_LOCATE and NaNs [message #81820 is a reply to message #81819] Thu, 25 October 2012 06:48 Go to previous message
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
On 10/25/2012 03:41 PM, Kai Muehlbauer wrote:
>
> I can confirm:
>
> IDL> print, !VERSION
> { x86_64 linux unix linux 7.1.1 Aug 21 2009 64 64}
>
> IDL> data = FINDGEN(10) & data[0] = !VALUES.F_NAN
> IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
> -1
> % Program caused arithmetic error: Floating illegal operand
> IDL>
>
> Cheers,
> Kai
>

At least the answer is right, but the warning is there ;-)
So three different behaviours of value locate with three input types:

IDL> data = FINDGEN(10) & data[0] = !VALUES.F_NAN
IDL> p = VALUE_LOCATE(INDGEN(10), data) & print, p[0]
0
% Program caused arithmetic error: Floating illegal operand
IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
-1
% Program caused arithmetic error: Floating illegal operand
IDL> p = VALUE_LOCATE(FINDGEN(10), data) & print, p[0]
-1
Re: VALUE_LOCATE and NaNs [message #81821 is a reply to message #81820] Thu, 25 October 2012 06:41 Go to previous message
Kai Muehlbauer is currently offline  Kai Muehlbauer
Messages: 13
Registered: February 2011
Junior Member
Am 25.10.2012 13:10, schrieb alx:
> Le jeudi 25 octobre 2012 11:57:31 UTC+2, Fab a �crit :
>> On 10/25/2012 11:34 AM, alx wrote:
>>
>>> Please note that:
>>
>>> IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
>>
>>> -1
>>
>>> gives the correct result.
>>
>>>
>>
>>> alx.
>>
>>
>>
>> Well this is even more confusing. But in my case it doesn't:
>>
>>
>>
>> IDL> data = FINDGEN(10) & data[0] = !VALUES.F_NAN
>>
>> IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
>>
>> -1
>>
>> % Program caused arithmetic error: Floating illegal operand
>>
>> IDL> print, !VERSION
>>
>> { x86_64 linux unix linux 7.1.1 Aug 21 2009 64 64}
>
> Well, I checked with
> { x86_64 Win32 Windows Microsoft Windows 8.2.1 Aug 20 2012 64 64}
> alx.
>

I can confirm:

IDL> print, !VERSION
{ x86_64 linux unix linux 7.1.1 Aug 21 2009 64 64}

IDL> data = FINDGEN(10) & data[0] = !VALUES.F_NAN
IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
-1
% Program caused arithmetic error: Floating illegal operand
IDL>

Cheers,
Kai
Re: VALUE_LOCATE and NaNs [message #81822 is a reply to message #81821] Thu, 25 October 2012 04:10 Go to previous message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
Le jeudi 25 octobre 2012 11:57:31 UTC+2, Fab a écrit :
> On 10/25/2012 11:34 AM, alx wrote:
>
>> Please note that:
>
>> IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
>
>> -1
>
>> gives the correct result.
>
>>
>
>> alx.
>
>
>
> Well this is even more confusing. But in my case it doesn't:
>
>
>
> IDL> data = FINDGEN(10) & data[0] = !VALUES.F_NAN
>
> IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
>
> -1
>
> % Program caused arithmetic error: Floating illegal operand
>
> IDL> print, !VERSION
>
> { x86_64 linux unix linux 7.1.1 Aug 21 2009 64 64}

Well, I checked with
{ x86_64 Win32 Windows Microsoft Windows 8.2.1 Aug 20 2012 64 64}
alx.
Re: VALUE_LOCATE and NaNs [message #81823 is a reply to message #81822] Thu, 25 October 2012 02:57 Go to previous message
Fabzi is currently offline  Fabzi
Messages: 305
Registered: July 2010
Senior Member
On 10/25/2012 11:34 AM, alx wrote:
> Please note that:
> IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
> -1
> gives the correct result.
>
> alx.

Well this is even more confusing. But in my case it doesn't:

IDL> data = FINDGEN(10) & data[0] = !VALUES.F_NAN
IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
-1
% Program caused arithmetic error: Floating illegal operand
IDL> print, !VERSION
{ x86_64 linux unix linux 7.1.1 Aug 21 2009 64 64}
Re: VALUE_LOCATE and NaNs [message #81824 is a reply to message #81823] Thu, 25 October 2012 02:34 Go to previous message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
Le jeudi 25 octobre 2012 11:14:47 UTC+2, Fab a écrit :
> Dear IDLers,
>
>
>
> I am quite an adept of using NaNs as missing values for my data, because
>
> many IDL routines go along with them. However, some of the routines are
>
> not really documented about how they handle NaNs.
>
> See the following example:
>
>
>
> IDL> data = FINDGEN(10) & data[0] = !VALUES.F_NAN
>
> IDL> p = VALUE_LOCATE(FINDGEN(10), data) & print, p[0]
>
> -1
>
> IDL> p = VALUE_LOCATE(INDGEN(10), data) & print, p[0]
>
> 0
>
> % Program caused arithmetic error: Floating illegal operand
>
>
>
> Which is quite dangerous! If I didn't debug my code to find the origin
>
> of the Floating illegal operand warning, value_locate's output would be
>
> wrong.
>
>
>
> Someone else than me thinking of this as a bug?
>
>
>
> Thanks,
>
>
>
> Fab

Please note that:
IDL> p = VALUE_LOCATE(LINDGEN(10), data) & print, p[0]
-1
gives the correct result.

alx.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: random numbers with gamma distribution
Next Topic: new graphics legend function: problems with symbol fill color

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:13:38 PDT 2025

Total time taken to generate the page: 0.00642 seconds