int main() { auto a = to_integral(42); auto b = to_integral(MyEnum::A); printf("%d\n", a); printf("%d\n", b); }
int SectionCurve::FillRequested(float val, int ind=-1){ lastval=val; if(ind>=0 && np<n){ pval.set(np-1,&val); to_integral(1); np++; } else{ to_integral(n-np); for(;np<n;np++)pval.add(&val,1); } return n-np; }
/// @brief Calculate A1 /// /// Calculate the probability of making a move divided by the /// probability of its reverse, that is: /// \f[a_1=\frac{move[i]}{\sum\limits_{i}move[i]}\f] /// /// @param move The type of move /// @return \f$a_1=\frac{move[i]}{\sum\limits_{i}move[i]}\f$ auto CalculateA1(const move_type move) const noexcept { auto total_moves = this->TotalMoves(); auto this_move = attempted_moves_[to_integral(move)]; // Set precision for initialization and assignment functions mpfr_set_default_prec(PRECISION); // Initialize for MPFR mpfr_t r1, r2, a1; mpfr_inits2(PRECISION, r1, r2, a1, nullptr); mpfr_init_set_ui(r1, this_move, MPFR_RNDD); // r1 = this_move mpfr_init_set_ui(r2, total_moves, MPFR_RNDD); // r2 = total_moves // The result mpfr_div(a1, r1, r2, MPFR_RNDD); // a1 = r1/r2 // std::cout << "A1 is " << mpfr_out_str(stdout, 10, 0, a1, MPFR_RNDD) // Convert mpfr_t total to Gmpzf result by using Gmpzf(double d) // Gmpzf result = Gmpzf(mpfr_get_d(a1, MPFR_RNDD)); // MP_Float result = MP_Float(mpfr_get_ld(a1, MPFR_RNDD)); auto result = mpfr_get_d(a1, MPFR_RNDD); // Free memory mpfr_clears(r1, r2, a1, nullptr); #ifndef NDEBUG std::cout << "TotalMoves() = " << total_moves << "\n"; std::cout << "A1 is " << result << "\n"; #endif return result; } // CalculateA1()
/// @brief Attempt a move of the selected type /// /// This function implements the core of the Metropolis-Hastings algorithm /// by generating a random number and comparing with the results of /// CalculateA1 and CalculateA2. If the move is accepted, this function /// calls make_move(). If not, it updates **attempted_moves_**. /// /// @param move The type of move void attempt_move(const move_type move) { // Calculate probability auto a1 = CalculateA1(move); // Make move if random number < probability auto a2 = CalculateA2(move); const auto trial_value = generate_probability(); // Convert to Gmpzf because trial_value will be set to 0 when // comparing with a1 and a2! // const auto trial = Gmpzf(static_cast<double>(trial_value)); const auto trial = static_cast<double>(trial_value); #ifndef NDEBUG std::cout << __PRETTY_FUNCTION__ << " called.\n"; std::cout << "trial_value = " << trial_value << "\n"; std::cout << "trial = " << trial << "\n"; #endif if (trial <= a1 * a2) { // Move accepted make_move(move); } else { // Move rejected // Increment attempted_moves_ ++attempted_moves_[to_integral(move)]; } #ifndef NDEBUG std::cout << __PRETTY_FUNCTION__ << " called.\n"; std::cout << "Attempting move.\n"; std::cout << "Move type = " << to_integral(move) << "\n"; std::cout << "Trial = " << trial << "\n"; std::cout << "A1 = " << a1 << "\n"; std::cout << "A2 = " << a2 << "\n"; std::cout << "A1*A2 = " << a1 * a2 << "\n"; std::cout << ((trial <= a1 * a2) ? "Move accepted." : "Move rejected.") << "\n"; print_run(); #endif } // attempt_move()
int SectionCurve::AddPointRequest(float x, float y){ to_integral(n-np); for(;np<n;np++){ pval.add(&lastval,1); } np=n; BoxedCurve::AddPoint(x,y); return n-np; }
mapnik::keys get_key(std::string const& name) { std::string name_copy(name); boost::algorithm::replace_all(name_copy,"_","-"); for (unsigned i=0; i< to_integral(keys::MAX_SYMBOLIZER_KEY) ; ++i) { property_meta_type const& item = key_meta[i]; if (name_copy == std::get<0>(item)) { return static_cast<mapnik::keys>(i); } } throw std::runtime_error("no key found for '" + name + "'"); return static_cast<mapnik::keys>(0); }
void Cube::internal_buffer_data(Abstract_material_ptr i_material) { const GLsizei vertices = 24; m_triangle_count = 36; // the 4 vertices of a box const GLfloat box[vertices][4] = { /* front */ { -m_size, -m_size, m_size, 1.0f }, { m_size, -m_size, m_size, 1.0f }, { m_size, m_size, m_size, 1.0f }, { -m_size, m_size, m_size, 1.0f }, /* left */ { -m_size, -m_size, -m_size, 1.0f }, { -m_size, -m_size, m_size, 1.0f }, { -m_size, m_size, m_size, 1.0f }, { -m_size, m_size, -m_size, 1.0f }, /* right */ { m_size, -m_size, m_size, 1.0f }, { m_size, -m_size, -m_size, 1.0f }, { m_size, m_size, -m_size, 1.0f }, { m_size, m_size, m_size, 1.0f }, /* top */ { -m_size, m_size, m_size, 1.0f }, { m_size, m_size, m_size, 1.0f }, { m_size, m_size, -m_size, 1.0f }, { -m_size, m_size, -m_size, 1.0f }, /* bottom */ { -m_size, -m_size, -m_size, 1.0f }, { m_size, -m_size, -m_size, 1.0f }, { m_size, -m_size, m_size, 1.0f }, { -m_size, -m_size, m_size, 1.0f }, /* back */ { m_size, -m_size, -m_size, 1.0f }, { -m_size, -m_size, -m_size, 1.0f }, { -m_size, m_size, -m_size, 1.0f }, { m_size, m_size, -m_size, 1.0f }, }; const GLuint boxindices[36] = { /* front */ 0, 1, 2, 2, 3, 0, /* left */ 4, 5, 6, 6, 7, 4, /* right */ 8, 9, 10, 10, 11, 8, /* top */ 12, 13, 14, 14, 15, 12, /* bottom */ 16, 17, 18, 18, 19, 16, /* back */ 20, 21, 22, 22, 23, 20, }; GLfloat normals[vertices][4]; // generate the normals calculate_normals(&box[0][0], vertices, &boxindices[0], m_triangle_count, &normals[0][0]); // buffer all data Shader_program * material_shader = i_material->get_shader(); glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id[to_integral(VBO_type::Position)]); glBufferData(GL_ARRAY_BUFFER, vertices * 4 * sizeof(GLfloat), box, GL_STATIC_DRAW); GLint vertex_attrib_location = material_shader->get_attribute_location(in_position); glEnableVertexAttribArray(vertex_attrib_location); glVertexAttribPointer(vertex_attrib_location, 4, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id[to_integral(VBO_type::Normal)]); glBufferData(GL_ARRAY_BUFFER, vertices * 4 * sizeof(GLfloat), normals, GL_STATIC_DRAW); GLint normals_attrib_location = material_shader->get_attribute_location(in_normal); glEnableVertexAttribArray(normals_attrib_location); glVertexAttribPointer(normals_attrib_location, 4, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vbo_id[to_integral(VBO_type::Index)]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_triangle_count * sizeof(GL_UNSIGNED_INT), boxindices, GL_STATIC_DRAW); // disable pointers & unbind buffers glDisableVertexAttribArray(vertex_attrib_location); glDisableVertexAttribArray(normals_attrib_location); glBindBuffer( GL_ARRAY_BUFFER, 0 ); glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); }
namespace mapnik { // tuple -> name, default value, enumeration to string converter lambda, target property type static const property_meta_type key_meta[to_integral(keys::MAX_SYMBOLIZER_KEY)] = { property_meta_type{ "gamma", 1.0, nullptr, property_types::target_double}, property_meta_type{ "gamma-method", static_cast<value_integer>(GAMMA_POWER), nullptr, property_types::target_integer}, property_meta_type{ "opacity", 1.0, nullptr, property_types::target_double}, property_meta_type{ "alignment", enumeration_wrapper(LOCAL_ALIGNMENT), [](enumeration_wrapper e) { return enumeration<pattern_alignment_enum,pattern_alignment_enum_MAX>(pattern_alignment_enum(e.value)).as_string();}, property_types::target_pattern_alignment}, property_meta_type{ "offset", 0.0, nullptr, property_types::target_double}, property_meta_type{ "comp-op", enumeration_wrapper(src_over), [](enumeration_wrapper e) { return *comp_op_to_string(composite_mode_e(e.value)); }, property_types::target_comp_op}, property_meta_type{ "clip", false, nullptr, property_types::target_bool}, property_meta_type{ "fill", mapnik::color(128,128,128), nullptr, property_types::target_color}, property_meta_type{ "fill-opacity", 1.0 , nullptr, property_types::target_double}, property_meta_type{ "stroke", mapnik::color(0,0,0), nullptr, property_types::target_color}, property_meta_type{ "stroke-width", 1.0 , nullptr, property_types::target_double}, property_meta_type{ "stroke-opacity", 1.0, nullptr, property_types::target_double}, property_meta_type{ "stroke-linejoin", enumeration_wrapper(MITER_JOIN), [](enumeration_wrapper e) { return enumeration<line_join_enum,line_join_enum_MAX>(line_join_enum(e.value)).as_string();}, property_types::target_double }, property_meta_type{ "stroke-linecap", enumeration_wrapper(BUTT_CAP), [](enumeration_wrapper e) { return enumeration<line_cap_enum,line_cap_enum_MAX>(line_cap_enum(e.value)).as_string();}, property_types::target_double }, property_meta_type{ "stroke-gamma", 1.0, nullptr, property_types::target_double }, property_meta_type{ "stroke-gamma-method",static_cast<value_integer>(GAMMA_POWER), nullptr, property_types::target_double }, property_meta_type{ "stroke-dashoffset", static_cast<value_integer>(0), nullptr, property_types::target_double }, property_meta_type{ "stroke-dasharray", false, nullptr, property_types::target_double }, property_meta_type{ "stroke-miterlimit", 4.0, nullptr, property_types::target_double }, property_meta_type{ "geometry-transform", false, nullptr, property_types::target_transform }, property_meta_type{ "line-rasterizer", enumeration_wrapper(RASTERIZER_FULL), [](enumeration_wrapper e) { return enumeration<line_rasterizer_enum,line_rasterizer_enum_MAX>(line_rasterizer_enum(e.value)).as_string();}, property_types::target_double }, property_meta_type{ "transform", false, nullptr, property_types::target_transform }, property_meta_type{ "spacing", 0.0, nullptr, property_types::target_double }, property_meta_type{ "max-error", 0.0, nullptr, property_types::target_double }, property_meta_type{ "allow-overlap",false, nullptr, property_types::target_bool }, property_meta_type{ "ignore-placement", false, nullptr, property_types::target_bool }, property_meta_type{ "width",static_cast<value_integer>(0), nullptr, property_types::target_double }, property_meta_type{ "height",static_cast<value_integer>(0), nullptr, property_types::target_double }, property_meta_type{ "file", "", nullptr, property_types::target_string }, property_meta_type{ "shield-dx", 0.0, nullptr, property_types::target_double }, property_meta_type{ "shield-dy", 0.0, nullptr, property_types::target_double }, property_meta_type{ "unlock-image",false, nullptr, property_types::target_bool }, property_meta_type{ "text-opacity", 1.0, nullptr, property_types::target_double }, property_meta_type{ "mode",false, nullptr, property_types::target_double }, property_meta_type{ "scaling", 1.0, nullptr, property_types::target_double }, property_meta_type{ "filter-factor", 1.0, nullptr, property_types::target_double }, property_meta_type{ "mesh-size", static_cast<value_integer>(0), nullptr, property_types::target_double }, property_meta_type{ "premultiplied", false, nullptr, property_types::target_bool }, property_meta_type{ "smooth", false, nullptr, property_types::target_double }, property_meta_type{ "simplify-algorithm", enumeration_wrapper(radial_distance), [](enumeration_wrapper e) { return *simplify_algorithm_to_string(simplify_algorithm_e(e.value));}, property_types::target_double }, property_meta_type{ "simplify-tolerance", 0.0, nullptr, property_types::target_double }, property_meta_type{ "halo-rasterizer", enumeration_wrapper(HALO_RASTERIZER_FULL), [](enumeration_wrapper e) { return enumeration<halo_rasterizer_enum,halo_rasterizer_enum_MAX>(halo_rasterizer_enum(e.value)).as_string();}, property_types::target_double }, property_meta_type{ "text-placements", false, nullptr, property_types::target_double }, property_meta_type{ "placement", enumeration_wrapper(MARKER_POINT_PLACEMENT), [](enumeration_wrapper e) { return enumeration<marker_placement_enum,marker_placement_enum_MAX>(marker_placement_enum(e.value)).as_string();}, property_types::target_double }, // FIXME - rename to "markers-placement-type" property_meta_type{ "multi-policy", enumeration_wrapper(MARKER_EACH_MULTI), [](enumeration_wrapper e) { return enumeration<marker_multi_policy_enum,marker_multi_policy_enum_MAX>(marker_multi_policy_enum(e.value)).as_string();}, property_types::target_double }, // FIXME - better naming ^^ property_meta_type{ "placement", enumeration_wrapper(CENTROID_POINT_PLACEMENT), [](enumeration_wrapper e) { return enumeration<point_placement_enum,point_placement_enum_MAX>(point_placement_enum(e.value)).as_string();}, property_types::target_double }, property_meta_type{ "colorizer", nullptr, nullptr, property_types::target_colorizer}, property_meta_type{ "halo-transform", false, nullptr, property_types::target_transform }, property_meta_type{ "num-columns", static_cast<value_integer>(0), nullptr, property_types::target_integer}, property_meta_type{ "start-column", static_cast<value_integer>(1), nullptr, property_types::target_integer}, property_meta_type{ "repeat-key", nullptr, nullptr, property_types::target_repeat_key}, property_meta_type{ "symbolizer-properties", nullptr, nullptr, property_types::target_group_symbolizer_properties} }; property_meta_type const& get_meta(mapnik::keys key) { return key_meta[static_cast<int>(key)]; } mapnik::keys get_key(std::string const& name) { std::string name_copy(name); boost::algorithm::replace_all(name_copy,"_","-"); for (unsigned i=0; i< to_integral(keys::MAX_SYMBOLIZER_KEY) ; ++i) { property_meta_type const& item = key_meta[i]; if (name_copy == std::get<0>(item)) { return static_cast<mapnik::keys>(i); } } throw std::runtime_error("no key found for '" + name + "'"); return static_cast<mapnik::keys>(0); } }