-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert vector/array to numpy array #37
base: master
Are you sure you want to change the base?
Conversation
Wentzell
commented
Jun 20, 2020
- For c2py of stl types take argument by value and move elements
- Convert any std::vector and std::array<T, R> to a numpy array
c++/cpp2py/converters/vector.hpp
Outdated
|
||
namespace cpp2py { | ||
|
||
template <typename T> static void delete_pycapsule(PyObject *capsule) { | ||
auto *ptr = static_cast<std::unique_ptr<T[]> *>(PyCapsule_GetPointer(capsule, "guard")); | ||
auto *ptr = static_cast<T *>(PyCapsule_GetPointer(capsule, "guard")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the deleter in general cpp2py file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we just do
auto delete_pycapsule = [](PyObject *capsule) {
auto *ptr = static_cast<std::vector<T> *>(PyCapsule_GetPointer(capsule, "guard"));
delete ptr;
};
PyObject * capsule = PyCapsule_New(vec_heap, "guard", delete_pycapsule);
right where we need it?
std::copy(data, data + size, begin(v)); | ||
|
||
if (p.element_type == npy_type<pyref>) { | ||
auto **data = static_cast<PyObject **>(p.data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which previous comment are you referring to?
@parcollet By taking |
e6da84e
to
ae0db29
Compare
ae0db29
to
c9932ee
Compare
c9932ee
to
80ec453
Compare