void ParseFloatOpt(const std::string stringOpt, Cpu::real_vector &optVec){ std::vector<std::string> tempArgs; std::vector<std::string> tempArgs2; std::vector<real_t> tmpresult; if (stringOpt.size()==0){ optVec.clear(); return; } boost::split(tempArgs, stringOpt, boost::is_any_of("_")); for (int i =0 ; i<tempArgs.size(); i++){ boost::split(tempArgs2, tempArgs[i], boost::is_any_of("*")); if (tempArgs2.size() == 2){ int cnt = boost::lexical_cast<int>(tempArgs2[0]); for (int j = 0; j < cnt; j++) tmpresult.push_back(boost::lexical_cast<real_t>(tempArgs2[1])); }else{ tmpresult.push_back(boost::lexical_cast<real_t>(tempArgs[i])); } } optVec.resize(tmpresult.size(), 0.0); for (int i=0;i<optVec.size();i++) optVec[i] = tmpresult[i]; }
int ReadRealData(const std::string dataPath, Cpu::real_vector &data) { // std::ifstream ifs(dataPath.c_str(), std::ifstream::binary | std::ifstream::in); if (!ifs.good()) throw std::runtime_error(std::string("Fail to open ")+dataPath); // get the number of we data std::streampos numEleS, numEleE; long int numEle; numEleS = ifs.tellg(); ifs.seekg(0, std::ios::end); numEleE = ifs.tellg(); numEle = (numEleE-numEleS)/sizeof(real_t); ifs.seekg(0, std::ios::beg); // read in the data if (data.size() < numEle) data.resize(numEle, 0); real_t tempVal; for (unsigned int i = 0; i<numEle; i++){ ifs.read ((char *)&tempVal, sizeof(real_t)); data[i] = tempVal; } //thrust::copy(tempVec.begin(), tempVec.end(), data.begin()); ifs.close(); return numEle; }