TRIQS/nda

The nda library set up to work with clair/c2py automatically. nda provides N-dimensional arrays and views for C++20. They are converted to/from numpy arrays in Python. Here is an example:

Warning

TBW: discuss the ownership of array/view with python

nda_example1.cpp
#include <c2py/c2py.hpp>
#include <nda/nda.hpp>

double my_sum(nda::array_const_view<double, 1> a) { return sum(a); }

nda::array<int, 1> make_array(int n) { return {n, n + 1}; }
CMakeLists.txt
find_package(nda)

Python_add_library(nda_example1 MODULE nda_example1.cpp)
target_link_libraries(nda_example1 PRIVATE c2py::c2py nda::nda_c nda::nda_py)
clair_c2py_generate_bindings(nda_example1)

Python usage:

>>> from nda_example1 import my_sum, make_array
>>> import numpy as np
>>> a = np.array([1,2,3], dtype = np.float64)
>>> my_sum(a)
6.0
>>> make_array(5)
array([5, 6], dtype=int32)