I’m trying to use the C++ Extension tutorial to write a custom convolution function for use in python.
const torch::Tensor input,
const torch::Tensor weight,
const torch::Tensor bias,
I was hoping that I could then call this function using pybind like this:
torchexplain_cpp.conv2d_forward(input, weight, bias, (1,1),(1,1),(1,1),1)
But I get an incompatible arguments error regarding the tuples.
How would I appropriately pass python tuples OR ints to the function?
Could you try to use
c10::ArrayRef<long int> as the type for
dilation and rerun the script?
Thank you for your reply, that works now. I’m still new to C++ and I realise now that
ExpandingArray is a template. Is it possible to use it for parameter types? or would I have to either:
Convert the ints to tuples in python
Write separate functions in C++ for int options vs. tuple options?
If you would like to pass integers directly, you could use the
int64_t type in C++, as you’ve already done with the
Could you explain the use case a bit, if I misunderstood it?
Of course sorry. To clarify I was hoping that by specifying the optional parameters as ExpandingArray, then the function would accept either tuples, or integers that would then be expanded to tuples. So I could either pass (1,1) or simply 1 for my stride and see the same behaviour.
Again I’m still learning c++ and it seems now incorrect.
Thank you again for your help!
Ah OK, thanks for the explanation.
I’m not sure what the proper way would be, but I’ve seen the usage of
c10::ArrayRef<long int> in C++ and passing a tuple with different number of elements on the Python side via:
(1, 2, 3)