FormulaList* FormulaList::GenerateFromFile() { FormulaList* fl = new FormulaList(); QFile file(MainWindow::genPath+"FormulaList.txt"); qDebug() << (MainWindow::genPath + "FormulaList.txt"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "Can't open the file!" << endl; SAFE_DELETE(fl); return nullptr; } QTextStream in(&file); QString in_text = in.readAll(); file.close(); if (in_text.isEmpty()) { SAFE_DELETE(fl); return nullptr; } QList<QString> split_text = in_text.split(','); for (auto& obj: split_text) { fl->push_back(obj); } return fl; }
//TODO: don't need this void petabricks::MatrixDef::extractCLDefines(FreeVars& defined, CLCodeGenerator& clo, unsigned int dims, std::map<std::string, std::string> &map){ unsigned int d=0; for(FormulaList::const_iterator i=_size.begin(); i!=_size.end(); ++i,++d){ FreeVarsPtr fv = (*i)->getFreeVariables(); if(fv->size()==1 && d < dims){ std::string var = *fv->begin(); FormulaPtr tmp = FormulaVariable::mktmp(); if(!defined.contains(var)){ defined.insert(var); FormulaList l; l.push_back(new FormulaEQ(tmp, *i)); l = *MaximaWrapper::instance().solve(l, var); JASSERT(l.size()==1)(*i)(var).Text("Failed to solve"); clo.os() << "unsigned int " << var << " = " << (*l.begin())->rhs()->replace(tmp, new FormulaVariable("dim_"+map[_name]+"_d"+jalib::XToString(d)))->toString() << ";\n"; } } } }
void petabricks::MatrixDef::extractDefines(FreeVars& defined, CodeGenerator& o){ int d=0; for(FormulaList::const_iterator i=_size.begin(); i!=_size.end(); ++i,++d){ FreeVarsPtr fv = (*i)->getFreeVariables(); if(fv->size()==1){ std::string var = *fv->begin(); FormulaPtr tmp = FormulaVariable::mktmp(); if(!defined.contains(var)){ defined.insert(var); FormulaList l; l.push_back(new FormulaEQ(tmp, *i)); l = *MaximaWrapper::instance().solve(l, var); JASSERT(l.size()==1)(*i)(var).Text("Failed to solve"); o.addMember("IndexT", var, ""); o.write(var + " = " + (*l.begin())->rhs()->replace(tmp, new FormulaVariable(_name+".size("+jalib::XToString(d)+")"))->toString() + ";"); } } } }