long GNEConnectorFrame::onCmdSelectConflicts(FXObject*, FXSelector, void*) { std::vector<GUIGlID> selectIDs; // conflicts happen per edge so we can look at each edge in isolation const std::vector<GNEEdge*> edges = myViewNet->getNet()->retrieveEdges(); for (std::vector<GNEEdge*>::const_iterator edge_it = edges.begin(); edge_it != edges.end(); edge_it++) { NBEdge* nbe = (*edge_it)->getNBEdge(); const EdgeVector destinations = nbe->getConnectedEdges(); const std::vector<NBEdge::Connection>& connections = nbe->getConnections(); for (EdgeVector::const_iterator dest_it = destinations.begin(); dest_it != destinations.end(); dest_it++) { GNEEdge* dest = myViewNet->getNet()->retrieveEdge((*dest_it)->getID()); const GNEEdge::LaneVector& destLanes = dest->getLanes(); for (GNEEdge::LaneVector::const_iterator it_lane = destLanes.begin(); it_lane != destLanes.end(); it_lane++) { const bool isConflicted = count_if( connections.begin(), connections.end(), NBEdge::connections_toedgelane_finder(*dest_it, (int)(*it_lane)->getIndex(), -1)) > 1; if (isConflicted) { selectIDs.push_back((*it_lane)->getGlID()); } } } } myViewNet->getViewParent()->getSelectorFrame()->handleIDs(selectIDs, false, GNESelectorFrame::SET_REPLACE); return 1; }
void Header::contextMenuEvent(QContextMenuEvent *event) { const shared_ptr<ViewItem> r = get_mouse_over_item(mouse_point_); if (!r) return; QMenu *menu = r->create_header_context_menu(this); if (!menu) menu = new QMenu(this); const vector< shared_ptr<TraceTreeItem> > items( view_.list_by_type<TraceTreeItem>()); if (count_if(items.begin(), items.end(), item_selected) > 1) { menu->addSeparator(); QAction *const group = new QAction(tr("Group"), this); QList<QKeySequence> shortcuts; shortcuts.append(QKeySequence(Qt::ControlModifier | Qt::Key_G)); group->setShortcuts(shortcuts); connect(group, SIGNAL(triggered()), this, SLOT(on_group())); menu->addAction(group); } menu->popup(event->globalPos()); }
//[[Rcpp::export]] int nTipsSafe (Rcpp::IntegerVector ances) { // count how many zeros are in the tabulated vector of ancestors // this gives the number of tips std::vector<int> tabTips = tabulateTips(ances); int j = count_if (tabTips.begin(), tabTips.end(), isZero); return j; }
void pure_numeric_algo(){ cout<<endl<<"pure_numeric_algo :"<<endl; int ia[11] = {0, 1, 2, 3, 4, 5, 6,6,6, 7, 8 }; vector<int> iv(ia,ia+11); vector<int> iv2(ia+6,ia+8); vector<int>::iterator itr; itr = adjacent_find(iv.begin(),iv.end(), equal_to<int>()); //找到相邻元素相等的第一个元素 cout<<"adjacent_find: "<<*itr<<endl; cout<<"count: "<<count(iv.begin(),iv.end(), 6)<<endl; //找到元素值等于6的个数 cout<<"count_if: "<<count_if(iv.begin(),iv.end(), bind2nd(less<int>() , 7))<<endl; //找到小于7的元素个数 itr = find(iv.begin(),iv.end(), 4); //找到元素等于4的第一个元素位置 cout<<"find: "<<*itr<<endl; itr = find_if(iv.begin(),iv.end(), bind2nd(greater<int>() , 2)); //找到元素大于2的第一个元素位置 cout<<"find_if: "<<*itr<<endl; itr = find_end(iv.begin(),iv.end(), iv2.begin(),iv2.end()); //找到iv序列中最后子序列匹配出现的位置 cout<<"find_end: "<<*(itr+3)<<endl; itr = find_first_of(iv.begin(),iv.end(), iv2.begin(),iv2.end()); //找到iv序列中最先子序列匹配出现的位置 cout<<"find_end: "<<*(itr+3)<<endl; remove(iv.begin(),iv.end(), 6); //删除元素,向前移,但是容器size不变,后面会剩余数据 cout<<"remove: "<<iv<<endl; vector<int> iv3(12,-1); remove_copy(iv.begin(),iv.end(), iv3.begin(), 6); //删除元素,将数据拷贝到新容器,后面会剩余数据 cout<<"remove_copy: "<<iv3<<endl; remove_if(iv.begin(),iv.end(), bind2nd(less<int>(), 6)); //删除小于6的元素,后面会剩余数据 cout<<"remove_if: "<<iv<<endl; remove_copy_if(iv.begin(),iv.end(), iv3.begin(), bind2nd(less<int>(), 7)); //删除小于7的元素,并拷贝到新容器 cout<<"remove_copy_if: "<<iv3<<endl; replace(iv.begin(),iv.end(), 6, 3); //将所有元素值为6的改为3 cout<<"replace: "<<iv<<endl; replace_copy(iv.begin(),iv.end(),iv3.begin(), 3, 5); //将所有元素值为3的改为5,结果保存在新容器中 cout<<"replace_copy: "<<iv3<<endl; replace_if(iv.begin(),iv.end(), bind2nd(less<int>(),5), 2); //将所有元素值小于5的改为2 cout<<"replace_if: "<<iv<<endl; replace_copy_if(iv.begin(),iv.end(),iv3.begin(), bind2nd(equal_to<int>(),8), 9); //将所有元素值为8的改为9,结果保存在新容器中 cout<<"replace_copy_if: "<<iv3<<endl; reverse(iv.begin(),iv.end()); cout<<"reverse: "<<iv<<endl; //反转 reverse_copy(iv.begin(),iv.end(),iv3.begin()); cout<<"reverse_copy: "<<iv3<<endl; //反转,结果保存在新容器 rotate(iv.begin(),iv.begin() + 4, iv.end()); cout<<"rotate: "<<iv<<endl; //互换元素 rotate_copy(iv.begin(),iv.begin() + 5,iv.end(),iv3.begin()); cout<<"rotate_copy: "<<iv3<<endl; //互换元素,结果保存在新容器 int ia2[] = {2, 8}; vector<int> iv4(ia2,ia2+2); cout<<"search: "<<*search(iv.begin(),iv.end(),iv4.begin(),iv4.end())<<endl; //查找子序列出现的第一次出现地点 swap_ranges(iv4.begin(),iv4.end(),iv.begin()); //按区域交换 cout<<"swap_ranges: "<<iv<<endl<<iv4<<endl; transform(iv.begin(),iv.end(),iv.begin(),bind2nd(minus<int>(), 2)); //所有元素减2 cout<<"transform: "<<iv<<endl; transform(iv4.begin(),iv4.end(),iv.begin(),iv4.begin(),plus<int>()); //区间对应元素相加 cout<<"transform: "<<iv4<<endl; /************************************************************************/ vector<int> iv5(ia,ia+11); vector<int> iv6(ia+4,ia+8); vector<int> iv7(15); cout<<"max_element: "<<*max_element(iv5.begin(), iv5.end())<<endl; //最大元素游标 cout<<"min_element: "<<*min_element(iv5.begin(), iv5.end())<<endl; cout<<"includes: "<<includes(iv5.begin(),iv5.end(),iv6.begin(),iv6.end())<<endl; //iv6中元素是不是都在iv5中,这两个必须排过序 merge(iv5.begin(),iv5.end(),iv6.begin(),iv6.end(),iv7.begin()); //两个排序号的容器合并 cout<<"merge: "<<iv7<<endl; partition(iv7.begin(),iv7.end(),bind2nd(equal_to<int>(), 5)); //满足条件的放在左边,不满足条件的放在右边 cout<<"partition: "<<iv7<<endl; unique(iv5.begin(),iv5.end()); //去重,重复的元素放在后面 cout<<"unique: "<<iv5<<endl; unique_copy(iv5.begin(),iv5.end(),iv7.begin()); //去重,结果保存在新容器 cout<<"unique_copy: "<<iv7<<endl; }
int main () { std::vector<int> myvector; for (int i=1; i<10; i++) myvector.push_back(i); // myvector: 1 2 3 4 5 6 7 8 9 int mycount = count_if (myvector.begin(), myvector.end(), IsOdd); std::cout << "myvector contains " << mycount << " odd values.\n"; return 0; }
void DialogTranslation::OnExternalCommit(int commit_type) { if (commit_type == AssFile::COMMIT_NEW || commit_type & AssFile::COMMIT_DIAG_ADDREM) { line_count = count_if(c->ass->Line.begin(), c->ass->Line.end(), cast<AssDialogue*>()); line_number_display->SetLabel(wxString::Format(_("Current line: %d/%d"), (int)line_number, (int)line_count)); } if (commit_type & AssFile::COMMIT_DIAG_TEXT) OnActiveLineChanged(active_line); }
int main() { int ia[] = {0,1,1,2,3,5,8,13,21,34}; list< int,allocator > ilist( ia, ia+10 ); /* * unsupported in current implementation ***************************************************** typedef iterator_traits<InputIterator>::distance_type distance_type; distance_type ia_count, list_count; // count even elements: 4 ia_count = count_if( &ia[0], &ia[10], Even() ); list_count = count_if( ilist.begin(), ilist_end(), bind2nd(less<int>(),10) ); ****************************************************** */ int ia_count = 0; count_if( &ia[0], &ia[10], Even(), ia_count ); // generates: // count_if(): there are 4 elements that are even. cout << "count_if(): there are " << ia_count << " elements that are even.\n"; int list_count = 0; count_if( ilist.begin(), ilist.end(), bind2nd(less<int>(),10), list_count ); // generates: // count_if(): there are 7 elements that are less than 10. cout << "count_if(): there are " << list_count << " elements that are less than 10.\n"; return 0; }
int main () { vector <int> numbers(100); for (int i = 0; i < 100; i++) numbers[i] = i % 3; int elements = 0; count_if (numbers.begin (), numbers.end (), odd, elements); cout << "Found " << elements << " odd elements." << endl; return 0; }
double pWaveOccurenceRatio(const QVector<Cit> &pWaveStarts, const Cit &endOfSignal) { if (biggestIteratorTooBig(pWaveStarts, endOfSignal)) throw PWaveStartTooCloseToEndOfSignal(); const int count = count_if(begin(pWaveStarts), end(pWaveStarts), [](const Cit &it) { return 0.2 < correlation(begin(averagePWave), end(averagePWave), it); }); return double(count) / pWaveStarts.size(); }
void UploadManager::addFailedUpload(const UserConnection& source, string filename) { { Lock l(cs); if (!count_if(waitingUsers.begin(), waitingUsers.end(), CompareFirst<User::Ptr, uint32_t>(source.getUser()))) waitingUsers.push_back(WaitingUser(source.getUser(), GET_TICK())); waitingFiles[source.getUser()].insert(filename); //files for which user's asked } fire(UploadManagerListener::WaitingAddFile(), source.getUser(), filename); }
bool JInnerProductParam::SetUniqueParam(const vector<string> param){ string line = ""; bool b_enter_weight = false; bool b_enter_bias = false; int i_left = 0; vector<string> v_temp; for (int i = 0; i < param.size(); i++){ line = param.at(i); if (!b_enter_bias && !b_enter_weight){ matchInt(line, "num_output:", &m_num_output); matchBool(line, "bias_term:", &m_bias_term); matchInt(line, "axis:", &m_axis); } // 进入 weight_filler 参数空间 if (line.find("weight_filler") != string::npos){ b_enter_weight = true; m_weight_filler = new JFillerParam; i_left += count_if(line.begin(), line.end(), IPisleft); } else if (b_enter_weight){ v_temp.push_back(line); i_left += count_if(line.begin(), line.end(), IPisleft); i_left -= count_if(line.begin(), line.end(), IPisright); if (i_left == 0){ v_temp.pop_back(); m_weight_filler->SetParameter(v_temp); v_temp.clear(); b_enter_weight = false; } } // 进入 bias_filler 参数空间 if (line.find("bias_filler") != string::npos){ b_enter_bias = true; m_bias_filler = new JFillerParam; i_left += count_if(line.begin(), line.end(), IPisleft); } else if (b_enter_bias){ v_temp.push_back(line); i_left += count_if(line.begin(), line.end(), IPisleft); i_left -= count_if(line.begin(), line.end(), IPisright); if (i_left == 0){ v_temp.pop_back(); m_bias_filler->SetParameter(v_temp); v_temp.clear(); b_enter_bias = false; } } } cout << "Done" << endl; return true; }
int main(int argc, char *argv[]) { int n = 100; int k = 100; double *x; struct timeval tv1, tv2; long counter; if (argc > 1) n = atoi(argv[1]); if (argc > 2) k = atoi(argv[2]); x = init(n); gettimeofday(&tv1, NULL); counter = count_if(x, n, k); gettimeofday(&tv2, NULL); printf("if condition: %.6lf (%ld)\n", tv2.tv_sec - tv1.tv_sec + 1.0e-6*(tv2.tv_usec - tv1.tv_usec), counter); gettimeofday(&tv1, NULL); counter = count_cond_expr(x, n, k); gettimeofday(&tv2, NULL); printf("condition expression: %.6lf (%ld)\n", tv2.tv_sec - tv1.tv_sec + 1.0e-6*(tv2.tv_usec - tv1.tv_usec), counter); free(x); x = init_cont(n, counter/k); gettimeofday(&tv1, NULL); counter = count_if(x, n, k); gettimeofday(&tv2, NULL); printf("if condition: %.6lf (%ld)\n", tv2.tv_sec - tv1.tv_sec + 1.0e-6*(tv2.tv_usec - tv1.tv_usec), counter); gettimeofday(&tv1, NULL); counter = count_cond_expr(x, n, k); gettimeofday(&tv2, NULL); printf("condition expression: %.6lf (%ld)\n", tv2.tv_sec - tv1.tv_sec + 1.0e-6*(tv2.tv_usec - tv1.tv_usec), counter); free(x); return EXIT_SUCCESS; }
unsigned int PollResult::getEventCount(EventClass event_class) const noexcept { auto events(consumer_->getEvents(event_class)); auto count(count_if( events.begin() , events.end() , [=](typename std::remove_reference< decltype(*events.begin()) >::type const &event) { return event.value_.version_ <= transaction_.getVersion(); }) ); return count; }
void DialogTranslation::OnActiveLineChanged(AssDialogue *new_line) { if (switching_lines) return; active_line = new_line; blocks = active_line->ParseTags(); cur_block = 0; line_number = count_if(c->ass->Line.begin(), c->ass->Line.iterator_to(*new_line), cast<AssDialogue*>()) + 1; if (bad_block(blocks[cur_block]) && !NextBlock()) { wxMessageBox(_("No more lines to translate.")); EndModal(1); } }
int algorithms() { vector<Person> people{ { "John", 27 }, { "Chris", 24 }, { "Ann", 31 } }; auto print_all = [&]() { cout << people.size() << " persons:" << endl; for_each(begin(people), end(people), [](const Person& p) { cout << p << endl; }); }; print_all(); // find out who is oldest auto oldest = *max_element(people.begin(), people.end(), [](const Person& a, const Person& b) { return a.name < b.name; }); cout << oldest.name << " is the oldest" << endl; // let's find john auto john = find_if(people.begin(), people.end(), [](const Person& p) { return p.name == string("John"); // change to Jill }); if (john != people.end()) cout << "Found " << john->name << " who is " << john->age << endl; // number of people younger than auto youngerThan30 = count_if(people.begin(), people.end(), [](const Person& p) {return p.age < 30; }); cout << "Found " << youngerThan30 << " people younger than 30." << endl; // sort by age sort(people.begin(), people.end(), [](const Person& a, const Person& b) { return a.age < b.age; }); cout << "People sorted by age:" << endl; print_all(); // replace john with jill Person jill{ "Jill", 44 }; replace_if(people.begin(), people.end(), [](const Person& p) -> bool { return p.name == "John"; }, jill); print_all(); getchar(); return 0; }
bool ClosedCurve::validateCurve(std::vector<cv::Point2i>& curve) { // Make sure that all consecutive points are 8-connected auto eight_connected = [](Point2i a, Point2i b){ return abs(a.x - b.x) <= 1 && abs(a.y - b.y) <= 1; }; if(!eight_connected(curve[0], curve.back())) return false; cout << "Checking for unconnected consecutive pts" << endl; for(size_t i = 1; i < curve.size(); i++) if(!eight_connected(curve[i - 1], curve[i])) { cout << "failure pts: " << curve[i - 1] << "\t" << curve[i] << endl; return false; } // Make sure that points that are not adjacent are never 8-connected vector<Point2i> forbidden_neighbors; forbidden_neighbors.push_back(curve.back()); cout << "Checking for non-adjacent neighbors" << endl; for(size_t i = 1; i < curve.size(); i++) { auto& pt = curve[i]; auto count = count_if(forbidden_neighbors.begin(), forbidden_neighbors.end(), [pt](const Point2i &test_pt) { return Perturbations::isNeighborPoint(pt, test_pt); }); forbidden_neighbors.push_back(curve[i - 1]); if(i > curve.size() - 2) // Should be neighbor with first one added only { if(count > 1) { auto conflict_pt = find_if(forbidden_neighbors.begin(), forbidden_neighbors.end(), [pt](Point2i test_pt){ return nav::Perturbations::isNeighborPoint(pt, test_pt); }); cout << "failure pts: " << curve[1] << "\t" << (conflict_pt != forbidden_neighbors.end()? Point2i(0,0) : *conflict_pt) << endl; return false; } } else { if(count > 0) { auto conflict_pt = find_if(forbidden_neighbors.begin(), forbidden_neighbors.end(), [pt](Point2i test_pt){ return nav::Perturbations::isNeighborPoint(pt, test_pt); }); cout << "failure pts: " << curve[1] << "\t" << (conflict_pt != forbidden_neighbors.end()? Point2i(0,0) : *conflict_pt) << endl; return false; } } } return true; // No failures! }
int main(void){ std::ifstream in; in.open("program.txt"); std::ofstream log; log.open("calculator.log"); std::ofstream err; err.open("debug.log"); Scanner scan{in}; Calculator calc{scan}; std::streambuf *logbuff = std::clog.rdbuf(log.rdbuf()); std::streambuf *errbuff = std::cerr.rdbuf(err.rdbuf()); while(calc.run(std::cout, std::clog)); auto vars = calc.get_table(); auto var_end = remove_if(begin(vars), end(vars), [](Calculator::symbol_t& a){return !a.writen;}); //std::cout << vars << std::endl; std::cout << std::endl << "Variable Statistics: " << std::endl; // print the things in alphabetical order sort(begin(vars), var_end); for_each(begin(vars), var_end, [](Calculator::symbol_t& a){std::cout << a << std::endl;}); std::cout << "Number of variable names > m: " << count_if(begin(vars), var_end, [](Calculator::symbol_t& a){return a.name > "m";}) << std::endl; std::cout << "Minimum element value: " << *min_element(begin(vars), var_end, val_comp) << std::endl; std::cout << "Maximum element value: " << *max_element(begin(vars), var_end, val_comp) << std::endl; std::cout << "Any of the elements have a value > 50? " <<std::boolalpha<< any_of(begin(vars), var_end, [](Calculator::symbol_t& a){return a.val > 50;}) << std::endl; std::cout << "Print the first variable found between i and n: " << *find_if(begin(vars), var_end, [](Calculator::symbol_t& a){return a.name > "i"&&a.name<"n";}) << std::endl; std::cout << "Increase every value of the table by 5: " << std::endl;// (hint transform) for_each(begin(vars), var_end, [](Calculator::symbol_t& a){a.val+=5;}); for_each(begin(vars), var_end, [](Calculator::symbol_t& a){std::cout << a << std::endl;}); std::cout << "Sort the table entries by value (not by variable name): " << std::endl; sort(begin(vars), var_end, val_comp); for_each(begin(vars), var_end, [](Calculator::symbol_t& a){std::cout << a << std::endl;}); std::cout << "Show the partial sum of all values in the table: " << std::endl; std::vector<Calculator::symbol_t> part_sums; partial_sum(begin(vars), var_end, back_inserter(part_sums)); for_each(begin(part_sums), end(part_sums), [](Calculator::symbol_t& a){std::cout << a << std::endl;}); in.close(); log.close(); err.close(); std::clog.rdbuf(logbuff); std::cerr.rdbuf(errbuff); return 0; }
void TestCountIfByBind() { std::string str = "the quick red fox jumps over the slow red turtle"; std::istringstream iss(str); std::string word; std::vector<std::string> words; while (iss >> word) { words.push_back(word); } int sz = 4; int count = count_if(words.begin(), words.end(), bind(CheckSize, std::placeholders::_1, sz)); std::cout << "there are " << count << " " << make_plural(count, "word", "s") << " that the length no longer that " << sz << std::endl; }
void TestStringSizeIs() { std::string file = "..\\Ch14\\data\\count-size"; std::vector<std::string> vec; PushString(file, vec); for (const auto& v : vec) { std::cout << v << " "; } std::cout << std::endl; for (size_t i = 1; i != 10; i++) { StringSizeIs ssi(i); std::cout << "The count of " << i << " size words is: " << count_if(vec.begin(), vec.end(), ssi) << std::endl; } }
double MaxKill::v_cost( vector< Unit > *vecVariables, TargetSelectionDomain *domain ) const { vector<double> hits; vector<UnitEnemy> *enemies = domain->getAllEnemies(); vector<UnitEnemy> copyEnemies(*enemies); for( const auto &v : *vecVariables ) { if( v.getValue() != -1 ) { hits = v.computeDamage( enemies ); for( int i = 0 ; i < copyEnemies.size() ; ++i ) copyEnemies[i].data.hp -= hits[i]; } } return 1. / count_if( begin(copyEnemies), end(copyEnemies), [](UnitEnemy &u){ return u.isDead(); } ); }
Rollable::MultipleResults Rollable::Roll(const std::list<int> &lDCList, const std::list<int> &lExtraModifiers) const { Rollable::MultipleResults mr; mr.RollResult = 1 + rand() % 20 + *iTotal + accumulate(lExtraModifiers.begin(), lExtraModifiers.end(), 0);; if ( mr.RollResult == 20 ) mr.RollResult = mr.RollResult + 10; else if ( mr.RollResult == 1 ) mr.RollResult = mr.RollResult - 10; if ( mr.RollResult < 1 ) mr.RollResult = 1; mr.Successes = count_if(lDCList.begin(), lDCList.end(), bind2nd(less_equal<int>(), mr.RollResult)); mr.Success = mr.Successes > 0; return mr; }
void Parser::checkCommands() { size_t n = this->_cmdtab.size(); if (!isCmd() || (n != 5 && n != 6)) throw Exception("Invalid options"); for (this->it = this->_cmdtab.begin(); it != this->_cmdtab.end(); ++this->it) { this->jt = this->it; ++this->jt; if (it->find("-p") != std::string::npos) { if ((jt == this->_cmdtab.end()) || (n = count_if(this->jt->begin(), this->jt->end(), isdigit)) != this->jt->size()) throw Exception("Invalid port"); this->toInt((*jt)); } this->checkIp(); this->setName(); } this->checkOrder(); }
void generate_find_demo(){ std::vector<int> v{}; srand(time(0)); generate_n(back_inserter(v),100,[]{return rand()%100;}); auto zero_it=find(begin(v),end(v),0); if (zero_it == end(v)){ std::cout << "\nno zero found \n"; } else { std::cout << "\nfound zero at position:" << distance(begin(v),zero_it)<<'\n'; } auto odd=find_if(begin(v),end(v),[](auto x){return x%2;}); if (odd == end(v)){ std::cout << "no odd number found\n"; } else { std::cout << "found odd number:" << *odd << "\nat position:"<<distance(begin(v),odd)<< '\n'; } std::cout << count(begin(v),end(v),42)<<" times 42\n"; std::cout << count_if(begin(v),end(v), [](auto x){return 0==(x%2);})<<" even numbers\n"; }
void write_catalog(string catfile, TMSTCat *MSTCat) { TMSTCat::iterator::difference_type ResultOfCount=count_if((*MSTCat).begin(), (*MSTCat).end(),NisGTThan<CMSTGroup>(MIN_NGRP)); cout<<"We Have TotalNgrp="<<(*MSTCat).size()<<endl; cout<<" But greather than "<<MIN_NGRP<<" = "<<ResultOfCount<<endl; std::ofstream fout(catfile.c_str()); if(ResultOfCount<0) { cout<<"Not groups in the MST analysis"<<endl; return; } if(fout.bad()){cout<<"cannot open file for catalog:\n"<<catfile<<"\n"<<endl;exit(0);}; uint i; for(i=0;i<(*MSTCat).size();i++) fout<<(*MSTCat)[i]; fout.close(); catfile+="_idx"; fout.open(catfile.c_str(), std::ios::binary); if(fout.bad()){cout<<"cannot open file for catalog:\n"<<catfile<<"\n"<<endl;exit(0);}; uint NGrp=ResultOfCount;//(*MSTCat).size(); fout.write((char*)&NGrp,sizeof(NGrp)); cout<<"We will write NGrp="<<NGrp<<" groups to file"<<endl; for(i=0;i<NGrp;i++)//(*MSTCat).size();i++) { fout.write((char*)&(*MSTCat)[i].Ntotal,sizeof(int)); for(int j=0;j<(*MSTCat)[i].Ntotal;j++) fout.write((char*)&(*MSTCat)[i].id[j],sizeof(int)); if(!(i%100))cout<<"iCat="<<i<<" Ntotal="<<(*MSTCat)[i].Ntotal<<"\r"; } fout.close(); }
void process_vocab( vector<textwords, allocator>*pvec ) { if ( !pvec ) // issue warning message return; vector< string, allocator > texts; vector<textwords, allocator>::iterator iter = pvec->begin(); for ( ; iter != pvec->end(); ++iter ) copy( (*iter).begin(), (*iter).end(), back_inserter( texts )); // sort the elements of texts sort( texts.begin(), texts.end() ); for_each( texts.begin(), texts.end(), PrintElem() ); cout << endl << endl; // delete all duplicate elements vector<string, allocator>::iterator it; it = unique( texts.begin(), texts.end() ); texts.erase( it, texts.end() ); for_each( texts.begin(), texts.end(), PrintElem() ); cout << endl << endl; stable_sort( texts.begin(), texts.end(), LessThan() ); for_each( texts.begin(), texts.end(), PrintElem() ); cout << endl << endl; // count number of strings greater than length 6 int cnt = 0; // obsolete form of count -- standard changes this count_if( texts.begin(), texts.end(), GreaterThan(), cnt ); cout << "Number of words greater than length six are " << cnt << endl; // ... static string rw[] = { "and", "if", "or", "but", "the" }; vector<string,allocator> remove_words( rw, rw+5 ); vector<string, allocator>::iterator it2 = remove_words.begin(); for ( ; it2 != remove_words.end(); ++it2 ) { int cnt = 0; // obsolete form of count -- standard changes this count( texts.begin(), texts.end(), *it2, cnt ); cout << cnt << " instances removed: " << (*it2) << endl; texts.erase( remove(texts.begin(),texts.end(),*it2), texts.end() ); } cout << endl << endl; for_each( texts.begin(), texts.end(), PrintElem() ); }
/* Convolution filter matrix example formats: {0, 1,2} { {0,1,2}, {1,2,1}, {0, 1, 0}} */ void extractConvolveFilterMatrix(topologyConfigSpec_t ¶ms, std::istringstream &ss) { char c; enum state_t { INIT, LEFTBRACE, RIGHTBRACE, COMMA, NUM }; enum action_t { SKIP, ILL, PLINC, PLDECX, STONYINC, STONXINC, ACCUM }; state_t lastState = INIT; state_t newState = INIT; int braceLevel = 0; vector<float> row; vector<vector<float>> mat; float num = 0.0; action_t table[5][5] = { /* INIT LEFTBRACE RIGHTBRACE COMMA NUM */ /* INIT */ { ILL, PLINC, ILL, ILL, ILL }, /* LEFTBRACE */ { ILL, PLINC, ILL, ILL, ACCUM }, /* RIGHTBRACE */ { ILL, ILL, PLDECX, SKIP, ILL }, /* COMMA */ { ILL, PLINC, ILL, ILL, ACCUM }, /* DIGIT */ { ILL, ILL, STONYINC, STONXINC, ACCUM }, }; bool done = false; while (!done && ss) { ss >> c; if (isspace(c)) { continue; } else if (c == '{') { newState = LEFTBRACE; } else if (c == '}') { newState = RIGHTBRACE; } else if (c == ',') { newState = COMMA; } else if (c == '-' || c == '+' || c == '.' || isdigit(c)) { newState = NUM; } else { configErrorThrow(params, "Warning: Internal error in parsing convolve filter matrix spec"); } action_t action = table[lastState][newState]; switch(action) { case SKIP: break; case ILL: configErrorThrow(params, "Syntax error in convolve filter matrix spec"); break; case PLINC: ++braceLevel; break; case PLDECX: --braceLevel; if (braceLevel != 0) { configErrorThrow(params, "Syntax error in convolve filter matrix spec"); } done = true; break; case STONYINC: row.push_back(num); // Add the element to the row mat.push_back(row); // Add the row to the matrix row.clear(); num = 0.0; // Start a new number after this if (--braceLevel == 0) { done = true; } break; case STONXINC: row.push_back(num); // Add the element to the row num = 0.0; // Start a new number after this break; case ACCUM: // We've got the first char of the number in c, which can be -, +, ., or a digit. // Now gather the rest of the numeric string: string numstr; numstr.clear(); numstr.push_back(c); while (ss.peek() == '.' || isdigit(ss.peek())) { char cc; ss >> cc; numstr.push_back(cc); } num = strtod(numstr.c_str(), NULL); break; } lastState = newState; } // Check that all rows have the same size: unsigned firstRowSize = mat[0].size(); if (0 != count_if(mat.begin() + 1, mat.end(), [firstRowSize](vector<float> row) { return row.size() != firstRowSize; })) { configErrorThrow(params, "Error in topology config file: inconsistent row size in convolve filter matrix spec"); } // We'll create (or recreate) a one-element flatConvolveMatrix in the params structure: // Convolution filtering only needs a single convolve matrix, so only element zero is // used in params.flatConvolveMatrix. That one element will be a flattened // container of the 2D convolve matrix: params.flatConvolveMatrix.clear(); params.flatConvolveMatrix.push_back(vector<float>()); // Start with one empty container for one kernel params.flatConvolveMatrix.back().assign(mat.size() * mat[0].size(), 0); // for (auto &row : mat) { // for (auto val : row) { for (uint32_t row = 0; row < mat.size(); ++row) { for (uint32_t col = 0; col < mat[row].size(); ++col) { params.flatConvolveMatrix.back()[flattenXY(col, row, mat.size())] = mat[row][col]; } } // The matrix is arranged so that we can access elements as [x][y]: params.kernelSize.x = mat.size(); params.kernelSize.y = mat[0].size(); }
bool VaapiDecoderH265::DPB::checkReorderPics(const H265SPS* const sps) { uint32_t num = count_if(m_pictures.begin(), m_pictures.end(), isOutputNeeded); return num > sps->max_num_reorder_pics[sps->max_sub_layers_minus1]; }
/** Количество действительных предложений по кампании campaign */ int count_valid_offers_by_campaign(const std::string &campaign_id) { list<Offer> offers = Offers::x()->offers_by_campaign(Campaign(campaign_id)); return count_if(offers.begin(), offers.end(), is_valid_offer); }
bool checkWord(std::string const &w){ return (w.empty() ||count_if(w.begin(),w.end(),[](char c){return !isalpha(c);})); }
/** * Given our grid / net, create a list of matching configurations */ vector<MatchConfig> FAsTMatch::createListOfConfigs( MatchNet& net, Size templ_size, Size image_size ) { /* Creating the steps for all the parameters (i.e. translation, rotation, and scaling) */ vector<float> tx_steps = net.getXTranslationSteps(), ty_steps = net.getYTranslationSteps(), r_steps = net.getRotationSteps(), s_steps = net.getScaleSteps(); /* Getting the proper number of steps for each configuration parameters */ int ntx_steps = static_cast<int>( tx_steps.size() ), nty_steps = static_cast<int>( ty_steps.size() ), ns_steps = static_cast<int>( s_steps.size() ), nr_steps = static_cast<int>( r_steps.size() ), nr2_steps = nr_steps; /* Refine the number of steps for the 2nd rotation parameter */ if( fabs((net.boundsRotate.second - net.boundsRotate.first) - (2 * M_PI)) < 0.1 ) { nr2_steps = (int) count_if( r_steps.begin(), r_steps.end(), [&]( float r ){ return r < (-M_PI / 2 + net.stepsRotate / 2); }); } int grid_size = ntx_steps * nty_steps * ns_steps * ns_steps * nr_steps * nr2_steps; vector<MatchConfig> configs( grid_size ); /* Iterate thru each possible affine configuration steps */ tbb::parallel_for( 0, ntx_steps, 1, [&](int tx_index) { float tx = tx_steps[tx_index]; for(int ty_index = 0; ty_index < nty_steps; ty_index++ ) { float ty = ty_steps[ty_index]; for( int r1_index = 0; r1_index < nr_steps; r1_index++ ) { float r1 = r_steps[r1_index]; for( int r2_index = 0; r2_index < nr2_steps; r2_index++ ) { float r2 = r_steps[r2_index]; for( int sx_index = 0; sx_index < ns_steps; sx_index++ ) { float sx = s_steps[sx_index]; for( int sy_index = 0; sy_index < ns_steps; sy_index++ ) { float sy = s_steps[sy_index]; /* Maybe there's a better way for indexing when multithreading ... */ int grid_index = (tx_index * nty_steps * nr_steps * nr2_steps * ns_steps * ns_steps) + (ty_index * nr_steps * nr2_steps * ns_steps * ns_steps) + (r1_index * nr2_steps * ns_steps * ns_steps) + (r2_index * ns_steps * ns_steps) + (sx_index * ns_steps) + sy_index; configs[grid_index].init( tx, ty, r2, sx, sy, r1 ); } } } } } }); return configs; }