Torch :: Greater and Torch:: Where functions

I am trying to consolidate torch::where and torch::greater into a single function. I have bypass the binary output from torch::where to store the indexes of into a tensor object; however, the performance is not efficient. I have included my solution:

  std::vector <int> idxs;
   
            for(int x = 0; x < tensor.numel(); x++){
                        if (tensor[x].item<float>() > threshold)
                                            idxs.push_back(x);
                                    
            }