void testComplex() { // Randomize test length uint testSize = 5 + (cOSRand::rand() % 2048); uint numberOfLocation = cOSRand::rand() % testSize; cSetArray simple(testSize); cArray<uint> locations(numberOfLocation); uint i; // Set locations for (i = 0; i < numberOfLocation; i++) { locations[i] = cOSRand::rand() % testSize; simple.set(locations[i]); } // Test locations for (i = 0; i < testSize; i++) { bool shouldSet = false; for (uint j = 0; j < numberOfLocation; j++) { if (locations[j] == i) { shouldSet = true; break; } } TESTS_ASSERT_EQUAL(simple.isSet(i), shouldSet); } }
std::vector<GLint> Program::getUniformLocations(const std::vector<std::string> & names) const { std::vector<GLint> locations(names.size()); for (unsigned i = 0; i<names.size(); ++i) { locations[i] = getUniformLocation(names[i]); } return locations; }
Gura_ImplementMethod(wx_RichTextHTMLHandler, SetTemporaryImageLocations) { Signal &sig = env.GetSignal(); Object_wx_RichTextHTMLHandler *pThis = Object_wx_RichTextHTMLHandler::GetObjectThis(arg); if (pThis->IsInvalid(sig)) return Value::Nil; std::unique_ptr<wxArrayString> locations(CreateArrayString(arg.GetList(0))); pThis->GetEntity()->SetTemporaryImageLocations(*locations); return Value::Nil; }
bool MemoryWatcher::LoadAddresses(const std::string& path) { std::ifstream locations(path); if (!locations) return false; std::string line; while (std::getline(locations, line)) ParseLine(line); return m_values.size() > 0; }
void SvnInternalRevertJob::run() { initBeforeRun(); svn::Client cli(m_ctxt); std::vector<svn::Path> targets; KUrl::List l = locations(); foreach( const KUrl &url, l ) { QByteArray ba = url.toLocalFile( KUrl::RemoveTrailingSlash ).toUtf8(); targets.push_back( svn::Path( ba.data() ) ); }
void SvnInternalUpdateJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread* /*thread*/) { initBeforeRun(); svn::Client cli(m_ctxt); std::vector<svn::Path> targets; QList<QUrl> l = locations(); foreach( const QUrl &url, l ) { QByteArray ba = url.toString( QUrl::PreferLocalFile | QUrl::StripTrailingSlash ).toUtf8(); targets.push_back( svn::Path( ba.data() ) ); }
void LiveSLAMWrapper::pubCameraLink() { cv::Mat linkListMap(500, 500, CV_8UC3 ) ; linkListMap.setTo( cv::Vec3b(200,200,200)); cv::Vector<cv::Point2f> locations(slidingWindowSize) ; double angle_K = 2.0*PI/slidingWindowSize ; double r = 200.0 ; for ( int i = 0 ; i < slidingWindowSize ; i++ ) { locations[i].x = sin(angle_K*i)*r + 250.0 ; locations[i].y = cos(angle_K*i)*r + 250.0 ; if ( monoOdometry->slidingWindow[i] == nullptr ){ continue ; } if ( monoOdometry->slidingWindow[i]->keyFrameFlag ){ cv::circle(linkListMap, locations[i], 6, cv::Scalar(255, 0, 0), 5); } else{ cv::circle(linkListMap, locations[i], 6, cv::Scalar(0, 0, 255), 5); } if ( i == monoOdometry->head ){ cv::circle(linkListMap, locations[i], 6, cv::Scalar(0, 255, 0), 5); } cv::putText(linkListMap, boost::to_string(i), locations[i], cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(255), 1); } int cnt = 0 ; for( int i = 0 ; i < monoOdometry->numOfState ; i++ ) { int idx = monoOdometry->head + i ; if ( idx >= slidingWindowSize ){ idx -= slidingWindowSize ; } if ( monoOdometry->slidingWindow[i] == nullptr ){ continue ; } if ( monoOdometry->slidingWindow[idx]->keyFrameFlag == false){ continue; } list<int>::iterator iter = monoOdometry->slidingWindow[idx]->cameraLinkList.begin(); for (; iter != monoOdometry->slidingWindow[idx]->cameraLinkList.end(); iter++ ) { int linkID = *iter; cv::line(linkListMap, locations[idx], locations[linkID], cv::Scalar(0, 255, 255), 3); cnt++ ; } } cv::imshow("linkListMap", linkListMap ) ; cv::waitKey(1) ; }
void CF<FactorizerType>::CleanData(const arma::mat& data) { // Generate list of locations for batch insert constructor for sparse // matrices. arma::umat locations(2, data.n_cols); arma::vec values(data.n_cols); for (size_t i = 0; i < data.n_cols; ++i) { // We have to transpose it because items are rows, and users are columns. locations(1, i) = ((arma::uword) data(0, i)); locations(0, i) = ((arma::uword) data(1, i)); values(i) = data(2, i); if (values(i) == 0) Log::Warn << "User rating of 0 ignored for user " << locations(1, i) << ", item " << locations(0, i) << "." << std::endl; } // Find maximum user and item IDs. const size_t maxItemID = (size_t) max(locations.row(0)) + 1; const size_t maxUserID = (size_t) max(locations.row(1)) + 1; // Fill sparse matrix. cleanedData = arma::sp_mat(locations, values, maxItemID, maxUserID); }
std::vector<int> getPath(const Locations& input) { if(input.empty()) return {}; Locations locations(input); std::vector<int> results; Locations::iterator current = locations.begin(); do { Position curPos = current->second; results.push_back(current->first); locations.erase(current); current = findClosest(curPos, locations); } while(!locations.empty()); return results; }
void FdmAutocallStepCondition::applyTo(Array& a, Time t) const { if (std::find(exerciseTimes_.begin(), exerciseTimes_.end(), t) != exerciseTimes_.end()) { boost::shared_ptr<FdmLinearOpLayout> layout = mesher_->layout(); const FdmLinearOpIterator endIter = layout->end(); const Size dims = layout->dim().size(); Array locations(dims); for (FdmLinearOpIterator iter = layout->begin(); iter != endIter; ++iter) { for (Size i = 0; i < dims; ++i) locations[i] = std::exp(mesher_->location(iter, i)); if ((*condition_)(locations)) { Real innerValue = calculator_->innerValue(iter, t); a[iter.index()] = innerValue; } } } }
QVector<QPoint> OpenCVAlgorithms::multipleMinMaxLoc(const cv::Mat &image, int maximumMatches, AlgorithmMethod method) { QVector<QPoint> locations(maximumMatches); QVector<float> matches(maximumMatches, (method == SquaredDifferenceMethod) ? std::numeric_limits<float>::max() : -std::numeric_limits<float>::max()); cv::Size size = image.size(); // extract the raw data for analysis for(int y = 0; y < size.height; ++y) { for(int x = 0; x < size.width; ++x) { float data = image.at<float>(y, x); // insert the data value into the array if it is greater than any of the // other array values, and bump the other values below it, down for(int j = 0; j < maximumMatches; ++j) { // require at least 50% confidence on the sub-sampled image // in order to make this as fast as possible if((method == SquaredDifferenceMethod && data < 0.5f && data < matches.at(j)) || (method != SquaredDifferenceMethod && data > 0.5f && data > matches.at(j))) { // move the maxima down for(int k = maximumMatches - 1; k > j; --k) { matches[k] = matches.at(k-1); locations[k] = locations.at(k-1); } // insert the value matches[j] = data; locations[j].setX(x); locations[j].setY(y); break; } } } } return locations; }
void SvnInternalAddJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread* /*thread*/) { initBeforeRun(); svn::Client cli(m_ctxt); QList<QUrl> l = locations(); foreach( const QUrl &url, l ) { try { QByteArray ba = url.toString( QUrl::PreferLocalFile | QUrl::StripTrailingSlash ).toUtf8(); cli.add( svn::Path( ba.data() ), recursive() ); }catch( svn::ClientException ce ) { qCDebug(PLUGIN_SVN) << "Exception while adding file: " << url << QString::fromUtf8( ce.message() ); setErrorMessage( QString::fromUtf8( ce.message() ) ); m_success = false; } } }
void CART::fit(Problem const &prob, std::vector<float> const &R, std::vector<float> &F1) { uint32_t const nr_field = prob.nr_field; uint32_t const nr_sparse_field = prob.nr_sparse_field; uint32_t const nr_instance = prob.nr_instance; std::vector<Location> locations(nr_instance); #pragma omp parallel for schedule(static) for(uint32_t i = 0; i < nr_instance; ++i) locations[i].r = R[i]; for(uint32_t d = 0, offset = 1; d < max_depth; ++d, offset *= 2) { uint32_t const nr_leaf = static_cast<uint32_t>(pow(2, d)); std::vector<Meta> metas0(nr_leaf); for(uint32_t i = 0; i < nr_instance; ++i) { Location &location = locations[i]; if(location.shrinked) continue; Meta &meta = metas0[location.tnode_idx-offset]; meta.s += location.r; ++meta.n; } std::vector<Defender> defenders(nr_leaf*nr_field); std::vector<Defender> defenders_sparse(nr_leaf*nr_sparse_field); for(uint32_t f = 0; f < nr_leaf; ++f) { Meta const &meta = metas0[f]; double const ese = meta.s*meta.s/static_cast<double>(meta.n); for(uint32_t j = 0; j < nr_field; ++j) defenders[f*nr_field+j].ese = ese; for(uint32_t j = 0; j < nr_sparse_field; ++j) defenders_sparse[f*nr_sparse_field+j].ese = ese; } std::vector<Defender> defenders_inv = defenders; std::thread thread_f(scan, std::ref(prob), std::ref(locations), std::ref(metas0), std::ref(defenders), offset, true); std::thread thread_b(scan, std::ref(prob), std::ref(locations), std::ref(metas0), std::ref(defenders_inv), offset, false); scan_sparse(prob, locations, metas0, defenders_sparse, offset, true); thread_f.join(); thread_b.join(); for(uint32_t f = 0; f < nr_leaf; ++f) { Meta const &meta = metas0[f]; double best_ese = meta.s*meta.s/static_cast<double>(meta.n); TreeNode &tnode = tnodes[f+offset]; for(uint32_t j = 0; j < nr_field; ++j) { Defender defender = defenders[f*nr_field+j]; if(defender.ese > best_ese) { best_ese = defender.ese; tnode.feature = j; tnode.threshold = defender.threshold; } defender = defenders_inv[f*nr_field+j]; if(defender.ese > best_ese) { best_ese = defender.ese; tnode.feature = j; tnode.threshold = defender.threshold; } } for(uint32_t j = 0; j < nr_sparse_field; ++j) { Defender defender = defenders_sparse[f*nr_sparse_field+j]; if(defender.ese > best_ese) { best_ese = defender.ese; tnode.feature = nr_field + j; tnode.threshold = defender.threshold; } } } #pragma omp parallel for schedule(static) for(uint32_t i = 0; i < nr_instance; ++i) { Location &location = locations[i]; if(location.shrinked) continue; uint32_t &tnode_idx = location.tnode_idx; TreeNode &tnode = tnodes[tnode_idx]; if(tnode.feature == -1) { location.shrinked = true; } else if(static_cast<uint32_t>(tnode.feature) < nr_field) { if(prob.Z[tnode.feature][i].v < tnode.threshold) tnode_idx = 2*tnode_idx; else tnode_idx = 2*tnode_idx+1; } else { uint32_t const target_feature = static_cast<uint32_t>(tnode.feature-nr_field); bool is_one = false; for(uint64_t p = prob.SJP[i]; p < prob.SJP[i+1]; ++p) { if(prob.SJ[p] == target_feature) { is_one = true; break; } } if(!is_one) tnode_idx = 2*tnode_idx; else tnode_idx = 2*tnode_idx+1; } } } std::vector<std::pair<double, double>> tmp(max_tnodes, std::make_pair(0, 0)); for(uint32_t i = 0; i < nr_instance; ++i) { float const r = locations[i].r; uint32_t const tnode_idx = locations[i].tnode_idx; tmp[tnode_idx].first += r; tmp[tnode_idx].second += fabs(r)*(1-fabs(r)); } for(uint32_t tnode_idx = 1; tnode_idx <= max_tnodes; ++tnode_idx) { double a, b; std::tie(a, b) = tmp[tnode_idx]; tnodes[tnode_idx].gamma = (b <= 1e-12)? 0 : static_cast<float>(a/b); } #pragma omp parallel for schedule(static) for(uint32_t i = 0; i < nr_instance; ++i) F1[i] = tnodes[locations[i].tnode_idx].gamma; }
main ( int argc, char *argv[] ) { int L, m2, myrank, pcounter,hin, h5, h6, h7, h16, h8, J1, liftL, mrs, tag = 1234, j4r[size],count, h1, h3, h4, numprocs, n = 0, i, j, cj, m, k = 1; double a1, a2, cf, sf, rf, ak, h2[10]; MPI_Status status; double angnum, ang, mult, C[size], S[size], temp[size], temprs[size], v[size], S2[size], Rnew[size], Snew[size], bm, cm, p1[size], S4[size], R4[size], R2[size], temp2rs[size], p2[size], mytime, pair1[size], pair2[size], R[size], xtemp[size], Rold[size], temp2[size], Sold[size], temp3[size], temp4[size]; double x[size], x1[size], c, s, r, s1, r1, p1a[size], p2a[size], p[size], xtemp1[size],fx1[size],fp[size]; MPI_Init ( &argc, &argv ); mytime = MPI_Wtime (); MPI_Comm_rank ( MPI_COMM_WORLD, &myrank ); MPI_Comm_size ( MPI_COMM_WORLD, &numprocs ); if ( myrank == 0 ) { //procs 0 starts in here //Input values do { //taking 8 values in x array x[n] = n + 1; n++; } while ( n < size ); //Build cosine, sine, R table for ( j = 1; j <= ( n / 4 ); j++ ) { angnum = 4 * ( j - 1 ) + 1; mult = PI / ( n * 4 ); ang = angnum * mult; C[j] = cos ( ang ); S[j] = sin ( ang ); R[j] = ( C[j] - 1 ) / S[j]; //printf("s value is %lf,R %lf\n", S[j],R[j]); } for ( j = 1; j <= ( n / 4 ); j++ ) { cj = 2 * ( j - 1 ); m = n - 1; //Tournament sort //0,7,4,3 in the first iteration and 2 5 6 1 in the second iteration pair1[0] = x[cj]; pair1[1] = x[ ( m - cj ) ]; pair2[0] = x[ ( cj + ( n / 2 ) ) ]; //xtemp(3:4) pair2[1] = x[ ( m - ( cj + ( n / 2 ) ) ) ]; lift ( pair1, S[j], R[j] ); v[0] = pout[0]; v[1] = pout[1]; sumdiff ( pair2, b / 2 ); pair2[0] = temp1[0] * SQH; pair2[1] = ( -1 * temp1[1] ) * SQH; lift ( pair2, S[j], R[j] ); v[2] = pout[0]; v[3] = pout[1]; sumdiff ( v, b ); p1[ ( 2 * j ) - 2] = temp1[0]; p1[ ( 2 * j ) - 1] = temp1[1]; p2[ ( 2 * j ) - 2] = temp1[2]; p2[ ( 2 * j ) - 1] = temp1[3]; } //p1 and p2 are now two sets of points, one for each processor m = size / 2; J1 = 3; mrs = 4; //Computes the next set of angles ///TODO: Move to lookup table for ( i = 0; i < mrs; i++ ) { double tempR = 1 + ( R[i + 1] * S[i + 1] ); double s = 2 * S[i + 1] * tempR; tempR = ( -1 * S[i + 1] ) / tempR; tempR = 1 + ( tempR * s ); S[i] = 2 * s * tempR; R[i] = ( -1 * s ) / tempR; } //This only executes twice pcounter = 1; //Loop one is first processor, two is the other while ( pcounter <= 2 ) { if ( pcounter == 1 ) { //Copy in first set of points for ( i = 0; i < n / 2; i++ ) { p[i] = p1[i]; } } else { m = size / 2; //do magic on second set of points lift90sr ( p2, S4, R4, m ); //Copy return values into first half of p[] for ( i = 0; i < n / 2; i++ ) { p[i] = poutb[i]; } } //Each processor rejoins here. liftL = 4; for ( i = 0; i < liftL; i++ ) { Rold[i] = R[i]; Sold[i] = S[i]; } //Also only executed twice for ( j = 1; j <= 2; j++ ) { //1 2 3 //4 5 6 on second loop m2 = pow ( 2, ( j - 1 ) ); L = 16 / m2; ///TODO: Use lookup table instead for ( i = 0; i < liftL; i++ ) { Rold[i] = -1 / (1 + Rold[i]); Sold[i] = 2 * Sold[i] * (Sold[i] * Rold[i] + 1); //Double angle } //Splittin up the work happens in here for ( k = 1; k <= m2; k++ ) { h1 = L * ( k - 1 ); h3 = ( L * k ) - 1; h6 = L * ( k - 1 ); h16 = 0; for ( h1; h1 <= h3; h1++ ) { temp[h1] = p[h1]; h16++; } sumdiff2 ( temp, h6, h3 + 1 ); for ( i = 0; i < h16; i++ ) { temp2[i] = sum2[i]; } h4 = L / 2; for ( i = 0, h4; h4 < L; h4++, i++ ) { temp3[i] = temp2[h4]; //8-1a5 } lift90sr ( temp3, Sold, Rold, i + 1 ); for ( i = 0, h5 = L / 2; h5 < L; i++, h5++ ) { temp2[h5] = poutb[i]; } h7 = L * ( k - 1 ); h8 = ( L * k ) - 1; for ( h7, i = 0; h7 <= h8; i++, h7++ ) { p[h7] = temp2[i]; } } //kloop ends here liftL = liftL / 2; } //end of for loop.... // printf ("\n****************\n"); // for (i = 0; i < 16; i++) // printf ("hi %lf\n", p[i]); j = J1; m2 = m / 4; L = 4; for ( k = 1; k <= m2; k++ ) { h1 = L * ( k - 1 ); h3 = ( L * k ) - 1; h6 = L * ( k - 1 ); h16 = 0; for ( h1; h1 <= h3; h1++ ) { temp[h1] = p[h1]; h16++; // printf("temp is here%lf\n",temp[h1]); } sumdiff2 ( temp, h6, h3 + 1 ); for ( i = 0; i < h16; i++ ) { temp2[i] = sum2[i]; //printf("Temp2 is here %lf\n",temp2[i]); } h4 = L / 2; for ( i = 0, h4; h4 < L; h4++, i++ ) { temp3[i] = temp2[h4]; //8-1a5 } sumdiff2 ( temp3,0,i ); for ( i = 0, h5 = L / 2; h5 < L; i++, h5++ ) { temp2[h5] = sum2[i]*SQH; // printf("sumdiff result is %lf\n",temp2[h5]); } h7 = L * ( k - 1 ); h8 = ( L * k ) - 1; for ( h7, i = 0; h7 <= h8; i++, h7++ ) { p[h7] = temp2[i]; } // printf("\n*****************\n"); locations ( n,pcounter ); j4r[k-1] = loc1[k]; //Final result vector fx1[ j4r[k-1] ] = temp2[0]; fx1[ ( n-1 )-j4r[k-1] ] = temp2[1]; fx1[ ( n/2 )-1-j4r[k-1] ] = temp2[2]; fx1[ j4r[k-1]+ ( n/2 ) ] = temp2[3]; }//k ends here pcounter++; //have to end after the program } mytime = MPI_Wtime () - mytime; for ( i=0;i<32;i++ ) printf ( "fx is %lf\n",fx1[i] ); mytime = mytime * 1000000; printf ( "Timing from rank %d is %lfus.\n", myrank, mytime ); } //end of rank 0 MPI_Finalize (); return 0; }
int main(int argc, char* argv[]) { #ifdef DEBUG auto start = get_time::now(); #endif Map mapData; if(argc != 6) { std::cout << "Modo de uso: " << std::endl << argv[0] << " [archivo ubicaciones data 3D]" << " [archivo ubicaciones a consultar 3D]" << " [ventana de busqueda en X Y Z]" << std::endl; return 0; } arma::mat data; arma::mat locations; arma::vec search_window; data.load(argv[1], arma::raw_ascii); locations.load(argv[2], arma::raw_ascii); search_window << std::stod(argv[3]) << std::stod(argv[4]) << std::stod(argv[5]); double minDataX = data.col(0).min(); double minDataY = data.col(1).min(); double minDataZ = data.col(2).min(); double maxDataX = data.col(0).max(); double maxDataY = data.col(1).max(); double maxDataZ = data.col(2).max(); for(int i = 0; i < data.n_rows; i++) { Triple dataLocation( ceil((abs(data(i,0) - minDataX)) / search_window(0)), ceil((abs(data(i,1) - minDataY)) / search_window(1)), ceil((abs(data(i,2) - minDataZ)) / search_window(2)) ); mapData.insert({dataLocation,i}); } for(int i = locations.n_rows-1; i >= 0 ; i--) { Triple location( ceil((abs(locations(i,0) - minDataX)) / search_window(0)), ceil((abs(locations(i,1) - minDataY)) / search_window(1)), ceil((abs(locations(i,2) - minDataZ)) / search_window(2)) ); std::pair <Map::const_iterator, Map::const_iterator> ret; ret = mapData.equal_range(location); if(ret.first==ret.second) continue; for (Map::const_iterator itRet=ret.first; itRet!=ret.second; ++itRet) if( abs(locations(i,0) - data(itRet->second,0)) <= search_window(0) && abs(locations(i,1) - data(itRet->second,1)) <= search_window(1) && abs(locations(i,2) - data(itRet->second,2)) <= search_window(2) ) { /* aca esta la data del mismo bloque donde esta la ubicacion data(itRet->second,0) data(itRet->second,1) data(itRet->second,2) */ } for(int z = -1; z <= 1; z++) for(int y = -1; y <= 1; y++) for(int x = -1; x <= 1; x++) { Triple currentLocation( std::get<0>(location)+x, std::get<1>(location)+y, std::get<2>(location)+z ); std::pair <Map::const_iterator, Map::const_iterator> retNeighbors; retNeighbors = mapData.equal_range(currentLocation); if(retNeighbors.first==retNeighbors.second) continue; for (Map::const_iterator itRet=retNeighbors.first; itRet!=retNeighbors.second; ++itRet) if( abs(locations(i,0) - data(itRet->second,0)) <= search_window(0) && abs(locations(i,1) - data(itRet->second,1)) <= search_window(1) && abs(locations(i,2) - data(itRet->second,2)) <= search_window(2) ) { /* aca estan los datos correspondientes de los bloque colindantes a donde esta la ubicacion data(itRet->second,0) data(itRet->second,1) data(itRet->second,2) */ } } } #ifdef DEBUG std::cout << "tama~no data: " << data.n_rows << "x" << data.n_cols << std::endl; std::cout << "tama~no ubicaciones: " << locations.n_rows << "x" << locations.n_cols << std::endl; std::cout << "tama~no de ventana de busqueda en XYZ respectivamente: " << search_window; std::cout << "data min x: " << minDataX << " y: " << minDataY << " z: " << minDataZ << std::endl; std::cout << "data max x: " << maxDataX << " y: " << maxDataY << " z: " << maxDataZ << std::endl; std::cout << ceil((maxDataX - minDataX) / search_window(0)) << " bloques en eje X" << std::endl; std::cout << ceil((maxDataY - minDataY) / search_window(1)) << " bloques en eje Y" << std::endl; std::cout << ceil((maxDataZ - minDataZ) / search_window(2)) << " bloques en eje Z" << std::endl; auto end = get_time::now(); auto diff = end - start; std::cout<<"Elapsed time is : "<< std::chrono::duration_cast<ms>(diff).count()<<" ms "<<std::endl; #endif return 0; }
double get_distance(const vector<vector<int> > &screen, pair<int, int> start_loc, pair<int, int> goal) { set<pair<int, int> > visited_closed; set<pair<int, int> > visited_opened; visited_opened.insert(start_loc); map<pair<int, int>, pair<int, int> > predecessor; map<pair<int, int>, int> g_score; g_score[start_loc] = 0; map<pair<int, int>, int> f_score; f_score[start_loc] = manhattan_distance(start_loc, goal); heuristic_comparison cmp(f_score); location_queue locations(cmp); locations.push(start_loc); int nodes_visited = 0; bool goal_reached = false; while (!locations.empty()) { nodes_visited += 1; pair<int, int> current_loc = locations.top(); if (current_loc == goal) { goal_reached = true; break; } visited_opened.erase(visited_opened.find(current_loc)); locations.pop(); visited_closed.insert(current_loc); vector<pair<int, int> > neighbors = get_adjacent_locations(current_loc); for (int i = 0; i < neighbors.size(); ++i) { if (screen[neighbors[i].first][neighbors[i].second] == 0 && (screen[neighbors[i].first - 1][neighbors[i].second] == 0 || screen[neighbors[i].first + 1][neighbors[i].second] == 0)) continue; if (visited_closed.find(neighbors[i]) != visited_closed.end()) continue; double estimated_g_score = g_score[current_loc] + 1; bool neighbor_pushed = false; if (visited_opened.find(neighbors[i]) == visited_opened.end()) { visited_opened.insert(neighbors[i]); neighbor_pushed = true; } else if (estimated_g_score > g_score[neighbors[i]]) continue; predecessor[neighbors[i]] = current_loc; g_score[neighbors[i]] = estimated_g_score; f_score[neighbors[i]] = g_score[neighbors[i]] + manhattan_distance(neighbors[i], goal); if (neighbor_pushed) locations.push(neighbors[i]); } } pair<int, int> current_loc = goal; if (!goal_reached) return numeric_limits<double>::max(); double distance = 0; while (current_loc != start_loc) { current_loc = predecessor[current_loc]; distance += 1; } return distance; }
string getDBStructure() { return "----------------------------------------------------------------------\n\ --\n\ -- MOPSLinux package system\n\ -- Database creation script\n\ -- $Id: dbstruct.cpp,v 1.3 2007/11/02 20:19:45 i27249 Exp $\n\ --\n\ ----------------------------------------------------------------------\n\ \n\ create table packages (\n\ package_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,\n\ package_name TEXT NOT NULL,\n\ package_version TEXT NOT NULL,\n\ package_arch TEXT NOT NULL,\n\ package_build TEXT NULL,\n\ package_compressed_size TEXT NOT NULL,\n\ package_installed_size TEXT NOT NULL,\n\ package_short_description TEXT NULL,\n\ package_description TEXT NULL, \n\ package_changelog TEXT NULL,\n\ package_packager TEXT NULL,\n\ package_packager_email TEXT NULL,\n\ package_installed INTEGER NOT NULL,\n\ package_configexist INTEGER NOT NULL,\n\ package_action INTEGER NOT NULL,\n\ package_md5 TEXT NOT NULL,\n\ package_filename TEXT NOT NULL,\n\ package_betarelease TEXT NOT NULL,\n\ package_installed_by_dependency INTEGER NOT NULL DEFAULT '0',\n\ package_type INTEGER NOT NULL DEFAULT '0'\n\ );\n\ create index ppname on packages (package_id, package_name, package_version, package_action, package_installed, package_md5);\n\ \n\ create table files (\n\ file_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,\n\ file_name TEXT NOT NULL,\n\ file_type INTEGER NOT NULL,\n\ packages_package_id INTEGER NOT NULL\n\ );\n\ create index pname on files (file_name, packages_package_id);\n\ \n\ create table conflicts (\n\ conflict_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,\n\ conflict_file_name TEXT NOT NULL,\n\ backup_file TEXT NOT NULL,\n\ conflicted_package_id INTEGER NOT NULL\n\ );\n\ \n\ create table locations (\n\ location_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,\n\ packages_package_id INTEGER NOT NULL,\n\ server_url TEXT NOT NULL,\n\ location_path TEXT NOT NULL\n\ );\n\ create index locpid on locations(packages_package_id, location_path, server_url);\n\ create table tags (\n\ tags_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,\n\ tags_name TEXT NOT NULL\n\ );\n\ create index ptag on tags (tags_id, tags_name);\n\ \n\ create table tags_links (\n\ tags_link_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,\n\ packages_package_id INTEGER NOT NULL,\n\ tags_tag_id INTEGER NOT NULL\n\ );\n\ create index ptaglink on tags_links (packages_package_id, tags_tag_id);\n\ \n\ create table dependencies (\n\ dependency_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,\n\ packages_package_id INTEGER NOT NULL,\n\ dependency_condition INTEGER NOT NULL DEFAULT '1',\n\ dependency_type INTEGER NOT NULL DEFAULT '1',\n\ dependency_package_name TEXT NOT NULL,\n\ dependency_package_version TEXT NULL,\n\ dependency_build_only INTEGER NOT NULL DEFAULT '0' \ );\n\ \n\ create index pdeps on dependencies (packages_package_id, dependency_id, dependency_package_name, dependency_package_version, dependency_condition);\n\ \n\ -- INTERNATIONAL SUPPORT\n\ \n\ --create table descriptions (\n\ -- description_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,\n\ -- packages_package_id INTEGER NOT NULL,\n\ -- description_language TEXT NOT NULL,\n\ -- description_text TEXT NOT NULL,\n\ -- short_description_text TEXT NOT NULL\n\ --);\n\ \n\ --create table changelogs (\n\ -- changelog_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,\n\ -- packages_package_id INTEGER NOT NULL,\n\ -- changelog_language TEXT NOT NULL,\n\ -- changelog_text TEXT NOT NULL\n\ --);\n\ \n\ -- RATING SYSTEM - SUPPORT FOR FUTURE\n\ --create table ratings (\n\ -- rating_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,\n\ -- rating_value INTEGER NOT NULL,\n\ -- packages_package_name TEXT NOT NULL\n\ --);\n\ "; }
array_data * fdm(char* image, double* potentials, double rel_par, int iterations, double desiredconv) { // Use locations() to build initial array with boundaries: array_data * sysdat; sysdat = locations(image, potentials[0], potentials[1], potentials[2], potentials[3]); double conv = 0; int prev_convcount = 0, convcount = 0, count = 0; bool lock = false; int pixels = sysdat->rows * sysdat->columns; int start = 0; cout << "Pixels: " << pixels << endl; double**u = sysdat -> values; double**pu = sysdat -> prev_values; // Loop until either desired convergence or maximum // iterations are achieved: while ( convcount < pixels && count < iterations ) // for (int count = 0; count < iterations; count++) { if (count % 2 == 0) { convcount = 0; } // Loop through x coordinates for (int i = 0; i < sysdat->columns; i++) { if (count % 2 == 0) { start = (i != 0 && i % 2 != 0) ? 1 : 0; } else { start = (i == 0 || i % 2 == 0) ? 1 : 0; } // Loop through y: for (int j = start; j < sysdat->rows; j += 2) { // Test if point is boundary value. If so, ignore: if (sysdat->mask[i][j]) { convcount++; continue; } // Finite Difference Method to calculate potential as // average of surrounding values, checking if point is // on an edge. If so, and it isn't a boundary value, // calculate as average of surrounding points inside box // - two for corners, three for points on edge. If not on // edge, calculate as average of four surrounding points. // Left edge and corners: if (i == 0) { if (j == 0) { u[i][j] = (1-rel_par)*pu[i][j] + rel_par*0.5*(u[i+1][j]+u[i][j+1]); } else if (j == sysdat->rows - 1) { u[i][j] = (1-rel_par)*pu[i][j] + rel_par*0.5*(u[i+1][j]+u[i][j-1]); } else { u[i][j] = (1-rel_par)*pu[i][j] + rel_par*(1/3.0)*(u[i+1][j]+u[i][j+1]+u[i][j-1]); } } // Right edge and corners: else if (i == (sysdat->columns - 1)) { if (j == 0) { u[i][j] = (1-rel_par)*pu[i][j] + rel_par*0.5*(u[i-1][j]+u[i][j+1]); } else if (j == sysdat->rows - 1) { u[i][j] = (1-rel_par)*pu[i][j] + rel_par*0.5*(u[i-1][j]+u[i][j-1]); } else { u[i][j] = (1-rel_par)*pu[i][j] + rel_par*(1/3.0)*(u[i-1][j]+u[i][j+1]+u[i][j-1]); } } // Top edge: else if (j == 0) { u[i][j] = (1-rel_par)*pu[i][j] + rel_par*(1/3.0)*(u[i-1][j]+u[i+1][j]+u[i][j+1]); } // Bottom edge: else if (j == (sysdat->rows - 1)) { u[i][j] = (1-rel_par)*pu[i][j] + rel_par*(1/3.0)*(u[i-1][j]+u[i+1][j]+u[i][j-1]); } // Rest of area: else { u[i][j]=(1-rel_par)*pu[i][j] + rel_par*0.25*(u[i+1][j]+u[i][j+1]+u[i-1][j]+u[i][j-1]); } // Find absolute value of convergence: conv = fabs(pu[i][j] - u[i][j]); //abs() returns int, use fabs() instead (also in cmath) if (conv < desiredconv) { convcount++; if (lock && mintrue(sysdat,i,j,3)) { sysdat->mask[i][j] = true; } } pu[i][j] = u[i][j]; } } count++; if (count % 200 == 0) { cout << "\rIteration: " << count / 2 << ", Convergence count: " << convcount << "." << std::flush; if (convcount > prev_convcount) { lock = true; } } prev_convcount = convcount; } cout << endl; // Pass iterations required to struct: sysdat->req_its = count / 2; // Create 2D arrays for grad: sysdat->xgrad = new double*[sysdat->columns]; sysdat->ygrad = new double*[sysdat->columns]; for (int i = 0; i < (sysdat->columns - 1); i++) { sysdat->xgrad[i] = new double[sysdat->rows]; sysdat->ygrad[i] = new double[sysdat->rows]; for (int j = 0; j < (sysdat->rows - 1); j++) { // Approximation of gradients: if (i != 0 && j != 0 ){ sysdat->xgrad[i][j] = 0.5*(u[i-1][j]-u[i+1][j]); // changed so the minus sign is not needed sysdat->ygrad[i][j] = 0.5*(u[i][j-1]-u[i][j+1]); // changed so the minus sign is not needed } } } return sysdat; }
void time_hog( const std::vector<carp::record_t>& pool, const std::vector<float>& sizes, int num_positions, int repeat ) { carp::Timing timing("HOG"); for (;repeat>0; --repeat) { for ( auto & size : sizes ) { for ( auto & item : pool ) { std::mt19937 rng(0); //uses same seed, reseed for all iteration cv::Mat cpu_gray; cv::cvtColor( item.cpuimg(), cpu_gray, CV_RGB2GRAY ); cv::Mat_<float> locations(num_positions, 2); cv::Mat_<float> blocksizes(num_positions, 2); size_t max_blocksize_x = std::ceil(size); size_t max_blocksize_y = std::ceil(size); //fill locations and blocksizes std::uniform_real_distribution<float> genx(size/2+1, cpu_gray.rows-1-size/2-1); std::uniform_real_distribution<float> geny(size/2+1, cpu_gray.cols-1-size/2-1); for( int i = 0; i < num_positions; ++i) { locations(i, 0) = genx(rng); locations(i, 1) = geny(rng); blocksizes(i, 0) = size; blocksizes(i, 1) = size; } const int HISTOGRAM_BINS = NUMBER_OF_CELLS * NUMBER_OF_CELLS * NUMBER_OF_BINS; std::vector<float> cpu_result(num_positions * HISTOGRAM_BINS), gpu_result(num_positions * HISTOGRAM_BINS), pen_result(num_positions * HISTOGRAM_BINS); std::chrono::duration<double> elapsed_time_cpu, elapsed_time_gpu_p_copy, elapsed_time_gpu_nocopy, elapsed_time_pencil; { //CPU implement static nel::HOGDescriptorCPP descriptor( NUMBER_OF_CELLS , NUMBER_OF_BINS , GAUSSIAN_WEIGHTS , SPARTIAL_WEIGHTS , SIGNED_HOG ); const auto cpu_start = std::chrono::high_resolution_clock::now(); const auto result = descriptor.compute(cpu_gray, locations, blocksizes); const auto cpu_end = std::chrono::high_resolution_clock::now(); std::copy(result.begin(), result.end(), cpu_result.begin()); elapsed_time_cpu = cpu_end - cpu_start; //Free up resources } { //GPU implement static nel::HOGDescriptorOCL descriptor( NUMBER_OF_CELLS , NUMBER_OF_BINS , GAUSSIAN_WEIGHTS , SPARTIAL_WEIGHTS , SIGNED_HOG ); const auto gpu_start = std::chrono::high_resolution_clock::now(); const auto result = descriptor.compute(cpu_gray, locations, blocksizes, max_blocksize_x, max_blocksize_y, elapsed_time_gpu_nocopy); const auto gpu_end = std::chrono::high_resolution_clock::now(); std::copy(result.begin(), result.end(), gpu_result.begin()); elapsed_time_gpu_p_copy = gpu_end - gpu_start; //Free up resources } { pen_result.resize(num_positions * HISTOGRAM_BINS, 0.0f); const auto pencil_start = std::chrono::high_resolution_clock::now(); pencil_hog( NUMBER_OF_CELLS, NUMBER_OF_BINS, GAUSSIAN_WEIGHTS, SPARTIAL_WEIGHTS, SIGNED_HOG , cpu_gray.rows, cpu_gray.cols, cpu_gray.step1(), cpu_gray.ptr<uint8_t>() , num_positions , reinterpret_cast<const float (*)[2]>(locations.data) , reinterpret_cast<const float (*)[2]>(blocksizes.data) , pen_result.data() ); const auto pencil_end = std::chrono::high_resolution_clock::now(); elapsed_time_pencil = pencil_end - pencil_start; //Free up resources } // Verifying the results if ( cv::norm( cpu_result, gpu_result, cv::NORM_INF) > cv::norm( gpu_result, cv::NORM_INF)*1e-5 || cv::norm( cpu_result, pen_result, cv::NORM_INF) > cv::norm( cpu_result, cv::NORM_INF)*1e-5 ) { std::vector<float> diff; std::transform(cpu_result.begin(), cpu_result.end(), gpu_result.begin(), std::back_inserter(diff), std::minus<float>()); std::cerr << "ERROR: Results don't match." << std::endl; std::cerr << "CPU norm:" << cv::norm(cpu_result, cv::NORM_INF) << std::endl; std::cerr << "GPU norm:" << cv::norm(gpu_result, cv::NORM_INF) << std::endl; std::cerr << "PEN norm:" << cv::norm(pen_result, cv::NORM_INF) << std::endl; std::cerr << "GPU-CPU norm:" << cv::norm(gpu_result, cpu_result, cv::NORM_INF) << std::endl; std::cerr << "PEN-CPU norm:" << cv::norm(pen_result, cpu_result, cv::NORM_INF) << std::endl; throw std::runtime_error("The OpenCL or PENCIL results are not equivalent with the C++ results."); } timing.print( elapsed_time_cpu, elapsed_time_gpu_p_copy, elapsed_time_gpu_nocopy, elapsed_time_pencil ); } } } }