-
Notifications
You must be signed in to change notification settings - Fork 14
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
Error when converting absl::Span<const bool> #4
Comments
Did you already try solving this with a lambda? That would be a good first step, and a good starting point for thinking about a general solution. |
The issue is the lack of a ".data()" method on the std::vector specialization, which causes absl::MakeSpan fail to compile when passed a std::vector. I can make the code compile if I pass a lambda that uses a different container type (e.g., const absl::InlinedVector<bool, 4>) as the argument, then converts this to a span using absl::MakeSpan before calling the underlying function that takes a Span. However this fails at runtime due to a TypeError in pybind11, presumably since there are no pybind11 convertors from Python's Sequence[bool] type to the C++ absl::InlinedVector<bool, 4> type: TypeError: ConvGeneralDilated(): incompatible function arguments. The following argument types are supported: Invoked with: <google3.third_party.tensorflow.compiler.xla.python.xla_extension.XlaOp object at 0x7fa600807430>, <google3.third_party.tensorflow.compiler.xla.python.xla_extension.XlaOp object at 0x7fa600807df0>, [1, 1], [(1, 0), (0, 1)], (2, 1), (1, 1), <google3.third_party.tensorflow.compiler.xla.python.xla_client.ConvolutionDimensionNumbers object at 0x7fa5f9482890>; kwargs: window_reversal=[False, True] Did you forget to Does pybind11 support any different C++ container types we could use here instead of std::vector? |
Wow, that's a lot of arguments, difficult to tell, but your guess makes sense. We have You could iterate over the sequence, which will give you Much better would be to add Yet another idea is to fix up pybind11/stl.h to work for |
When trying to specify a py::arg with C++ type absl::Span (or more specifically in my case absl::optional<absl::Span>), I get an compile error:
./third_party/pybind11_abseil/absl_casters.h:378:12: error: no matching function for call to 'MakeSpan'
return absl::MakeSpan(static_cast<std::vector<value_type>&>(caster));
...
I guess this might be related to std::vector being potentially specialized as a bitset instead of an array of byte sized bools (abseil/abseil-cpp#644). It would be nice to be able to define an py::arg as absl::Span though if it's possible to side-step this issue.
The text was updated successfully, but these errors were encountered: