Skip to content

Commit f69c612

Browse files
committedJan 13, 2025
Fixes numpy header.
1 parent a539f75 commit f69c612

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed
 

‎CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ endif()
227227
add_library(emupython INTERFACE)
228228

229229
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
231231
include/python/emu/pybind11/cast/container.hpp
232232
include/python/emu/pybind11/cast/cstring_view.hpp
233233
include/python/emu/pybind11/cast/detail/capsule.hpp
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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

‎include/python/emu/pybind11/numpy.h ‎include/python/emu/pybind11/numpy.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ namespace emu::pybind11::numpy
107107
return dt.is(py::dtype::from_args(py::type::of(py::str())));
108108
}
109109

110-
py::dtype to_dtype(dlpack::data_type_ext_t dtype) {
110+
inline py::dtype to_dtype(dlpack::data_type_ext_t dtype) {
111111
return py::dtype(dlpack_type_to_numpy(dtype));
112112
}
113113

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)));
116116
}
117117

118-
dlpack::data_type_ext_t from_dtype(py::dtype dtype) {
118+
inline dlpack::data_type_ext_t from_dtype(py::dtype dtype) {
119119
return dlpack::data_type_ext_t{
120120
.code = code_from_np_types(dtype.num()),
121121
.bits = dtype.itemsize() * CHAR_BIT,

0 commit comments

Comments
 (0)
Please sign in to comment.