diff --git a/src/basic.cpp b/src/basic.cpp index 36c71f9eba6581b4fe08b3b334e1150df4f2205b..316f2f1f19077c406379659886d0bdeb4e1a79fe 100644 --- a/src/basic.cpp +++ b/src/basic.cpp @@ -579,7 +579,9 @@ string mpfrCodeGenerator(const ast_ptr &expr, size_t &mpfr_variables, const std: ++mpfr_variables; NumberExprAST *numberExpr = dynamic_cast(expr.get()); double number = (numberExpr->getNumber()); - number_str = "mpfr_set_d(mp" + to_string(mpfr_variables) + ", " + to_string(number) + ", MPFR_RNDN);"; + std::stringstream ss; + ss << std::setprecision(DOUBLE_PRECISION) << number; + number_str = "mpfr_set_d(mp" + to_string(mpfr_variables) + ", " + ss.str() + ", MPFR_RNDN);"; // cout << number_str << endl; ofs << "\t" << number_str << endl; return "mp" + to_string(mpfr_variables); diff --git a/src/geneCode.cpp b/src/geneCode.cpp index e9d4567ff83f1e313d7024ef093e83d7822b5441..9e01aedb42c45d9c85db89d48ab234c9ce469d2b 100644 --- a/src/geneCode.cpp +++ b/src/geneCode.cpp @@ -96,6 +96,8 @@ bool getVariablesFromExpr(const ast_ptr &expr, vector &vars) exit(EXIT_FAILURE); } } + std::sort(vars.begin(), vars.end()); // sort to unique the parameters queue + vars.erase(std::unique(vars.begin(), vars.end()), vars.end()); return true; } if (type != "Binary") diff --git a/src/main.cpp b/src/main.cpp index 3f42a75c521c2489a6a28a4ca257035a3006cb86..daebe47a90bc4f5d0ce8ac9fd68837c66dcbc479 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -70,7 +70,8 @@ int main() fprintf(stderr, "you do not need to add a ';' after the expression\n"); inputStr.pop_back(); // remove the last char ';' } - bool runAllFlag = false; + bool runAllFlag = true; + std::chrono::_V2::system_clock::time_point tmp1, tmp2, tmp3; if(runAllFlag) { // the whole process auto uniqueLabel = getUniqueLabel(); @@ -92,38 +93,16 @@ int main() int scale = 256; vector intervals{3.8, 7.8, -4.5, -0.3, 0.4, 0.9}; vector scales{scale, scale, scale}; + tmp1 = std::chrono::high_resolution_clock::now(); testError(uniqueLabel, "origin", intervals, scales); - - // switch (vars.size()) // choose the test error version according to the input parameters number - // { - // case 1: { - // int scale = 50000; - // testError(uniqueLabel, "origin", 0, 1, scale); // for 1 param - // break; - // } - // case 2: { - // int scale = 1024; - // testError(uniqueLabel, "origin", 0, 1, 0, 1, scale, scale); // for 2 params - // break; - // } - // case 3: { - // int scale = 256; - // testError(uniqueLabel, "origin", 3.8, 7.8, -4.5, -0.3, 0.4, 0.9, scale, scale, scale); // for 3 params - // break; - // } - // default: { - // fprintf(stderr, "WRONG: main: the variables number is %ld, which we don't support now.\n", vars.size()); - // exit(EXIT_FAILURE); - // break; - // } - // } - + tmp2 = std::chrono::high_resolution_clock::now(); // geneBoundaryData(inputStr, uniqueLabel); // matlab // geneIntervalData(inputStr, uniqueLabel); cout << "=-=-=-=-=-=-=-=-=-=-=-=-= rewrite start =-=-=-=-=-=-=-=-=-=-=-=-=" << endl; auto exprInfoVector = rewrite(inputStr, uniqueLabel); + tmp3 = std::chrono::high_resolution_clock::now(); cout << "=-=-=-=-=-=-=-=-=-=-=-=-= rewrite end =-=-=-=-=-=-=-=-=-=-=-=-=" << endl; auto funcNameFinal = geneFinalCodeKernel(inputStr, uniqueLabel, exprInfoVector, vars); } // the whole process end @@ -138,15 +117,19 @@ int main() auto &result = results.at(i); // string treeStr; // printAST(result, treeStr, MAIN_PRECISION); - // fout << "No." << i << ": " << PrintExpression(result, MAIN_PRECISION) << endl; - fout << "*resultPtr = " << PrintExpression(result, DOUBLE_PRECISION) << ";" << endl; + fout << PrintExpression(result, MAIN_PRECISION) << endl; + // fout << "*resultPtr = " << PrintExpression(result, DOUBLE_PRECISION) << ";" << endl; // fout << treeStr << endl; } fout << endl; } // only rewrite end auto end = std::chrono::high_resolution_clock::now(); + std::chrono::duration testError_seconds = tmp2 - tmp1; + std::chrono::duration rewrite_seconds = tmp3 - tmp2; std::chrono::duration elapsed_seconds = end - start; + cout << BLUE << "testError time: " << testError_seconds.count() << "s" << RESET << endl; + cout << BLUE << "rewrite time: " << rewrite_seconds.count() << "s" << RESET << endl; cout << BLUE << "elapsed time: " << elapsed_seconds.count() << "s" << RESET << endl; fprintf(stderr, GREEN "ready> " RESET); }