workaround to assert introduced in #549 #605
Replies: 2 comments 1 reply
-
It would be helpful if you can post a more minimal example that reproduces the regression (in case it is one), it would take too much time time to really understand the PETSc code. Let me also CC @oremanj, who added this assertion check. |
Beta Was this translation helpful? Give feedback.
-
My understanding: you have a type C++ metaprogramming can't see typedefs; whenever you write It's a little tricky for nanobind to figure out what type of value the caster is actually storing. In the example you provided, the type you pass to Here's a workaround that I think will solve your problem without getting too complicated. It's operating on the assumption that if the type caster can produce a
I'm out of town the rest of this week, but hopefully that gives enough information to fix your use case. Some final notes:
|
Beta Was this translation helpful? Give feedback.
-
Hi,
in dolfinx we are interfacing objects from a library called
PETSc
(written in C), its Cython wrapperpetsc4py
, andnanobind
.To do so we prepared our own caster at
https://github.com/FEniCS/dolfinx/blob/main/python/dolfinx/wrappers/caster_petsc.h
In there, the types
Vec
andMat
are part of the external libraryPETSc
, and are pointers to private data structures_p_Vec
and_p_Mat
.Since
nanobind
2.0, we are hitting the assert atnanobind/include/nanobind/nb_cast.h
Line 126 in c36584e
when using
nanobind
-wrapped types in astd::array<..., 2>
(but I guess it would be the same in other STL containers).To my understanding, the assert is saying that in order to use STL containers with
Vec
(orMat
), we also need to wrap the corresponding non-pointer type_p_Vec
(or_p_Mat
). However, we definitely do NOT want to do that, because_p_Vec
/_p_Mat
are part ofPETSc
private interface, and we don't want to fiddle with that. We are not concerned about memory management for the pointed object, because that's done bypetsc4py
.In this case how should we work around the assert introduced in #549?
I am aware that there is a description of the changes in the changelog at the top of https://github.com/wjakob/nanobind/pull/549/files , but I couldn't get from there what to do in this case.
Thanks,
Francesco
Beta Was this translation helpful? Give feedback.
All reactions