本文整理汇总了C++中py::module类的典型用法代码示例。如果您正苦于以下问题:C++ module类的具体用法?C++ module怎么用?C++ module使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了module类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init_ex10
void init_ex10(py::module &m) {
// Vectorize all arguments of a function (though non-vector arguments are also allowed)
m.def("vectorized_func", py::vectorize(my_func));
// Vectorize a lambda function with a capture object (e.g. to exclude some arguments from the vectorization)
m.def("vectorized_func2",
[](py::array_dtype<int> x, py::array_dtype<float> y, float z) {
return py::vectorize([z](int x, float y) { return my_func(x, y, z); })(x, y);
}
);
// Vectorize a complex-valued function
m.def("vectorized_func3", py::vectorize(my_func3));
}
示例2: init_ex12
void init_ex12(py::module &m) {
/* Important: use the wrapper type as a template
argument to class_<>, but use the original name
to denote the type */
py::class_<PyExample12>(m, "Example12")
/* Declare that 'PyExample12' is really an alias for the original type 'Example12' */
.alias<Example12>()
.def(py::init<int>())
/* Reference original class in function definitions */
.def("run", &Example12::run)
.def("pure_virtual", &Example12::pure_virtual);
m.def("runExample12", &runExample12);
m.def("runExample12Virtual", &runExample12Virtual);
}
示例3: define_target
void define_target(py::module &m) {
// Disambiguate some ambigious methods
int (Target::*natural_vector_size_method)(const Type &t) const = &Target::natural_vector_size;
bool (Target::*supports_type1_method)(const Type &t) const = &Target::supports_type;
bool (Target::*supports_type2_method)(const Type &t, DeviceAPI device) const = &Target::supports_type;
auto target_class =
py::class_<Target>(m, "Target")
.def(py::init<>())
.def(py::init<const std::string &>())
.def(py::init<Target::OS, Target::Arch, int>())
.def(py::init<Target::OS, Target::Arch, int, std::vector<Target::Feature>>())
.def("__eq__", [](const Target &value, Target *value2) { return value2 && value == *value2; })
.def("__ne__", [](const Target &value, Target *value2) { return !value2 || value != *value2; })
.def_readwrite("os", &Target::os)
.def_readwrite("arch", &Target::arch)
.def_readwrite("bits", &Target::bits)
.def("__repr__", &target_repr)
.def("__str__", &Target::to_string)
.def("to_string", &Target::to_string)
.def("has_feature", &Target::has_feature)
.def("features_any_of", &Target::features_any_of, py::arg("features"))
.def("features_all_of", &Target::features_all_of, py::arg("features"))
.def("set_feature", &Target::set_feature, py::arg("f"), py::arg("value") = true)
.def("set_features", &Target::set_features, py::arg("features"), py::arg("value") = true)
.def("with_feature", &Target::with_feature, py::arg("feature"))
.def("without_feature", &Target::without_feature, py::arg("feature"))
.def("has_gpu_feature", &Target::has_gpu_feature)
.def("supports_type", supports_type1_method, py::arg("type"))
.def("supports_type", supports_type2_method, py::arg("type"), py::arg("device"))
.def("supports_device_api", &Target::supports_device_api, py::arg("device"))
.def("natural_vector_size", natural_vector_size_method, py::arg("type"))
.def("has_large_buffers", &Target::has_large_buffers)
.def("maximum_buffer_size", &Target::maximum_buffer_size)
.def("supported", &Target::supported)
.def_static("validate_target_string", &Target::validate_target_string, py::arg("name"));
;
m.def("get_host_target", &get_host_target);
m.def("get_target_from_environment", &get_target_from_environment);
m.def("get_jit_target_from_environment", &get_jit_target_from_environment);
m.def("target_feature_for_device_api", &target_feature_for_device_api);
}
示例4: wrap_messaging
void wrap_messaging(py::module &m) {
py::module mMessaging = m.def_submodule("messaging");
mMessaging.def("init_transport", &xmessaging::init_transport);
mMessaging.def("stop_transport", &xmessaging::stop_transport);
mMessaging.def("alloc_read_buffer", []() {
xmessaging::alloc_read_buffer(BUFFER_LEN);
});
mMessaging.def("dealloc_read_buffer", []() {
xmessaging::dealloc_read_buffer();
});
// this will change to a buffer object
mMessaging.def("send_bytes", [](py::buffer pb) {
py::buffer_info req = pb.request();
xmessaging::queue((const char*)req.ptr, req.size);
});
mMessaging.def("update", []() -> bool {
bool message_read = false;
char *buffer;
size_t buffer_len;
xmessaging::update(message_read, buffer, buffer_len);
if (message_read)
{
simulation::process_step(buffer, buffer_len);
}
return message_read;
});
}
示例5: define_module
void define_module(py::module &m) {
auto module_class = py::class_<Module>(m, "Module")
.def(py::init<const std::string &, const Target &>(), py::arg("name"), py::arg("target"))
.def("target", &Module::target)
.def("name", &Module::name)
.def("auto_schedule", &Module::auto_schedule)
.def("buffers", &Module::buffers)
.def("submodules", &Module::submodules)
.def("append", (void (Module::*)(const Buffer<> &)) &Module::append, py::arg("buffer"))
.def("append", (void (Module::*)(const Module &)) &Module::append, py::arg("module"))
.def("compile", &Module::compile, py::arg("outputs"))
.def("compile_to_buffer", &Module::compile_to_buffer)
.def("resolve_submodules", &Module::resolve_submodules)
.def("remap_metadata_name", &Module::remap_metadata_name)
.def("get_metadata_name_map", &Module::get_metadata_name_map)
.def("set_auto_schedule", &Module::set_auto_schedule)
// TODO: ExternalCode-related methods deliberately skipped for now.
// .def("append", (void (Module::*)(const ExternalCode &)) &Module::append, py::arg("external_code"))
// .def("external_code", &Module::external_code)
// TODO: Internal::LoweredFunc-related methods deliberately skipped for now.
// .def("functions", &Module::functions)
// .def("get_function_by_name", &Module::get_function_by_name, py::arg("name"))
// .def("append", (void (Module::*)(const Internal::LoweredFunc &)) &Module::append, py::arg("function"))
.def("__repr__", [](const Module &m) -> std::string {
std::ostringstream o;
o << "<halide.Module '" << m.name() << "'>";
return o.str();
})
;
m.def("link_modules", &link_modules, py::arg("name"), py::arg("modules"));
m.def("compile_standalone_runtime", (void (*)(const std::string &, Target)) &compile_standalone_runtime, py::arg("filename"), py::arg("target"));
m.def("compile_standalone_runtime", (Outputs (*)(const Outputs &, Target)) &compile_standalone_runtime, py::arg("outputs"), py::arg("target"));
// TODO: compile_multitarget() deliberately skipped for now.
}
示例6: init_ex9
void init_ex9(py::module &m) {
py::module m_sub = m.def_submodule("submodule");
m_sub.def("submodule_func", &submodule_func);
py::class_<A>(m_sub, "A")
.def(py::init<int>())
.def("__repr__", &A::toString);
py::class_<B>(m_sub, "B")
.def(py::init<>())
.def("get_a1", &B::get_a1, "Return the internal A 1", py::return_value_policy::reference_internal)
.def("get_a2", &B::get_a2, "Return the internal A 2", py::return_value_policy::reference_internal)
.def_readwrite("a1", &B::a1) // def_readonly uses an internal reference return policy by default
.def_readwrite("a2", &B::a2);
m.attr("OD") = py::module::import("collections").attr("OrderedDict");
}
示例7: python_export_igl_tetgen
void python_export_igl_tetgen(py::module &me) {
py::module m = me.def_submodule(
"tetgen", "Wrappers for libigl functions that use tetgen");
#include "../../py_igl/copyleft/tetgen/py_tetrahedralize.cpp"
}
示例8: python_export_igl_png
void python_export_igl_png(py::module &me) {
py::module m = me.def_submodule(
"png", "Wrappers for libigl functions that use png");
#include "../py_igl/png/py_readPNG.cpp"
#include "../py_igl/png/py_writePNG.cpp"
}
示例9: python_export_igl_embree
void python_export_igl_embree(py::module &me) {
py::module m = me.def_submodule(
"embree", "Wrappers for libigl functions that use embree");
#include "../py_igl/embree/py_ambient_occlusion.cpp"
#include "../py_igl/embree/py_reorient_facets_raycast.cpp"
#include "../py_igl/embree/py_line_mesh_intersection.cpp"
}
示例10: define_lambda
void define_lambda(py::module &m) {
// TODO: 'lambda' is a reserved word in Python, so we
// can't use it for a function. Using 'lambda_func' for now.
m.def("lambda_func", [](py::args args) -> Func {
auto vars = args_to_vector<Var>(args, 0, 1);
Expr e = args[args.size() - 1].cast<Expr>();
Func f("lambda" + Internal::unique_name('_'));
f(vars) = e;
return f;
});
}
示例11: init_ex4
void init_ex4(py::module &m) {
m.def("test_function", &test_function1);
m.def("test_function", &test_function2);
m.def("test_function", &test_function3);
m.attr("some_constant") = py::int_(14);
py::enum_<EMyEnumeration>(m, "EMyEnumeration")
.value("EFirstEntry", EFirstEntry)
.value("ESecondEntry", ESecondEntry)
.export_values();
py::class_<Example4> ex4_class(m, "Example4");
ex4_class.def_static("test_function", &Example4::test_function);
py::enum_<Example4::EMode>(ex4_class, "EMode")
.value("EFirstMode", Example4::EFirstMode)
.value("ESecondMode", Example4::ESecondMode)
.export_values();
m.def("return_bytes", &return_bytes);
m.def("print_bytes", &print_bytes);
}
示例12: import
bool Context::import(py::module m)
{
if (!m)
return false;
string name = PyModule_GetName(m.ptr());
if (!name.empty())
{
py_global[name.c_str()] = m;
}
return true;
}
示例13: pyqpp_cell_export
void pyqpp_cell_export (py::module m) {
py_cell_export<float>(m, "periodic_cell_f");
qpp::gen_cell<float, qpp::matrix3<float> >::py_export(
m, "point_group_f");
qpp::gen_cell<float, qpp::rotrans<float,false> >::py_export(
m, "crystal_group_f");
qpp::gen_cell<float, qpp::rotrans<float,true> >::py_export(
m, "finite_crystal_group_f");
qpp::array_group<qpp::matrix3<float> >::py_export(
m, "array_point_group_f");
qpp::array_group<qpp::rotrans<float,true> >::py_export(
m, "array_fincryst_group_f");
m.def("generator_form", py_generator_form<float, qpp::matrix3<float>,
qpp::array_group<qpp::matrix3<float> > > );
m.def("generator_form", py_generator_form<float, qpp::rotrans<float,true>,
qpp::array_group<qpp::rotrans<float,true> > >);
#ifdef PYTHON_EXP_EXT
py_cell_export<double>(m, "periodic_cell_d");
qpp::gen_cell<double, qpp::matrix3<double> >::py_export(
m, "point_group_d");
qpp::gen_cell<double, qpp::rotrans<double,false> >::py_export(
m, "crystal_group_d");
qpp::gen_cell<double, qpp::rotrans<double,true> >::py_export(
m, "finite_crystal_group_d");
qpp::array_group<qpp::matrix3<double> >::py_export(
m, "array_point_group_d");
qpp::array_group<qpp::rotrans<double,true> >::py_export(
m, "array_fincryst_group_d");
m.def("generator_form", py_generator_form<double, qpp::matrix3<double>,
qpp::array_group<qpp::matrix3<double> > >);
m.def("generator_form", py_generator_form<double, qpp::rotrans<double,true>,
qpp::array_group<qpp::rotrans<double,true> > >);
#endif
}
示例14: wrap_world_map
// World map is generally a point of danger
// A global static contains all of the tiles
// Python accesses those by reference, and is not necessarily aware of mutations to the global static map of tiles
void wrap_world_map(py::module &m)
{
py::module mMap = m.def_submodule("map");
mMap.def("get_map", &world_map::get_map, py::return_value_policy::reference);
mMap.def("get_tile", &world_map::get_tile, py::return_value_policy::reference);
mMap.def("tile_owner", &world_map::tile_owner);
mMap.def("get_map_size", &world_map::get_map_size);
mMap.def("save_file_fb", &world_map::save_file_fb);
mMap.def("for_each_tile", [](py::function func) {
auto fp = [&func](const sf::Vector3i& coord, const Tile& tile) { func(coord, tile); };
world_map::for_each_tile(fp);
});
}
示例15: init_ex11
void init_ex11(py::module &m) {
m.def("kw_func", &kw_func, py::arg("x"), py::arg("y"));
m.def("kw_func2", &kw_func, py::arg("x") = 100, py::arg("y") = 200);
m.def("kw_func3", [](const char *) { }, py::arg("data") = std::string("Hello world!"));
/* A fancier default argument */
std::vector<int> list;
list.push_back(13);
list.push_back(17);
m.def("kw_func4", &kw_func4, py::arg("myList") = list);
m.def("call_kw_func", &call_kw_func);
m.def("args_function", &args_function);
m.def("args_kwargs_function", &args_kwargs_function);
using namespace py::literals;
m.def("kw_func_udl", &kw_func, "x"_a, "y"_a=300);
m.def("kw_func_udl_z", &kw_func, "x"_a, "y"_a=0);
}