How to fill a PyTorch string_view input #1390
-
The PyTorch bindings have a bunch of functions taking a Example: @Namespace("at") public static native @ByVal Tensor einsum(@ByVal @Cast("c10::string_view*") Pointer equation, @ByVal @Cast("at::TensorList*") TensorArrayRef tensors); I'm trying to call import org.bytedeco.pytorch.*;
var rand = global.torch.torch_randn(4,4);
global.torch.einsum(BytePointer("ii"), new TensorArrayRef(rand.position(0), 1)); But that doesn't work:
The error is the same when calling the Python API with an empty string. Any idea how to correctly add the Tagging @HGuillemet because you're deep into the PyTorch mappings right now. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I'll look into this. |
Beta Was this translation helpful? Give feedback.
-
@saudet, please advise about this: I first tried to create a custom adapter Then I realized that the @Cast({"", "", "std::basic_string<char>"}) @StdString String f() because string_view knows how to be cast to For functions taking a string_view, we simply need:
We must not cast to Is there an existing trick to generate the A third option that should work, but less friendly, is to map string_view to a specific Java class. |
Beta Was this translation helpful? Give feedback.
Ok. I have came up with a solution with an adapter working. New PR coming.
Like in
StringAdapter
, I tested the size passed to the(ptr, size, owner)
constructors and did astrlen
if it's 0.But I wonder if it won't be better to have the generator produce a JNI call to
getStringUTFLength
, along withgetStringUTFChars
, and pass this length to the adapter.