Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scipy error "Inexact indices into sparse matrices are not allowed" when generating RRG #113

Closed
Karos64 opened this issue Feb 10, 2025 · 2 comments

Comments

@Karos64
Copy link

Karos64 commented Feb 10, 2025

Hello all,

I know that this repository was last updated like 4 years ago so I'm not expecting a fix for this issue. However I want to highlight it if anybody else will meet the same problem, maybe this issue will be helpful for them to fix it.

I've tried to create a simple Random Regular Graph using following code:

from pygsp import graphs

G = graphs.RandomRegular(N=4, k=2)

And I've got following error:

Traceback (most recent call last):
  File "C:\Users\X\Documents\GitHub\Y\.venv\lib\site-packages\scipy\sparse\_sputils.py", line 359, in isintlike
    operator.index(x)
TypeError: 'numpy.float64' object cannot be interpreted as an integer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\X\Documents\GitHub\Y\tests\benchmarks.py", line 3, in <module>
    G = graphs.RandomRegular(N=4, k=2)
  File "C:\Users\X\Documents\GitHub\Y\.venv\lib\site-packages\pygsp\graphs\randomregular.py", line 85, in __init__
    if v1 == v2 or A[v1, v2] == 1:
  File "C:\Users\X\Documents\GitHub\Y\.venv\lib\site-packages\scipy\sparse\_lil.py", line 162, in __getitem__
    return IndexMixin.__getitem__(self, key)
  File "C:\Users\X\Documents\GitHub\Y\.venv\lib\site-packages\scipy\sparse\_index.py", line 30, in __getitem__
    index, new_shape = self._validate_indices(key)
  File "C:\Users\X\Documents\GitHub\Y\.venv\lib\site-packages\scipy\sparse\_index.py", line 218, in _validate_indices
    elif isinstance(idx, slice) or isintlike(idx):
  File "C:\Users\X\Documents\GitHub\Y\.venv\lib\site-packages\scipy\sparse\_sputils.py", line 367, in isintlike
    raise ValueError(msg)
ValueError: Inexact indices into sparse matrices are not allowed

I've went and try to figure out what is the cause, I've found that in the following file:

.venv\lib\site-packages\pygsp\graphs\randomregular.py

simply changing lines 81 and 82 from:

v1 = U[i1]
v2 = U[i2]

to

v1 = int(U[i1])
v2 = int(U[i2])

fixes the issue. This might be related to some specific version of numpy/scipy so I'm pasting here what is currently in use in my venv:

$ pip list
Package         Version
--------------- -----------
contourpy       1.3.1
cycler          0.12.1
fonttools       4.55.3
kiwisolver      1.4.8
matplotlib      3.10.0
networkx        3.4.2
numpy           2.2.1
packaging       24.2
pillow          11.1.0
pip             24.3.1
PyGSP           0.5.1
pyparsing       3.2.1
python-dateutil 2.9.0.post0
scipy           1.15.1
setuptools      57.4.0
six             1.17.0

So as I said at the beginning, I don't expect to see fix for this issue, but I'm leaving it here if somebody will ever try to generate RRG using this library ;>

@Landuu

This comment has been minimized.

@mdeff
Copy link
Collaborator

mdeff commented Feb 12, 2025

Fixed by #112.

@mdeff mdeff closed this as completed Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants