How to deal with nan value in the buffer? #8138
-
Hi, I'm a beginner in Halide. This work is truly remarkable. My question is how to deal with nan value in the buffer. Expr average3(Expr a, Expr b, Expr c) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Generally, unless one turns on
As a practical matter, for performant pipelines in many domains, a NaN in the input is an error and it is best to to preprocess the input to filter them if they can occur. |
Beta Was this translation helpful? Give feedback.
-
I recommend having a separate uint8 buffer that's 1 where there is valid data and 0 elsewhere. You then do the convolution by doing a weighted convolution using the separate buffer for the weights. You'll need to divide by the local sum of the weights to normalize. |
Beta Was this translation helpful? Give feedback.
Generally, unless one turns on
strict_float
, NaN is not allowed. Ifstrict_float
is in effect, NaNs should propagate through most mathematical operations. Comparisons involving NaN always fail per their specification. There are of course multiple kinds of NaN and theoreticallystrict_float
should obey IEEE 754 rules, but we don't have test coverage for this and I wouldn't be at all surprised if the exact rules are not always followed. That said one should get a NaN result for calculations using NaN inputs.strict_float
can either be specified as a target flag or used as an operator around specific expressions.As a practical matter, for performant pipelines in many domains, a NaN in the i…