mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-26 07:02:11 +00:00
numpy.h: fixed a leak, added some comments to buffer_info
This commit is contained in:
parent
d33361a6d7
commit
e45b29047a
@ -143,12 +143,13 @@ PYBIND11_DECL_FMT(float, "f"); PYBIND11_DECL_FMT(double, "d"); PYBIND11_DECL
|
|||||||
|
|
||||||
/// Information record describing a Python buffer object
|
/// Information record describing a Python buffer object
|
||||||
struct buffer_info {
|
struct buffer_info {
|
||||||
void *ptr;
|
void *ptr; // Pointer to the underlying storage
|
||||||
size_t itemsize, size;
|
size_t itemsize; // Size of individual items in bytes
|
||||||
std::string format; // for dense contents, this should be set to format_descriptor<T>::value
|
size_t size; // Total number of entries
|
||||||
int ndim;
|
std::string format; // For homogeneous buffers, this should be set to format_descriptor<T>::value
|
||||||
std::vector<size_t> shape;
|
int ndim; // Number of dimensions
|
||||||
std::vector<size_t> strides;
|
std::vector<size_t> shape; // Shape of the tensor (1 entry per dimension)
|
||||||
|
std::vector<size_t> strides; // Number of entries between adjacent entries (for each per dimension)
|
||||||
|
|
||||||
buffer_info(void *ptr, size_t itemsize, const std::string &format, int ndim,
|
buffer_info(void *ptr, size_t itemsize, const std::string &format, int ndim,
|
||||||
const std::vector<size_t> &shape, const std::vector<size_t> &strides)
|
const std::vector<size_t> &shape, const std::vector<size_t> &strides)
|
||||||
|
@ -128,9 +128,11 @@ public:
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
API &api = lookup_api();
|
API &api = lookup_api();
|
||||||
PyObject *descr = api.PyArray_DescrFromType_(npy_format_descriptor<T>::value);
|
PyObject *descr = api.PyArray_DescrFromType_(npy_format_descriptor<T>::value);
|
||||||
return api.PyArray_FromAny_(ptr, descr, 0, 0,
|
PyObject *result = api.PyArray_FromAny_(
|
||||||
API::NPY_C_CONTIGUOUS_ | API::NPY_ENSURE_ARRAY_ |
|
ptr, descr, 0, 0, API::NPY_C_CONTIGUOUS_ | API::NPY_ENSURE_ARRAY_
|
||||||
API::NPY_ARRAY_FORCECAST_, nullptr);
|
| API::NPY_ARRAY_FORCECAST_, nullptr);
|
||||||
|
Py_DECREF(ptr);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user