daducci / COMMIT

Linear framework to combine tractography and tissue micro-structure estimation with diffusion MRI
Other
43 stars 33 forks source link

"Inhomogeneous shape error" with Numpy version 1.24.0 #121

Closed SiemondeLange closed 9 months ago

SiemondeLange commented 1 year ago

When attempting to run the example code for creating the group_idx variable for COMMIT2 using Numpy version 1.24.0, I encounter an "inhomogeneous shape error":

>>> group_idx = np.array( [np.arange(tmp[i],tmp[i+1]) for i in range(len(tmp)-1)] )
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2255,) + inhomogeneous part.

This error might potentially also be an issue for COMMIT2, because the structureIC parameter of commit.solvers.init_regularisation is expected to be an inhomogeneous numpy array, as shown in the example provided in the documentation np.array([[0,2,5],[1,3,4],[0,1,2,3,4,5],[6]]).

It appears that this issue is caused by Numpy deprecating the construction of inhomogeneous arrays in version 24. While a long-term solution may require modifications to the code, a short-term solution could advice users to use Numpy version 1.23.5 until the issue is resolved.

nightwnvol commented 1 year ago

Hi @SiemondeLange,

thank you for reporting us this issue. You can still create the group_idx variable as a numpy array with inhomogeneous shape by specifying the parameter dtype=np.object_, i.e. group_idx = np.array( [np.arange(tmp[i],tmp[i+1]) for i in range(len(tmp)-1)], dtype=np.object_ ).

This should resolve your issue. We will update the documentation and the example code in the wiki with this tip.

SiemondeLange commented 1 year ago

Thank you @nightwnvol for your prompt response to my issue. The error was indeed solved when I tried your suggestion to specify dtype=np.object_.