void manager::start_file(const string& file, client *cl, bool temp) { pthread_setspecific(client_key, cl); scheduler_type sched_type(SCHED_SERIAL_UI); try { router rout(1, 0, NULL, is_mpi_sched(sched_type)); machine mac(file, rout, 1, sched_type); cl->all = mac.get_all(); LOG_PROGRAM_RUNNING(); if(temp) { delete_temp_file(file); } mac.start(); LOG_PROGRAM_STOPPED(); } catch(std::exception& e) { cerr << e.what() << endl; } client_mtx.lock(); cl->all = NULL; client_mtx.unlock(); }
BSONObj MozJSImplScope::callThreadArgs(const BSONObj& args) { MozJSEntry entry(this); JS::RootedValue function(_context); ValueReader(_context, &function).fromBSONElement(args.firstElement(), args, true); int argc = args.nFields() - 1; JS::AutoValueVector argv(_context); BSONObjIterator it(args); it.next(); JS::RootedValue value(_context); for (int i = 0; i < argc; ++i) { ValueReader(_context, &value).fromBSONElement(*it, args, true); argv.append(value); it.next(); } JS::RootedValue out(_context); JS::RootedObject thisv(_context); _checkErrorState(JS::Call(_context, thisv, function, argv, &out), false, true); JS::RootedObject rout(_context, JS_NewPlainObject(_context)); ObjectWrapper wout(_context, rout); wout.setValue("ret", out); return wout.toBSON(); }
// compute distances from rows of inmat1 to rows of inmat2 RcppExport SEXP rthpdist(SEXP inmat1,SEXP inmat2, SEXP nthreads) { Rcpp::NumericMatrix im1(inmat1); Rcpp::NumericMatrix im2(inmat2); int nr1 = im1.nrow(); int nc = im1.ncol(); int nr2 = im2.nrow(); #if RTH_OMP omp_set_num_threads(INT(nthreads)); #elif RTH_TBB // tbb::task_scheduler_init init(INT(nthreads)); // for unknown reasons, this code does not work under TBB return Rcpp::wrap(-1); #endif thrust::device_vector<double> dmat1(im1.begin(),im1.end()); thrust::device_vector<double> dmat2(im2.begin(),im2.end()); // make space for the output thrust::device_vector<double> ddst(nr1*nr2); // iterators for row number of inmat1 thrust::counting_iterator<int> iseqb(0); thrust::counting_iterator<int> iseqe = iseqb + nr1; // for each i in [iseqb,iseqe) find the distances from row i in inmat1 // to all rows of inmat2 thrust::for_each(iseqb,iseqe, do1ival(dmat1.begin(),dmat2.begin(),ddst.begin(),nr1,nc,nr2)); Rcpp::NumericMatrix rout(nr1,nr2); thrust::copy(ddst.begin(),ddst.end(),rout.begin()); return rout; }
int main() { cout << setiosflags(ios::uppercase); ofstream out("RandomData.out"); out << setiosflags(ios::uppercase); ofstream rout("Random.out"); rout << setiosflags(ios::uppercase); //NUR FUER DEBUGZWECKE double x, a; double x1, x2, h, n, xu, xi1, xi2; cin >> x >> a; cin >> x1 >> x2 >> n; h = (x2 -x1)/n; cout << "+++ PARAMETER RANDOM +++" << endl; cout << "x = " << x << endl; cout << "a = " << a << endl; cout << '\v' ; cout << "x1 = " << x1 << endl; cout << "x2 = " << x2 << endl; cout << "h = " << h << endl; cout << "n = " << n << endl; for(int i = 0;i <= n; i++) { xu = x1 + i * h; xi1 = Xi1(xu); // mit N default double fr1 = f1(xu) + 0.01 * xi1; double s1_rel = fabs(fr1 - f1(xu))/fabs(f1(xu)); s1_rel *= 100.0; xi2 = Xi2(xu); double fr2 = f1(xu) + 0.01 * xi2; double s2_rel = fabs(fr2 - f1(xu))/fabs(f1(xu)); s2_rel *= 100.0; double xi3 = Xi3(xu); double fr3 = f1(xu) + 0.01 * xi3; double s3_rel = fabs(fr3 - f1(xu))/fabs(f1(xu)); s3_rel *= 100.0; out << xu << '\t' << f1(xu) << '\t' << fr1 <<'\t' << fr2 << '\t' << fr3 << '\t' << s1_rel <<'\t' << s2_rel <<'\t' << s3_rel << endl; rout << xu << '\t' << xi1 <<'\t' << xi2 <<'\t' << xi3 << endl; } return 0; }
void rvdsp(rvector b , int n){ int i,n1; n1=n ; printf("\n") ; for( i=0 ; i<n1 ; i++ ){ rout(b[i]) ; printf("\n") ; } }
void rmdsp(rmatrix a , int n){ int i,j,n1; n1=n ; printf("\n") ; for( i=0 ; i<n1 ; i++ ){ for ( j=0 ; j<n1 ; j++){ rout(a[i][j]) ; } printf("\n") ; } }
void bob::ap::Ceps::addDerivative(const blitz::Array<double,2>& input, blitz::Array<double,2>& output) const { // Initialize output to zero output = 0.; const int n_frames = input.extent(0); blitz::Range rall = blitz::Range::all(); // Fill in the inner part as follows: // \f$output[i] += \sum_{l=1}^{DW} l * (input[i+l] - input[i-l])\f$ for (int l=1; l<=(int)m_delta_win; ++l) { blitz::Range rout(l,n_frames-l-1); blitz::Range rp(2*l,n_frames-1); blitz::Range rn(0,n_frames-2*l-1); output(rout,rall) += l*(input(rp,rall) - input(rn,rall)); } const double factor = m_delta_win*(m_delta_win+1)/2; // Continue to fill the left boundary part as follows: // \f$output[i] += (\sum_{l=1+i}^{DW} l*input[i+l]) - (\sum_{l=i+1}^{DW}l)*input[0])\f$ for (int i=0; i<(int)m_delta_win; ++i) { output(i,rall) -= (factor - i*(i+1)/2) * input(0,rall); for (int l=1+i; l<=(int)m_delta_win; ++l) { output(i,rall) += l*(input(i+l,rall)); } } // Continue to fill the right boundary part as follows: // \f$output[i] += (\sum_{l=Nframes-1-i}^{DW}l)*input[Nframes-1]) - (\sum_{l=Nframes-1-i}^{DW} l*input[i-l])\f$ for (int i=n_frames-(int)m_delta_win; i<n_frames; ++i) { int ii = (n_frames-1)-i; output(i,rall) += (factor - ii*(ii+1)/2) * input(n_frames-1,rall); for (int l=1+ii; l<=(int)m_delta_win; ++l) { output(i,rall) -= l*input(i-l,rall); } } // Sum of the integer squared from 1 to delta_win // pavel - remove division for the sake of compitability with Matlab code of RFFC features comparison paper //const double sum = m_delta_win*(m_delta_win+1)*(2*m_delta_win+1)/3; //output /= sum; }
int main() { cout << setiosflags(ios::uppercase); ofstream out1("Daten_Gauss.out"); out1 << setiosflags(ios::uppercase); ofstream out("LIP.out"); out << setiosflags(ios::uppercase); ofstream outs("Y2D.out"); outs << setiosflags(ios::uppercase); ofstream rout("REGLIP_Gauss.out"); rout << setiosflags(ios::uppercase); cout << "*** Imaginaerteilgleichung ***" << endl; cout << "*** Filter: Gauss ***" << endl; mp_init(); cout << "*** Precision = " << mpipl << " ***" << endl; int M, N, MD; double xa, xb, x1, x2, xr1, xr2, h, step, step2, b1, dfactor, dpi; mp_real b, mpx1, mpx2, mpstep, mpx; dpi = 4.0 * atan(1.0); mp_real pi = mppic; // pi aus der Bibliothek !!! mp_real pi2 = pi * pi; static mp_real factor; cin >> b1; cin >> xa >> xb >> MD; cin >> x1 >> x2 >> M; cin >> xr1 >> xr2 >> N ; cout << '\v'; /* KERNELARRY ANFANG */ mp_real* const mpregKern = new mp_real [M+1]; b = mp_real(b1); mpx1 = mp_real(x1); mpx2 = mp_real(x2); mpstep = (mpx2 - mpx1)/mp_real(M); /* Vorfaktor */ factor = mp_real(2.0)*b/power(pi,mp_real(1.5)); factor *= exp(mp_real(0.25) * pi2 * b * b); dfactor = 2.0 * (b1/pow(dpi,1.5)) * exp(b1*b1*dpi*dpi*.25); cout << "*** Begin: Init. Kernel *** " << endl; cout << "b1 = " << b1 << endl; cout << "b = " << b ; cout << "x1 = " << x1 << endl; /* Anfangs-/Endpunkt der Regularisierung */ cout << "x2 = " << x2 << endl; cout << "M = " << M << endl; cout << "h = " << mpstep; cout << "factor = " << factor ; cout << "dfactor = " << dfactor << endl; for(int i = 0; i <= M; i++) { mpx = mpx1 + i * mpstep; mpregKern[i] = mpregkerne2(mpx, b); } cout << "*** End: Init. Kernel *** " << endl; /* KERNELARRY ENDE */ double x0, datlinpol, Error_splint, DataError, e2core; /* Index der Vektoren beginnt mit 1 und *nicht* mit 0 */ double* y2d = dvector(1,MD); /* 2.Ableitung der SPL-Funktion */ double* data = dvector(1,MD); /* Datenvektor */ double* x = dvector(1,MD); /* x-Vektor */ /* Datenarrays fuellen */ h = (xb - xa)/(MD - 1); double rho = MD/(xb -xa); cout << '\v'; cout << "*** Begin: Init. Data-Array ***" << endl; cout << "xa = " << xa << endl; /* Anfangs-/Endpunkte der Daten */ cout << "xb = " << xb << endl; cout << "MD = " << MD << endl; /* Zahl der Datenpunkte */ cout << "h = " << h << endl; cout << "rho = " << rho << endl; x[1] = xa; data[1] = e2data(xa); for(int i = 2; i <= MD ; i++) { x[i] = xa + (i-1) * h; data[i] = e2data(x[i]); } x[MD] = xb; data[MD] = e2data(xb); cout << "*** End: Init. Data-Array ***" << endl; cout << '\v' ; /* Kontrollausgabe, Datenausgabe */ for(int i = 1; i <= MD; i++) { DataError = fabs(data[i] - e2(x[i]))/fabs(e2(x[i])); DataError *= 100.0; out1 << i << '\t' << x[i] << '\t' << data[i] << '\t' << e2(x[i]) << '\t' << DataError << endl; } cout << "*** Begin: Interpol. *** " << endl; intlinear(x,data,MD,y2d); for(int i = 1; i <= MD; i++) outs << i << '\t' << y2d[i] << endl; cout << "*** End: Interpol. *** " << endl; cout << '\v'; for(int j = 0; j <= M; j++) { step = dble(mpstep); x0 = x1 + j * step; datlinpol = linint(x,data,y2d,MD,x0); e2core = e2(x0); Error_splint = fabs(datlinpol - e2core)/fabs(e2core); Error_splint *= 100.0; out << x0 << '\t' << datlinpol << '\t' << e2core << '\t' << Error_splint << endl; } /* REGULARISIERUNG */ double xi; mp_real mp_regsum, mpdata, mpError, mpreg; double regsum, Error, Reg; step2 = (xr2 - xr1)/N; cout <<"*** Begin: Regularisation ***" << endl; cout << "b1 = " << b1 << endl; cout << "b = " << b ; cout << "x1 = " << xr1 << endl; cout << "x2 = " << xr2 << endl; cout << "N = " << N << endl; cout << "h = " << step2 << endl; cout << '\v' ; for(int jj = 0; jj <= N; jj++) { mp_regsum = mp_real(0.0); x0 = xr1 + jj * step2; for(int j = 0; j <= M; j++) { xi = x1 + j * step; xi = x0 - xi; datlinpol = linint(x,data,y2d,MD,xi); mpdata = mp_real(datlinpol); mp_regsum += mpregKern[j] * mpdata; } mp_regsum *= mpstep; mp_regsum *= factor; mpreg = mpRegexakt(mp_real(x0),b); mpError = abs(mp_regsum - mpreg)/abs(mpreg); mpError *= mp_real(100.0); regsum = dble(mp_regsum); Error = dble(mpError); Reg = dble(mpreg); cout << x0 << endl; cout << mpreg << mp_regsum << mpError << endl; rout << x0 << '\t' << Reg << '\t' << regsum << '\t' << Error << '\t' << b1 << endl; } cout <<"*** End: Regularisation ***" << endl; free_dvector(y2d,1,MD); free_dvector(data,1,MD); free_dvector(x,1,MD); delete [] mpregKern; return 0; }
int main() { cout << setiosflags(ios::uppercase); ofstream out("LIPGauss.out"); out << setiosflags(ios::uppercase); ofstream out1("DATENGaussLip.out"); out1 << setiosflags(ios::uppercase); ofstream outs("Y2D.out"); outs << setiosflags(ios::uppercase); ofstream rout("RegGaussLIP.out"); rout << setiosflags(ios::uppercase); cout << "*** Filter: Gauss *** " << endl; cout << "*** Imaginaerteil *** " << endl; mp_init(); cout << "*** Precision = " << mpipl << " ***" << endl; // pi aus der Bibliothek !!! mp_real pi = mppic; mp_real pi2 = pi * pi; static mp_real factor; static double dpi = 4.0 * atan(1.0); static double dfactor; int M, MD, N; double b1, xa, xb, h, x1, x2, hreg; mp_real b; /* Parameter einlesen */ cin >> b1; cin >> xa >> xb >> MD; cin >> hreg >> N; cin >> x1 >> x2 >> M; b = mp_real(b1); /* Vorfaktor */ factor = mp_real(2.0)*b/power(pi,mp_real(1.5)); factor *= exp(mp_real(0.25) * pi2 * b * b); dfactor = 2.0 * (b1/pow(dpi,1.5)) * exp(b1*b1*dpi*dpi*.25); /* DATEN UND SPLINE-ROUTINE */ /* 1. Ableitung der Funktion an den Eckpunkten */ double yp1, ypn; double x0, dataspl, Error_splint, DataError, e2core; /* Index der Vektoren beginnt mit 1 und *nicht* mit 0 */ double* y2d = dvector(1,MD); /* 2.Ableitung der SPL-Funktion */ double* data = dvector(1,MD); /* Datenvektor */ double* x = dvector(1,MD); /* x-Vektor */ /* Nebenbedingung natuerliche Splinefunktion setzen */ yp1 = ypn = 1E30; // yp1 = ypn = 0.0 ; /* Datenarrays fuellen */ h = (xb - xa)/(MD - 1); double rho = MD/(xb - xa); cout << '\v'; cout << "*** Begin: Init. Data-Array ***" << endl; cout << "xa = " << xa << endl; /* Anfangs-/Endpunkte der Daten */ cout << "xb = " << xb << endl; cout << "MD = " << MD << endl; /* Zahl der Datenpunkte */ cout << "h = " << h << endl; cout << "rho = " << rho << endl; x[1] = xa; data[1] = e2data(xa); for(int i = 2; i <= MD ; i++) { x[i] = xa + (i-1) * h; data[i] = e2data(x[i]); //cout << i << '\t' << x[i] << '\t' << data[i] << '\t' << e2data(x[i]) << endl; } x[MD] = xb; data[MD] = e2data(xb); cout << "*** End: Init. Data-Array ***" << endl; cout << '\v' ; /* Kontrollausgabe, Datenausgabe */ for(int i = 1; i <= MD; i++) { DataError = fabs(data[i] - e2(x[i]))/fabs(e2(x[i])); DataError *= 100.0; out1 << i << '\t' << x[i] << '\t' << data[i] << '\t' << e2(x[i]) << '\t' << DataError << endl; } cout << "*** Begin: LinInt. *** " << endl; intlinear(x,data,MD,y2d); for(int i = 1; i <= MD; i++) outs << i << '\t' << y2d[i] << endl; cout << "*** End: LinInt *** " << endl; cout << '\v'; // static double step = (xb - xa)/MD; double xmax = N * hreg ; for(int j = 0; j <= (2 * N); j++) { x0 = j * hreg - xmax ; dataspl = linint(x,data,y2d,MD,x0); e2core = e2(x0); Error_splint = fabs(dataspl - e2core)/fabs(e2core); Error_splint *= 100.0; // cout << x0 << '\t' << dataspl << '\t' << e2core << '\t' << Error_splint << endl; out << x0 << '\t' << dataspl << '\t' << e2core << '\t' << Error_splint << endl; } /* REGULARISATION */ mp_real mp_regsum, mpdataup, mpdatadown , fu, fd, mpx0, zu, zd; mp_real mpx1, mpx2; mp_real mp_theoreg, mp_Error; double theoreg, Errorel; static mp_real mph = mp_real(hreg); static mp_real mprstep; double dregsum, x0d, dzu, dzd; mpx1 = mp_real(x1); mpx2 = mp_real(x2); mprstep = (mpx2 - mpx1)/mp_real(M); cout <<"*** Begin: Regularisation ***" << endl; cout << "b = " << b1 << endl; cout << "N = " << N << endl; cout << "h = " << hreg << endl; cout << "xmax = " << N * hreg << endl; cout << "hreg = " << mph << endl; cout << "x1 = " << x1 << endl; cout << "x2 = " << x2 << endl; cout << "h = " << mprstep << endl; cout << "dFaktor = " << dfactor << endl; cout << "Faktor = " << factor << endl; for(int jj = 0; jj <= M; jj++) { mpx0 = mpx1 + jj * mprstep; x0d = dble(mpx0); mpdataup = mp_real(linint(x,data,y2d,MD,x0d)); mp_regsum = mpregkerne2(mpx0, mpx0 , b) * mpdataup; for(int j = 1; j <= N; j++) { zu = mpx0 + j * mph; dzu = dble(zu); zd = mpx0 - j * mph; dzd = dble(zd); mpdataup = mp_real(linint(x,data,y2d,MD,dzu)); fu = mpregkerne2(zu,mpx0,b) * mpdataup; mpdatadown = mp_real(linint(x,data,y2d,MD,dzd)); fd = mpregkerne2(zd,mpx0,b) * mpdatadown; mp_regsum += (fu + fd) ; } mp_regsum *= mph; mp_regsum *= factor; mp_theoreg = mpRegexakt(mpx0, b); mp_Error = abs(mp_regsum - mp_theoreg)/abs(mp_theoreg); mp_Error *= mp_real(100.0); dregsum = dble(mp_regsum); theoreg = dble(mp_theoreg); Errorel = dble(mp_Error); cout << mpx0 << mp_theoreg << mp_regsum << mp_Error << endl; rout << x0d << '\t' << theoreg << '\t' << dregsum << '\t' << Errorel << '\t' << b1 << endl; } cout <<"*** End: Regularisation ***" << endl; return 0; }