Kaydet (Commit) 127c2683 authored tarafından Tor Lillqvist's avatar Tor Lillqvist Kaydeden (comit) Michael Meeks

tdf#94924: Return correct result 0 from OpenCL MIN and MAX when all args empty

Used the same style as existing code, added a new virtual isMinOrMax()
and add some special casing in Reduction::GenSlidingWindowFunction(),
and fsim_count() and fmax_count() functions that count how many
non-NaN numbers we actually see. As such, I am not sure at all that
this is an ideal way to do this, but will have to do for now.

Change-Id: I846a8d24f4563f8fae1a45971a4ce202ed918487
Signed-off-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst a6fa35ab
......@@ -64,6 +64,18 @@ static const char* publicFunc =
" (*p) += t?0:1;\n"
" return t?b:a+b;\n"
"}\n"
"double fmin_count(double a, double b, __private int *p) {\n"
" double result = fmin(a, b);\n"
" bool t = isnan(result);\n"
" (*p) += t?0:1;\n"
" return result;\n"
"}\n"
"double fmax_count(double a, double b, __private int *p) {\n"
" double result = fmax(a, b);\n"
" bool t = isnan(result);\n"
" (*p) += t?0:1;\n"
" return result;\n"
"}\n"
"double fsum(double a, double b) { return isNan(a)?b:a+b; }\n"
"double legalize(double a, double b) { return isNan(a)?b:a;}\n"
"double fsub(double a, double b) { return a-b; }\n"
......@@ -1698,7 +1710,7 @@ public:
ss << ") {\n";
ss << "double tmp = " << GetBottom() << ";\n";
ss << "int gid0 = get_global_id(0);\n";
if (isAverage())
if (isAverage() || isMinOrMax())
ss << "int nCount = 0;\n";
ss << "double tmpBottom;\n";
unsigned i = vSubArguments.size();
......@@ -1778,12 +1790,17 @@ public:
ss <<
"if (nCount==0)\n"
" return CreateDoubleError(errDivisionByZero);\n";
else if (isMinOrMax())
ss <<
"if (nCount==0)\n"
" return 0;\n";
ss << "return tmp";
if (isAverage())
ss << "*pow((double)nCount,-1.0)";
ss << ";\n}";
}
virtual bool isAverage() const { return false; }
virtual bool isMinOrMax() const { return false; }
virtual bool takeString() const SAL_OVERRIDE { return false; }
virtual bool takeNumeric() const SAL_OVERRIDE { return true; }
};
......@@ -2198,12 +2215,13 @@ class OpMin : public Reduction
public:
OpMin( int nResultSize ) : Reduction(nResultSize) {}
virtual std::string GetBottom() SAL_OVERRIDE { return "MAXFLOAT"; }
virtual std::string GetBottom() SAL_OVERRIDE { return "NAN"; }
virtual std::string Gen2( const std::string& lhs, const std::string& rhs ) const SAL_OVERRIDE
{
return "fmin(" + lhs + "," + rhs + ")";
return "fmin_count(" + lhs + "," + rhs + ", &nCount)";
}
virtual std::string BinFuncName() const SAL_OVERRIDE { return "min"; }
virtual bool isMinOrMax() const SAL_OVERRIDE { return true; }
};
class OpMax : public Reduction
......@@ -2211,12 +2229,13 @@ class OpMax : public Reduction
public:
OpMax( int nResultSize ) : Reduction(nResultSize) {}
virtual std::string GetBottom() SAL_OVERRIDE { return "-MAXFLOAT"; }
virtual std::string GetBottom() SAL_OVERRIDE { return "NAN"; }
virtual std::string Gen2( const std::string& lhs, const std::string& rhs ) const SAL_OVERRIDE
{
return "fmax(" + lhs + "," + rhs + ")";
return "fmax_count(" + lhs + "," + rhs + ", &nCount)";
}
virtual std::string BinFuncName() const SAL_OVERRIDE { return "max"; }
virtual bool isMinOrMax() const SAL_OVERRIDE { return true; }
};
class OpSumProduct : public SumOfProduct
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment