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

Home » Public Forums » archive » MIN(), MAX() with NaN values
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
MIN(), MAX() with NaN values [message #89051] Sat, 19 July 2014 07:24 Go to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
The documentation for MIN() says that

"Note: If the MIN function is run on an array containing NaN values and the NAN keyword is not set, an invalid result will occur."

However, most of the time MIN() seems to work fine with NaN values.

IDL> print,!version
{ x86_64 darwin unix Mac OS X 8.3 Nov 15 2013 64 64}
IDL> a = randomn(seed,500,500)
IDL> a[1,1] = replicate(!values.f_nan,4)
IDL> print,min(a)
-4.76949

The invalid results seem to occur when the NaN values are at the edge of the image (or in the first or last value of a vector)

IDL> a = findgen(10)
IDL> a[0] = !values.f_nan
IDL> print,min(a)
NaN

I can't fault the design or documentation of MIN() -- it says to use /NAN when NaN values are present. But we had difficulty debugging our code since our images have a few randomly located NaN values, and so using MIN() without /NaN was working 99% of the time. We have now added /NaN to the code -- and taken the factor of ~3 speed penalty -- so it works 100% of the time.
Re: MIN(), MAX() with NaN values [message #89053 is a reply to message #89051] Sat, 19 July 2014 20:00 Go to previous message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
I noticed the same thing earlier today!

IDL> print, min([1.0, !values.f_nan])
1.00000
IDL> print, max([1.0, !values.f_nan])
1.00000
IDL> print, min([1.0, !values.f_nan], NAN=0)
1.00000
IDL> print, max([1.0, !values.f_nan], NAN=0)
1.00000
IDL> help, !version
** Structure !VERSION, 8 tags, length=104, data length=100:
ARCH STRING 'x86_64'
OS STRING 'darwin'
OS_FAMILY STRING 'unix'
OS_NAME STRING 'Mac OS X'
RELEASE STRING '8.2'
BUILD_DATE STRING 'Apr 10 2012'
MEMORY_BITS INT 64
FILE_OFFSET_BITS
INT 64
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Matrix a*b in loop
Next Topic: mpfitfun

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

Current Time: Wed Oct 08 09:20:12 PDT 2025

Total time taken to generate the page: 0.00418 seconds