Skip to content

shape matching issue in set_diag #98

@allenhaozhu

Description

@allenhaozhu

It seems like pytorch_sparse issue:
Traceback (most recent call last):
File "preprocessing.py", line 142, in
main()
File "preprocessing.py", line 100, in main
adj = get_adj(row, col, N, asymm_norm=args.undirected_asymm_norm, set_diag=args.undirected_set_diag, remove_diag=args.undirected_remove_diag)
File "preprocessing.py", line 19, in get_adj
adj = adj.set_diag()
File "/home/zhu044/.local/lib/python3.6/site-packages/torch_sparse/diag.py", line 96, in
self, values, k)
File "/home/zhu044/.local/lib/python3.6/site-packages/torch_sparse/diag.py", line 47, in set_diag
new_row[mask] = row
RuntimeError: shape mismatch: value tensor of shape [50238473] cannot be broadcast to indexing result of shape [50056641]

Activity

rusty1s

rusty1s commented on Dec 14, 2020

@rusty1s
Owner

Can you give a little more information of the adj that produces this error? Do you have a simple example to reproduce?

allenhaozhu

allenhaozhu commented on Dec 14, 2020

@allenhaozhu
Author

Can you give a little more information of the adj that produces this error? Do you have a simple example to reproduce?

parser = argparse.ArgumentParser(description='OGBN-papers100M (MLP)')
parser.add_argument('--num_propagations', type=int, default=3)
parser.add_argument('--dropedge_rate', type=float, default=0.3)
args = parser.parse_args()

# SGC pre-processing ######################################################

dataset = PygNodePropPredDataset('ogbn-papers100M')
split_idx = dataset.get_idx_split()
data = dataset[0]

x = data.x.numpy()
N = data.num_nodes

print('Making the graph undirected.')
### Randomly drop some edges to save computation
data.edge_index, _ = dropout_adj(data.edge_index, p = args.dropedge_rate, num_nodes= data.num_nodes)
data.edge_index = to_undirected(data.edge_index, data.num_nodes)

print(data)

row, col = data.edge_index

print('Computing adj...')

adj = SparseTensor(row=row, col=col, sparse_sizes=(N, N))
adj = adj.set_diag()

I also tried SIGN code on papers100, the same problem happend

Gmrylbx

Gmrylbx commented on Aug 7, 2023

@Gmrylbx

Has this bug been fixed? I also encountered a similar problem

rusty1s

rusty1s commented on Aug 8, 2023

@rusty1s
Owner

It works fine for me on my end. What's the problem you encounter?

hieuvt29

hieuvt29 commented on Sep 29, 2024

@hieuvt29

I encountered the same issue and after a quick check, I found that it happens because this function (https://github.com/rusty1s/pytorch_sparse/blob/master/torch_sparse/diag.py#L32) assumes that the columns are sorted but it is not true for my case. Best!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @rusty1s@hieuvt29@allenhaozhu@Gmrylbx

        Issue actions

          shape matching issue in set_diag · Issue #98 · rusty1s/pytorch_sparse