Skip to content

Numpy triangles array - #11

Merged
artem-ogre merged 8 commits into
artem-ogre:masterfrom
sccolbert:numpy-triangles-array
Sep 15, 2026
Merged

artem-ogre merged 8 commits into
artem-ogre:masterfrom
sccolbert:numpy-triangles-array

Conversation

@sccolbert

Copy link
Copy Markdown
Contributor

This adds method to export the full triangles vector as a numpy array via a single memcopy. This avoids the overhead of converting to a list of python objects, and the overhead of iterating them into a numpy array. Since the lib already accepts buffer input, this is analogue for getting buffer output.

I also updated the binding the release the GIL where possible. This allows multiple independent triangulations to computed across Python threads.

@artem-ogre
artem-ogre force-pushed the numpy-triangles-array branch 2 times, most recently from d306834 to 3331669 Compare September 14, 2026 22:04
@artem-ogre

Copy link
Copy Markdown
Owner

Hi @sccolbert and thanks for the PR. 🙂

I've done it slightly different, please take a look and let me know what you think.
There are three ways of accessing the data now:

              count        list        copy        view
vertices     200003   56.439 ms    0.118 ms    0.001 ms
triangles    400001  127.027 ms    0.398 ms    0.001 ms
  • copy version is as you proposed, but there's also zero-copy read-only view which is as fast as it gets.
  • I also refactored GIL lock release and made it safer by keeping a lock on a triangulation.

Let me know if you have any feedback, and I'll merge it otherwise.

@artem-ogre artem-ogre self-assigned this Sep 14, 2026
@sccolbert

sccolbert commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor Author

Hey there @artem-ogre, thanks for looking! The reason I went with the copy approach instead of a view, is because I am using the output before erasing the super triangle, and further edits to the triangulation would invalidate the view. The reason I don't erase is that the internal book-keeping of the erase is slow compared to what I need from the vertices after accounting for the presence of the of the super triangle.

@sccolbert

Copy link
Copy Markdown
Contributor Author

I think your updates are good. My only worry would be taking a view, doing something that would reallocate the internal vector memory, then reading from the view again, causing a corrupted view or a crash.

@sccolbert

Copy link
Copy Markdown
Contributor Author

Oh, and now that I have your attention, I have a WASM build of the core C++ lib that I could contribute, if you like?

@artem-ogre

Copy link
Copy Markdown
Owner

I wouldn't maintain WASM build but would be interested to see it if you decide to put it in public. I've myself experimented with an idea a while ago.

@artem-ogre
artem-ogre merged commit afbbe94 into artem-ogre:master Sep 15, 2026
12 checks passed
@artem-ogre

Copy link
Copy Markdown
Owner

FYI @sccolbert I added you to the contributors list in #13

@sccolbert

Copy link
Copy Markdown
Contributor Author

Thanks! I appreciate that.

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