Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Convert vector/array to numpy array#37

Open
Wentzell wants to merge 1 commit intomasterTRIQS/cpp2py:masterfrom
PR_VECOBJ_AS_NPYTRIQS/cpp2py:PR_VECOBJ_AS_NPYCopy head branch name to clipboard
Open

Convert vector/array to numpy array#37
Wentzell wants to merge 1 commit intomasterTRIQS/cpp2py:masterfrom
PR_VECOBJ_AS_NPYTRIQS/cpp2py:PR_VECOBJ_AS_NPYCopy head branch name to clipboard

Conversation

@Wentzell
Copy link
Member

  • 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

@Wentzell Wentzell requested a review from parcollet June 20, 2020 22:36
c++/cpp2py/converters/map.hpp Outdated Show resolved Hide resolved
c++/cpp2py/converters/std_array.hpp Outdated Show resolved Hide resolved
c++/cpp2py/converters/std_array.hpp Outdated Show resolved Hide resolved
c++/cpp2py/converters/std_array.hpp Outdated Show resolved Hide resolved
c++/cpp2py/converters/std_array.hpp Outdated Show resolved Hide resolved
c++/cpp2py/converters/tuple.hpp Outdated Show resolved Hide resolved
c++/cpp2py/converters/tuple.hpp Outdated Show resolved Hide resolved

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"));
Copy link
Member

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

Copy link
Member Author

@Wentzell Wentzell Jun 23, 2020

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?

c++/cpp2py/converters/vector.hpp Outdated Show resolved Hide resolved
std::copy(data, data + size, begin(v));

if (p.element_type == npy_type<pyref>) {
auto **data = static_cast<PyObject **>(p.data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as before

Copy link
Member Author

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?

@Wentzell
Copy link
Member Author

@parcollet By taking c2py arguments by value will no longer be able to e.g. convert a member std::vector as a np.ndarray viewing the data. Taking by value cannot be the full solution.

@Wentzell Wentzell changed the title DO NOT MERGE -- For Discussion c2py of stl types take argument by value, convert vector/array to numpy array Jun 23, 2020
@Wentzell Wentzell force-pushed the PR_VECOBJ_AS_NPY branch 3 times, most recently from e6da84e to ae0db29 Compare June 26, 2020 22:11
@Wentzell Wentzell changed the title c2py of stl types take argument by value, convert vector/array to numpy array Be sure to properly treat both rvalues and lvalues in c2py functions, convert vector/array to numpy array Jul 9, 2020
@Wentzell Wentzell changed the title Be sure to properly treat both rvalues and lvalues in c2py functions, convert vector/array to numpy array Convert vector/array to numpy array Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.