#include <torch/extension.h>

#include <iostream>
#include <vector>

std::vector<at::Tensor> lltm_forward(torch::Tensor dummy, 
torch::Tensor mult1, int element_per_filter, int mult1_shape_0, 
int y_index_2, int mult1_shape_1)
{
    // auto dummy1 = dummy.accessor<float, 2>();
    // auto mult11 = mult1.accessor<float, 2>();
    int iterator = 0;
    float number = 0;
    //mult1 = mult1.data<float>;
    int temp = 0;
    int filternumber = -1;
    for (int i = 0; i < mult1_shape_0 + 1; i = i + y_index_2)
    {
        for (int j = 0; j < mult1_shape_1; j++)
        {
            number = 0;

            for (int k = iterator; k < i; k++)
            {
                number = number + mult1[k][j].item().to<double>();
                temp = k;
            }
            dummy[temp][j] = number;


    return {dummy};
}
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m)
{
    m.def("nice", &lltm_forward, "LLTM forward");
}


This code works but it around 400 x slower than it’s python variant. When i replace  mult1[k][j].item().to(); with a float number (let say i from the loop) it becomes 66%  faster which is what i want from this operator. I was thinking if a float tensor is passed at the python end instead of torch::Tensor mult1 and i loop through it it would be faster (by just doing mult1[k][j]), i have tried to convert mult1 to float as follows but couldn’t make that work either.
    auto x = mult1.to(torch::kFloat32);

Which still gives:
: error: cannot convert ‘at::Tensor’ to ‘float’ in assignment
                 number = number + x[k][j]; //.item().to<double>();

Guidance on this issue is required from respected members. Is it possible to send numpy arrays to C++ operator perform looping on it and return a numpy array. I have tried that too but could not make to work yet.