Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

Passing Element Vectors for C++ to Python

More
4 years 3 months ago #2269 by NilsHM
Hello everyone!

We are trying to pass individual element vectors from our C++ extension MyCollect to Python. The C++ extension code is in the attachments.
In Minimum.py a small test case is given.

From py:print() we can see that the output values are being overwritten during the iteration over all elements, although the element vectors should be written for every element individually. Also the values that MyCollect returns are nonsense.

Does anyone know what's going wrong or how to fix these problems?

Thanks and best regards.
Nils



File Attachment:

File Name: Minimum.py
File Size:1 KB

File Attachment:

File Name: myCollecting.hpp
File Size:0 KB

File Attachment:

File Name: myCollecting.cpp
File Size:2 KB

File Attachment:

File Name: ngsextension.cpp
File Size:2 KB
More
4 years 3 months ago #2270 by joachim
Hi Nils,

you allocate your element vectors at LocalHeap. This memory is gone after your IterateElements kernel function, and your FlatVector pointers point to garbage.

Use a vector of Vector<double> entries, which take care of dynamic memory allocation.

Joachim
The following user(s) said Thank You: NilsHM
Time to create page: 0.131 seconds