std::shared_ptr<dataset> generic_sample_factory::create_sample(const std::string & path_sample) { std::shared_ptr<dataset> sample_data(new dataset); size_t sample_dimension = 0; std::ifstream file_sample(path_sample); if (file_sample.is_open()) { std::string file_line; while(std::getline(file_sample, file_line)) { if (file_line.empty()) continue; double value = 0.0; point sample_point; std::istringstream stream_value(file_line); while(stream_value >> value) { sample_point.push_back(value); } if (sample_dimension == 0) { sample_dimension = sample_point.size(); } else { if (sample_dimension != sample_point.size()) { throw std::runtime_error("Points from input data set should have the same dimension."); } } sample_data->push_back(sample_point); } }
void graphene::sample() { ofstream file_sample("sample", ios_base::app); for(int i=0; i<TOT; i++) { file_sample<<setprecision(15)<<p[i]<<endl; } file_sample.close(); }
bool strref_samples() { // separating full path into name, extension, directory strref file_sample("c:\\windows\\system32\\autochk.exe"); strref file_ext = file_sample.after_last('.'); // file extension strref file_name = file_sample.after_last_or_full('\\', '/'); // file name including extension strref file_name_no_ext = file_name.before_last('.'); // file name excluding extension strref file_dir = file_sample.before_last('\\', '/'); // file path excluding name printf("\nfull path: " STRREF_FMT "\nextension: " STRREF_FMT "\nname: " STRREF_FMT "\nname no ext: " STRREF_FMT "\ndirectory: " STRREF_FMT "\n\n", STRREF_ARG(file_sample), STRREF_ARG(file_ext), STRREF_ARG(file_name), STRREF_ARG(file_name_no_ext), STRREF_ARG(file_dir)); // fnv1a helper unsigned int hash = file_sample.fnv1a(); printf("fnv1a hash of \"" STRREF_FMT "\" is 0x%08x\n", STRREF_ARG(file_sample), hash); // find substrings in text strref text("Many gnomes don't live underwater, this is a widely appreciated convenience among fish."); // case insensitive substring find int pos = text.find(strref("THIS")); if (pos < 0 || text[pos] != 't') return false; // find by rolling hash is an option, may be a performance improvement in large text blocks pos = text.find_rh_case(strref("Many")); if (pos < 0 || text[pos] != 'M') return false; pos = text.find_rh_case(strref("widely")); if (pos < 0 || text[pos] != 'w') return false; // search character by character, usually performing well pos = text.find_case("Many"); if (pos < 0 || text[pos] != 'M') return false; // find the position of a secondary search pos = text.find_after_last(' ', 'i'); if (pos < 0 || text[pos] != 'i') return false; // find last string match pos = text.find_last("on"); if (pos < 0 || text[pos] != 'o') return false; pos = text.find(','); if (pos < 0 || text[pos] != ',') return false; pos = text.find_after('i', (strl_t)pos); if (pos < 0 || (text[pos] != 'i' && pos <= text.find('i'))) return false; pos = (int)text.find_or_full(';', 10); if ((strl_t)pos != text.get_len()) return false; pos = (int)text.find_or_full('.', 10); if (pos <= 0 || text[pos] != '.') return false; pos = text.find(strref("this")); if (pos < 0 || text[pos] != 't') return false; pos = text.find("among"); if (pos < 0 || text[pos] != 'a') return false; pos = text.find_case("This"); if (pos >= 0) return false; pos = text.find_case("this"); if (pos < 0 || text[pos] != 't') return false; pos = text.find_last(strref("fi")); if (pos < 0 || text[pos] != 'f') return false; pos = text.find_last("on"); if (pos < 0 || text[pos] != 'o') return false; return true; }