elephant icon indicating copy to clipboard operation
elephant copied to clipboard

fix/#410, UE cast to int in 'unsafe' mode

Open Moritz-Alexander-Kern opened this issue 2 years ago • 3 comments

This PR addresses Issue #410

The following error occurred in https://github.com/NeuralEnsemble/elephant/blob/0df45812b93229b3186c061cb84ec29fd380e09c/elephant/unitary_event_analysis.py#L585

TypeError: Cannot cast array data from dtype('int64') to dtype('int32') according to the rule 'safe'

This might be fixed by using np.astype(int) instead of np.in64() to cast to int. np.astype allows 'unsafe' casting by default, see: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.astype.html

Moritz-Alexander-Kern avatar Jun 28 '22 09:06 Moritz-Alexander-Kern

The numpy documentation suggest the following for casting:

To convert the type of an array, use the .astype() method (preferred) or the type itself as a function. For example:

z.astype(float)                 
array([0.,  1.,  2.])

np.int8(z)
array([0, 1, 2], dtype=int8)

See: https://numpy.org/doc/stable/user/basics.types.html

I suggest to follow numpys preferred method, but I don't have a strong opinion on this.

Moritz-Alexander-Kern avatar Jul 20 '22 08:07 Moritz-Alexander-Kern

Hey @sanjayankur31 ,

This should fix in PR #410 , please let me know if this solves the issue.

Moritz-Alexander-Kern avatar Aug 01 '22 07:08 Moritz-Alexander-Kern

Thanks, it's on my list, just not managed to get to it yet. Will hopefully find some time in the next couple of days.

sanjayankur31 avatar Aug 01 '22 08:08 sanjayankur31

Seems to fix the issue on arm, all tests pass with this set of changes:

https://koji.fedoraproject.org/koji/taskinfo?taskID=91845461

Fedora's also dropped armv7hl support from the next release (F37), so we shouldn't have armv7hl related issues in the future:

https://www.fedoraproject.org/wiki/Changes/RetireARMv7

sanjayankur31 avatar Sep 09 '22 22:09 sanjayankur31

Thanks @sanjayankur31 for having a look.

Build report looks good: https://koji.fedoraproject.org/koji/taskinfo?taskID=91845461 arm runner

Moritz-Alexander-Kern avatar Sep 21 '22 06:09 Moritz-Alexander-Kern