12#include <rtl/string.hxx>
15#include <unordered_map>
24 const char* m, std::string fn,
int ln ) :
25 mMessage(
m), mFile(
std::move(fn)), mLineNumber(ln) {}
28 mFunction(
std::move(function)), mError(error), mFile(
std::move(file)), mLineNumber(
line)
38 mFile(
std::move(fn)), mLineNumber(ln) {}
41 mParameterCount(parameterCount), mFile(
std::move(file)), mLineNumber(ln) {}
49 return std::string(
"");
55 return std::string(
"");
73 return std::string(
"");
112 assert(
string !=
nullptr );
113 if( string->length == 0 )
116 stringIdsMap =
new std::unordered_map<const rtl_uString*, int>;
118 auto aItInsertedPair =
stringIdsMap->insert( std::pair(
string, newId ));
119 return aItInsertedPair.first->second;
152 ss <<
"__global double *" <<
mSymName;
184 return pCurDVR->GetRefRowSize();
199 return std::string(
"");
229 assert( arg <
int( vSubArguments.size()));
230 FormulaToken *token = vSubArguments[arg]->GetFormulaToken();
231 if( token ==
nullptr )
239 ss <<
" double " <<
name <<
" = NAN;\n";
241 ss <<
" bool " <<
name <<
"_is_string = false;\n";
245 ss <<
" " <<
name <<
" = ";
246 ss << vSubArguments[arg]->GenSlidingWindowDeclRef(
true ) <<
";\n";
249 ss <<
" " <<
name <<
"_is_string = ";
250 ss << vSubArguments[arg]->GenIsString(
true ) <<
";\n";
256 ss <<
" if( isnan( " <<
name <<
" ))\n";
257 ss <<
" " <<
name <<
" = 0;\n";
268 ss <<
" double " <<
name <<
" = " << token->
GetDouble() <<
";\n";
270 ss <<
" bool " <<
name <<
"_is_string = "
271 << vSubArguments[arg]->GenIsString() <<
";\n";
279 ss <<
" double " <<
name <<
" = 0.0;\n";
281 ss <<
" bool " <<
name <<
"_is_string = "
282 << vSubArguments[arg]->GenIsString() <<
";\n";
289 ss <<
" double " <<
name <<
" = ";
290 ss << vSubArguments[arg]->GenSlidingWindowDeclRef() <<
";\n";
292 ss <<
" bool " <<
name <<
"_is_string = "
293 << vSubArguments[arg]->GenIsString() <<
";\n";
300 OString buf =
"arg" + OString::number(arg);
301 GenerateArg( buf.getStr(), arg, vSubArguments, ss, empty, generateType );
307 if( arg <
int(vSubArguments.size()))
310 ss <<
" double " <<
name <<
" = " << def <<
";\n";
316 assert( firstArg >= 0 );
317 assert( firstArg <= lastArg );
318 assert( lastArg <
int( vSubArguments.size()));
319 for(
int i = firstArg;
324 if( token ==
nullptr )
333 ss <<
" double arg = ";
334 ss << vSubArguments[
i]->GenSlidingWindowDeclRef();
339 ss <<
" if( isnan( arg ))\n";
345 ss <<
" if( isnan( arg ))\n";
346 ss <<
" continue;\n";
358 ss <<
" double arg = ";
359 ss << vSubArguments[
i]->GenSlidingWindowDeclRef() <<
";\n";
363 ss <<
" if( isnan( arg ))\n";
371 ss <<
" if( !isnan( arg ))\n";
382 ss <<
" double arg = " << token->
GetDouble() <<
";\n";
390 ss <<
" double arg = 0.0;\n";
400 ss <<
" double arg = ";
401 ss << vSubArguments[
i]->GenSlidingWindowDeclRef() <<
";\n";
423 assert( arg1 >= 0 && arg1 <
int (vSubArguments.size()));
424 assert( arg2 >= 0 && arg2 <
int (vSubArguments.size()));
425 assert( arg1 != arg2 );
426 FormulaToken *token1 = vSubArguments[arg1]->GetFormulaToken();
427 if( token1 ==
nullptr )
429 FormulaToken *token2 = vSubArguments[arg2]->GetFormulaToken();
430 if( token2 ==
nullptr )
445 if(nCurWindowSize1 != nCurWindowSize2)
472 ss <<
" double arg1 = ";
473 ss << vSubArguments[arg1]->GenSlidingWindowDeclRef(!checkBounds) <<
";\n";
474 ss <<
" double arg2 = ";
475 ss << vSubArguments[arg2]->GenSlidingWindowDeclRef(!checkBounds) <<
";\n";
479 ss <<
" if( isnan( arg1 ))\n";
480 ss <<
" arg1 = 0;\n";
481 ss <<
" if( isnan( arg2 ))\n";
482 ss <<
" arg2 = 0;\n";
487 ss <<
" if( isnan( arg1 ) || isnan( arg2 ))\n";
488 ss <<
" continue;\n";
498 assert( arg >= 0 && arg <
int (vSubArguments.size()));
499 FormulaToken *token = vSubArguments[arg]->GetFormulaToken();
500 if( token ==
nullptr )
506 ss <<
" double " <<
name <<
" = NAN;\n";
509 ss <<
" int i = 0;\n";
514 ss <<
" " <<
name <<
" = " << vSubArguments[arg]->GenSlidingWindowDeclRef(
true) <<
";\n";
519 ss <<
" if( isnan( " <<
name <<
" ))\n";
520 ss <<
" " <<
name <<
" = 0;\n";
534 std::string startDiff;
535 if( firstElementDiff )
536 startDiff = std::string(
" + " ) + firstElementDiff;
537 ss <<
" for (int i = ";
541 ss <<
" && i < " << nCurWindowSize <<
"; i++)\n";
547 ss <<
" && i < gid0+" << nCurWindowSize <<
"; i++)\n";
552 ss <<
"0" << startDiff <<
"; i + gid0 < " << pDVR->
GetArrayLength();
553 ss <<
" && i < " << nCurWindowSize <<
"; i++)\n";
558 ss <<
"0" << startDiff <<
"; i < " << pDVR->
GetArrayLength() <<
"; i++)\n";
566 ss <<
"\ndouble " << sSymName;
568 for (
size_t i = 0;
i < vSubArguments.size();
i++)
572 vSubArguments[
i]->GenSlidingWindowDecl(ss);
582 ss <<
"double tmp = " <<
GetBottom() <<
";\n\t";
583 ss <<
"int gid0 = get_global_id(0);\n\t";
585 std::vector<std::string> argVector;
586 for (
size_t i = 0;
i < vSubArguments.size();
i++)
587 argVector.push_back(vSubArguments[
i]->GenSlidingWindowDeclRef());
588 ss <<
Gen(argVector);
590 ss <<
"return tmp;\n";
597 for (
size_t i = 0;
i < vSubArguments.size();
i++)
609 if (vSubArguments[
i]->GetFormulaToken()->GetType() ==
614 ss <<
" if(singleIndex>=";
618 ss << vSubArguments[
i]->GenSlidingWindowDeclRef(
true);
622 ss <<
"=0;\n else \n";
626 ss << vSubArguments[
i]->GenSlidingWindowDeclRef(
true);
629 if (vSubArguments[
i]->GetFormulaToken()->GetType() ==
634 ss <<
" if(doubleIndex>=";
638 ss << vSubArguments[
i]->GenSlidingWindowDeclRef();
642 ss <<
"=0;\n else \n";
646 ss << vSubArguments[
i]->GenSlidingWindowDeclRef();
650 vSubArguments[
i]->GetFormulaToken()->GetOpCode() !=
ocPush)
654 ss << vSubArguments[
i]->GenSlidingWindowDeclRef();
658 ss <<
"=0;\n else \n";
662 ss << vSubArguments[
i]->GenSlidingWindowDeclRef();
670 SubArguments& vSubArguments,
int argumentNum,
const std::string& p )
678 vSubArguments[
i]->GenDeclRef(ss);
686 vSubArguments[
i]->GenDeclRef(ss);
687 if (vSubArguments[
i]->GetFormulaToken()->GetType() ==
689 ss <<
"[" <<
p.c_str() <<
"]";
690 else if (vSubArguments[
i]->GetFormulaToken()->GetType() ==
692 ss <<
"[get_group_id(1)]";
699 ss <<
" int k = gid0;\n";
700 for (
size_t i = 0;
i < vSubArguments.size();
i++)
713 ss <<
" loop = (" << nCurWindowSize <<
" - gid0)/";
714 ss << unrollSize <<
";\n";
718 ss <<
" loop = (" << nCurWindowSize <<
" + gid0)/";
719 ss << unrollSize <<
";\n";
724 ss <<
" loop = " << nCurWindowSize <<
"/" << unrollSize <<
";\n";
727 ss <<
" for ( int j = 0;j< loop; j++)\n";
732 ss <<
"gid0 + j * " << unrollSize <<
";\n";
736 ss <<
"j * " << unrollSize <<
";\n";
741 ss <<
" int doubleIndex = i+gid0;\n";
745 ss <<
" int doubleIndex = i;\n";
748 for (
int j = 0; j < unrollSize; j++)
750 ss << unrollstr.str();
752 ss <<
"doubleIndex++;\n";
755 ss <<
" for (int i = ";
758 ss <<
"gid0 + loop *" << unrollSize <<
"; i < ";
759 ss << nCurWindowSize <<
"; i++)\n";
763 ss <<
"0 + loop *" << unrollSize <<
"; i < gid0+";
764 ss << nCurWindowSize <<
"; i++)\n";
768 ss <<
"0 + loop *" << unrollSize <<
"; i < ";
769 ss << nCurWindowSize <<
"; i++)\n";
774 ss <<
" int doubleIndex = i+gid0;\n";
778 ss <<
" int doubleIndex = i;\n";
780 ss << unrollstr.str();
785 const std::string& sSymName,
SubArguments& vSubArguments )
789 ss <<
"double tmp = " <<
GetBottom() <<
";\n";
790 ss <<
"int gid0 = get_global_id(0);\n";
792 ss <<
"int nCount = 0;\n";
793 ss <<
"double tmpBottom;\n";
794 unsigned i = vSubArguments.size();
800 NR->GenReductionLoopHeader(ss, needBody);
807 NRS->GenReductionLoopHeader(ss, needBody);
814 bool bNeedBody =
false;
815 PNR->GenReductionLoopHeader(ss,
mnResultSize, bNeedBody);
823 SR->GenReductionLoopHeader(ss, needBody);
836 if (
ocPush == vSubArguments[
i]->GetFormulaToken()->GetOpCode())
840 ss <<
" tmpBottom = " <<
GetBottom() <<
";\n";
845 ss << vSubArguments[
i]->GenSlidingWindowDeclRef();
848 ss <<
" return 0;\n";
852 ss <<
Gen2(
"tmpBottom",
"tmp") <<
";\n";
857 ss <<
Gen2(vSubArguments[
i]->GenSlidingWindowDeclRef(),
"tmp");
863 ss <<
Gen2(vSubArguments[
i]->GenSlidingWindowDeclRef(),
"tmp");
871 " return CreateDoubleError(DivisionByZero);\n";
878 ss <<
"/(double)nCount";
static void CheckSubArgumentIsNan2(outputstream &ss, SubArguments &vSubArguments, int argumentNum, const std::string &p)
static void CheckSubArgumentIsNan(outputstream &ss, SubArguments &vSubArguments, int argumentNum)
static void GenTmpVariables(outputstream &ss, const SubArguments &vSubArguments)
static void UnrollDoubleVector(outputstream &ss, const outputstream &unrollstr, const formula::DoubleVectorRefToken *pCurDVR, int nCurWindowSize)
static void CheckAllSubArgumentIsNan(outputstream &ss, SubArguments &vSubArguments)
(Partially) abstract base class for an operand
virtual std::string GenStringSlidingWindowDeclRef(bool=false) const
When Mix, it will be called.
static int GetStringId(const rtl_uString *string)
virtual void DumpInlineFun(std::set< std::string > &, std::set< std::string > &) const
virtual std::string DumpOpName() const
formula::FormulaToken * GetFormulaToken() const
virtual bool NeedParallelReduction() const
virtual void GenDeclRef(outputstream &ss) const
Generate use/references to the argument.
const std::string & GetName() const
virtual void GenSlidingWindowFunction(outputstream &)
static void ClearStringIds()
DynamicKernelArgument(const DynamicKernelArgument &)=delete
delete copy constructor
FormulaTreeNodeRef mFormulaTree
virtual std::string GenDoubleSlidingWindowDeclRef(bool=false) const
When Mix, it will be called.
Handling a Double Vector that is used as a sliding window input to either a sliding window average or...
InvalidParameterCount(int parameterCount, std::string file, int ln)
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual std::string GetBottom()
virtual bool ZeroReturnZero()
virtual std::string Gen2(const std::string &, const std::string &) const
static std::string Gen(std::vector< std::string > &)
virtual bool takeString() const =0
virtual std::string BinFuncName() const
virtual bool forceStringsToZero() const
OpenCLError(std::string function, cl_int error, std::string file, int line)
Handling a Double Vector that is used as a sliding window input Performs parallel reduction based on ...
virtual bool isMinOrMax() const
virtual void GenSlidingWindowFunction(outputstream &ss, const std::string &sSymName, SubArguments &vSubArguments) override
virtual bool isAverage() const
virtual bool HandleNaNArgument(outputstream &, unsigned, SubArguments &) const
void GenerateArg(const char *name, int arg, SubArguments &vSubArguments, outputstream &ss, EmptyArgType empty=EmptyIsZero, GenerateArgTypeType generateType=DoNotGenerateArgType)
static void GenerateDoubleVectorLoopHeader(outputstream &ss, const formula::DoubleVectorRefToken *pDVR, const char *firstElementDiff)
static void GenerateRangeArgElement(const char *name, int arg, const char *element, SubArguments &vSubArguments, outputstream &ss, EmptyArgType empty)
static void GenerateRangeArg(int arg, SubArguments &vSubArguments, outputstream &ss, EmptyArgType empty, const char *code)
void GenerateArgWithDefault(const char *name, int arg, double def, SubArguments &vSubArguments, outputstream &ss, EmptyArgType empty=EmptyIsZero)
void GenerateFunctionDeclaration(const std::string &sSymName, SubArguments &vSubArguments, outputstream &ss)
static void GenerateRangeArgPair(int arg1, int arg2, SubArguments &vSubArguments, outputstream &ss, EmptyArgType empty, const char *code, const char *firstElementDiff=nullptr)
static void GenerateRangeArgs(int firstArg, int lastArg, SubArguments &vSubArguments, outputstream &ss, EmptyArgType empty, const char *code)
std::vector< DynamicKernelArgumentRef > SubArguments
UnhandledToken(const char *m, std::string fn, int ln)
Unhandled(std::string fn, int ln)
VectorRefStringsToZero(const ScCalcConfig &config, const std::string &s, const FormulaTreeNodeRef &ft, int index=0)
Holds an input (read-only) argument reference to a SingleVectorRef.
VectorRef(const ScCalcConfig &config, const std::string &s, const FormulaTreeNodeRef &ft, int index=0)
virtual bool NeedParallelReduction() const override
virtual void GenSlidingWindowDecl(outputstream &ss) const override
When declared as input to a sliding window function.
virtual std::string GenSlidingWindowDeclRef(bool=false) const override
When referenced in a sliding window function.
virtual void GenDecl(outputstream &ss) const override
Generate declaration.
const std::string & GetName() const
virtual void DumpInlineFun(std::set< std::string > &, std::set< std::string > &) const override
cl_mem GetCLBuffer() const
virtual std::string DumpOpName() const override
virtual size_t GetWindowSize() const override
virtual ~VectorRef() override
virtual void GenSlidingWindowFunction(outputstream &) override
#define SAL_WARN_IF(condition, area, stream)
const char * errorString(cl_int nError)
static std::unordered_map< const rtl_uString *, int > * stringIdsMap
std::shared_ptr< FormulaTreeNode > FormulaTreeNodeRef
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
Configuration options for formula interpreter.