File tree 3 files changed +41
-5
lines changed
include/python/emu/pybind11
3 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -227,7 +227,7 @@ endif()
227
227
add_library (emupython INTERFACE )
228
228
229
229
target_sources (emupython INTERFACE FILE_SET HEADERS BASE_DIRS include /python FILES
230
- include /python/emu/pybind11/numpy.h
230
+ include /python/emu/pybind11/numpy.hpp
231
231
include /python/emu/pybind11/cast/container.hpp
232
232
include /python/emu/pybind11/cast/cstring_view.hpp
233
233
include /python/emu/pybind11/cast/detail/capsule.hpp
Original file line number Diff line number Diff line change
1
+ #pragma once
2
+
3
+ #include < emu/scoped.hpp>
4
+
5
+ #include < Python.h>
6
+
7
+ namespace emu ::pybind11
8
+ {
9
+
10
+ namespace detail {
11
+
12
+ struct buffer_deleter {
13
+
14
+ void operator ()(Py_buffer buffer) const noexcept {
15
+ PyBuffer_Release (&buffer);
16
+ }
17
+ };
18
+
19
+ using scoped_buffer = scoped<Py_buffer, buffer_deleter>;
20
+ } // namespace detail
21
+
22
+
23
+ struct buffer
24
+ {
25
+ buffer () = default ;
26
+
27
+
28
+ [[nodiscard]] Py_buffer& view () { return buffer_.value ; }
29
+ [[nodiscard]] const Py_buffer& view () const { return buffer_.value ; }
30
+
31
+
32
+ private:
33
+ detail::scoped_buffer buffer_;
34
+ };
35
+
36
+ } // namespace emu::pybind11
Original file line number Diff line number Diff line change @@ -107,15 +107,15 @@ namespace emu::pybind11::numpy
107
107
return dt.is (py::dtype::from_args (py::type::of (py::str ())));
108
108
}
109
109
110
- py::dtype to_dtype (dlpack::data_type_ext_t dtype) {
110
+ inline py::dtype to_dtype (dlpack::data_type_ext_t dtype) {
111
111
return py::dtype (dlpack_type_to_numpy (dtype));
112
112
}
113
113
114
- py::dtype to_dtype (dlpack::data_type_t dtype) {
115
- return py::dtype (dlpack_type_to_numpy (dtype));
114
+ inline py::dtype to_dtype (dlpack::data_type_t dtype) {
115
+ return py::dtype (dlpack_type_to_numpy (dlpack::from_data_type ( dtype) ));
116
116
}
117
117
118
- dlpack::data_type_ext_t from_dtype (py::dtype dtype) {
118
+ inline dlpack::data_type_ext_t from_dtype (py::dtype dtype) {
119
119
return dlpack::data_type_ext_t {
120
120
.code = code_from_np_types (dtype.num ()),
121
121
.bits = dtype.itemsize () * CHAR_BIT,
You can’t perform that action at this time.
0 commit comments