<HTML>
<HEAD>
<TITLE>Re: [vtk-developers] vtkMath inline choices...</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>numeric_limits provides the value for NaN (two values actually).  It is already used for the implementation of vtkMath::Nan(), which returns the double value for NaN.  numic_limits does not, however, provide any means for testing for NaN.<BR>
<BR>
-Ken<BR>
<BR>
<BR>
On 1/31/11 1:12 PM, "Will Schroeder" <<a href="will.schroeder@kitware.com">will.schroeder@kitware.com</a>> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>It's been a long time but I remember using templating magic in particular C++ numeric_limits which has some support for NaN...does it make sense to use something along these lines? ITK uses numeric traits pretty extensively, but I'm not sure whether it would fit into the VTK world.<BR>
<BR>
W<BR>
<BR>
On Mon, Jan 31, 2011 at 1:51 PM, David Gobbi <<a href="david.gobbi@gmail.com">david.gobbi@gmail.com</a>> wrote:<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>I think it is best if all code that uses isnan() is explicit about the<BR>
data type, rather than using an overloaded isnan().<BR>
<BR>
The reason is as follows: when I see any float/double function<BR>
being applied to an integer, including functions like sin(), cos(),<BR>
rint(), etcetera, my immediate thought is "something is wrong<BR>
here".  And I don't want to have to search for a header file and<BR>
look at the isnan() definition to convince myself that the code is,<BR>
in fact, correct.  I'd rather have the code in vtkLookupTable.cxx<BR>
(or in any other class that uses isnan) be sufficiently explicit<BR>
that I don't have to look elsewhere.<BR>
<BR>
That's just my 2 cents.<BR>
<FONT COLOR="#888888"><BR>
 - David<BR>
</FONT><BR>
<BR>
On Mon, Jan 31, 2011 at 11:17 AM, Moreland, Kenneth <<a href="kmorel@sandia.gov">kmorel@sandia.gov</a>> wrote:<BR>
> Since we are talking about inlining vtkMath::IsNaN anyway, why not just<BR>
> provide overloaded inlined functions for integer types that always return<BR>
> false?  That way the compiler removes the check for you without having to<BR>
> write any type-dependent case code.<BR>
><BR>
> -Ken<BR>
><BR>
><BR>
> On 1/30/11 11:24 AM, "David Gobbi" <<a href="david.gobbi@gmail.com">david.gobbi@gmail.com</a>> wrote:<BR>
><BR>
> Hi Ken,<BR>
><BR>
> The main issue with performance and IsNan() is more about how it is used<BR>
> than about whether it is inlined.  My guess is that Sean saw a performance<BR>
> hit because IsNan() was used inside vtkLookupTable, which has some of the<BR>
> hottest loops in all of VTK.  The IsNan() check was applied to all<BR>
> datatypes, even though it is not relevant for integer data.<BR>
><BR>
> I've patched vtkLookupTable so that it overloads vtkLinearLookup() and the<BR>
> IsNan check is only done on float and double.  The new code gives me a 40%<BR>
> speedup in color mapping a 16-bit image to RGBA.  The patch can be seen<BR>
> here: <a href="http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=1c348fcb">http://vtk.org/gitweb?p=VTK.git;a=commitdiff;h=1c348fcb</a>.  I merged it<BR>
> directly into master.<BR>
><BR>
> There is also a function in vtkScalarsToColorsPainter that applies IsNan()<BR>
> regardless of scalar type.  It could benefit from a similar patch.<BR>
><BR>
>  - David<BR>
><BR>
><BR>
><BR>
>    ****      Kenneth Moreland<BR>
>     ***      Sandia National Laboratories<BR>
> ***********<BR>
> *** *** ***  email: <a href="kmorel@sandia.gov">kmorel@sandia.gov</a><BR>
> **  ***  **  phone: (505) 844-8919<BR>
>     ***      web:   <a href="http://www.cs.unm.edu/~kmorel">http://www.cs.unm.edu/~kmorel</a><BR>
><BR>
><BR>
_______________________________________________<BR>
Powered by www.kitware.com <<a href="http://www.kitware.com">http://www.kitware.com</a>> <BR>
<BR>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><BR>
<BR>
Follow this link to subscribe/unsubscribe:<BR>
<a href="http://www.vtk.org/mailman/listinfo/vtk-developers">http://www.vtk.org/mailman/listinfo/vtk-developers</a><BR>
<BR>
</SPAN></FONT></BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
<BR>
</SPAN></FONT></BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT><FONT SIZE="2"><FONT FACE="Consolas, Courier New, Courier"><SPAN STYLE='font-size:10pt'><BR>
   ****      Kenneth Moreland<BR>
    ***      Sandia National Laboratories<BR>
***********  <BR>
*** *** ***  email: <a href="kmorel@sandia.gov">kmorel@sandia.gov</a><BR>
**  ***  **  phone: (505) 844-8919<BR>
    ***      web:   <a href="http://www.cs.unm.edu/~kmorel">http://www.cs.unm.edu/~kmorel</a><BR>
</SPAN></FONT></FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'><BR>
</SPAN></FONT>
</BODY>
</HTML>