I am working on wrapping a function written in C++ to PyTorch. The C++ function takes 3 floats and produces 1 float.

Is there a C++ PyTorch API to perform the broadcasting of the wrapped function?

Probably something like np.nditer in numpy.

I think tensors will be automatically broadcasted in the C++ API in the same manner as in Python, won’t they?

To trigger broadcasting you could `unsqueeze`

dimensions if necessary.

Let me know, if I misunderstood your use case.

Thanks for your answer.

I have a C++ code with signature `double some_fcn(double a, double b)`

, and I want to wrap it to PyTorch function `Tensor some_fcn_wrap(Tensor& a, Tensor& b)`

with some broadcasting capability.

The problem of wrapping it is I need to implement the broadcasting inside the function, but I’m sure there’s a function (or class) in PyTorch’s C++ source code to do that.

That’s what I’m looking for. Something like numpy.nditer.