Replies: 2 comments 7 replies
-
@wjakob I am also curious about whether or not there is an idiomatic way of exposing an Currently, it seems that an
The below does not work:
So, |
Beta Was this translation helpful? Give feedback.
-
@wjakob thanks a lot and sorry for the delayed answer. With the release, the "issue" I mentioned initially has indeed disappeared. One question remains: which version is "right"? E.g., For what it's worth, I tried the following: v2.vec[0] = 10
print(v2.vec)
v2.vec_rw_nbcast[0] = 10
print(v2.vec_rw_nbcast) And neither seems to work (i.e., output is Also, I could not find |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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