The library is designed with ABI compatibility in mind. That is the compiled module doesn't depend on particular Python version, it should properly wo

yglukhov / nimpy Public

submited by
Style Pass
2021-09-23 10:30:03

The library is designed with ABI compatibility in mind. That is the compiled module doesn't depend on particular Python version, it should properly work with any. The C API symbols are loaded in runtime from whichever process has launched your module.

Make sure that the module you're importing from Python has exactly the same name as the nim file which the module is implemented in.

nimpy converts Nim strings to Python strings usually, but since Nim strings are encoding agnostic and may contain invalid utf8 sequences, nimpy will fallback to Python bytes in such cases.

nimpy allows manipulating numpy objects just how you would do it in Python, however it is not much more efficient. To get the maximum performance nimpy exposes Buffer protocol, see raw_buffers.nim. tpyfromnim.nim contains a very basic test for this (grep numpy). This issue demonstrates possible higher level concepts that could be built on top. Higher level API might be considered in the future, PRs are welcome.

nimpy internally does everything needed to run the GC properly (keeps the stack bottom actual, and appropriate nim references alive), and doesn't introduce any special rules on top. So the GC question boils down to proper GC usage in nim shared libraries, you'd better lookup elsewhere. The following guidelines are by no means comprehensive, but should be enough for the quick start:

Leave a Comment
Related Posts