Re: the NaN effect :-| [message #54391] |
Tue, 12 June 2007 09:45  |
Conor
Messages: 138 Registered: February 2007
|
Senior Member |
|
|
On Jun 12, 12:11 pm, metachronist <rkombi...@gmail.com> wrote:
> On Jun 13, 12:59 am, Paolo Grigis <pgri...@astro.phys.ethz.ch> wrote:
>
>> metachronist wrote:
>>> [...]
>
>>> IDL's docu says:
>>> <snip from IDL ref guide: Page 1269/4090>
>>> If the MAX function is run on an array containing NaN values and the
>>> NAN keyword is not set, an invalid result will occur.
>>> </snip>
>>> The same is said for MIN also.
>
>>> So the result (OPS with MIN/MAX) is directly proportional to the
>>> number of NaN's we eat? er, add to the array? :P
>
>>> So what is right and what is wrong? Enlighten, please.
>
>> Why do you expect an "invalid" result to make sense?
>
>> Ciao,
>> Paolo
>
> Paolo,
> I know the right way to do is include the NaN keyword, but minus the
> keyword, shouldn't it fail even with single 'NaN' in the array, per
> the documentation? That's what I was wondering. I mean the min and max
> values were "valid" in the first two cases? Am I making sense?
> /rk
I think what Paolo was implying (and what the documentation also
implies) is not that an error is returned, but that the result itself
is invalid - i.e. wrong. Just because the result is invalid doesn't
mean that an error will be returned, and it doesn't mean that the
result might not be correct sometimes. It just means that you
shouldn't use it :)
|
|
|
Re: the NaN effect :-| [message #54392 is a reply to message #54391] |
Tue, 12 June 2007 09:42   |
Paolo Grigis
Messages: 171 Registered: December 2003
|
Senior Member |
|
|
metachronist wrote:
> On Jun 13, 12:59 am, Paolo Grigis <pgri...@astro.phys.ethz.ch> wrote:
>> metachronist wrote:
>>> [...]
>>> IDL's docu says:
>>> <snip from IDL ref guide: Page 1269/4090>
>>> If the MAX function is run on an array containing NaN values and the
>>> NAN keyword is not set, an invalid result will occur.
>>> </snip>
>>> The same is said for MIN also.
>>> So the result (OPS with MIN/MAX) is directly proportional to the
>>> number of NaN's we eat? er, add to the array? :P
>>> So what is right and what is wrong? Enlighten, please.
>> Why do you expect an "invalid" result to make sense?
>>
>> Ciao,
>> Paolo
>>
> Paolo,
> I know the right way to do is include the NaN keyword, but minus the
> keyword, shouldn't it fail even with single 'NaN' in the array, per
> the documentation? That's what I was wondering. I mean the min and max
> values were "valid" in the first two cases? Am I making sense?
Well, my point was that if something is declared as "invalid", it does
not means "it is always wrong", rather that "it is *not* always right",
and therefore one should treat *all* the results as suspect to be on
the safe side (of course this is a simple example, in other cases it
may be less obvious).
Of course it is nice to know the rationale (see Lajos' post).
Ciao,
Paolo
> /rk
>
>
|
|
|
Re: the NaN effect :-| [message #54394 is a reply to message #54392] |
Tue, 12 June 2007 09:11   |
rkombiyil
Messages: 59 Registered: March 2006
|
Member |
|
|
On Jun 13, 12:59 am, Paolo Grigis <pgri...@astro.phys.ethz.ch> wrote:
> metachronist wrote:
>> [...]
>
>> IDL's docu says:
>> <snip from IDL ref guide: Page 1269/4090>
>> If the MAX function is run on an array containing NaN values and the
>> NAN keyword is not set, an invalid result will occur.
>> </snip>
>> The same is said for MIN also.
>
>> So the result (OPS with MIN/MAX) is directly proportional to the
>> number of NaN's we eat? er, add to the array? :P
>
>> So what is right and what is wrong? Enlighten, please.
>
> Why do you expect an "invalid" result to make sense?
>
> Ciao,
> Paolo
>
Paolo,
I know the right way to do is include the NaN keyword, but minus the
keyword, shouldn't it fail even with single 'NaN' in the array, per
the documentation? That's what I was wondering. I mean the min and max
values were "valid" in the first two cases? Am I making sense?
/rk
|
|
|
|
Re: the NaN effect :-| [message #54396 is a reply to message #54395] |
Tue, 12 June 2007 08:53   |
Brian Larsen
Messages: 270 Registered: June 2006
|
Senior Member |
|
|
This probably have everything to do with the way that min() and max()
are written. They are probably quite clever (or like to think they
are :) ) and so I think that if you move the NaN around you will get
different answers just as with different numbers of NaN's.
I have never tested to see if/how much slower they are if you just
always use the /nan keyword. Might me interesting...
Brian
------------------------------------------------------------ ---------------------
Brian Larsen
Boston University
Center for Space Physics
On Jun 12, 11:33 am, metachronist <rkombi...@gmail.com> wrote:
> This stumps me.. We had some discussions on NaN's earlier, but mostly
> wrt 'TOTAL'
> Lets say,
> IDL>a=[6.2,12.5,14.1,0.,22,!values.f_nan]
> IDL> print,max(a)
> 22.0000
> IDL> print,min(a)
> 0.00000
>
> ; Now I increase number of NaN's in the array :D
>
> IDL> a=[6.2,12.5,14.1,0.,!values.f_nan,22,!values.f_nan]
> IDL> print,max(a)
> 22.0000
> IDL> print,min(a)
> 0.00000
>
> ; go on, repeat this (it is 00:23 where I am @, so CARPE NOCTEM! ) :-P
>
> IDL> a=[!values.f_nan,6.2,12.5,14.1,0.,!values.f_nan,22,!values.f _nan]
> IDL> print,min(a)
> NaN
> IDL> print,max(a)
> NaN
> ============================================
> Same goes for MIN also. ??!!
>
> IDL's docu says:
> <snip from IDL ref guide: Page 1269/4090>
> If the MAX function is run on an array containing NaN values and the
> NAN keyword is not set, an invalid result will occur.
> </snip>
> The same is said for MIN also.
>
> So the result (OPS with MIN/MAX) is directly proportional to the
> number of NaN's we eat? er, add to the array? :P
>
> So what is right and what is wrong? Enlighten, please.
> /metachronist
|
|
|
Re: the NaN effect :-| [message #54471 is a reply to message #54396] |
Wed, 13 June 2007 13:51  |
Brian Larsen
Messages: 270 Registered: June 2006
|
Senior Member |
|
|
> I have never tested to see if/how much slower they are if you just
> always use the /nan keyword. Might me interesting...
OK, so I had to know what the difference was and it certainly
exists...
running this code I see a difference, of course attach the normal
disclaimers that I just tried once and I was still using my laptop
while this was running and all that jazz
a=findgen(10000)
print, systime()
for i=0l, 1e6 do b=max(a)
print, systime()
print, systime()
for i=0l, 1e6 do b=max(a, /nan)
print, systime()
end
and the output:
Wed Jun 13 16:39:06 2007
Wed Jun 13 16:40:18 2007
Wed Jun 13 16:40:18 2007
Wed Jun 13 16:44:02 2007
So the NaN adds a lot of time, but better safe than "invalid"
certainly.
Brian
------------------------------------------------------------ ---------------------
Brian Larsen
Boston University
Center for Space Physics
|
|
|