Skip to content

Update custom type_caster doc with a more complete example #747

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

Open
tjcorona opened this issue Mar 20, 2017 · 2 comments
Open

Update custom type_caster doc with a more complete example #747

tjcorona opened this issue Mar 20, 2017 · 2 comments
Labels
docs Docs or GitHub info

Comments

@tjcorona
Copy link

I have recently come across strange errors (XXX undetected error) when calling overloaded methods that take as input objects that have custom type_caster instantiations. After some debugging, I found that a custom pybind11 type_caster<>::load(handle,bool) method must not only return a bool to denote its successful conversion, but must also throw a reference_cast_error() when the handle is not the expected type (to facilitate its use in pybind11's try/catch dispatch for overloaded methods). Also, the failed attempts to convert the handle likely raise a python error which, if left uncleared, will manifest in strange behavior elsewhere in the program. The readthedocs for custom type casters doesn't really cover these crucial requirements on the load method. It would have been useful for me to read about this in the documentation, so I figure it would probably be useful for someone else to read it too!

@tjcorona
Copy link
Author

If you'd like, I can take a stab at updating your doc and put up a merge request. Just let me know!

@wjakob
Copy link
Member

wjakob commented Mar 22, 2017

Please do -- that would be great!

dean0x7d pushed a commit that referenced this issue May 7, 2017
`EigenConformable::stride_compatible` returns false if the strides are
negative. In this case, do not use `EigenConformable::stride`, as it
is {0,0}. We cannot write negative strides in this element, as Eigen
will throw an assertion if we do.

The `type_caster` specialization for regular, dense Eigen matrices now
does a second `array_t::ensure` to copy data in case of negative strides.
I'm not sure that this is the best way to implement this.

I have added "TODO" tags linking these changes to Eigen bug #747, which,
when fixed, will allow Eigen to accept negative strides.
@bstaletic bstaletic added the docs Docs or GitHub info label Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Docs or GitHub info
Projects
None yet
Development

No branches or pull requests

3 participants