Skip to content

Commit

Permalink
use combination of getattr and hasattr, include float96 and complex19…
Browse files Browse the repository at this point in the history
…2 to the list
  • Loading branch information
mscheltienne committed Aug 29, 2023
1 parent 4cdba01 commit 2398cc3
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions nibabel/casting.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,24 @@ class CastingError(Exception):

# np.sctypes is deprecated in numpy 2.0 and np.core.sctypes should not be used instead.
sctypes = {
'int': [np.int8, np.int16, np.int32, np.int64],
'uint': [np.uint8, np.uint16, np.uint32, np.uint64],
'float': [np.float16, np.float32, np.float64, np.longdouble],
'complex': [np.complex64, np.complex128, np.complex256],
'int': [
getattr(np, dtype) for dtype in ('int8', 'int16', 'int32', 'int64') if hasattr(np, dtype)
],
'uint': [
getattr(np, dtype)
for dtype in ('uint8', 'uint16', 'uint32', 'uint64')
if hasattr(np, dtype)
],
'float': [
getattr(np, dtype)
for dtype in ('float16', 'float32', 'float64', 'float96', 'float128')
if hasattr(np, dtype)
],
'complex': [
getattr(np, dtype)
for dtype in ('complex64', 'complex128', 'complex192', 'complex256')
if hasattr(np, dtype)
],
'others': [bool, object, bytes, str, np.void],
}

Expand Down

0 comments on commit 2398cc3

Please sign in to comment.