How to save three kinds sparse adjacency matrix of graph?

Hello, I want a graph with all three sparse adjacency matrix.
I created three kind of sparse adjacency matrix (coo, csr, csc) and save it on distk.
When I load the graph again I find the graph only contains coo format.
Does anyone else have this problem ?

g2 = dgl.heterograph({
...     ('user', 'follow', 'user'): ([0, 1, 1, 2, 3], [1, 2, 3, 0, 0]),
...     ('user', 'view', 'item'): ([0, 0, 1, 2, 3, 3], [0, 1, 1, 2, 2, 1]),
...     ('item', 'viewed-by', 'user'): ([0, 1, 1, 2, 2, 1], [0, 0, 1, 2, 3, 3]) })
>>> g2.formats()
{'created': ['coo'], 'not created': ['csr', 'csc']}
>>> g3 = g2.formats(['coo', 'csr', 'csc'])
>>> g3.create_formats_()
>>> g3.formats()
{'created': ['coo', 'csr', 'csc'], 'not created': []}
>>> dgl.save_graphs('tmp.dgl', g3)
>>> dgl.load_graphs('tmp.dgl')[0][0].formats()
{'created': ['coo'], 'not created': ['csr', 'csc']}

Only one format will be saved to save the disk space. May I ask what’s your scenario that you prefer to save all three formats?

Hi!
In my scenario, I may remove some edges which need coo format.
I also may get degree of all nodes which is slow on coo but fast on csc/scr.
The graph is large so I don’t want to create_formats_() each time when I run the program.
That is why I want to save all three kinds of formats of graph.

Hi,

Modifying graph will only be done on coo, and csr and csc will be invalidated, which means it will be regenerated if needed. Did you mean your graph will be modified frequently? Or can you check whether subgraph API satisfy your need?

Also we think saving multiple graph formats is a valid feature request. Currently the only workaround is to save three graphs separately. Could this solve your problem?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.