Torch deg power produces error?

I am getting a confusing error that I’m not sure why is occurring. This is the error I am getting:

tensor([1315, 1318, 1472, 1454, 1318, 1337, 1453, 1454, 1317, 1310])

Traceback (most recent call last):
    deg_inv = deg.pow(-1)
RuntimeError: Integers to negative integer powers are not allowed.

And this is part of the code:

from torch_scatter import scatter_add
from torch_geometric.utils import add_remaining_self_loops, add_self_loops, remove_self_loops
    if edge_weight ==None:
        edge_weight = torch.ones((edge_index.size(1), ), dtype=dtype,
    fill_value = 1
    edge_index, edge_weight = add_self_loops(
        edge_index, edge_weight, fill_value, num_nodes)  
    row, col = edge_index
    deg = scatter_add(edge_weight, row, dim=0, dim_size=num_nodes)


    deg_inv = deg.pow(-1) 

I have not found anything related to this online. I’m not sure why this would be occurring?


I think this means that the pow function does not support raising integer values to negative integer powers?
In particular, taking the inverse of an integer is not well defined because you don’t get an integer back.
I think you wnat to change your input to be floating point numbers for this to work fine: deg.float().pow(-1) (and the result will be a floating point number as well).