void on_future_ready_(Index i, threads::thread_id_type const& id, boost::mpl::true_) { if (lazy_values_[i].has_value()) { if (success_counter_) ++*success_counter_; // invoke callback function f_(i); } // keep track of ready futures on_future_ready_(id); }
ublas::matrix<double> dp2(const ublas::vector<double>& p) const { ublas::matrix<double> result(parameterCount(), parameterCount()); result.clear(); for (typename Data::const_iterator it=data_.begin(); it!=data_.end(); ++it) { std::complex<double> diffconj = conj(std::complex<double>(f_(it->x, p) - it->y)); ublas::vector<value_type> dp = f_.dp(it->x,p); ublas::matrix<value_type> dp2 = f_.dp2(it->x,p); result += 2 * real(diffconj*dp2 + outer_prod(conj(dp),dp)); } return result; }
ConditionalIterator<Iterator_t, Functor_t>& operator++() { if (iterator_ == end_) return *this; ++iterator_; while (iterator_ != end_ && !f_(*(iterator_))) { ++iterator_; } return *this; }
hpx::performance_counters::counter_value raw_counter::get_counter_value(bool reset) { hpx::performance_counters::counter_value value; value.value_ = f_(reset); // gather the current value reset_ = false; value.scaling_ = 1; value.scale_inverse_ = false; value.status_ = status_new_data; value.time_ = static_cast<boost::int64_t>(hpx::get_system_uptime()); value.count_ = ++invocation_count_; return value; }
void operator()( const tbb::blocked_range<size_t>& r) const { for( std::size_t i = r.begin(); i != r.end(); ++i) { typename View1::x_iterator srcIt1 = src1_.row_begin(i); typename View2::x_iterator srcIt2 = src2_.row_begin(i); typename View3::x_iterator srcIt3 = src3_.row_begin(i); typename View4::x_iterator dstIt = dst_.row_begin(i); for( int x = 0, e = dst_.width(); x < e; ++x) dstIt[x]=f_( srcIt1[x], srcIt2[x], srcIt3[x]); } }
Future<R> operator()(const UPID& pid, F&& f) { std::shared_ptr<Promise<R>> promise(new Promise<R>()); std::shared_ptr<std::function<void(ProcessBase*)>> f_( new std::function<void(ProcessBase*)>( [=](ProcessBase*) { promise->set(f()); })); internal::dispatch(pid, f_); return promise->future(); }
Future<R> dispatch(const UPID& pid, const std::function<Future<R>()>& f) { std::shared_ptr<Promise<R>> promise(new Promise<R>()); std::shared_ptr<std::function<void(ProcessBase*)>> f_( new std::function<void(ProcessBase*)>( [=](ProcessBase*) { promise->associate(f()); })); internal::dispatch(pid, f_); return promise->future(); }
ResultT operator()(::std::vector<ParamT> const& x) const { ResultT fx = f_(x); if (::std::isinf(x)) { DCS_EXCEPTION_THROW(::std::runtime_error, "Function evaluates to a non-real value"); } if (::std::isnan(x)) { DCS_EXCEPTION_THROW(::std::runtime_error, "Function evaluates to a NaN value"); } return fx; }
void do_run() { if (!f_) return; // do nothing if no deferred task is given try { f_(); // trigger action this->wait(); // wait for value to come back } catch (...) { this->set_exception(boost::current_exception()); } }
void Map::evalGen(const T** arg, T** res, int* iw, T* w) const { int n_in = this->n_in(), n_out = this->n_out(); const T** arg1 = arg+n_in; copy_n(arg, n_in, arg1); T** res1 = res+n_out; copy_n(res, n_out, res1); for (int i=0; i<n_; ++i) { f_(arg1, res1, iw, w, 0); for (int j=0; j<n_in; ++j) { if (arg1[j]) arg1[j] += f_.nnz_in(j); } for (int j=0; j<n_out; ++j) { if (res1[j]) res1[j] += f_.nnz_out(j); } } }
void operator () (const tbb::blocked_range<Index>& br) const { Counter curTick = tick_; for ( Index i = br.begin(); i < br.end(); ++i ) { // Call function f_(i); // Do progress bar maintenance if ( --curTick <= 0 ) { updateProgress(tick_); curTick = tick_; } } updateProgress(tick_ - curTick); }
void AsyncTimer::CallFunc(const boost::system::error_code & err) { if(err) { return ; } else { f_(); if(loop_) { t_.expires_at(t_.expires_at() + boost::posix_time::seconds(time_)); t_.async_wait(boost::bind(&AsyncTimer::CallFunc,this,boost::asio::placeholders::error)); } } }
void trigger() { LLCO_(info) << "typed_continuation<void>::trigger(" << this->get_id() << ")"; if (f_.empty()) { if (!this->get_id()) { HPX_THROW_EXCEPTION(invalid_status, "typed_continuation<void>::trigger", "attempt to trigger invalid LCO (the id is invalid)"); return; } trigger_lco_event(this->get_id(), this->get_addr()); } else { f_(this->get_id()); } }
void trigger_value(Result && result) { LLCO_(info) << "typed_continuation<Result>::trigger_value(" << this->get_id() << ")"; if (f_.empty()) { if (!this->get_id()) { HPX_THROW_EXCEPTION(invalid_status, "typed_continuation<Result>::trigger_value", "attempt to trigger invalid LCO (the id is invalid)"); return; } hpx::set_lco_value(this->get_id(), this->get_addr(), std::move(result)); } else { f_(this->get_id(), std::move(result)); } }
Foam::scalar Foam::NewtonSecantRoot<Func, Deriv>::root ( scalar xN ) const { if (0 == d_(xN)) { FatalErrorIn ( "Foam::scalar Foam::NewtonSecantRoot<Func, Deriv>::root\n" "(\n" " const scalar xN,\n" ") const" ) << "Jacobian equal to zero. f'(xN) = " << d_(xN) << abort(FatalError); } scalar xNp1; for (label nIter = 0; nIter < maxIter; ++nIter) { scalar fN = this->f_(xN); scalar dN = this->d_(xN); scalar dx = fN/dN; scalar xBar = xN - dx; xNp1 = xN - fN*fN/(dN*(fN - f_(xBar))); if (mag(xN - xNp1) <= this->eps_) { return xNp1; } xN = xNp1; } return xNp1; }
inline auto cify(F&& f, signature<R(A...)>) noexcept { static F f_(std::forward<F>(f)); static bool full; if (full) { f_.~F(); new (static_cast<void*>(&f_)) F(std::forward<F>(f)); } else { full = true; } return +[](A... args) noexcept(noexcept( std::declval<F>()(std::forward<A>(args)...))) { return f_(std::forward<A>(args)...); }; }
void QpToImplicit::init() { // Call the base class initializer ImplicitFunctionInternal::init(); // Free variable in the NLP MX u = MX::sym("u", input(iin_).sparsity()); // So that we can pass it on to createParent std::vector<MX> inputs; for (int i=0; i<nIn(); ++i) { if (i!=iin_) { stringstream ss; ss << "p" << i; inputs.push_back(MX::sym(ss.str(), input(i).sparsity())); } } MX p = veccat(inputs); // Dummy NLP objective MX nlp_f = 0; // NLP constraints std::vector< MX > args_call(nIn()); args_call[iin_] = u; for (int i=0, i2=0; i<nIn(); ++i) if (i!=iin_) args_call[i] = inputs[i2++]; MX nlp_g = f_(args_call).at(iout_); // We're going to use two-argument objective and constraints to allow the use of parameters MXFunction nlp("nlp", nlpIn("x", u, "p", p), nlpOut("f", nlp_f, "g", nlp_g)); Dict options; if (hasSetOption(optionsname())) options = getOption(optionsname()); // Create an NlpSolver instance solver_ = NlpSolver("nlpsolver", getOption(solvername()), nlp, options); }
/* Compared to operator(), this method avoids 2 floating point operations (we use average=0 and sigma=1 most of the time). The speed difference is noticeable. */ static Real standard_value(Real x) { Real z; if (x < x_low_ || x_high_ < x) { z = tail_value(x); } else { z = x - 0.5; Real r = z*z; z = (((((a1_*r+a2_)*r+a3_)*r+a4_)*r+a5_)*r+a6_)*z / (((((b1_*r+b2_)*r+b3_)*r+b4_)*r+b5_)*r+1.0); } // The relative error of the approximation has absolute value less // than 1.15e-9. One iteration of Halley's rational method (third // order) gives full machine precision. // #define REFINE_TO_FULL_MACHINE_PRECISION_USING_HALLEYS_METHOD #ifdef REFINE_TO_FULL_MACHINE_PRECISION_USING_HALLEYS_METHOD // error (f_(z) - x) divided by the cumulative's derivative const Real r = (f_(z) - x) * M_SQRT2 * M_SQRTPI * exp(0.5 * z*z); // Halley's method z -= r/(1+0.5*z*r); #endif return z; }
constexpr decltype(auto) operator()(Ts && ...xs) const { return f_( g_(), std::forward<Ts>(xs)...); }
void raw_counter::reset_counter_value() { f_(true); }
void operator()( viennagrid::detail::tag< viennagrid::static_pair<key_type, value_type> > ) { f_( viennagrid::get<key_type>(collection_) ); }
void operator ()(T &...t) { (*runs_)++; if(f_) f_(t...); }
FT operator() (const Point_3& p) const { return f_(p); }
result_type operator()(A1 a1, A2 a2) const { return f_(a1, a2); }
result_type operator()(A1 a1) const { return f_(a1); }
result_type operator()() const { return f_(); }
result_type operator()() { return f_(); }
constexpr decltype(auto) operator()(T1 && x1, T2 && x2, Ts && ...xs) const { return f_(g_(std::forward<T1>(x1)), g_(std::forward<T2>(x2)), std::forward<Ts>(xs)...); }
void run() { f_(); }
result_type operator()(A1 a1, A2 a2, A3 a3, A4 a4) const { return f_(a1, a2, a3, a4); }