Solved by richard in post #2 
              
              
                I think this is the function you are looking for: https://pytorch.org/cppdocs/api/function_namespacetorch_1afa32eb8069eda5ae03b45ee9f26de3c3.html?highlight=sparse#_CPPv4N5torch17sparse_coo_tensorERKN2at6TensorERKN2at6TensorERKN2at13TensorOptionsE