MCPcopy Create free account
hub / github.com/boostorg/histogram / data_visitor

Class data_visitor

src/python/histogram.cpp:69–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

67 };
68
69 struct data_visitor {
70 template <typename T, typename Buffer>
71 bp::object operator()(T* tp, const Buffer&, const bp::list&, const bp::list&) const {
72 return bp::make_tuple(reinterpret_cast<uintptr_t>(tp), true);
73 }
74 template <typename Buffer>
75 bp::object operator()(void*, const Buffer&, const bp::list& shapes,
76 const bp::list&) const {
77 // cannot pass non-existent memory to numpy; make new
78 // zero-initialized uint8 array, and pass it
79 return np::zeros(bp::tuple(shapes), np::dtype::get_builtin<uint8_t>());
80 }
81 template <typename Buffer>
82 bp::object operator()(mp_int* tp, const Buffer& b, const bp::list& shapes,
83 const bp::list& strides) const {
84 // cannot pass cpp_int to numpy; make new
85 // double array, fill it and pass it
86 auto a = np::empty(bp::tuple(shapes), np::dtype::get_builtin<double>());
87 for (std::size_t i = 0, n = bp::len(shapes); i < n; ++i)
88 const_cast<Py_intptr_t*>(a.get_strides())[i] = bp::extract<int>(strides[i]);
89 auto* buf = (double*)a.get_data();
90 for (std::size_t i = 0; i < b.size; ++i) { buf[i] = static_cast<double>(tp[i]); }
91 return a;
92 }
93 };
94
95 static bp::object array_interface(const pyhistogram& self) {
96 bp::dict d;

Callers 1

array_interfaceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected