networkit
networkit copied to clipboard
addEdges raises IndexError if data array has 32 bit numbers
Hi,
Thank you very much for your work! NetworKit is awesome!
I wanted to create a graph from scratch using the Python interface and the function addEdges
. It is not mentioned in the documentation, that the data
array needs to be a 64-bit data type!
Here is a minimal example:
import numpy as np
import networkit as nk
g = nk.Graph()
a = np.random.randint(0, 10, 10)
b = np.random.randint(0, 10, 10)
c = np.random.randint(0, 10, 10)
print(c.dtype)
g.addEdges((c, (a, b)), addMissing=True)
Output:
int32
Traceback (most recent call last):
File "...", line 11, in <module>
g.addEdges((c, (a, b)), addMissing=True)
File "networkit\\graph.pyx", line 487, in networkit.graph.Graph.addEdges
IndexError: Out of bounds on buffer access (axis 0)
But if c
has a 64 bit data type, it does not raise any error:
import numpy as np
import networkit as nk
g = nk.Graph()
a = np.random.randint(0, 10, 10)
b = np.random.randint(0, 10, 10)
c = np.random.randint(0, 10, 10).astype(np.int64)
print(c.dtype)
g.addEdges((c, (a, b)), addMissing=True)
It took me a while to figure this out, as I would expect a TypeError
if one of the input parameters does not have the required type. However, I would prefer to be able to use smaller numerical data types for edge weights.
If this is not possible, it should be added in the documentation, that the data
array is limited to 64-bit numerical data types.
Another suggestion is to mention, that data
is supposed to be the weights of the edges.