void KdTree::partial(const std::vector<Vector<float> >& data, std::vector<size_t>& idx, size_t k, size_t lb, size_t hb, size_t d) { if (lb == hb - 1) { return; } int pivot = (lb + hb) / 2; std::swap(idx[pivot], idx[hb - 1]); int i = lb - 1; for (int j = lb; j < hb - 1; ++j) { if (data[idx[j]][d] < data[idx[hb - 1]][d]) { ++i; std::swap(idx[i], idx[j]); } } ++i; std::swap(idx[i], idx[hb - 1]); if (i > k) { partial(data, idx, k, lb, i, d); } else if (i < k) { partial(data, idx, k - i - 1, lb + 1, hb, d); } }
static constexpr decltype(auto) apply(F&& f, X&& x) { return node( f.value(x.value), concat( transform(x.subforest, partial(flip(transform), f.value)), transform(f.subforest, partial(flip(ap), x)) ) ); }
int main (void) { char a[10], b[10], da, db; while (scanf ("%s %c %s %c", a, &da, b, &db) != EOF) printf ("%d\n", partial (a, da) + partial (b, db)); return 0; }
/** * @brief Performs the worker's main work. * * This function implements the functionality of the worker process. * The worker will receive partially completed work items from the * master process and will then complete the assigned work and send * back the results. Then again the worker will receive more work from the * master process. * If no more work is available (termination message is received instead of * new work), then this function will return. */ void worker_main() { unsigned int n, k; // TODO receive the parameters `n` and `k` from the master process via MPI_Bcast MPI_Bcast(&n, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); MPI_Bcast(&k, 1, MPI_UNSIGNED, 0, MPI_COMM_WORLD); //Request Work unsigned int rcv = 0; MPI_Send(&rcv, 1, MPI_UNSIGNED, 0, REQUESTTAG, MPI_COMM_WORLD); // TODO: implement the worker's functions: receive partially completed solutions, // calculate all possible solutions starting with these queen positions // and send solutions to the master process. then ask for more work. std::vector<unsigned int> partial(n); MPI_Status status; while (1) { MPI_Recv(&(partial.front()), n, MPI_UNSIGNED, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &status); if (status.MPI_TAG == KILLTAG) return; //terminate else { // generate all solutions and call the // worker solution function nqueens_by_level(partial, k, n, &worker_solution_func); std::vector<unsigned int> sols = SolutionStore::solutions(); SolutionStore::clear_solutions(); unsigned int len = sols.size(); MPI_Send(&len, 1, MPI_UNSIGNED, 0, WORKTAG, MPI_COMM_WORLD); MPI_Send(&(sols.front()), len, MPI_UNSIGNED, 0, WORKTAG, MPI_COMM_WORLD); } } }
void PrefixTree::getWordsFromClue (string clue, vector <string>& results, bool* usable) { string partial(""); canUse = usable; getWordsFromClue (root, results, partial, clue); }
Point2D getOptFlow(IplImage* currentFrame,Point2D p,IplImage* preFrame) { Point2D temp; double b[2]; b[0]=0;b[1]=0; double M11=0,M12=0,M22=0; for(int i = -OPTICAL_FLOW_POINT_AREA/2; i < OPTICAL_FLOW_POINT_AREA/2; i++) { for (int j = -OPTICAL_FLOW_POINT_AREA/2;j < OPTICAL_FLOW_POINT_AREA/2;j++) { temp = partial(currentFrame,Point2D(p.row+i,p.col+j)); M11 += temp.dcol*temp.dcol; M12 += temp.dcol*temp.drow; M22 += temp.drow*temp.drow; b[0] += temp.dcol*(pixval8U(currentFrame,p.row+i,p.col+j)-pixval8U(preFrame,p.row+i,p.col+j)); b[1] += temp.drow*(pixval8U(currentFrame,p.row+i,p.col+j)-pixval8U(preFrame,p.row+i,p.col+j)); } } double a[] = {M11,M12,M12,M22}; CvMat M=cvMat(2, 2, CV_64FC1, a); CvMat *Mi = cvCloneMat(&M); cvInvert(&M,Mi,CV_SVD); temp.col=0; temp.row=0; b[0] = -b[0]; b[1] = -b[1]; CvMat Mb = cvMat(2,1,CV_64FC1,b); CvMat *Mr = cvCloneMat(&Mb); cvMatMul( Mi, &Mb, Mr); double vy = (cvmGet(Mr,1,0)); double vx = (cvmGet(Mr,0,0)); return (Point2D(vy,vx)); }
string WED_PackageMgr::ReducePath(const string& package, const string& full_file) const { string prefix = ComputePath(package,string()); string partial(full_file); #if IBM if(prefix.size() >= 2 && partial.size() >= 2 && prefix[1] == ':' && partial[1] == ':' && prefix[0] != partial[0]) return full_file; #endif int n = 0; do { int p = prefix.find_first_of("\\/:", n); if(p == prefix.npos) break; ++p; if(p != prefix.npos && p <= prefix.size() && p <= partial.size() && strncmp(prefix.c_str(), partial.c_str(), p) == 0) n = p; else break; } while(1); prefix.erase(0,n); partial.erase(0,n); while(!prefix.empty()) { string::size_type chop = prefix.find_first_of("\\/:"); if (chop == prefix.npos) break; prefix.erase(0,chop+1); partial = string("../") + partial; } return partial; }
void patchExpressionDistributionFunctionObject::getDistributionInternal( autoPtr<SimpleDistribution<T> > &dist ) { if(drivers_[0].getResultType()!=pTraits<T>::typeName) { return; } bool firstTime=true; forAll(patchIDs_,i) { autoPtr<SimpleDistribution<T> > partial; partial=setData( drivers_[i].getResult<T>()(), drivers_[i].patch().magSf() ); if(partial.valid()) { if(firstTime) { firstTime=false; dist=partial; } else { SimpleDistribution<T> &d=dist(); d=d+partial(); } } }
void VtoRouter::CheckForVtoWrite() { if(!mVtoTxBuffer.empty()) { VtoMessage msg = mVtoTxBuffer.front(); mVtoTxBuffer.pop_front(); // type DATA means this is a buffer and we need to pull the data out and send it to the vto writer if(msg.type == VTODT_DATA) { size_t numWritten = mpVtoWriter->Write(msg.data.Buffer(), msg.data.Size(), this->GetChannelId()); LOG_BLOCK(LEV_INTERPRET, "VtoWriter: " << numWritten << " of " << msg.data.Size()); if(numWritten < msg.data.Size()) { size_t remainder = msg.data.Size() - numWritten; VtoMessage partial(VTODT_DATA, msg.data.Buffer() + numWritten, remainder); mVtoTxBuffer.push_front(partial); } else this->CheckForVtoWrite(); } else { // if we have generated REMOTE_OPENED or REMOTE_CLOSED message we need to send the SetLocalVtoState // update to the vtowriter so it can be serialized in the correct order. mpVtoWriter->SetLocalVtoState(msg.type == VTODT_REMOTE_OPENED, this->GetChannelId()); this->CheckForVtoWrite(); } } this->CheckForPhysRead(); }
static constexpr decltype(auto) apply(M&& m, F&& f) { return unpack( transform( cppcon::rows(std::forward<M>(m)), partial(flip(transform), std::forward<F>(f)) ), cppcon::matrix ); }
clsparseStatus dot(clsparse::array_base<T>& pR, const clsparse::array_base<T>& pX, const clsparse::array_base<T>& pY, const clsparseControl control) { cl_int status; //not necessary to have it, but remember to init the pR with the proper value init_scalar(pR, (T)0, control); // with REDUCE_BLOCKS_NUMBER = 256 final reduction can be performed // within one block; const cl_ulong REDUCE_BLOCKS_NUMBER = 256; /* For future optimisation //workgroups per compute units; const cl_uint WG_PER_CU = 64; const cl_ulong REDUCE_BLOCKS_NUMBER = control->max_compute_units * WG_PER_CU; */ const cl_ulong REDUCE_BLOCK_SIZE = 256; cl_ulong xSize = pX.size(); cl_ulong ySize = pY.size(); assert (xSize == ySize); cl_ulong size = xSize; if (size > 0) { cl::Context context = control->getContext(); //partial result clsparse::vector<T> partial(control, REDUCE_BLOCKS_NUMBER, 0, CL_MEM_READ_WRITE, false); status = inner_product<T>(partial, pX, pY, size, REDUCE_BLOCKS_NUMBER, REDUCE_BLOCK_SIZE, control); if (status != clsparseSuccess) { return clsparseInvalidKernelExecution; } status = atomic_reduce<T>(pR, partial, REDUCE_BLOCK_SIZE, control); if (status != CL_SUCCESS) { return clsparseInvalidKernelExecution; } } return clsparseSuccess; }
void test_rethrow() { try { partial(); } catch( int i ) { if( i != 765 ) { printf( "test_rethrow failed\n" ); } } }
CGAL::MP_Float PolynomialKernel::K(arma::vec X1, arma::vec X2) { if(Q==0) return CGAL::MP_Float(1.0); CGAL::MP_Float partial(C+arma::as_scalar(X1.t()*X2)); if(Q==1) return partial; for(int i=0; i<Q; i++){ partial *= partial; } // std::cout << "El innerProduct vale: " << partial << std::endl; return partial; }
int main() { int x[] = { 1, 2, 3, 4 }; int y[] = { 1, 2, 3, 4 }; int i; pfunc f = partial(square); pfunc g = partial(dbl); printf("partial square:\n"); f(x, 4); for (i = 0; i < 4; i++) printf("%d\n", x[i]); printf("partial double:\n"); g(y, 4); for (i = 0; i < 4; i++) printf("%d\n", y[i]); return 0; }
int main(int argc, char **argv) { //test_resize("data/bad.jpg"); //test_box(); //test_convolutional_layer(); if(argc < 2){ fprintf(stderr, "usage: %s <function>\n", argv[0]); return 0; } gpu_index = find_int_arg(argc, argv, "-i", 0); if(find_arg(argc, argv, "-nogpu")) gpu_index = -1; #ifndef GPU gpu_index = -1; #else if(gpu_index >= 0){ cudaSetDevice(gpu_index); } #endif if(0==strcmp(argv[1], "imagenet")){ run_imagenet(argc, argv); } else if (0 == strcmp(argv[1], "detection")){ run_detection(argc, argv); } else if (0 == strcmp(argv[1], "writing")){ run_writing(argc, argv); } else if (0 == strcmp(argv[1], "test")){ test_resize(argv[2]); } else if (0 == strcmp(argv[1], "captcha")){ run_captcha(argc, argv); } else if (0 == strcmp(argv[1], "nightmare")){ run_nightmare(argc, argv); } else if (0 == strcmp(argv[1], "change")){ change_rate(argv[2], atof(argv[3]), (argc > 4) ? atof(argv[4]) : 0); } else if (0 == strcmp(argv[1], "rgbgr")){ rgbgr_net(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "partial")){ partial(argv[2], argv[3], argv[4], atoi(argv[5])); } else if (0 == strcmp(argv[1], "visualize")){ visualize(argv[2], (argc > 3) ? argv[3] : 0); } else if (0 == strcmp(argv[1], "imtest")){ test_resize(argv[2]); } else { fprintf(stderr, "Not an option: %s\n", argv[1]); } return 0; }
void SplineChainMovementGenerator::Initialize(Unit* owner) { RemoveFlag(MOVEMENTGENERATOR_FLAG_INITIALIZATION_PENDING | MOVEMENTGENERATOR_FLAG_DEACTIVATED); AddFlag(MOVEMENTGENERATOR_FLAG_INITIALIZED); if (!_chainSize) { TC_LOG_ERROR("movement", "SplineChainMovementGenerator::Initialize: couldn't initialize generator, referenced spline is empty! (%s)", owner->GetGUID().ToString().c_str()); return; } if (_nextFirstWP) // this is a resumed movegen that has to start with a partial spline { if (HasFlag(MOVEMENTGENERATOR_FLAG_FINALIZED)) return; SplineChainLink const& thisLink = _chain[_nextIndex]; if (_nextFirstWP >= thisLink.Points.size()) { TC_LOG_ERROR("movement.splinechain", "SplineChainMovementGenerator::Initialize: attempted to resume spline chain from invalid resume state, _nextFirstWP >= path size (_nextIndex: %u, _nextFirstWP: %u). (%s)", _nextIndex, _nextFirstWP, owner->GetGUID().ToString().c_str()); _nextFirstWP = thisLink.Points.size() - 1; } owner->AddUnitState(UNIT_STATE_ROAMING_MOVE); Movement::PointsArray partial(thisLink.Points.begin() + (_nextFirstWP-1), thisLink.Points.end()); SendPathSpline(owner, partial); TC_LOG_DEBUG("movement.splinechain", "SplineChainMovementGenerator::Initialize: resumed spline chain generator from resume state. (%s)", owner->GetGUID().ToString().c_str()); ++_nextIndex; if (_nextIndex >= _chainSize) _msToNext = 0; else if (!_msToNext) _msToNext = 1; _nextFirstWP = 0; } else { _msToNext = std::max(_chain[_nextIndex].TimeToNext, 1u); SendSplineFor(owner, _nextIndex, _msToNext); ++_nextIndex; if (_nextIndex >= _chainSize) _msToNext = 0; } }
void toppart(board *b,turn *t, char *part,t_node *node,int horiz_i,int vert_i, int lim) { if (b->space[horiz_i][vert_i-1].tile_letter!='-') { char part2[BOARD_LENGTH]; get_seg_up(b,horiz_i,vert_i,part2); if(trie_ispartial(node,part2)==true) { t_node *node2; node2=partial(node,part2); extenddown(b,t,part2,node2,horiz_i,vert_i,&b->space[horiz_i][vert_i]); } } else { extenddown(b,t,part,node,horiz_i,vert_i,&b->space[horiz_i][vert_i]); t_node *curr; char part2[BOARD_LENGTH]; char ltr[2]; if (lim > 0) { for (curr=node;curr!=NULL;curr=curr->next) { if (contains_letter(t->curr,curr->key)) { hold_letter(t->curr,curr->key); stringify(curr->key,ltr); strcpy(part2,part); strcat(part2,ltr); toppart(b,t,part2,curr->children,horiz_i,vert_i,lim-1); putback_letter(t->curr,curr->key); } else if (contains_blank(t->curr)) { hold_letter(t->curr,'0'); if (t->blank1=='\0') t->blank1=curr->key; else t->blank2=curr->key; stringify(curr->key,ltr); strcpy(part2,part); strcpy(part2,ltr); extenddown(b,t,part2,curr->children,horiz_i,vert_i,&b->space[horiz_i][vert_i]); putback_letter(t->curr,'0'); } } } } }
void CheckBox::toggleChecked() { if (checkable()) { if (_buttonFlag & Tristate) { if (checked()) { setChecked(false); _buttonFlag = (ButtonFlags) (_buttonFlag | Partial); update(); sigCheckStateChanged(Partial); } else if (partial()) { _buttonFlag = (ButtonFlags) (_buttonFlag & ~Partial); update(); sigCheckStateChanged(Unchecked); } else { setChecked(true); update(); sigCheckStateChanged(Checked); } } else { if (checked()) { setChecked(false); update(); sigCheckChanged(false); sigCheckStateChanged(Unchecked); } else { setChecked(true); update(); sigCheckChanged(true); sigCheckStateChanged(Checked); } } } }
KdNode* KdTree::buildTree(const std::vector<Vector<float> >& data, std::vector<size_t>& idx, KdNode* parent, size_t lb, size_t hb, size_t d) { if (lb == hb) { return nullptr; } KdNode* cur = new KdNode; cur->dim = d; cur->parent = parent; cur->lbound = data[idx[lb]][d]; cur->hbound = data[idx[lb]][d]; cur->data = idx[lb]; if (lb == hb - 1) { cur->left = nullptr; cur->right = nullptr; return cur; } for (size_t i = lb; i < hb; ++i) { if (data[idx[i]][d] < cur->lbound) { cur->lbound = data[idx[i]][d]; } if (data[idx[i]][d] > cur->hbound) { cur->hbound = data[idx[i]][d]; } } size_t pivot = (lb + hb) / 2; partial(data, idx, pivot, lb, hb, d); cur->data = idx[pivot]; cur->left = buildTree(data, idx, cur, lb, pivot, (d + 1) % data.front().dim()); cur->right = buildTree(data, idx, cur, pivot + 1, hb, (d + 1) % data.front().dim()); }
CStringA FxInternal::TranscodeHandleToPlug (const CStringA& handleStr) { int iLastPos=0; int iThisPos=0; CStringA result(DirectXShader::RootLongName.asChar()); CStringA partial(DirectXShader::RootShortName.asChar()); CStringA subStr; while( iLastPos= iThisPos, subStr=handleStr.Tokenize(".[]", iThisPos), iThisPos != -1 ) { if(iLastPos == 0 || handleStr[iLastPos-1]=='.' || (handleStr[iLastPos-1]==']' && handleStr[iLastPos]=='.')) { partial.Append(subStr.GetString()); result.AppendFormat(".%s", partial.GetString()); } else if(handleStr[iLastPos-1]=='[' && handleStr[iThisPos-1]==']') { result.AppendFormat("[%s]", subStr); } else DXCC_ASSERT(false); } D3DXPARAMETER_DESC desc; D3DXHANDLE handle= DecodeHandle(handleStr); Effect->GetParameterDesc(handle, &desc); if( desc.StructMembers == 0 && desc.Elements == 0 ) { partial.Append("Value"); result.AppendFormat(".%s", partial); } return result; }
void SplineChainMovementGenerator::Initialize(Unit* me) { if (_chainSize) { if (_nextFirstWP) // this is a resumed movegen that has to start with a partial spline { if (finished) return; SplineChainLink const& thisLink = _chain[_nextIndex]; if (_nextFirstWP >= thisLink.Points.size()) { TC_LOG_ERROR("movement.splinechain", "%s: Attempted to resume spline chain from invalid resume state (%u, %u).", me->GetGUID().ToString().c_str(), _nextIndex, _nextFirstWP); _nextFirstWP = thisLink.Points.size()-1; } Movement::PointsArray partial(thisLink.Points.begin() + (_nextFirstWP-1), thisLink.Points.end()); SendPathSpline(me, partial); TC_LOG_DEBUG("movement.splinechain", "%s: Resumed spline chain generator from resume state.", me->GetGUID().ToString().c_str()); ++_nextIndex; if (!_msToNext) _msToNext = 1; _nextFirstWP = 0; } else { _msToNext = std::max(_chain[_nextIndex].TimeToNext, 1u); SendSplineFor(me, _nextIndex, _msToNext); ++_nextIndex; if (_nextIndex >= _chainSize) _msToNext = 0; } } else { TC_LOG_ERROR("movement", "SplineChainMovementGenerator::Initialize - empty spline chain passed for %s.", me->GetGUID().ToString().c_str()); } }
// -------------------------------------------------------------------------- // // void Test_Specswap::testNotify() { // Setup a specswap object with many different data sets. std::string path("./testfiles/testlibLarge"); int sample = 12; Mlrnd rand; rand.set_seed(39); Specswap ss1(sample, rand, path); // Mean scalar. std::string scalarname("VP-Volume"); double target = 0.5; double sigma = 1.0; ss1.add_scalar_mean(scalarname, target, sigma); sigma = 0.0012; ss1.add_scalar_mean(scalarname, target, sigma); // Value scalar. scalarname = "VP-Area"; double value_low = 0.5; double value_high = 1.0; double fraction = 0.6; sigma = 0.0001; ss1.add_scalar_value(scalarname, value_low, value_high, fraction, sigma); fraction = 0.1; sigma = 0.0001; ss1.add_scalar_value(scalarname, value_low, value_high, fraction, sigma); value_low = 0.0; value_high = 1.3; fraction = 0.99; sigma = 0.01; ss1.add_scalar_value(scalarname, value_low, value_high, fraction, sigma); // Scalar distribution. scalarname = "VP-Volume"; std::string filename("./testfiles/vvol_ref.data"); sigma = 0.0002; ss1.add_scalar_distribution(scalarname, filename, sigma); sigma = 0.0099; ss1.add_scalar_distribution(scalarname, filename, sigma); // Curve. std::string curve_name("bas"); filename = "./testfiles/exafs_ref.data"; sigma = 0.0002; bool area_renorm = true; ss1.add_curve(sigma, area_renorm, curve_name, filename); area_renorm = false; ss1.add_curve(sigma, area_renorm, curve_name, filename); // Setup input for adding a pcf. double rmin = 0.0; double rmax = 5.0; double dr = 0.02; double numberdensity = 0.4; std::pair<double,double> fit_interval(1.3, 3.0); int nbins = 250; std::pair<int,int> partial(0,1); std::string ref_path("./testfiles/gr_ref.data"); sigma = 0.01; ss1.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path); sigma = 0.0123; ss1.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path); // Set the initial chi2_ value to some thing unreasonable. ss1.chi2_new_ = -1.123; // Call the setup function. ss1.from_sample_ = 0; ss1.from_basis_ = 12; ss1.setup(); // Call notify. ss1.notify(); // Check that the chi2 value has been updated. CPPUNIT_ASSERT_DOUBLES_EQUAL(735129583.538380026817, ss1.chi2_new_, 1.0e-8); }
int pload (int tbl) { int c = 0, i, status; if (verbose > 0) { fprintf (stderr, "Starting %d children to load %s", children, tdefs[tbl].comment); } for (c = 0; c < children; c++) { pids[c] = SPAWN (); if (pids[c] == -1) { perror ("Child loader not created"); kill_load (); exit (-1); } else if (pids[c] == 0) /* CHILD */ { SET_HANDLER (stop_proc); verbose = 0; partial (tbl, c+1); exit (0); } else if (verbose > 0) /* PARENT */ fprintf (stderr, "."); } if (verbose > 0) fprintf (stderr, "waiting..."); c = children; while (c) { i = WAIT (&status, pids[c - 1]); if (i == -1 && children) { if (errno == ECHILD) fprintf (stderr, "\nCould not wait on pid %d\n", pids[c - 1]); else if (errno == EINTR) fprintf (stderr, "\nProcess %d stopped abnormally\n", pids[c - 1]); else if (errno == EINVAL) fprintf (stderr, "\nProgram bug\n"); } if (! WIFEXITED(status)) { (void) fprintf(stderr, "\nProcess %d: ", i); if (WIFSIGNALED(status)) { (void) fprintf(stderr, "rcvd signal %d\n", WTERMSIG(status)); } else if (WIFSTOPPED(status)) { (void) fprintf(stderr, "stopped, signal %d\n", WSTOPSIG(status)); } } c--; } if (verbose > 0) fprintf (stderr, "done\n"); return (0); }
/* * MAIN * * assumes the existance of getopt() to clean up the command * line handling */ int main (int ac, char **av) { DSS_HUGE i; table = (1 << CUST) | (1 << SUPP) | (1 << NATION) | (1 << REGION) | (1 << PART_PSUPP) | (1 << ORDER_LINE); force = 0; insert_segments=0; delete_segments=0; insert_orders_segment=0; insert_lineitem_segment=0; delete_segment=0; verbose = 0; set_seeds = 0; scale = 1; flt_scale = 1.0; updates = 0; step = -1; tdefs[ORDER].base *= ORDERS_PER_CUST; /* have to do this after init */ tdefs[LINE].base *= ORDERS_PER_CUST; /* have to do this after init */ tdefs[ORDER_LINE].base *= ORDERS_PER_CUST; /* have to do this after init */ children = 1; d_path = NULL; #ifdef NO_SUPPORT signal (SIGINT, exit); #endif /* NO_SUPPORT */ process_options (ac, av); validate_options(); #if (defined(WIN32)&&!defined(_POSIX_)) for (i = 0; i < ac; i++) { spawn_args[i] = malloc (((int)strlen (av[i]) + 1) * sizeof (char)); MALLOC_CHECK (spawn_args[i]); strcpy (spawn_args[i], av[i]); } spawn_args[ac] = NULL; #endif if (verbose >= 0) { fprintf (stderr, "%s Population Generator (Version %d.%d.%d)\n", NAME, VERSION, RELEASE, PATCH); fprintf (stderr, "Copyright %s %s\n", TPC, C_DATES); } load_dists (); #ifdef RNG_TEST for (i=0; i <= MAX_STREAM; i++) Seed[i].nCalls = 0; #endif /* have to do this after init */ tdefs[NATION].base = nations.count; tdefs[REGION].base = regions.count; /* * updates are never parallelized */ if (updates) { /* * set RNG to start generating rows beyond SF=scale */ set_state (ORDER, scale, 100, 101, &i); rowcnt = (int)(tdefs[ORDER_LINE].base / 10000 * scale * UPD_PCT); if (step > 0) { /* * adjust RNG for any prior update generation */ for (i=1; i < step; i++) { sd_order(0, rowcnt); sd_line(0, rowcnt); } upd_num = step - 1; } else upd_num = 0; while (upd_num < updates) { if (verbose > 0) fprintf (stderr, "Generating update pair #%ld for %s", upd_num + 1, tdefs[ORDER_LINE].comment); insert_orders_segment=0; insert_lineitem_segment=0; delete_segment=0; minrow = upd_num * rowcnt + 1; gen_tbl (ORDER_LINE, minrow, rowcnt, upd_num + 1); if (verbose > 0) fprintf (stderr, "done.\n"); pr_drange (ORDER_LINE, minrow, rowcnt, upd_num + 1); upd_num++; } exit (0); } /** ** actual data generation section starts here **/ /* * traverse the tables, invoking the appropriate data generation routine for any to be built */ for (i = PART; i <= REGION; i++) if (table & (1 << i)) { if (children > 1 && i < NATION) { partial ((int)i, step); } else { minrow = 1; if (i < NATION) rowcnt = tdefs[i].base * scale; else rowcnt = tdefs[i].base; if (verbose > 0) fprintf (stderr, "Generating data for %s", tdefs[i].comment); gen_tbl ((int)i, minrow, rowcnt, upd_num); if (verbose > 0) fprintf (stderr, "done.\n"); } } return (0); }
/* * MAIN * * assumes the existance of getopt() to clean up the command * line handling */ int main (int ac, char **av) { DSS_HUGE i; o_table = 0; o_force = 0; insert_segments=0; delete_segments=0; insert_orders_segment=0; insert_lineitem_segment=0; delete_segment=0; o_verbose = 0; o_columnar = 0; o_set_seeds = 0; o_header = 0; o_direct = 0; o_scale = 1; flt_scale = 1.0; o_updates = 0; o_refresh = UPD_PCT; tdefs[ORDER].base *= ORDERS_PER_CUST; /* have to do this after init */ tdefs[LINE].base *= ORDERS_PER_CUST; /* have to do this after init */ tdefs[ORDER_LINE].base *= ORDERS_PER_CUST; /* have to do this after init */ o_fnames = 0; o_db_name = NULL; o_schema_name = NULL; o_gen_sql = 0; o_gen_rng = 0; o_d_path = NULL; o_step = 1; o_stepmax = 1; #ifdef NO_SUPPORT signal (SIGINT, exit); #endif /* NO_SUPPORT */ process_options (ac, av); if (o_table == 0) { usage(); fprintf(stderr, "Error: please specify -T option\n"); exit(1); } if (o_stepmax <= 0) { usage(); fprintf(stderr, "Error: invalid -N option\n"); exit(1); } if (! (0 < o_step && o_step <= o_stepmax)) { usage(); fprintf(stderr, "Error: invalid -n option\n"); exit(1); } if (o_verbose >= 0) { fprintf (stderr, "%s Population Generator (Version %d.%d.%d build %d)\n", NAME, VERSION, RELEASE, PATCH, BUILD); fprintf (stderr, "Copyright %s %s\n", TPC, C_DATES); } load_dists (); /* have to do this after init */ tdefs[NATION].base = nations.count; tdefs[REGION].base = regions.count; /* * updates are never parallelized */ if (o_updates) { /* * set RNG to start generating rows beyond SF=scale */ set_state (ORDER, o_scale, o_stepmax, o_stepmax + 1, &i); rowcnt = (int)(tdefs[ORDER_LINE].base / 10000 * o_scale * o_refresh); if (o_step > 0) { /* * adjust RNG for any prior update generation */ for (i=1; i < o_step; i++) { sd_order(0, rowcnt); sd_line(0, rowcnt); } upd_num = o_step - 1; } else upd_num = 0; while (upd_num < o_updates) { if (o_verbose > 0) fprintf (stderr, "Generating update pair #%ld for %s [pid: %d]", upd_num + 1, tdefs[ORDER_LINE].comment, (int)DSS_PROC); insert_orders_segment=0; insert_lineitem_segment=0; delete_segment=0; minrow = upd_num * rowcnt + 1; gen_tbl (ORDER_LINE, minrow, rowcnt, upd_num + 1); if (o_verbose > 0) fprintf (stderr, "done.\n"); pr_drange (ORDER_LINE, minrow, rowcnt, upd_num + 1); upd_num++; } exit (0); } /** ** actual data generation section starts here **/ /* * open database connection or set all the file names, as appropriate */ if (o_fnames) for (i = PART; i <= REGION; i++) { if (o_table & (1 << i)) if (set_files ((int)i, -1)) { fprintf (stderr, "Load aborted!\n"); exit (1); } } /* * traverse the tables, invoking the appropriate data generation routine for any to be built */ for (i = PART; i <= REGION; i++) { if (0 == (o_table & (1 << i))) continue; minrow = 1; if (i < NATION) rowcnt = tdefs[i].base * o_scale; else rowcnt = tdefs[i].base; if (o_verbose > 0) fprintf (stderr, "%s data for %s [pid: %ld, step: %d]", (o_validate)?"Validating":"Generating", tdefs[i].comment, (long)DSS_PROC, o_step); if (i < NATION) { partial(i, o_step); } else { gen_tbl ((int)i, minrow, rowcnt, upd_num); } if (o_verbose > 0) fprintf (stderr, "done.\n"); if (o_validate) printf("Validation checksum for %s at %ld GB: %0x\n", tdefs[i].name, o_scale, (unsigned int) tdefs[i].vtotal); } return (0); }
// Generate full CRC for data. ui32 nuCRC::calculate(const void* p_data, size_t sz) { ui32 ret = 0xffffffff; // Initilaize return value. partial(&ret, p_data, sz); return ret ^ 0xffffffff; }
// -------------------------------------------------------------------------- // // void Test_Specswap::testAddPCF() { // Setup a specswap object. int sample = 250; Mlrnd rand; std::string path("./testfiles/testlibLarge"); Specswap ss(sample, rand, path); // Check that there are no pcf data added. CPPUNIT_ASSERT_EQUAL( static_cast<int>(ss.pcf_data_.size()), 0 ); // Setup input for adding a pcf. double rmin = 0.0; double rmax = 5.0; double dr = 0.02; double sigma = 0.01; double numberdensity = 0.4; std::pair<double,double> fit_interval(1.3, 3.0); int nbins = 250; std::pair<int,int> partial(0,1); std::string ref_path("./testfiles/gr_ref.data"); ss.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path); // Check that a pcf has been added. CPPUNIT_ASSERT_EQUAL( static_cast<int>(ss.pcf_data_.size()), 1 ); // Add another one. ss.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path); // Check. CPPUNIT_ASSERT_EQUAL( static_cast<int>(ss.pcf_data_.size()), 2 ); // Make sure we fail with wrong rmin rmax and dr. { double rmin = 2.3; double rmax = 4.0; double dr = 0.02; //ss.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path); CPPUNIT_ASSERT_THROW( ss.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path), IOException ); } // Make sure we fail with wrong rmin rmax and dr. { std::pair<double, double> fit_interval(12.3,1.23); //ss.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path); CPPUNIT_ASSERT_THROW( ss.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path), IOException ); } // Make sure we fail with a too large number of bins. { int nbins = 1000; double rmin = 0.0; double rmax = 10.0; double dr = 0.02; //ss.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path); CPPUNIT_ASSERT_THROW( ss.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path), IOException ); } // Make sure we fail with wrong reference path. { std::string ref_path("./testfiles/NO_SUCH_FILE"); //ss.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path); CPPUNIT_ASSERT_THROW( ss.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path), IOException ); } }
int main(int argc, char **argv) { //test_resize("data/bad.jpg"); //test_box(); //test_convolutional_layer(); if(argc < 2){ fprintf(stderr, "usage: %s <function>\n", argv[0]); return 0; } gpu_index = find_int_arg(argc, argv, "-i", 0); if(find_arg(argc, argv, "-nogpu")) { gpu_index = -1; } #ifndef GPU gpu_index = -1; #else if(gpu_index >= 0){ cudaError_t status = cudaSetDevice(gpu_index); check_error(status); } #endif if(0==strcmp(argv[1], "imagenet")){ run_imagenet(argc, argv); } else if (0 == strcmp(argv[1], "average")){ average(argc, argv); } else if (0 == strcmp(argv[1], "yolo")){ run_yolo(argc, argv); } else if (0 == strcmp(argv[1], "cifar")){ run_cifar(argc, argv); } else if (0 == strcmp(argv[1], "go")){ run_go(argc, argv); } else if (0 == strcmp(argv[1], "rnn")){ run_char_rnn(argc, argv); } else if (0 == strcmp(argv[1], "vid")){ run_vid_rnn(argc, argv); } else if (0 == strcmp(argv[1], "coco")){ run_coco(argc, argv); } else if (0 == strcmp(argv[1], "classifier")){ run_classifier(argc, argv); } else if (0 == strcmp(argv[1], "tag")){ run_tag(argc, argv); } else if (0 == strcmp(argv[1], "compare")){ run_compare(argc, argv); } else if (0 == strcmp(argv[1], "dice")){ run_dice(argc, argv); } else if (0 == strcmp(argv[1], "writing")){ run_writing(argc, argv); } else if (0 == strcmp(argv[1], "test")){ test_resize(argv[2]); } else if (0 == strcmp(argv[1], "captcha")){ run_captcha(argc, argv); } else if (0 == strcmp(argv[1], "nightmare")){ run_nightmare(argc, argv); } else if (0 == strcmp(argv[1], "change")){ change_rate(argv[2], atof(argv[3]), (argc > 4) ? atof(argv[4]) : 0); } else if (0 == strcmp(argv[1], "rgbgr")){ rgbgr_net(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "denormalize")){ denormalize_net(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "normalize")){ normalize_net(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "rescale")){ rescale_net(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "partial")){ partial(argv[2], argv[3], argv[4], atoi(argv[5])); } else if (0 == strcmp(argv[1], "stacked")){ stacked(argv[2], argv[3], argv[4]); } else if (0 == strcmp(argv[1], "visualize")){ visualize(argv[2], (argc > 3) ? argv[3] : 0); } else if (0 == strcmp(argv[1], "imtest")){ test_resize(argv[2]); } else { fprintf(stderr, "Not an option: %s\n", argv[1]); } return 0; }
// -------------------------------------------------------------------------- // // void Test_Specswap::testAccept() { // Setup a specswap object with many different data sets. std::string path("./testfiles/testlibLarge"); int sample = 12; Mlrnd rand; rand.set_seed(39); Specswap ss1(sample, rand, path); // Mean scalar. std::string scalarname("VP-Volume"); double target = 0.5; double sigma = 1.0; ss1.add_scalar_mean(scalarname, target, sigma); sigma = 0.0012; ss1.add_scalar_mean(scalarname, target, sigma); // Value scalar. scalarname = "VP-Area"; double value_low = 0.5; double value_high = 1.0; double fraction = 0.6; sigma = 0.0001; ss1.add_scalar_value(scalarname, value_low, value_high, fraction, sigma); fraction = 0.1; sigma = 0.0001; ss1.add_scalar_value(scalarname, value_low, value_high, fraction, sigma); value_low = 0.0; value_high = 1.3; fraction = 0.99; sigma = 0.01; ss1.add_scalar_value(scalarname, value_low, value_high, fraction, sigma); // Scalar distribution. scalarname = "VP-Volume"; std::string filename("./testfiles/vvol_ref.data"); sigma = 0.0002; ss1.add_scalar_distribution(scalarname, filename, sigma); sigma = 0.0099; ss1.add_scalar_distribution(scalarname, filename, sigma); // Curve. std::string curve_name("bas"); filename = "./testfiles/exafs_ref.data"; sigma = 0.0002; bool area_renorm = true; ss1.add_curve(sigma, area_renorm, curve_name, filename); area_renorm = false; ss1.add_curve(sigma, area_renorm, curve_name, filename); // Setup input for adding a pcf. double rmin = 0.0; double rmax = 5.0; double dr = 0.02; double numberdensity = 0.4; std::pair<double,double> fit_interval(1.3, 3.0); int nbins = 250; std::pair<int,int> partial(0,1); std::string ref_path("./testfiles/gr_ref.data"); sigma = 0.01; ss1.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path); sigma = 0.0123; ss1.add_pcf(rmin, rmax, dr, sigma, numberdensity, fit_interval, nbins, partial, ref_path); // Setup. ss1.setup(); // Move. ss1.move(); // Check what slot and indices will be swapped. CPPUNIT_ASSERT_EQUAL( ss1.from_sample_, 583); CPPUNIT_ASSERT_EQUAL( ss1.from_basis_, 2354); CPPUNIT_ASSERT_EQUAL( ss1.slot_, 11); // Check that the sample set is correct. CPPUNIT_ASSERT_EQUAL( ss1.sampleset_.index_at(ss1.slot_), ss1.from_sample_); // Notify. ss1.notify(); // Check the chi2 value. double diff = 7.2603029936e+08 - 6.5624713898e-04 - ss1.chi2_; CPPUNIT_ASSERT_DOUBLES_EQUAL( diff, 0.0, 1.0e-10 ); // Check that the chi2_new value has been updated. diff = 7.4256423439e+08 + 1.9059181213e-03 - ss1.chi2_new_; CPPUNIT_ASSERT_DOUBLES_EQUAL( diff, 0.0, 1.0e-10 ); // Call the accept and make sure Chi2 has been accepted. ss1.accept(); CPPUNIT_ASSERT_DOUBLES_EQUAL( ss1.chi2_, ss1.chi2_new_, 1.0e-10 ); // Check that the sample set is correct. CPPUNIT_ASSERT_EQUAL( ss1.sampleset_.index_at(ss1.slot_), ss1.from_basis_); }
static constexpr auto apply(F fset, Set set) { return flatten(transform(fset, partial(transform, set))); }