const Value & SimpleTensorEngine::join(const Value &a, const Value &b, join_fun_t function, Stash &stash) const { if (a.is_double() && b.is_double()) { return stash.create<DoubleValue>(function(a.as_double(), b.as_double())); } return to_value(SimpleTensor::join(to_simple(a, stash), to_simple(b, stash), function), stash); }
const Value & SimpleTensorEngine::map(const Value &a, map_fun_t function, Stash &stash) const { if (a.is_double()) { return stash.create<DoubleValue>(function(a.as_double())); } return to_value(to_simple(a, stash).map(function), stash); }
/** * Main routine, setup and execute daemon, print errors. * * @param argc,argv * The command line arguments * @return * An exit code * @see Exit */ int main(int argc, char * argv[]) try { read_args(argc, argv); init(); print_sysctls(); run(); return to_value(Exit::OK); } catch (Exception & e) { if (e.msg != "") { std::cerr << "loadrec: " << e.msg << '\n'; } return to_value(e.exitcode); } catch (sys::sc_error<sys::ctl::error> e) { std::cerr << "loadrec: untreated sysctl failure: " << e.c_str() << '\n'; return to_value(Exit::EEXCEPT); } catch (...) { std::cerr << "loadrec: untreated failure\n"; return to_value(Exit::EEXCEPT); }
void dual_box_flux_to_cell(DeviceT const & device, CellT const & cell, FacetContainerT const & facets, CellSetterT & cell_setter, FacetAccessorT const & facet_access) { typedef typename viennagrid::result_of::iterator<FacetContainerT>::type FacetOnCellIterator; typedef typename DeviceT::mesh_type MeshType; typedef typename FacetOnCellIterator::value_type FacetType; typedef typename viennagrid::result_of::point<CellT>::type PointType; typedef typename viennagrid::result_of::const_coboundary_range<MeshType, FacetType, CellT>::type CellOnFacetContainer; viennashe::math::dense_matrix<double> M(PointType::dim, PointType::dim); std::vector<double> b(PointType::dim); std::vector<PointType> normals(facets.size()); std::vector<double> flux_contributions(facets.size()); // for all edges connected with the current vertex std::size_t facet_ctr = 0; for (FacetOnCellIterator focit = facets.begin(); focit != facets.end(); ++focit, ++facet_ctr ) { flux_contributions[facet_ctr] = facet_access(*focit); normals[facet_ctr] = outer_cell_normal_at_facet(cell, *focit); // vector along the edge pointing away from Vertex 'to' // flip orientation of flux contribution if global orientation is different: CellOnFacetContainer cells_on_facet(device.mesh(), viennagrid::handle(device.mesh(), *focit)); if (&cells_on_facet[0] != &cell) flux_contributions[facet_ctr] *= -1.0; } // assemble mass matrix and rhs: M_i * V_i = rhs_i for ( std::size_t i = 0; i < static_cast<std::size_t>(PointType::dim); ++i ) { for ( std::size_t j = 0; j < static_cast<std::size_t>(PointType::dim); ++j ) { for ( std::size_t k = 0; k < normals.size(); ++k ) M(i, j) += normals[k][i] * normals[k][j]; } for ( std::size_t k = 0; k < normals.size(); ++k ) b[i] += normals[k][i] * flux_contributions[k]; } std::vector<double> to_value(PointType::dim); // default: zero vector std::vector<double> result = viennashe::solvers::solve(M, b); for (std::size_t i=0; i<result.size(); ++i) to_value[i] = result[i]; cell_setter(cell, to_value); } // dual_box_flux_to_cell
bool json_tree_builder::process_first(const token &token_) { auto jval = to_value(token_); if (jval == nullptr || (jval->jtype() != json_type::J_OBJECT && jval->jtype() != json_type::J_ARRAY)) { // object or array expected return false; } _current = jval; // object or array _accept_value = _current->jtype() == json_type::J_ARRAY; return true; }
void run(Vector v, int *r){ int size = Vector_size(v); struct Inst *instrs = Vector_data(v); for(int i = 0;i < size; ++i){ struct Inst *inst = &instrs[i]; switch(inst->op_code){ case cpy: r[inst->y.x] = to_value(r, inst->x); break; case inc: ++r[inst->x.x]; break; case dec: --r[inst->x.x]; break; case jnz: if (to_value(r, inst->x)) i += to_value(r, inst->y)-1; break; default: printf("Error bad instruction\n"); } } }
Value::UP SimpleTensorEngine::decode(nbostream &input) const { return to_value(SimpleTensor::decode(input)); }
bool json_tree_builder::insert_to_array(const token &token_) { auto arr = std::static_pointer_cast< json_array >(_current); switch (token_.type()) { case T_COMMA: if (_accept_comma) { _accept_comma = false; _accept_end = false; _accept_value = true; return true; } else { return false; } break; case T_RBRACKET: if (_accept_end) { if (_parents.empty()) { // parsing successfully finished _finished = true; return true; } _current = _parents.top(); _parents.pop(); _accept_colon = false; _accept_comma = true; _accept_end = true; _accept_name = false; _accept_value = _current->jtype() == json_type::J_ARRAY; return true; } else { return false; } break; case T_LBRACE: case T_LBRACKET: if (_accept_value) { auto new_val = to_value(token_); _parents.push(_current); _current = new_val; arr->insert(new_val); _accept_colon = false; _accept_comma = false; _accept_end = true; _accept_name = true; _accept_value = new_val->jtype() == json_type::J_ARRAY; return true; } else { return false; } break; case T_STR: case T_NUM: case T_TRUE: case T_FALSE: case T_NULL: if (_accept_value) { arr->insert(to_value(token_)); _accept_comma = true; _accept_end = true; _accept_value = false; return true; } else { return false; } break; default: return false; // unexpected token } return false; // should not get here }
bool json_tree_builder::insert_to_object(const token &token_) { auto obj = std::static_pointer_cast< json_object >(_current); switch (token_.type()) { case T_STR: if (_accept_name) { if (obj->contains(token_.text())) throw std::logic_error("duplicit key: " + token_.text()); // duplicit key name obj->insert(token_.text()); _accept_colon = true; _accept_comma = false; _accept_name = false; _accept_value = false; _accept_end = false; return true; } else if (_accept_value) { auto str = to_value(token_); obj->insert(str); _accept_colon = false; _accept_comma = true; _accept_name = false; _accept_value = false; _accept_end = true; return true; } else { // unexpected token return false; } break; case T_COLON: if (_accept_colon) { _accept_colon = false; _accept_comma = false; _accept_end = false; _accept_name = false; _accept_value = true; return true; } else { return false; } break; case T_LBRACE: // new object if (_accept_value) { auto new_obj = to_value(token_); _parents.push(_current); _current = new_obj; obj->insert(new_obj); _accept_colon = false; _accept_comma = false; _accept_end = true; _accept_name = true; _accept_value = false; return true; } else { return false; } break; case T_COMMA: if (_accept_comma) { _accept_colon = false; _accept_comma = false; _accept_end = true; // not valid JSON _accept_name = true; _accept_value = false; return true; } else { return false; } break; case T_LBRACKET: // new array if (_accept_value) { auto new_arr = to_value(token_); _parents.push(_current); _current = new_arr; obj->insert(new_arr); _accept_colon = false; _accept_comma = false; _accept_end = true; _accept_name = false; _accept_value = true; return true; } else { return false; } break; case T_RBRACE: if (_accept_end) { if (_parents.empty()) { // parsing successfully finished _finished = true; return true; } _current = _parents.top(); _parents.pop(); _accept_colon = false; _accept_comma = true; _accept_end = true; _accept_name = true; _accept_value = _current->jtype() == json_type::J_ARRAY; return true; } else { return false; } break; case T_TRUE: case T_FALSE: case T_NULL: case T_NUM: if (_accept_value) { obj->insert(to_value(token_)); _accept_colon = false; _accept_comma = true; _accept_end = true; _accept_name = false; _accept_value = false; return true; } else { return false; } break; default: return false; // unexpected token } return false; // should not get here }
Value::UP SimpleTensorEngine::from_spec(const TensorSpec &spec) const { return to_value(SimpleTensor::create(spec)); }
const Value & SimpleTensorEngine::rename(const Value &a, const std::vector<vespalib::string> &from, const std::vector<vespalib::string> &to, Stash &stash) const { return to_value(to_simple(a, stash).rename(from, to), stash); }
const Value & SimpleTensorEngine::concat(const Value &a, const Value &b, const vespalib::string &dimension, Stash &stash) const { return to_value(SimpleTensor::concat(to_simple(a, stash), to_simple(b, stash), dimension), stash); }
const Value & SimpleTensorEngine::reduce(const Value &a, Aggr aggr, const std::vector<vespalib::string> &dimensions, Stash &stash) const { return to_value(to_simple(a, stash).reduce(Aggregator::create(aggr, stash), dimensions), stash); }
bool is_lt(expr const & a, expr const & b, bool use_hash) { if (is_eqp(a, b)) return false; unsigned da = get_depth(a); unsigned db = get_depth(b); if (da < db) return true; if (da > db) return false; if (a.kind() != b.kind()) return a.kind() < b.kind(); if (use_hash) { if (a.hash() < b.hash()) return true; if (a.hash() > b.hash()) return false; } if (a == b) return false; if (is_var(a)) return var_idx(a) < var_idx(b); switch (a.kind()) { case expr_kind::Var: lean_unreachable(); // LCOV_EXCL_LINE case expr_kind::Constant: return const_name(a) < const_name(b); case expr_kind::App: if (num_args(a) != num_args(b)) return num_args(a) < num_args(b); for (unsigned i = 0; i < num_args(a); i++) { if (arg(a, i) != arg(b, i)) return is_lt(arg(a, i), arg(b, i), use_hash); } lean_unreachable(); // LCOV_EXCL_LINE case expr_kind::Lambda: // Remark: we ignore get_abs_name because we want alpha-equivalence case expr_kind::Pi: if (abst_domain(a) != abst_domain(b)) return is_lt(abst_domain(a), abst_domain(b), use_hash); else return is_lt(abst_body(a), abst_body(b), use_hash); case expr_kind::Type: return ty_level(a) < ty_level(b); case expr_kind::Value: return to_value(a) < to_value(b); case expr_kind::Let: if (let_type(a) != let_type(b)) { return is_lt(let_type(a), let_type(b), use_hash); } else if (let_value(a) != let_value(b)){ return is_lt(let_value(a), let_value(b), use_hash); } else { return is_lt(let_body(a), let_body(b), use_hash); } case expr_kind::MetaVar: if (metavar_name(a) != metavar_name(b)) { return metavar_name(a) < metavar_name(b); } else { auto it1 = metavar_lctx(a).begin(); auto it2 = metavar_lctx(b).begin(); auto end1 = metavar_lctx(a).end(); auto end2 = metavar_lctx(b).end(); for (; it1 != end1 && it2 != end2; ++it1, ++it2) { if (it1->kind() != it2->kind()) { return it1->kind() < it2->kind(); } else if (it1->s() != it2->s()) { return it1->s() < it2->s(); } else if (it1->is_inst()) { if (it1->v() != it2->v()) return is_lt(it1->v(), it2->v(), use_hash); } else { if (it1->n() != it2->n()) return it1->n() < it2->n(); } } return it1 == end1 && it2 != end2; } } lean_unreachable(); // LCOV_EXCL_LINE }
>> local.doc_copyright_year [state.values.entry(ph::arg1, doc_info_tags::copyright_year_end)] >> space ) >> !cl::ch_p(',') >> space ) >> to_value(doc_info_tags::copyright_name) [ local.doc_copyright_holder ] >> !cl::ch_p(',') >> space ) ; local.attribute_rules[doc_info_attributes::copyright] = &local.doc_copyright; local.doc_phrase = to_value() [ nested_phrase ]; local.attribute_rules[doc_info_attributes::purpose] = &local.doc_phrase; local.attribute_rules[doc_info_attributes::license] = &local.doc_phrase; local.doc_author = '[' >> space >> to_value(doc_info_tags::author_surname) [*(~cl::eps_p(',') >> local.char_)] >> ',' >> space >> to_value(doc_info_tags::author_first) [*(~cl::eps_p(']') >> local.char_)] >> ']' ; local.doc_authors =
//------------------------------------------------------------------------- value &value::operator=(const value_ref &v) { *this = to_value(v); return *this; }
virtual expr get_type() const { return to_value(m_value).get_type(); }
virtual name get_name() const { return to_value(m_value).get_name(); }
virtual bool in_builtin_set(expr const & v) const { return is_value(v) && typeid(to_value(v)) == typeid(to_value(m_representative)); }
virtual name get_name() const { return to_value(m_representative).get_name(); }