/** * Parse text files using regex. Skip if line dimension is 0 (only blank). * Stores data in_data. * @brief File::parseText * @param computeCenterTp yes to compute center of data. Use T to teleport to this center. */ void File::parseText(bool computeCenterTp){ // Find max number of valid lines in the file std::ifstream inFile0(filename_); totalLines_ = std::count(std::istreambuf_iterator<char>(inFile0), std::istreambuf_iterator<char>(), '\n'); std::regex regex("([^\\s]+)"); int i=0; data_ = new double *[totalLines_*2]; std::ifstream inFile(filename_); std::string line; // check each line and register them in _data. while (std::getline(inFile, line)){ i++; if (i==lineDimension_) { //Compute dimension. dimension_ = getCount(line, regex); logger->info(logger->get() << "dimension_ is now " << dimension_ << ". It was found in '" << line << "' (line " << lineDimension_ << ")."); } if (i>=lineDimension_) { checkIfExceptionInFile(line, regex, &i, computeCenterTp); } } totalLines_ = i-lineDimension_+1; logger->info(logger->get()<< "Found "<<totalLines_<<" usefull lines in '"<<filename_<<"'.\n"); // printData(); }
void MemoryBackingStoreTransaction::objectStoreDeleted(std::unique_ptr<MemoryObjectStore> objectStore) { ASSERT(objectStore); ASSERT(m_objectStores.contains(objectStore.get())); m_objectStores.remove(objectStore.get()); auto addResult = m_deletedObjectStores.add(objectStore->info().name(), nullptr); if (addResult.isNewEntry) addResult.iterator->value = WTF::move(objectStore); }
/** * Print all data stored in dataCah_. * @brief File::printDataCah */ void File::printDataCah() { logger->info(logger->get() << "Printing (totalLines_, dimension_) = (" << totalLines_ << ", " << dimension_ << ") : "); int i=0, j=0; for (i=0; i<=totalLinesCah_ - 1; i++) { for (j=0; j<=dimension_ - 1; j++) { cout << "(" << i << ", " << j << ") = " << data_[i][j] << "\t"; } cout << "\n"; } }
/** * Test if the file filename_ exists. * @brief File::exists_test */ void File::exists_test() { bool isFile = false; ifstream f(filename_.c_str()); if (f.good()) { f.close(); isFile=true; } else { f.close(); isFile=false; } if (!isFile) { logger->info(logger->get() << "ERROR : File '" << filename_ << "' not found. Please Copy '" << filename_ << "' to '../build-Simulation-Clang-Debug/' and" << "'./Shaders/*' to '../build-Simulation-Clang-Debug/' and './Textures/*' to '../build-Simulation-Clang-Debug/'\n"); exit(-1); } else { logger->info(logger->get()<<"File '" << filename_ << "' found."); } }
void MemoryObjectStore::maybeRestoreDeletedIndex(std::unique_ptr<MemoryIndex> index) { LOG(IndexedDB, "MemoryObjectStore::maybeRestoreDeletedIndex"); ASSERT(index); if (m_info.hasIndex(index->info().name())) return; m_info.addExistingIndex(index->info()); ASSERT(!m_indexesByIdentifier.contains(index->info().identifier())); index->clearIndexValueStore(); auto error = populateIndexWithExistingRecords(*index); // Since this index was installed in the object store before this transaction started, // assuming things were in a valid state then, we should definitely be able to successfully // repopulate the index with the object store's pre-transaction records. ASSERT_UNUSED(error, error.isNull()); registerIndex(WTFMove(index)); }
/** * Compute a Hierarchical Clustering (CAH in french), clustering is saved into clusters_ * @brief File::cah * @param cluster, the number of clusters */ void File::cah(int cluster){ logger->info(logger->get() << "Hierarchical Clustering in " << cluster << " clusters" ); // initalize the number of clusters int nbClusters = this->getTotalLines(); for(int i=0; i<nbClusters; i++){ std::vector<int> clust; clust.push_back(i); clusters_.push_back(clust); } while((int)clusters_.size()>cluster){ double **matDissim; int csize = (int)clusters_.size(); matDissim = new double*[csize]; for(int i=0; i<csize; i++){ matDissim[i] = new double[csize]; for(int j=i+1; j<csize; j++){ matDissim[i][j] = dissimG(clusters_[i], clusters_[j]); } } std::vector<int> ijmin = minMatDissim(matDissim, csize); logger->info(logger->get() << "Clustering of (" << ijmin[0] << "," << ijmin[1] << ") at level " << csize); for(int i=0; i<(int)clusters_[ijmin[1]].size(); i++) { clusters_[ijmin[0]].push_back(clusters_[ijmin[1]][i]); } clusters_.erase (clusters_.begin()+ijmin[1]); for(int i=0; i<csize; i++){ delete matDissim[i]; } delete matDissim; } }
/** * Check if there is an exception in the file. (1 line has more column). * @brief File::checkIfExceptionInFile * @param text * @param regex * @param i * @return */ std::sregex_iterator File::checkIfExceptionInFile(std::string text, std::regex regex, int* i, bool computeCenterTp) { auto words_begin = std::sregex_iterator(text.begin(), text.end(), regex); auto words_end = std::sregex_iterator(); int dimLine = std::distance(words_begin, words_end); bool skip = false; if (dimLine == 0 || dimLine != dimension_) { logger->info(logger->get() << "checkIfExceptionInFile: W: Skipping blank or invalid line at l "<< *i << ". dimLine was " << dimLine << " but should be (dimension_=" << dimension_ << ") in '"<<filename_<<"'."); skip = true; (*i)--; } registerData(words_begin, words_end, *i - lineDimension_, skip, computeCenterTp); return words_end; }
void info(const std::string& msg, const std::string& file, std::size_t line) { if (active_logger) active_logger->info(msg, file, line); }