gpilab / core-nodes

The core nodes are a collection of basic data manipulation and visualization algorithms.
http://docs.gpilab.com/en/develop/NodeDev/devguide.html
BSD 3-Clause "New" or "Revised" License
12 stars 6 forks source link

Possible numpy compatibility issue #46

Closed JuanCab closed 2 years ago

JuanCab commented 2 years ago

When running through the Tutorial videos, I ran into an issue in a call to the FFT_NUMPY node (FFT_NUMPY_GPI.py) which caused a crash. The relevant part of the error message was

  File "/Users/XXXXX/miniforge3/envs/gpi_env/lib/python3.7/site-packages/gpi_core/math/GPI/FFT_NUMPY_GPI.py", line 248, in compute
    np.ones(zpad_after), 0.0, (-i-1))
  File "<__array_function__ internals>", line 6, in insert
  File "/Users/XXXXX/miniforge3/envs/gpi_env/lib/python3.7/site-packages/numpy/lib/function_base.py", line 4744, in insert
    old_mask[indices] = False
IndexError: arrays used as indices must be of integer (or boolean) type

Examination of lines 247-248 of FFT_NUMPY_GPI.py:

                        temp = np.insert(temp, data.shape[-i-1] *
                                         np.ones(zpad_after), 0.0, (-i-1))

reveals the problem is that the second argument of np.insert is supposed to be the index/indices of the insertion. These indices have to be an int or boolean, but np.ones defaults to creating an array of floats.

I know the code used to work, so this may be a more general problem due to a change in behavior in a recent update of numpy (I am using version 1.21.5). I couldn't find anything obvious in the release notes since 1.16.0 to indicate a change in numpy causing this problem, but the fact it worked before and now doesn't suggests this approach to np.insert argument construction may need to be checked elsewhere in the GPI codebase.

JuanCab commented 2 years ago

I forgot to note the fix was to replace the np.ones(zpad_after) calls in the two lines noted above with np.ones(zpad_after).astype(int).