std::vector<track> parse_cue_file(char const *path) { std::ifstream cue_file; cue_file.open(path); std::vector<std::string> file; for (std::string line; std::getline(cue_file, line);) file.push_back(line); cue_file.close(); interpreter interp(file); return interp.track_list; }
void SetVtx(TLITVERTEX &v, TLITVERTEX &v1, TLITVERTEX &v2, float r) { v.x = interp(v1.x,v2.x,r); v.y = interp(v1.y,v2.y,r); //v.z = (v1.z-r*v2.z)/(1-r); v.dcSpecular = v2.dcSpecular; //fix me here v.r = (uint8)(interp((int)v1.r,(int)v2.r,r)); v.g = (uint8)(interp((int)v1.g,(int)v2.g,r)); v.b = (uint8)(interp((int)v1.b,(int)v2.b,r)); v.a = (uint8)(interp((int)v1.a,(int)v2.a,r)); for( int i=0; i<2; i++ ) { v.tcord[i].u = interp(v1.tcord[i].u,v2.tcord[i].u,r); v.tcord[i].v = interp(v1.tcord[i].v,v2.tcord[i].v,r); } }
void CKeyframe::Update(float timestep) { if (!loaded) return; if (!active) return; keytime += timestep; if (keytime >= frames[keyidx].val[0]) { keyidx++; keytime = 0; } if (keyidx >= frames.size()-1 || frames.size() < 2) { active = false; return; } double frac; TVector3d pos; CCharShape *shape = g_game.character->shape; if (std::fabs(frames[keyidx].val[0]) < 0.0001) frac = 1.0; else frac = (frames[keyidx].val[0] - keytime) / frames[keyidx].val[0]; pos.x = interp(frac, frames[keyidx].val[1], frames[keyidx+1].val[1]) + refpos.x; pos.z = interp(frac, frames[keyidx].val[3], frames[keyidx+1].val[3]) + refpos.z; pos.y = interp(frac, frames[keyidx].val[2], frames[keyidx+1].val[2]); pos.y += Course.FindYCoord(pos.x, pos.z); shape->ResetRoot(); shape->ResetJoints(); g_game.player->ctrl->cpos = pos; double disp_y = pos.y + TUX_Y_CORR + heightcorr; shape->ResetNode(0); shape->TranslateNode(0, TVector3d(pos.x, disp_y, pos.z)); InterpolateKeyframe(keyidx, frac, shape); }
real32 dng_gain_map::Interpolate (int32 row, int32 col, uint32 plane, const dng_rect &bounds) const { dng_gain_map_interpolator interp (*this, bounds, row, col, plane); return interp.Interpolate (); }
void sfac_spag() { int nlu; fclose (fis); fis = NULL; fis=fopen(ficcdimp,"r"); if ( fis == NULL) { message(16); return; } nuli=0; while ( (nlu=lect_fis()) > 0 ) { if ( strncmp(ze, "PAGSUIV",7) == 0) break; } while ( (nlu=lect_fis()) > 0 ) { nmot = isolmot(ze,nlu); interp(); } }
inline Eigen::VectorXd interpolate(const Model & model, const Eigen::VectorXd & q0, const Eigen::VectorXd & q1, const double u) { Eigen::VectorXd interp(model.nq); for( Model::JointIndex i=1; i<(Model::JointIndex) model.nbody; ++i ) { InterpolateStep::run(model.joints[i], InterpolateStep::ArgsType (q0, q1, u, interp) ); } return interp; }
/** * Redirect the std out to this object */ void PythonScript::beginStdoutRedirect() { if (!redirectStdOut()) return; stdoutSave = PyDict_GetItemString(interp()->sysDict(), "stdout"); Py_XINCREF(stdoutSave); stderrSave = PyDict_GetItemString(interp()->sysDict(), "stderr"); Py_XINCREF(stderrSave); interp()->setQObject(this, "stdout", interp()->sysDict()); interp()->setQObject(this, "stderr", interp()->sysDict()); }
static double interp_cubic_coords(const double* src, double t) { double ab = interp(src[0], src[2], t); double bc = interp(src[2], src[4], t); double cd = interp(src[4], src[6], t); double abc = interp(ab, bc, t); double bcd = interp(bc, cd, t); double abcd = interp(abc, bcd, t); return abcd; }
static double romberg(double (*fcn)(double), double eps) { int j,j1; double sum,errsum=0,x[16],fx[16]; x[0]=1.0; for(j=0;j<16;j++){ j1=j+1; fx[j]=evalfn(fcn,j1); if(j1>=5){ interp(&x[j1-5],&fx[j1-5],&sum,&errsum); if(fabs(errsum)<eps*fabs(sum))return(sum);} x[j1]=x[j]/9.0; fx[j1]=fx[j];} sum=R_NaN; return(sum);}
/// linear interpolation of the function v = f(x, y) at points xi, yi /// assumes that x and y are strictly increasing Vector interp(const Vector& x, const Vector& y, const Matrix& v, const Vector& xi, double yi, InterpMethod interpMethod, ExtrapMethod extrapMethod) { unsigned M = x.size(); Vector result(M); if (M != v.size1()) { return result; } for (unsigned i = 0; i < M; ++i) { result(i) = interp(x, y, v, xi(i), yi, interpMethod, extrapMethod); } return result; }
/// linear interpolation of the function v = f(x, y) at points xi, yi /// assumes that x and y are strictly increasing Vector interp(const Vector& x, const Vector& y, const Matrix& v, double xi, const Vector& yi, InterpMethod interpMethod, ExtrapMethod extrapMethod) { unsigned N = y.size(); Vector result(N); if (N != v.size2()) { return result; } for (unsigned j = 0; j < N; ++j) { result(j) = interp(x, y, v, xi, yi(j), interpMethod, extrapMethod); } return result; }
/// linear interpolation of the function y = f(x) at points xi /// assumes that x is strictly increasing Vector interp(const Vector& x, const Vector& y, const Vector& xi, InterpMethod interpMethod, ExtrapMethod extrapMethod){ unsigned N = x.size(); Vector result(N); if (y.size() != N){ return result; } for (unsigned i = 0; i < N; ++i){ result(i) = interp(x, y, xi(i), interpMethod, extrapMethod); } return result; }
/* * relative curvature -> RGB value */ color_t crv2color(double in) { double h = crv_conv(in); if(crv_style == 0) // lines { if ( (0.101>h && h>0.09) || (0.201>h && h>0.19) || (0.301>h && h>0.29) || (0.401>h && h>0.39) || (0.501>h && h>0.49) || (0.601>h && h>0.59) || (0.701>h && h>0.69) || (0.801>h && h>0.79) || (0.901>h && h>0.89) ) return mkcolor3(0,0,0); else return mkcolor3(0.9f, 0.9f, 0.9f); } else if (crv_style == 1) // colors { // B -> C -> G -> Y -> R color_t c[5] = { {0.0f, 0.0f, 0.85f, 1.0f}, // blue {0.0f, 0.9f, 0.9f, 1.0f}, // cyan {0.0f, 0.75f, 0.0f, 1.0f}, // green {0.9f, 0.9f, 0.0f, 1.0f}, // yellow {0.85f, 0.0f, 0.0f, 1.0f} };// red if (h>=crv_scale[4]) return c[4]; else if (h<=crv_scale[0]) return c[0]; // blue else { int i; for(i=0;i<4;i++) if (crv_scale[i+1] >= h) break; double u = (h - crv_scale[i]) /(crv_scale[i+1] - crv_scale[i]); return interp(u, c[i], c[i+1]); } } else // gray scale { float u = (float) (0.9f-0.7f*h); // gray scale from 0.2 to 0.9 return mkcolor3(u,u,u); } }
uchar key_getchar(chardevice_t* dev){ uchar c; while(1){ if (nextchar) { c = nextchar; nextchar=0; return c; } //get and interpret next keycode interp(key_getcode(NULL)); } }
bool InterpolateConstrainedPath(Robot& robot,const vector<Config>& milestones,const vector<IKGoal>& ikGoals,vector<Config>& path,Real xtol) { if(ikGoals.empty()) { path = milestones; return true; } RobotSmoothConstrainedInterpolator interp(robot,ikGoals); interp.ftol = xtol*gConstraintToleranceScale; interp.xtol = xtol; GeneralizedCubicBezierSpline spline; if(!MultiSmoothInterpolate(interp,milestones,spline)) return false; path.resize(spline.segments.size()+1); path[0] = spline.segments[0].x0; for(size_t i=0;i<spline.segments.size();i++) path[i+1] = spline.segments[i].x3; return true; }
TEST(RealVectorFilter, InterpEvenOdd) { double inputData[] = {1, 0, -1, -2, -3, -4, -5, -6, -7}; int filterTaps[] = {1, 2, 3, 4, 5}; double expectedData[] = {1, 2, 3, 4, 5, 0, -1, -2, -3, -6, -9, -6, -11, -16, -9, -16, -23, -12, -21, -30, -15, -26, -37, -18, -31, -44, -21, -28, -35}; unsigned numElements = sizeof(inputData)/sizeof(inputData[0]); NimbleDSP::RealVector<double> buf(inputData, numElements); numElements = sizeof(filterTaps)/sizeof(filterTaps[0]); NimbleDSP::RealVector<double> filter(filterTaps, numElements); NimbleDSP::RealVector<double> input = buf; int rate = 3; interp(buf, rate, filter); EXPECT_EQ(input.size()*rate + filter.size() - rate, buf.size()); for (unsigned i=0; i<buf.size(); i++) { EXPECT_EQ(expectedData[i], buf[i]); } }
TEST(RealVectorMethods, ComplexInterpEvenOdd) { std::complex<double> inputData[] = {std::complex<double>(1, 2), std::complex<double>(0, 3), std::complex<double>(-1, 4), std::complex<double>(-2, 5), std::complex<double>(-3, 6), std::complex<double>(-4, 7), std::complex<double>(-5, 8), std::complex<double>(-6, 9), std::complex<double>(-7, 10)}; double filterTaps[] = {1, 2, 3, 4, 5}; std::complex<double> expectedData[] = {std::complex<double>(1, 2), std::complex<double>(2, 4), std::complex<double>(3, 6), std::complex<double>(4, 11), std::complex<double>(5, 16), std::complex<double>(0, 9), std::complex<double>(-1, 16), std::complex<double>(-2, 23), std::complex<double>(-3, 12), std::complex<double>(-6, 21), std::complex<double>(-9, 30), std::complex<double>(-6, 15), std::complex<double>(-11, 26), std::complex<double>(-16, 37), std::complex<double>(-9, 18), std::complex<double>(-16, 31), std::complex<double>(-23, 44), std::complex<double>(-12, 21), std::complex<double>(-21, 36), std::complex<double>(-30, 51), std::complex<double>(-15, 24), std::complex<double>(-26, 41), std::complex<double>(-37, 58), std::complex<double>(-18, 27), std::complex<double>(-31, 46), std::complex<double>(-44, 65), std::complex<double>(-21, 30), std::complex<double>(-28, 40), std::complex<double>(-35, 50), std::complex<double>(0, 0), std::complex<double>(0, 0)}; unsigned numElements = sizeof(inputData)/sizeof(inputData[0]); NimbleDSP::ComplexVector<double> buf(inputData, numElements); numElements = sizeof(filterTaps)/sizeof(filterTaps[0]); NimbleDSP::RealVector<double> filter(filterTaps, numElements); NimbleDSP::ComplexVector<double> input = buf; int rate = 3; interp(buf, rate, filter); EXPECT_EQ(input.size()*rate + filter.size() - rate, buf.size()); for (unsigned i=0; i<buf.size(); i++) { EXPECT_EQ(expectedData[i], buf[i]); } }
TEST(MonotoneCubicInterpolationTest, fitAkimaDataSet) { std::vector<double> x(11); std::vector<double> y(11); x[0] = 0; y[0] = 10; x[1] = 2; y[1] = 10; x[2] = 3; y[2] = 10; x[3] = 5; y[3] = 10; x[4] = 6; y[4] = 10; x[5] = 8; y[5] = 10; x[6] = 9; y[6] = 10.5; x[7] = 11; y[7] = 15; x[8] = 12; y[8] = 50; x[9] = 14; y[9] = 60; x[10] = 15; y[10] = 85; MonotoneCubicInterpolation interp(x, y); EXPECT_NEAR(interp.sample(0.), 10., tol); EXPECT_NEAR(interp.sample(2.), 10., tol); EXPECT_NEAR(interp.sample(3.), 10., tol); EXPECT_NEAR(interp.sample(5.), 10., tol); EXPECT_NEAR(interp.sample(6.), 10., tol); EXPECT_NEAR(interp.sample(8.), 10., tol); EXPECT_NEAR(interp.sample(9.), 10.5, tol); EXPECT_NEAR(interp.sample(11.), 15., tol); EXPECT_NEAR(interp.sample(12.), 50., tol); EXPECT_NEAR(interp.sample(14.), 60., tol); EXPECT_NEAR(interp.sample(15.), 85., tol); for (double z = 0; z <= 15.; z += .1) EXPECT_GE(interp.sampleDerivative(z), -tol); }
int main (int argc, char *argv[]) { context_init_default (); char *body = ""; if (argc > 1) { if (strcmp (argv[1], "-e") == 0) { body = argv[2]; } else { body = malloc (2 * 4096); FILE *in_file; if (!(in_file = fopen (argv[1], "r"))) { perror ("Error opening input file"); exit (1); } fread (body, 2, 4096, in_file); if (!feof (in_file)) { fprintf (stderr, "Error: file larger than current maximum size (8192).\n"); exit (1); } } struct cons *result = interp (sexp_parse_str (&ctx->symbols, body)); if (box_type (result) == &Q_z1) { return *((char *) result->first.p); } else { return 0; } } else { fprintf (stderr, "Interactive mode not implemented yet.\n"); return 0; } }
T interpolate(It xbegin, It xend, It ybegin, It yend, T xvalue) { auto upper = std::upper_bound(xbegin, xend, xvalue); if (upper == xbegin) return *ybegin; if (upper == xend) return *(yend - 1); auto lower = upper; std::advance(lower, -1); auto lowery = ybegin; std::advance(lowery, std::distance(xbegin, lower)); auto uppery = ybegin; std::advance(uppery, std::distance(xbegin, upper)); return interp( *lower, *upper, *lowery, *uppery, xvalue); }
uchar key_charkbhit(chardevice_t* dev){ while(1){ //if we have a character, then its ready if (nextchar){ return 1; } //if we have a keycode interpret it if (key_kbhit(NULL)) interp(key_getcode(NULL)); else return 0; } }
void LocalClient::interpolate_positions() { if (peers.num_peers() <= 0) { posupd_timer.begin(); // workaround, don't know what for though return; } static const float HALF_GRANULARITY = POSITION_UPDATE_GRANULARITY_MS/2.0; const float DT_COEFF = HALF_GRANULARITY/16.666; //float local_DT_COEFF = time_since_last_posupd_ms()/16.666; auto it = peers.begin(); while (it != peers.end()) { Car &car = it->second.car; interp(car, DT_COEFF); ++it; } }
double test_interp(NFunction& f1, NFunction& f2) { Interp interp(f1.quad, f2.quad); StopWatch timer; timer.start(); interp.apply(f1, f2); interp.apply(f1, f2); interp.apply(f1, f2); interp.apply(f1, f2); interp.apply(f1, f2); interp.apply(f1, f2); interp.apply(f1, f2); interp.apply(f1, f2); interp.apply(f1, f2); interp.apply(f1, f2); double time = timer.stop() / 10; return time; }
/// linear interpolation of the function v = f(x, y) at points xi, yi /// assumes that x and y are strictly increasing Matrix interp(const Vector& x, const Vector& y, const Matrix& v, const Vector& xi, const Vector& yi, InterpMethod interpMethod, ExtrapMethod extrapMethod) { unsigned M = x.size(); unsigned N = y.size(); Matrix result(M, N); if ((M != v.size1()) || (N != v.size2())) { return result; } for (unsigned i = 0; i < M; ++i) { for (unsigned j = 0; j < N; ++j) { result(i,j) = interp(x, y, v, xi(i), yi(j), interpMethod, extrapMethod); } } return result; }
std::string matches_regex(cmdline_param const & param, char const * value, void /*precpp::RE*/ const * regex) { precondition(regex != nullptr); pcrecpp::RE const & re = *reinterpret_cast<pcrecpp::RE const *>(regex); if (!re.FullMatch(value)) { auto pat = re.pattern(); pcrecpp::RE comment_pat("#\\s*(.*?)\n.*"); string name; if (comment_pat.FullMatch(pat, &name)) { pat = "<" + name + ">"; } else { pat = "\"" + pat + "\""; } return interp("Error with {1}=\"{2}\": expected a value matching regex {3}.", {param.get_preferred_name(), value, pat}); } return ""; }
void prim_interp(PRIM_PROTOTYPE) { struct inst *oper1, *oper2, *oper3, *rv; char buf[BUFFER_LEN]; CHECKOP(3); oper3 = POP(); /* string -- top stack argument */ oper2 = POP(); /* dbref -- trigger */ oper1 = POP(); /* dbref -- Program to run */ if (!valid_object(oper1) || Typeof(oper1->data.objref) != TYPE_PROGRAM) abort_interp("Bad program reference. (1)"); if (!valid_object(oper2)) abort_interp("Bad object. (2)"); if ((mlev < 3) && !permissions(ProgUID, oper2->data.objref)) abort_interp("Permission denied."); if (fr->level > 8) abort_interp("Interp call loops not allowed."); CHECKREMOTE(oper2->data.objref); strcpy(buf, match_args); strcpy(match_args, oper3->data.string? oper3->data.string->data : ""); rv = interp(player, DBFETCH(player)->location, oper1->data.objref, oper2->data.objref, PREEMPT, STD_HARDUID, 1); strcpy(match_args, buf); CLEAR(oper3); CLEAR(oper2); CLEAR(oper1); if (rv) { if (rv->type < PROG_STRING) { push(arg, top, rv->type, MIPSCAST (&rv->data.number)); } else { push(arg, top, rv->type, MIPSCAST (rv->data.string)); } } else { PushNullStr; } }
bool InterpolateAndTimeOptimize(const vector<Config>& configs, GeodesicManifold* space, VectorFieldFunction* constraint, Real constraintTolerance, const Vector& vmin,const Vector& vmax, const Vector& amin,const Vector& amax, TimeScaledBezierCurve& output) { if(constraint) { SmoothConstrainedInterpolator interp(space,constraint); interp.xtol = constraintTolerance; if(!MultiSmoothInterpolate(interp,configs,output.path)) return false; } else { GeneralizedCubicBezierSpline path; SplineInterpolate(configs,path.segments,space); path.durations.resize(path.segments.size()); for(size_t i=0;i+1<path.segments.size();i++) path.durations[i] = 1.0/path.durations.size(); //treat constraintTolerance as a resolution, discretize the curves into //n pieces int n=(int)Ceil(1.0/constraintTolerance); output.path.segments.resize(n); output.path.durations.resize(n); Config xp,vp,xn,vn; path.Eval(0,xp); path.Deriv(0,vp); for(int i=0;i<n;i++) { Real u2=Real(i+1)/Real(n); path.Eval(u2,xn); path.Deriv(u2,vn); output.path.segments[i].x0 = xp; output.path.segments[i].x3 = xn; output.path.segments[i].SetNaturalTangents(vp,vn); output.path.durations[i] = 1.0/Real(n); } swap(xp,xn); swap(vp,vn); } if(!output.OptimizeTimeScaling(vmin,vmax,amin,amax)) return false; return true; }
InterpolatorVec ReadInterpolatedLimits(const std::string& input_dir_name, Range& mass_range, Units units) { const auto& file_names = GetOrderedFileList(input_dir_name, ".*\\.root"); std::vector<std::vector<double>> limits(all_limit_quantiles.size()); std::set<double> masses; const double units_factor = GetUnitsFactor(units); if(!file_names.size()) throw exception("No input files are found."); for(const auto& file_entry : file_names) { const std::string& file_name = file_entry.second; const double mass = file_entry.first; std::cout << "Reading " << file_name << std::endl; if(masses.count(mass)) throw exception("More than one file with for the mass point = %1%") % mass; masses.insert(mass); std::shared_ptr<TFile> file(new TFile(file_name.c_str(), "READ")); std::shared_ptr<TTree> tree(dynamic_cast<TTree*>(file->Get("limit"))); double limit; float quantileExpected; tree->SetBranchAddress("limit", &limit); tree->SetBranchAddress("quantileExpected", &quantileExpected); for(Long64_t n = 0; n < tree->GetEntries(); ++n) { tree->GetEntry(n); const size_t quantile_id = GetQuantileId(quantileExpected); limits.at(quantile_id).push_back(limit * units_factor); } } const std::vector<double> mass_vec(masses.begin(), masses.end()); mass_range = Range(mass_vec.front(), mass_vec.back()); InterpolatorVec interps; for(size_t n = 0; n < limits.size(); ++n) { if(limits[n].size() != masses.size()) throw exception("Inconsistent input limits."); InterpolatorPtr interp(new ROOT::Math::Interpolator(mass_vec, limits[n], ROOT::Math::Interpolation::kCSPLINE)); interps.push_back(interp); } return interps; }
int main( int argc, char **argv ) { llvm::llvm_shutdown_obj shutdownTrigger; //llvm::sys::PrintStackTraceOnErrorSignal(); //llvm::PrettyStackTraceProgram X(argc, argv); // Set up the interpreter cling::Interpreter interp(argc, argv); if (interp.getOptions().Help) { return 0; } clang::CompilerInstance* CI = interp.getCI(); interp.AddIncludePath("."); for (size_t I = 0, N = interp.getOptions().LibsToLoad.size(); I < N; ++I) { interp.loadFile(interp.getOptions().LibsToLoad[I]); } bool ret = true; const std::vector<clang::FrontendInputFile>& Inputs = CI->getInvocation().getFrontendOpts().Inputs; // Interactive means no input (or one input that's "-") bool Interactive = Inputs.empty() || (Inputs.size() == 1 && Inputs[0].File == "-"); cling::UserInterface ui(interp); // If we are not interactive we're supposed to parse files if (!Interactive) { for (size_t I = 0, N = Inputs.size(); I < N; ++I) { ret = ui.getMetaProcessor()->executeFile(Inputs[I].File); } } else { cling::UserInterface ui(interp); ui.runInteractively(interp.getOptions().NoLogo); } return ret ? 0 : 1; }
int main(int argc, char** argv) { for(int i = 0; i < 32; i++) { registers[i] = getV<VW>(); } loop_body(); double acc = 0; for(int i = 0; i < ROUNDS; i++) { for(int j = 0; j < VL; j++) { interp(); acc += registers[ret_val][0]; } } printf("Result: %f\n", acc / (ROUNDS * VW * VL)); return 0; }