-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vectorizing POD types #2258
Comments
Not sure if I understood you correctly. Do you mean I should try the following? vec = np.array([object_1, object_2], dtype=np.object) If so, this doesn't work either. In fact, I think it is equivalent to my original snippet, as in the error it seems that pybind was already inferring the |
From #1152 it seems support for If so, the current documentation about
I will try and deep dive on #1152 further soon, and can try to contribute if possible - if it is in the project's plan to in fact add that feature. |
Ah, actually, for the POD type, have you tried structured dtypes? (I mentioned it as option (1) in #2259, but I should've put that at the forefront here - sorry!) |
So really, I think the docs mean "structured dtype-compatible POD types" |
Oh, derp, sorry x 2! You already did by way of |
@chaitan94 I wasn't able to reproduce your problem; I modified the unittest here, and it seemed to work fine? |
Oh, triple derp, and sorry x 3. It's b/c of the mixture of |
Just pushed 337dc9c showing a reproduction of your issue. Basically, it's just a mix of how NumPy can represent scalars (either as Dunno what the right solution is, but at least this captures some of the weirdness? |
Well, I did try this before raising this issue: import example
import numpy as np
object_1 = example.PODClass()
object_1.value = 10
object_2 = example.PODClass()
object_2.value = 20
pod_dtype = np.dtype([('value', np.int32)])
vec = np.array([object_1, object_2], dtype=pod_dtype) But this fails as well, with the following error:
But from you sample unit test, it seems right now import example
import numpy as np
object_1 = (10, )
object_2 = (20, )
vec = np.array([object_1, object_2])
print(example.pod_passthrough(vec)) Constructing with |
Also, the |
Hey @EricCousineau-TRI, I have tried pulling in the changes from #1152 and tried re-running the original code I put in this issue. I am still facing the same error (incompatible function arguments). Is this expected, or did I misunderstand you somewhere? If the changes in #1152 do add support for Or maybe perhaps #1152 only adds support for |
Hi @chaitan94! Sorry for the delay - can I ask if you're still facing this issue? Also, for tracking - here's your request for a doc change: #2260 (comment) |
Issue description
In the documentation for vectorization, this is mentioned:
However, it seems that if we use a POD type,
py::vectorize
does not work as expected. When I check the tests, it seems we do test that non-POD types pass through without vectorization, but there are no tests/examples for how to vectorize POD types.Reproducible example code
This compiles. When we try to use in python, however:
Not sure if this is expected or I am doing something wrong.
The text was updated successfully, but these errors were encountered: