You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mostly for performance reasons, I am porting pyvinecopulib from pybind11 to nanobind. In pybind11, I used def_property and def_property_readonly for private internal variables (Eigen objects) that can only be accessed via setters and getters. I tried to do the same with nanobind, and an MWE is below:
I am sure that there's something that I don't understand with how objects are passed between C++ and Python. I've read attentively nanobind's related doc page but for the life of me, I don't understand what I'm doing wrong. Why are we supposed to cast the output of the getter in this way?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
Mostly for performance reasons, I am porting pyvinecopulib from pybind11 to nanobind. In pybind11, I used
def_property
anddef_property_readonly
for private internal variables (Eigen
objects) that can only be accessed via setters and getters. I tried to do the same with nanobind, and an MWE is below:However, when trying to use this in Python, something weird happens:
>>> import numpy as np >>> import nanobind_example as m >>> v = np.array([1, 2, 3]) >>> v2 = m.EigenVector(v) >>> print(v2.vec) [5.50215936e-310 0.00000000e+000 3.00000000e+000] >>> print(v2.vec_ro) [ 5.50216011e-310 -1.84063345e+286 3.00000000e+000] >>> print(v2.vec_def()) [1. 2. 3.] >>> print(v2.vec_ro_nbcast) [1. 2. 3.] >>> print(v2.vec_rw_nbcast) [1. 2. 3.]
I am sure that there's something that I don't understand with how objects are passed between C++ and Python. I've read attentively nanobind's related doc page but for the life of me, I don't understand what I'm doing wrong. Why are we supposed to cast the output of the getter in this way?
Beta Was this translation helpful? Give feedback.
All reactions