Where is the C++ definition of Tensor located

I’m trying to find the definition of Tensor as used in the C++ parts of PyTorch, for example in pytorch/aten/src/ATen/native/ReduceOps.cpp in line 746 we have the function

Tensor prod(const Tensor& self, int64_t dim, bool keepdim, c10::optional<ScalarType> opt_dtype) {
  ScalarType dtype = get_dtype_from_self(self, opt_dtype, true);
  Tensor result = create_reduction_result(self, dim, keepdim, dtype);
  native::prod_out_impl(result, self, dim, keepdim, dtype);
  return result;
}

but for some reason the IDE I’m using (CLion) can’t find the declaration of the type Tensor.

Could you kindly direct me to the declaration.

This is declared in a generated header include/ATen/core/TensorBody.h which you find in LibTorch / PyTorch installations. The template is in aten/src/ATen/templates/TensorBody.h.

I asked this because I wanted to understand the following: I have a function

- func: function(Tensor self) -> Tensor
  variants: method, function
  dispatch:
    CPU: function_cpu
    CUDA: function_cuda

whose implementation I want to change.

The current version’s return tensor is declared this way:

Tensor result;
result = at::empty({}, self.options().dtype(dtype));

I computed the result I want to return with std::vectors (probably not optimal, feel free to suggest something better). Now I’m wondering how I can pass this vector to the result tensor. I think I have to use following in some way, and was trying to find its implementation by asking about the location of the Tensor class:

self.data_ptr<scalar_t>()

I can’t seem to infer this from the information you gave me above. Can you explain to me to how I can properly give my data to the return tensor? Is there maybe an instructive function somewhere I could look at.

Hello, I can’t find Tensorbody.h in the project. Can you tell me how to generate theses files?