//------------------------------------------------------------------------------ bool get_note( Elf_Word index, Elf_Word& type, std::string& name, void*& desc, Elf_Word& descSize ) const { if ( index >= note_section->get_size() ) { return false; } const char* pData = note_section->get_data() + note_start_positions[index]; const endianess_convertor& convertor = elf_file.get_convertor(); type = convertor( *(Elf_Word*)( pData + 2*sizeof( Elf_Word ) ) ); Elf_Word namesz = convertor( *(Elf_Word*)( pData ) ); name.assign( pData + 3*sizeof( Elf_Word ), namesz ); descSize = convertor( *(Elf_Word*)( pData + sizeof( namesz ) ) ); if ( 0 == descSize ) { desc = 0; } else { int align = sizeof( Elf_Xword ); if ( elf_file.get_class() == ELFCLASS32 ) { align = sizeof( Elf_Word ); } desc = const_cast<char*> ( pData + 3*sizeof( Elf_Word ) + ( ( namesz + align - 1 ) / align ) * align ); } return true; }
//------------------------------------------------------------------------------ void process_section() { const endianess_convertor& convertor = elf_file.get_convertor(); const char* data = note_section->get_data(); Elf_Xword size = note_section->get_size(); Elf_Xword current = 0; note_start_positions.clear(); // Is it empty? if ( 0 == data || 0 == size ) { return; } int align = sizeof( Elf_Word ); while ( current + 3*align <= size ) { note_start_positions.push_back( current ); Elf_Word namesz = convertor( *(const Elf_Word*)( data + current ) ); Elf_Word descsz = convertor( *(const Elf_Word*)( data + current + sizeof( namesz ) ) ); current += 3*sizeof( Elf_Word ) + ( ( namesz + align - 1 ) / align ) * align + ( ( descsz + align - 1 ) / align ) * align; } }
//------------------------------------------------------------------------------ void add_note( Elf_Word type, const std::string& name, const void* desc, Elf_Word descSize ) { const endianess_convertor& convertor = elf_file.get_convertor(); int align = sizeof( Elf_Word ); Elf_Word nameLen = (Elf_Word)name.size() + 1; Elf_Word nameLenConv = convertor( nameLen ); std::string buffer( reinterpret_cast<char*>( &nameLenConv ), align ); Elf_Word descSizeConv = convertor( descSize ); buffer.append( reinterpret_cast<char*>( &descSizeConv ), align ); type = convertor( type ); buffer.append( reinterpret_cast<char*>( &type ), align ); buffer.append( name ); buffer.append( 1, '\x00' ); const char pad[] = { '\0', '\0', '\0', '\0' }; if ( nameLen % align != 0 ) { buffer.append( pad, align - nameLen % align ); } if ( desc != 0 && descSize != 0 ) { buffer.append( reinterpret_cast<const char*>( desc ), descSize ); if ( descSize % align != 0 ) { buffer.append( pad, align - descSize % align ); } } note_start_positions.push_back( note_section->get_size() ); note_section->append_data( buffer ); }
bool generic_get_symbol( Elf_Xword index, std::string& name, Elf64_Addr& value, Elf_Xword& size, unsigned char& bind, unsigned char& type, Elf_Half& section_index, unsigned char& other ) const { bool ret = false; if ( index < get_symbols_num() ) { const T* pSym = reinterpret_cast<const T*>( symbol_section->get_data() + index * symbol_section->get_entry_size() ); const endianess_convertor& convertor = elf_file.get_convertor(); section* string_section = elf_file.sections[get_string_table_index()]; string_section_accessor str_reader( string_section ); const char* pStr = str_reader.get_string( convertor( pSym->st_name ) ); if ( 0 != pStr ) { name = pStr; } value = convertor( pSym->st_value ); size = convertor( pSym->st_size ); bind = ELF_ST_BIND( pSym->st_info ); type = ELF_ST_TYPE( pSym->st_info ); section_index = convertor( pSym->st_shndx ); other = pSym->st_other; ret = true; } return ret; }
//------------------------------------------------------------------------------ bool get_note( Elf_Word index, Elf_Word& type, std::string& name, void*& desc, Elf_Word& descSize ) const { if ( index >= note_section->get_size() ) { return false; } const char* pData = note_section->get_data() + note_start_positions[index]; int align = sizeof( Elf_Word ); const endianess_convertor& convertor = elf_file.get_convertor(); type = convertor( *(const Elf_Word*)( pData + 2*align ) ); Elf_Word namesz = convertor( *(const Elf_Word*)( pData ) ); descSize = convertor( *(const Elf_Word*)( pData + sizeof( namesz ) ) ); Elf_Xword max_name_size = note_section->get_size() - note_start_positions[index]; if ( namesz > max_name_size || namesz + descSize > max_name_size ) { return false; } name.assign( pData + 3*align, namesz - 1); if ( 0 == descSize ) { desc = 0; } else { desc = const_cast<char*> ( pData + 3*align + ( ( namesz + align - 1 )/align )*align ); } return true; }
void generic_add_entry( Elf64_Addr offset, Elf_Xword info ) { const endianess_convertor& convertor = elf_file.get_convertor(); T entry; entry.r_offset = offset; entry.r_info = info; entry.r_offset = convertor( entry.r_offset ); entry.r_info = convertor( entry.r_info ); relocation_section->append_data( reinterpret_cast<char*>( &entry ), sizeof( entry ) ); }
void generic_add_entry( Elf_Xword tag, Elf_Xword value ) { const endianess_convertor& convertor = elf_file.get_convertor(); T entry; switch ( tag ) { case DT_NULL: case DT_SYMBOLIC: case DT_TEXTREL: case DT_BIND_NOW: value = 0; case DT_NEEDED: case DT_PLTRELSZ: case DT_RELASZ: case DT_RELAENT: case DT_STRSZ: case DT_SYMENT: case DT_SONAME: case DT_RPATH: case DT_RELSZ: case DT_RELENT: case DT_PLTREL: case DT_INIT_ARRAYSZ: case DT_FINI_ARRAYSZ: case DT_RUNPATH: case DT_FLAGS: case DT_PREINIT_ARRAYSZ: entry.d_un.d_val = convertor( value ); break; case DT_PLTGOT: case DT_HASH: case DT_STRTAB: case DT_SYMTAB: case DT_RELA: case DT_INIT: case DT_FINI: case DT_REL: case DT_DEBUG: case DT_JMPREL: case DT_INIT_ARRAY: case DT_FINI_ARRAY: case DT_PREINIT_ARRAY: default: entry.d_un.d_ptr = convertor( value ); break; } entry.d_tag = convertor( tag ); dynamic_section->append_data( reinterpret_cast<char*>( &entry ), sizeof( entry ) ); }
Array HHVM_METHOD(MongoDBDriverReadPreference, __debugInfo) { MongoDBDriverReadPreferenceData* data = Native::data<MongoDBDriverReadPreferenceData>(this_); Array retval = Array::Create(); Variant v_tags; const bson_t *tags = mongoc_read_prefs_get_tags(data->m_read_preference); mongoc_read_mode_t mode = mongoc_read_prefs_get_mode(data->m_read_preference); switch (mode) { case MONGOC_READ_PRIMARY: retval.set(s_mode, "primary"); break; case MONGOC_READ_PRIMARY_PREFERRED: retval.set(s_mode, "primaryPreferred"); break; case MONGOC_READ_SECONDARY: retval.set(s_mode, "secondary"); break; case MONGOC_READ_SECONDARY_PREFERRED: retval.set(s_mode, "secondaryPreferred"); break; case MONGOC_READ_NEAREST: retval.set(s_mode, "nearest"); break; default: /* Do nothing */ break; } if (!bson_empty(tags)) { hippo_bson_conversion_options_t options = HIPPO_TYPEMAP_INITIALIZER; BsonToVariantConverter convertor(bson_get_data(tags), tags->len, options); convertor.convert(&v_tags); retval.set(s_tags, v_tags.toArray()); } if (mongoc_read_prefs_get_max_staleness_ms(data->m_read_preference) != 0) { retval.set(s_maxStalenessMS, mongoc_read_prefs_get_max_staleness_ms(data->m_read_preference)); } return retval; }
Array HHVM_METHOD(MongoDBDriverServer, getInfo) { MongoDBDriverServerData* data = Native::data<MongoDBDriverServerData>(this_); mongoc_server_description_t *sd; if ((sd = mongoc_client_get_server_description(data->m_client, data->m_server_id))) { const bson_t *is_master = mongoc_server_description_ismaster(sd); Variant v; hippo_bson_conversion_options_t options = HIPPO_TYPEMAP_DEBUG_INITIALIZER; /* Yeah, this is not pretty. But, C++ doesn't have finally, and I don't * want to bson_copy the is_master thing just because of that */ try { BsonToVariantConverter convertor(bson_get_data(is_master), is_master->len, options); convertor.convert(&v); } catch (...) { mongoc_server_description_destroy(sd); throw; } return v.toArray(); } throw MongoDriver::Utils::CreateAndConstruct(MongoDriver::s_MongoDriverExceptionRuntimeException_className, "Failed to get server description", HPHP::Variant((uint64_t) 0)); }
static bool mongodb_driver_add_server_debug(mongoc_server_description_t *sd, Array *retval) { mongoc_host_list_t *host = mongoc_server_description_host(sd); const bson_t *is_master = mongoc_server_description_ismaster(sd); Variant v_last_is_master; Array a_last_is_master; retval->set(s_MongoDriverServer_host, host->host); retval->set(s_MongoDriverServer_port, host->port); retval->set(s_MongoDriverServer_type, hippo_server_description_type(sd)); retval->set(s_MongoDriverServer_is_primary, strcmp(mongoc_server_description_type(sd), hippo_server_description_type_map[HIPPO_SERVER_RS_PRIMARY].name) == 0); retval->set(s_MongoDriverServer_is_secondary, strcmp(mongoc_server_description_type(sd), hippo_server_description_type_map[HIPPO_SERVER_RS_SECONDARY].name) == 0); retval->set(s_MongoDriverServer_is_arbiter, strcmp(mongoc_server_description_type(sd), hippo_server_description_type_map[HIPPO_SERVER_RS_ARBITER].name) == 0); hippo_bson_conversion_options_t options = HIPPO_TYPEMAP_DEBUG_INITIALIZER; BsonToVariantConverter convertor(bson_get_data(is_master), is_master->len, options); convertor.convert(&v_last_is_master); a_last_is_master = v_last_is_master.toArray(); retval->set(s_MongoDriverServer_is_hidden, a_last_is_master.exists(s_MongoDriverServer_hidden) && !!a_last_is_master[s_MongoDriverServer_hidden].toBoolean()); retval->set(s_MongoDriverServer_is_passive, a_last_is_master.exists(s_MongoDriverServer_passive) && !!a_last_is_master[s_MongoDriverServer_passive].toBoolean()); if (a_last_is_master.exists(s_MongoDriverServer_tags)) { retval->set(s_MongoDriverServer_tags, a_last_is_master[s_MongoDriverServer_tags]); } retval->set(s_MongoDriverServer_last_is_master, a_last_is_master); retval->set(s_MongoDriverServer_round_trip_time, mongoc_server_description_round_trip_time(sd)); return true; }
void generic_get_entry_rela( Elf_Xword index, Elf64_Addr& offset, Elf_Word& symbol, Elf_Word& type, Elf_Sxword& addend ) const { const endianess_convertor& convertor = elf_file.get_convertor(); const T* pEntry = reinterpret_cast<const T*>( relocation_section->get_data() + index * relocation_section->get_entry_size() ); offset = convertor( pEntry->r_offset ); Elf_Xword tmp = convertor( pEntry->r_info ); symbol = get_sym_and_type<T>::get_r_sym( tmp ); type = get_sym_and_type<T>::get_r_type( tmp ); addend = convertor( pEntry->r_addend ); }
// Convert a line from a hits file into a vector of overlaps and sets the flag // indicating whether the read was found to be a substring of other reads // Only the forward read table is used since we only care about the IDs and length // of the read, not the sequence, so that we don't need an explicit reverse read table void OverlapCommon::parseHitsString(const std::string& hitString, const ReadInfoTable* pQueryRIT, const ReadInfoTable* pTargetRIT, const SuffixArray* pFwdSAI, const SuffixArray* pRevSAI, bool bCheckIDs, size_t& readIdx, size_t& sumBlockSize, OverlapVector& outVector, bool& isSubstring) { OverlapVector outvec; std::istringstream convertor(hitString); sumBlockSize = 0; // Read the overlap blocks for a read size_t numBlocks; convertor >> readIdx >> isSubstring >> numBlocks; //std::cout << "<Read> idx: " << readIdx << " count: " << numBlocks << "\n"; for(size_t i = 0; i < numBlocks; ++i) { // Read the block OverlapBlock record; convertor >> record; //std::cout << "\t" << record << "\n"; // Iterate through the range and write the overlaps for(int64_t j = record.ranges.interval[0].lower; j <= record.ranges.interval[0].upper; ++j) { sumBlockSize += 1; const SuffixArray* pCurrSAI = (record.flags.isTargetRev()) ? pRevSAI : pFwdSAI; const ReadInfo& queryInfo = pQueryRIT->getReadInfo(readIdx); int64_t saIdx = j; // The index of the second read is given as the position in the SuffixArray index const ReadInfo& targetInfo = pTargetRIT->getReadInfo(pCurrSAI->get(saIdx).getID()); // Skip self alignments and non-canonical (where the query read has a lexo. higher name) if(queryInfo.id != targetInfo.id) { Overlap o = record.toOverlap(queryInfo.id, targetInfo.id, queryInfo.length, targetInfo.length); //std::cout << queryInfo.id << " " << targetInfo.id << " " << queryInfo.length << " " << targetInfo.length << "\n"; // The alignment logic above has the potential to produce duplicate alignments // To avoid this, we skip overlaps where the id of the first coord is lexo. lower than // the second or the match is a containment and the query is reversed (containments can be // output up to 4 times total). if(bCheckIDs && (o.id[0] < o.id[1] || (o.match.isContainment() && record.flags.isQueryRev()))) continue; outVector.push_back(o); } } } }
static void hippo_cursor_rewind(MongoDBDriverCursorData* data) { if (data->next_after_rewind != 0) { if (data->zchild_active) { throw MongoDriver::Utils::throwLogicException("Cursors cannot rewind after starting iteration"); } else { /* If we're not active, image we're now have fully iterated */ throw MongoDriver::Utils::throwLogicException("Cursors cannot yield multiple iterators"); } } invalidate_current(data); data->current = 0; data->zchild_active = false; if (data->first_batch) { if (data->is_command_cursor) { if (!bson_iter_init(&data->first_batch_iter, data->first_batch)) { return; } if (bson_iter_next(&data->first_batch_iter)) { if (BSON_ITER_HOLDS_DOCUMENT(&data->first_batch_iter)) { const uint8_t *document = NULL; uint32_t document_len = 0; Variant v; bson_iter_document(&data->first_batch_iter, &document_len, &document); BsonToVariantConverter convertor(document, document_len, data->bson_options); convertor.convert(&v); data->zchild_active = true; data->zchild = v; } } } else { Variant v; BsonToVariantConverter convertor(bson_get_data(data->first_batch), data->first_batch->len, data->bson_options); convertor.convert(&v); data->zchild_active = true; data->zchild = v; } } }
TEST(GTestConvertor, testsGetAddedToCurrentTestRegistry) { TestTestingFixture fixture; TestRegistry::getCurrentRegistry()->unDoLastAddTest(); GTestConvertor convertor(false); convertor.addAllGTestToTestRegistry(); LONGS_EQUAL(9, TestRegistry::getCurrentRegistry()->countTests()); }
Array HHVM_METHOD(MongoDBDriverReadPreference, getTagSets) { MongoDBDriverReadPreferenceData* data = Native::data<MongoDBDriverReadPreferenceData>(this_); Variant v_tags; const bson_t *tags = mongoc_read_prefs_get_tags(data->m_read_preference); hippo_bson_conversion_options_t options = HIPPO_TYPEMAP_DEBUG_INITIALIZER; BsonToVariantConverter convertor(bson_get_data(tags), tags->len, options); convertor.convert(&v_tags); return v_tags.toArray(); }
void main(int argc,char *argv[]) { if(argc!=3) { usage(); getch(); exit(1); } fontcon convertor("Kruti Dev to True Type Font",argv[1],argv[2]); convertor.getdata(); convertor.convert(); convertor.putdata(); convertor.generate_log(); }
void main(int argc,char *argv[]) { if(argc!=3) { usage(); getch(); exit(1); } fontcon convertor("True-Type Fonts to Web-Dunia Fonts",argv[1],argv[2]); convertor.getdata(); convertor.convert(); convertor.putdata(); convertor.generate_log(); }
static bool hippo_cursor_load_next(MongoDBDriverCursorData* data) { const bson_t *doc; if (mongoc_cursor_next(data->cursor, &doc)) { Variant v; BsonToVariantConverter convertor(bson_get_data(doc), doc->len, data->bson_options); convertor.convert(&v); data->zchild_active = true; data->zchild = v; return true; } return false; }
void DataHandler::DataImporter(cv::Mat &sampleData, cv::Mat &labels) { vector<vector<double>> input(sampleData.rows, vector<double>(sampleData.cols+1)); ifstream file(_filepath); string line; int col = 0; int row = 0; while (getline(file, line)) { istringstream iss(line); string result; while (getline(iss, result, ';')) //The delimiter of the csv file is ";" { istringstream convertor(result); //Convert the string into a float number convertor >> input[row][col]; //Fill the sampleData matrix with the values of the .csv col = col + 1; } row = row + 1; col = 0; } file.close(); double variable; //variables are the input explanatory variables int label; //label is the output classes labels for (int i = 0; i < input.size(); i++) { for (int j = 0; j < input[0].size(); j++) { //the input file gathers both the variables and the output classes //select the variables and the labels separately if (j < input[0].size()-1) { variable = input[i][j]; sampleData.at<double>(i, j) = variable; } else if (j == input[0].size()-1) { label = input[i][j]; labels.at<double>(i, label) = 1.0; //the labels begin at 3 and go to 9 } } //we have two cv::Matrices which contain the input and output data for the NN } }
Elf_Word generic_add_symbol( Elf_Word name, Elf64_Addr value, Elf_Xword size, unsigned char info, unsigned char other, Elf_Half shndx ) { const endianess_convertor& convertor = elf_file.get_convertor(); T entry; entry.st_name = convertor( name ); entry.st_value = value; entry.st_value = convertor( entry.st_value ); entry.st_size = size; entry.st_size = convertor( entry.st_size ); entry.st_info = convertor( info ); entry.st_other = convertor( other ); entry.st_shndx = convertor( shndx ); symbol_section->append_data( reinterpret_cast<char*>( &entry ), sizeof( entry ) ); Elf_Word nRet = symbol_section->get_size() / sizeof( entry ) - 1; return nRet; }
////////////////////////////////////////////////////////////////////// // Initialize the parser. // Inputs: // const TsString& dataDir The directory containing data files. // Outputs: // std::String& errorMsg The message if an error occured. // Return value: // bool true on success, false on error. ////////////////////////////////////////////////////////////////////// bool RegularExprWrapper::ReadPatternToolConfiguration( const TsString& patternsConfigurationFile, TsString& errorMsg ) { // Deserialize a configuration TsString configStr; TsString errorMsg2; if (!FileSys::ReadFileIntoString(patternsConfigurationFile, configStr, errorMsg2)) { errorMsg = errorMsg2; return false; } // New-style XML configuration DomHelper helper; DOMDocument* doc = helper.DomParseString(configStr.c_str(), errorMsg2); if (doc == 0) { errorMsg = errorMsg2; return false; } XMLToDataItem convertor(doc); DataItemRef config = convertor.MakeDataItem(); if (config == 0) { errorMsg = "Error reading address pattern file."; return false; } // Get all process node configs and walk them DataItemRef processNodeConfigs = config["PROCESS_NODES"]; if (processNodeConfigs == 0 || processNodeConfigs->GetType() != DataItem::Array) { // ProcessNodes config must exist even if it is empty errorMsg = "Error reading configuration file."; return false; } ListenerRef configListener = new ListenerNull; // Loop over all process nodes for ( int nodeIdx = 0; nodeIdx < processNodeConfigs.toArray()->GetSize(); nodeIdx++ ) { DataItemRef nodeMetaConfig = (*processNodeConfigs.toArray())[nodeIdx]; if (nodeMetaConfig->GetType() != DataItem::Association) { errorMsg = "Error reading configuration file."; return false; } DataItemRef nodeConfig = nodeMetaConfig["CONFIG"]; if (nodeConfig == 0) { errorMsg = "Error reading configuration file."; return false; } DataItemRef nodeId = nodeMetaConfig["ID"]; if (nodeId == 0) { errorMsg = "Error reading configuration file."; return false; } if( TsString(*nodeId) == "ProcessNodeTokenizer" ) { tokenizer = new Tokenizer(); if (!tokenizer->Bind(nodeConfig , configListener)) { errorMsg = "Error reading configuration file."; return false; } } if( TsString(*nodeId) == "ProcessNodeSymbolizer" ) { symbolizer = new Symbolizer(); if (!symbolizer->Bind(nodeConfig , configListener)) { errorMsg = "Error reading configuration file."; return false; } } if( TsString(*nodeId) == "ProcessNodePatternMatch" ) { patternMatcher = new PatternMatcher(); if (!patternMatcher->Bind(nodeConfig , configListener)) { errorMsg = "Error reading configuration file."; return false; } } } if( tokenizer == 0 || symbolizer == 0 || patternMatcher == 0 ) { return false; } return true; }
void MitsubishiArmInterface::readHW() { //boost::mutex::scoped_lock lock(io_mutex); // WRITE READ to robot unsigned char cmd_msg[] = "1\r\n"; int n_written = 0; do { n_written += write( USB, &cmd_msg[n_written], 1 ); } while (cmd_msg[n_written-1] != '\n'); // READ RESPONSE (R) char buf [256]; memset (&buf, '\0', sizeof buf); int n = 0; std::string response; do { n += read( USB, &buf, 1); response.append( buf ); } while( buf[0] != '\n'); if (response.find("R\r\n") == std::string::npos) { std::cout << "didn-t find R!" << '\n'; exit(-1); } response.clear(); // END READ // READ JOINTS STATE n_written = 0; memset (&buf, '\0', sizeof buf); do { n_written += read( USB, &buf, 1); response.append( buf ); } while( buf[0] != '\n'); std::stringstream convertor(response); // READ RESPONSE (E) memset (&buf, '\0', sizeof buf); n = 0; do { n += read( USB, &buf, 1); response.append( buf ); } while( buf[0] != '\n'); if (response.find("E\r\n") == std::string::npos) { std::cout << "didn-t find E!" << '\n'; exit(-1); } // END READ char dummy_char; convertor >> dummy_char >> pos[0] >> dummy_char >> pos[1] >> dummy_char >> pos[2] >> dummy_char >> pos[3] >> dummy_char >> pos[4] >> dummy_char >> pos[5] >> dummy_char >> pos[6] >> dummy_char; // convert to radians and add to state for(int i=0; i< pos.size(); ++i) { pos[i]=pos[i]*(DEG_TO_RAD); } eff[0]=0.0; eff[1]=0.0; eff[2]=0.0; eff[3]=0.0; eff[4]=0.0; eff[5]=0.0; vel[0]=0.0; vel[1]=0.0; vel[2]=0.0; vel[3]=0.0; vel[4]=0.0; vel[5]=0.0; }
void generic_get_entry_dyn( Elf_Xword index, Elf_Xword& tag, Elf_Xword& value ) const { const endianess_convertor& convertor = elf_file.get_convertor(); // Check unusual case when dynamic section has no data if( dynamic_section->get_data() == 0 || ( index + 1 ) * dynamic_section->get_entry_size() > dynamic_section->get_size() ) { tag = DT_NULL; value = 0; return; } const T* pEntry = reinterpret_cast<const T*>( dynamic_section->get_data() + index * dynamic_section->get_entry_size() ); tag = convertor( pEntry->d_tag ); switch ( tag ) { case DT_NULL: case DT_SYMBOLIC: case DT_TEXTREL: case DT_BIND_NOW: value = 0; break; case DT_NEEDED: case DT_PLTRELSZ: case DT_RELASZ: case DT_RELAENT: case DT_STRSZ: case DT_SYMENT: case DT_SONAME: case DT_RPATH: case DT_RELSZ: case DT_RELENT: case DT_PLTREL: case DT_INIT_ARRAYSZ: case DT_FINI_ARRAYSZ: case DT_RUNPATH: case DT_FLAGS: case DT_PREINIT_ARRAYSZ: value = convertor( pEntry->d_un.d_val ); break; case DT_PLTGOT: case DT_HASH: case DT_STRTAB: case DT_SYMTAB: case DT_RELA: case DT_INIT: case DT_FINI: case DT_REL: case DT_DEBUG: case DT_JMPREL: case DT_INIT_ARRAY: case DT_FINI_ARRAY: case DT_PREINIT_ARRAY: default: value = convertor( pEntry->d_un.d_ptr ); break; } }
void DataHandler::DataAdapter(vector<vector<double>> dataMatrix) { //Import the .csv file using the fstream class vector<vector<double>> inputdata(dataMatrix.size()+1,vector<double>(dataMatrix[0].size())); ifstream file(_filepath); string line; int col = 0; int row = 0; while (getline(file, line)) { istringstream iss(line); string result; while (getline(iss, result, ';')) //The delimiter of the csv file is ";" { istringstream convertor(result); //Convert the string into a float number convertor >> inputdata[row][col]; //Fill the inputdata matrix with the values of the .csv col = col + 1; } row = row + 1; col = 0; } //Delete the first row of the matrix (headers) for (int i = 1; i < inputdata.size(); i++) //Start from the second line of inputdata { for (int j = 0; j < inputdata[0].size(); j++) { dataMatrix[i - 1][j] = inputdata[i][j]; } } //Normalization of the matrix (except the last column) for (int j = 0; j<dataMatrix[0].size() - 1; j++) { vector<double> v(dataMatrix.size()); vector<double> w(dataMatrix.size()); for (int i = 0; i < dataMatrix.size(); i++) { w[i] = dataMatrix[i][j]; } double a = *max_element(w.begin(),w.end()); double b = *min_element(w.begin(), w.end()); for (int i = 0; i < inputdata.size() - 1; i++) { v[i] = (w[i] - b) / (a - b); dataMatrix[i][j] = v[i]; } } //Shuffle the matrix random_device rd; mt19937 g(rd()); shuffle(dataMatrix.begin(), dataMatrix.end(), g); //Save the adapted data into 3 .csv's ofstream myfile1; myfile1.open("..\\..\\Results\\training_dataset.csv"); for (int i = 0; i<floor((0.666)*dataMatrix.size()); i++) //select the first 2/3 elements of the database { for (int j = 0; j < dataMatrix[0].size(); j++) { myfile1 << dataMatrix[i][j] << ";"; } myfile1 << endl; } myfile1.close(); ofstream myfile2; myfile2.open("..\\..\\Results\\testing_dataset.csv"); for (int i = floor((0.666)*dataMatrix.size()); i< floor((0.666)*dataMatrix.size()) + floor((0.166)*dataMatrix.size()); i++) //Select the next 1/6 samples { for (int j = 0; j < dataMatrix[0].size(); j++) { myfile2 << dataMatrix[i][j] << ";"; } myfile2 << endl; } myfile2.close(); ofstream myfile3; myfile3.open("..\\..\\Results\\predict_dataset.csv"); for (int i = floor((0.666)*dataMatrix.size()) + floor((0.166)*dataMatrix.size()); i< dataMatrix.size(); i++) //Select the last samples { for (int j = 0; j < dataMatrix[0].size(); j++) { myfile3 << dataMatrix[i][j] << ";"; } myfile3 << endl; } myfile3.close(); }
void Experiment1_2::DrawParallelPlot() { //Read the CSV file and figure out the number of rows. We do not need to store the data anywhere and can be plotted on the fly on the second pass, after we have figured out the max and min for each column std::string line; std::ifstream input_file; input_file.open( csv_filename.c_str() ); int32 row=0, column=0; if ( input_file.is_open() ) { while( getline(input_file,line) ) { if(row == 0) { //Count Columns and resize Data_Attr //Traverse the string and count for (int c=0; c< line.length(); c++ ) { if(line[c] == ',') { column ++; } } column=column+1; Data_Attr.clear(); Data_Attr.resize(column); Data_Size[1]=column; } else //Get Max and Min { line= line + std::string(","); std::stringstream iss(line); for(int32 i=0; i< column; i++) { std::string val; std::getline(iss, val, ','); if ( !iss.good() ) break; std::stringstream convertor(val); convertor >> Data_Attr[i][0]; if(row == 1) { Data_Attr[i][1]=Data_Attr[i][0]; Data_Attr[i][2]=Data_Attr[i][0]; } else //Determine max and min { if(Data_Attr[i][0]>Data_Attr[i][1]) //Max { Data_Attr[i][1]= Data_Attr[i][0]; } if(Data_Attr[i][0]<Data_Attr[i][2]) //Min { Data_Attr[i][2]= Data_Attr[i][0]; } } } } row++; } } else //If file couldn't be opened. {
Object hippo_write_result_init(bson_t *reply, bson_error_t *error, mongoc_client_t *client, int server_id, int success, const mongoc_write_concern_t *write_concern) { static Class* c_writeResult; c_writeResult = Unit::lookupClass(s_MongoDriverWriteResult_className.get()); assert(c_writeResult); Object obj = Object{c_writeResult}; MongoDBDriverWriteResultData* wr_data = Native::data<MongoDBDriverWriteResultData>(obj.get()); wr_data->m_client = client; wr_data->m_server_id = server_id; wr_data->m_write_concern = mongoc_write_concern_copy(write_concern); /* Convert the whole BSON reply into a Variant */ Variant v; Array a; hippo_bson_conversion_options_t options = HIPPO_TYPEMAP_DEBUG_INITIALIZER; BsonToVariantConverter convertor(bson_get_data(reply), reply->len, options); convertor.convert(&v); a = v.toArray(); obj->o_set(s_nUpserted, Variant(a[s_nUpserted]), s_MongoDriverWriteResult_className); obj->o_set(s_nMatched, Variant(a[s_nMatched]), s_MongoDriverWriteResult_className); obj->o_set(s_nRemoved, Variant(a[s_nRemoved]), s_MongoDriverWriteResult_className); obj->o_set(s_nInserted, Variant(a[s_nInserted]), s_MongoDriverWriteResult_className); obj->o_set(s_nModified, Variant(a[s_nModified]), s_MongoDriverWriteResult_className); if (write_concern) { Array debugInfoResult = Array::Create(); mongodb_driver_add_write_concern_debug((mongoc_write_concern_t*) write_concern, &debugInfoResult); obj->o_set(s_writeConcern, debugInfoResult, s_MongoDriverWriteConcern_className); } else { obj->o_set(s_writeConcern, Variant(), s_MongoDriverWriteConcern_className); } if (a.exists(s_upserted)) { obj->o_set(s_upsertedIds, a[s_upserted], s_MongoDriverWriteResult_className); } else { Array a = Array::Create(); obj->o_set(s_upsertedIds, a, s_MongoDriverWriteResult_className); } if (a.exists(s_writeErrors)) { Array writeErrors = Array::Create(); for (ArrayIter iter(a[s_writeErrors].toArray()); iter; ++iter) { const Variant& value = iter.second(); static Class* c_writeError; Array a_we = value.toArray(); c_writeError = Unit::lookupClass(s_MongoDriverWriteError_className.get()); assert(c_writeError); Object we_obj = Object{c_writeError}; if (a_we.exists(s_errmsg)) { we_obj->o_set(s_message, a_we[s_errmsg], s_MongoDriverWriteError_className); } if (a_we.exists(s_code)) { we_obj->o_set(s_code, a_we[s_code], s_MongoDriverWriteError_className); } if (a_we.exists(s_index)) { we_obj->o_set(s_index, a_we[s_index], s_MongoDriverWriteError_className); } if (a_we.exists(s_info)) { we_obj->o_set(s_info, a_we[s_info], s_MongoDriverWriteError_className); } writeErrors.append(we_obj); } obj->o_set(s_writeErrors, writeErrors, s_MongoDriverWriteResult_className); } if (a.exists(s_writeConcernErrors)) { Array a_v; a_v = a[s_writeConcernErrors].toArray(); static Class* c_writeConcernError; c_writeConcernError = Unit::lookupClass(s_MongoDriverWriteConcernError_className.get()); assert(c_writeConcernError); Object wce_obj = Object{c_writeConcernError}; if (a_v.exists(0) && a_v[0].isArray()) { Array first_item = a_v[0].toArray(); if (first_item.exists(s_errmsg)) { wce_obj->o_set(s_message, first_item[s_errmsg], s_MongoDriverWriteConcernError_className); } if (first_item.exists(s_code)) { wce_obj->o_set(s_code, first_item[s_code], s_MongoDriverWriteConcernError_className); } if (first_item.exists(s_info)) { wce_obj->o_set(s_info, first_item[s_info], s_MongoDriverWriteConcernError_className); } else { wce_obj->o_set(s_info, Variant(), s_MongoDriverWriteConcernError_className); } obj->o_set(s_writeConcernError, Variant(wce_obj), s_MongoDriverWriteResult_className); } } if (success == 0) { if ((error->domain == MONGOC_ERROR_COMMAND && error->code != MONGOC_ERROR_COMMAND_INVALID_ARG) || error->domain == MONGOC_ERROR_WRITE_CONCERN) { auto bw_exception = MongoDriver::Utils::throwBulkWriteException(error->message); bw_exception->o_set(s_MongoDriverExceptionBulkWriteException_writeResult, obj, MongoDriver::s_MongoDriverExceptionBulkWriteException_className); throw bw_exception; } else { throw MongoDriver::Utils::throwExceptionFromBsonError(error); } } return obj; }
Array HHVM_METHOD(MongoDBDriverCursor, __debugInfo) { MongoDBDriverCursorData* data = Native::data<MongoDBDriverCursorData>(this_); Array retval = Array::Create(); if (data->cursor) { Array cretval = Array::Create(); const bson_t *tags = mongoc_read_prefs_get_tags(data->cursor->read_prefs); cretval.add(s_MongoDBDriverCursor_stamp, (int64_t) data->cursor->stamp); cretval.add(s_MongoDBDriverCursor_is_command, !!(data->cursor->is_command)); cretval.add(s_MongoDBDriverCursor_sent, !!data->cursor->sent); cretval.add(s_MongoDBDriverCursor_done, !!data->cursor->done); cretval.add(s_MongoDBDriverCursor_end_of_event, !!data->cursor->end_of_event); cretval.add(s_MongoDBDriverCursor_in_exhaust, !!data->cursor->in_exhaust); cretval.add(s_MongoDBDriverCursor_has_fields, !!data->cursor->has_fields); { Variant v_query; hippo_bson_conversion_options_t options = HIPPO_TYPEMAP_INITIALIZER; BsonToVariantConverter convertor(bson_get_data(&data->cursor->query), data->cursor->query.len, options); convertor.convert(&v_query); cretval.add(s_MongoDBDriverCursor_query, v_query); } { Variant v_fields; hippo_bson_conversion_options_t options = HIPPO_TYPEMAP_INITIALIZER; BsonToVariantConverter convertor(bson_get_data(&data->cursor->fields), data->cursor->fields.len, options); convertor.convert(&v_fields); cretval.add(s_MongoDBDriverCursor_fields, v_fields); } if (tags->len) { Array rp_retval = Array::Create(); Variant v_read_preference; rp_retval.add(s_MongoDBDriverCursor_read_preference_mode, (int64_t) mongoc_read_prefs_get_mode(data->cursor->read_prefs)); hippo_bson_conversion_options_t options = HIPPO_TYPEMAP_DEBUG_INITIALIZER; BsonToVariantConverter convertor(bson_get_data(tags), tags->len, options); convertor.convert(&v_read_preference); rp_retval.add(s_MongoDBDriverCursor_read_preference_tags, v_read_preference); cretval.add(s_MongoDBDriverCursor_read_preference, rp_retval); } else { cretval.add(s_MongoDBDriverCursor_read_preference, Variant()); } cretval.add(s_MongoDBDriverCursor_flags, (int64_t) data->cursor->flags); cretval.add(s_MongoDBDriverCursor_skip, (int64_t) data->cursor->skip); cretval.add(s_MongoDBDriverCursor_limit, (int64_t) data->cursor->limit); cretval.add(s_MongoDBDriverCursor_count, (int64_t) data->cursor->count); cretval.add(s_MongoDBDriverCursor_batch_size, (int64_t) data->cursor->batch_size); cretval.add(s_MongoDBDriverCursor_ns, data->cursor->ns); if (data->cursor->current) { Array doc_retval = Array::Create(); Variant v_doc; hippo_bson_conversion_options_t options = HIPPO_TYPEMAP_INITIALIZER; BsonToVariantConverter convertor(bson_get_data(data->cursor->current), data->cursor->current->len, options); convertor.convert(&v_doc); cretval.add(s_MongoDBDriverCursor_current_doc, v_doc); } retval.add(s_MongoDBDriverCursor_cursor, cretval); } else { retval.add(s_MongoDBDriverCursor_cursor, Variant()); } retval.add(s_MongoDBDriverCursor_server_id, data->m_server_id); return retval; }
// Convert the Python values to a raw array. static void *convert_values(Array *array, PyObject *values, GLenum gl_type, sipErrorState *estate) { #if PY_VERSION_HEX >= 0x02060300 int rc = sipGetBufferInfo(values, &array->buffer); if (rc < 0) { *estate = sipErrorFail; return 0; } if (rc > 0) { // Check the buffer is compatible with what we need. GLenum array_type; switch (*array->buffer.bi_format) { case 'b': array_type = GL_BYTE; break; case 'B': array_type = GL_UNSIGNED_BYTE; break; case 'h': array_type = GL_SHORT; break; case 'H': array_type = GL_UNSIGNED_SHORT; break; case 'i': array_type = GL_INT; break; case 'I': array_type = GL_UNSIGNED_INT; break; case 'f': array_type = GL_FLOAT; break; #if defined(SIP_FEATURE_PyQt_Desktop_OpenGL) case 'd': array_type = GL_DOUBLE; break; #endif default: PyErr_Format(PyExc_TypeError, "unsupported buffer type '%s'", array->buffer.bi_format); *estate = sipErrorFail; return 0; } if (array_type != gl_type) { PyErr_SetString(PyExc_TypeError, "the buffer type is not the same as the array type"); *estate = sipErrorFail; return 0; } return array->buffer.bi_buf; } #else PyBufferProcs *bf = Py_TYPE(values)->tp_as_buffer; if (bf && bf->bf_getreadbuffer && bf->bf_getsegcount) { if (bf->bf_getsegcount(values, 0) != 1) { PyErr_SetString(PyExc_TypeError, "single-segment buffer object expected"); *estate = sipErrorFail; return 0; } if (bf->bf_getreadbuffer(values, 0, reinterpret_cast<void **>(&array)) < 0) { *estate = sipErrorFail; return 0; } Py_INCREF(values); array->buffer = values; return array; } #endif PyObject *seq = PySequence_Fast(values, "array must be a sequence or a buffer"); if (!seq) { *estate = sipErrorContinue; return 0; } Py_ssize_t nr_items = Sequence_Fast_Size(seq); if (nr_items < 1) { Py_DECREF(seq); PyErr_SetString(PyExc_TypeError, "array must have at least one element"); *estate = sipErrorFail; return 0; } void (*convertor)(PyObject *, void *, Py_ssize_t); size_t element_size; switch (gl_type) { case GL_BYTE: convertor = convert_byte; element_size = sizeof (GLbyte); break; case GL_UNSIGNED_BYTE: convertor = convert_ubyte; element_size = sizeof (GLubyte); break; case GL_SHORT: convertor = convert_short; element_size = sizeof (GLshort); break; case GL_UNSIGNED_SHORT: convertor = convert_ushort; element_size = sizeof (GLushort); break; case GL_INT: convertor = convert_int; element_size = sizeof (GLint); break; case GL_UNSIGNED_INT: convertor = convert_uint; element_size = sizeof (GLuint); break; case GL_FLOAT: convertor = convert_float; element_size = sizeof (GLfloat); break; #if defined(SIP_FEATURE_PyQt_Desktop_OpenGL) #if GL_DOUBLE != GL_FLOAT case GL_DOUBLE: convertor = convert_double; element_size = sizeof (GLdouble); break; #endif #endif default: Py_DECREF(seq); PyErr_SetString(PyExc_TypeError, "unsupported GL element type"); *estate = sipErrorFail; return 0; } void *data = sipMalloc(nr_items * element_size); if (!data) { Py_DECREF(seq); *estate = sipErrorFail; return 0; } for (Py_ssize_t i = 0; i < nr_items; ++i) { PyErr_Clear(); convertor(Sequence_Fast_GetItem(seq, i), data, i); if (PyErr_Occurred()) { sipFree(data); Py_DECREF(seq); *estate = sipErrorFail; return 0; } } Py_DECREF(seq); array->data = data; return data; }