Kaydet (Commit) d6c0c215 authored tarafından mulei's avatar mulei Kaydeden (comit) I-Jui (Ray) Sung

GPU Calc: implemented for ODDLYIELD

AMLOEXT-68 FIX

Change-Id: I5a955a7488829621cf4ad905239f915784b1f374
Signed-off-by: 's avatarhaochen <haochen@multicorewareinc.com>
Signed-off-by: 's avatarI-Jui (Ray) Sung <ray@multicorewareinc.com>
üst 0487d675
...@@ -1295,6 +1295,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments( ...@@ -1295,6 +1295,12 @@ DynamicKernelSoPArguments::DynamicKernelSoPArguments(
mvSubArguments.push_back(SoPHelper(ts, mvSubArguments.push_back(SoPHelper(ts,
ft->Children[i], new OpOddlprice)); ft->Children[i], new OpOddlprice));
} }
else if ( !(pChild->GetExternal().compareTo(OUString(
"com.sun.star.sheet.addin.Analysis.getOddlyield"))))
{
mvSubArguments.push_back(SoPHelper(ts, ft->Children[i],
new OpOddlyield));
}
break; break;
default: default:
throw UnhandledToken(pChild, "unhandled opcode"); throw UnhandledToken(pChild, "unhandled opcode");
......
...@@ -2786,6 +2786,138 @@ void OpOddlprice::GenSlidingWindowFunction(std::stringstream &ss, ...@@ -2786,6 +2786,138 @@ void OpOddlprice::GenSlidingWindowFunction(std::stringstream &ss,
ss <<" return tmp;\n"; ss <<" return tmp;\n";
ss <<"}"; ss <<"}";
} }
void OpOddlyield::BinInlineFun(std::set<std::string>& decls,
std::set<std::string>& funs)
{
decls.insert(GetDiffDateDecl);decls.insert(DaysToDateDecl);
decls.insert(GetYearDiffDecl);decls.insert(IsLeapYearDecl);
decls.insert(GetNullDateDecl);decls.insert(DateToDaysDecl);
decls.insert(DaysInMonthDecl);
decls.insert(GetYearFracDecl);decls.insert(GetOddlyieldDecl);
funs.insert(GetDiffDate);funs.insert(DaysToDate);
funs.insert(GetYearDiff);funs.insert(IsLeapYear);
funs.insert(GetNullDate);funs.insert(DaysInMonth);
funs.insert(DateToDays);
funs.insert(GetYearFrac);funs.insert(GetOddlyield);
}
void OpOddlyield::GenSlidingWindowFunction(std::stringstream &ss,
const std::string sSymName, SubArguments &vSubArguments)
{
ss << "\ndouble " << sSymName;
ss << "_"<< BinFuncName() <<"(";
for (unsigned i = 0; i < vSubArguments.size(); i++)
{
if (i)
ss << ", ";
vSubArguments[i]->GenSlidingWindowDecl(ss);
}
ss <<") {\n";
ss <<" double tmp = 0;\n";
ss <<" int gid0 = get_global_id(0);\n";
ss <<" double tmp0=0;\n";
ss <<" double tmp1=0;\n";
ss <<" double tmp2=0;\n";
ss <<" double tmp3=0;\n";
ss <<" double tmp4=0;\n";
ss <<" double tmp5=0;\n";
ss <<" double tmp6=0;\n";
ss <<" double tmp7=0;\n";
size_t nItems = 0;
ss <<" \n";
for (size_t i = 0; i < vSubArguments.size(); i++)
{
FormulaToken *pCur = vSubArguments[i]->GetFormulaToken();
assert(pCur);
if (pCur->GetType() == formula::svDoubleVectorRef)
{
const formula::DoubleVectorRefToken* pDVR =
dynamic_cast<const formula::DoubleVectorRefToken *>(pCur);
size_t nCurWindowSize = pDVR->GetRefRowSize();
ss << " for (int i = ";
if (!pDVR->IsStartFixed() && pDVR->IsEndFixed()) {
#ifdef ISNAN
ss << "gid0; i < " << pDVR->GetArrayLength();
ss << " && i < " << nCurWindowSize << "; i++){\n";
#else
ss << "gid0; i < "<< nCurWindowSize << "; i++)\n";
#endif
} else if (pDVR->IsStartFixed() && !pDVR->IsEndFixed()) {
#ifdef ISNAN
ss << "0; i < " << pDVR->GetArrayLength();
ss << " && i < gid0+"<< nCurWindowSize << "; i++){\n";
#else
ss << "0; i < gid0+"<< nCurWindowSize << "; i++)\n";
#endif
} else if (!pDVR->IsStartFixed() && !pDVR->IsEndFixed()){
#ifdef ISNAN
ss << "0; i + gid0 < " << pDVR->GetArrayLength();
ss << " && i < "<< nCurWindowSize << "; i++){\n";
#else
ss << "0; i < "<< nCurWindowSize << "; i++)\n";
#endif
}
else {
#ifdef ISNAN
ss << "0; i < "<< nCurWindowSize << "; i++){\n";
#else
ss << "0; i < "<< nCurWindowSize << "; i++)\n";
#endif
}
nItems += nCurWindowSize;
}
else if (pCur->GetType() == formula::svSingleVectorRef)
{
#ifdef ISNAN
const formula::SingleVectorRefToken* pSVR =
dynamic_cast< const formula::SingleVectorRefToken* >(pCur);
ss << " if (gid0 < " << pSVR->GetArrayLength() << "){\n";
#else
nItems += 1;
#endif
}
else if (pCur->GetType() == formula::svDouble)
{
#ifdef ISNAN
ss << "{\n";
#endif
nItems += 1;
}
else
{
#ifdef ISNAN
#endif
nItems += 1;
}
#ifdef ISNAN
if(ocPush==vSubArguments[i]->GetFormulaToken()->GetOpCode())
{
ss << " if (isNan(";
ss << vSubArguments[i]->GenSlidingWindowDeclRef();
ss << "))\n";
ss << " tmp"<<i<<"= 0;\n";
ss << " else\n";
ss << " tmp"<<i<<"=";
ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
ss << ";\n";
ss <<" }\n";
}
else
{
ss << " tmp"<<i<<"=";
ss <<vSubArguments[i]->GenSlidingWindowDeclRef();
ss <<";\n";
}
#else
ss << " tmp"<<i<<"="<<vSubArguments[i]->GenSlidingWindowDeclRef();
ss <<";\n";
#endif
}
ss <<" int nNullDate = GetNullDate();\n";
ss <<" tmp = GetOddlyield(nNullDate,tmp0,tmp1";
ss <<",tmp2,tmp3,tmp4,tmp5,tmp6,tmp7);\n";
ss <<" return tmp;\n";
ss <<"}";
}
void OpNPER::GenSlidingWindowFunction(std::stringstream &ss, void OpNPER::GenSlidingWindowFunction(std::stringstream &ss,
const std::string sSymName, SubArguments &vSubArguments) const std::string sSymName, SubArguments &vSubArguments)
{ {
......
...@@ -351,6 +351,15 @@ public: ...@@ -351,6 +351,15 @@ public:
std::set<std::string>& ); std::set<std::string>& );
virtual std::string BinFuncName(void) const { return "Oddlprice"; } virtual std::string BinFuncName(void) const { return "Oddlprice"; }
}; };
class OpOddlyield: public Normal
{
public:
virtual void GenSlidingWindowFunction(std::stringstream &ss,
const std::string sSymName, SubArguments &vSubArguments);
virtual void BinInlineFun(std::set<std::string>& ,
std::set<std::string>& );
virtual std::string BinFuncName(void) const { return "Oddlyield"; }
};
class OpPPMT: public Normal class OpPPMT: public Normal
{ {
public: public:
......
...@@ -1153,6 +1153,24 @@ std::string GetOddlprice= ...@@ -1153,6 +1153,24 @@ std::string GetOddlprice=
" return p;\n" " return p;\n"
"}\n"; "}\n";
std::string GetOddlyieldDecl=
"double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
" double fRate, double fPrice, double fRedemp, int nFreq, int nBase );\n";
std::string GetOddlyield=
"double GetOddlyield( int nNullDate, int nSettle, int nMat, int nLastCoup,\n"
" double fRate, double fPrice, double fRedemp, int nFreq, int nBase ) \n"
"{\n"
" double fFreq = nFreq ;\n"
" double fDCi= GetYearFrac( nNullDate, nLastCoup, nMat, nBase ) * fFreq;\n"
" double fDSCi= GetYearFrac( nNullDate, nSettle, nMat, nBase ) * fFreq;\n"
" double fAi= GetYearFrac( nNullDate, nLastCoup, nSettle, nBase )*fFreq;\n"
" double y = fRedemp + fDCi * 100.0 * fRate / fFreq;\n"
" y /= fPrice + fAi * 100.0 * fRate / fFreq;\n"
" y -= 1.0;\n"
" y *= fFreq / fDSCi;\n"
" return y;\n"
"}\n";
#endif #endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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