Returning Eigen::Matrix as multi-dimensional ndarray #185
-
Hi, thanks for this awesome project, it's my first time using nanobind and the journey has been very smooth due to the awesome documentation and easy-to-follow API! I'm trying to bind a class method that returns an Although I can bind this function successfully using the nanobind-provided Eigen type-casters, I would like to return a Numpy array with the correct shape, as opposed to the flattened array. I could do this easily following the excellent documentation in here. The problem is that I would like my class method to still return a You may wonder why I would want to do this - I'm trying to create a self-contained library in C++, and adding python bindings as another module. Ideally I would be able to compile the library itself without nanobind dependencies (which would prevent writing the nanobind wrapper inside the C++ class). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Based on the specificity of the question, I would say it is outside the scope of this project. Options might be to write wrappers/adapters that you can then bind using nanobind (with |
Beta Was this translation helpful? Give feedback.
Based on the specificity of the question, I would say it is outside the scope of this project. Options might be to write wrappers/adapters that you can then bind using nanobind (with
nb::cast
), or further wrapping code in Python that adapts the shape of the returned numpy arrays (probably the easier route).