Skip to content

Commit ec5157d

Browse files
committed
BF - add intp dtype alias for numpy hashing changes
1 parent 98ea9b5 commit ec5157d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

nibabel/volumeutils.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,23 @@ def make_dt_codes(codes):
262262
of the corresponding code, name, type, dtype, or swapped dtype
263263
'''
264264
dt_codes = []
265+
intp_dt = np.dtype(np.intp)
265266
for code, name, np_type in codes:
266267
this_dt = np.dtype(np_type)
268+
code_syns = [code, name, np_type]
269+
dtypes = [this_dt]
270+
# intp type is effectively same as int32 on 32 bit and int64 on 64 bit.
271+
# They compare equal, but in some (all?) numpy versions, they may hash
272+
# differently. If so we need to add them
273+
if this_dt == intp_dt and hash(this_dt) != hash(intp_dt):
274+
dtypes.append(intp_dt)
267275
# To satisfy an oddness in numpy dtype hashing, we need to add the dtype
268-
# with native order as well as the default dtype (=) order
269-
dt_codes.append((code, name,
270-
np_type,
271-
this_dt,
272-
this_dt.newbyteorder(native_code),
273-
this_dt.newbyteorder(swapped_code)))
276+
# with explicit native order as well as the default dtype (=) order
277+
for dt in dtypes:
278+
code_syns +=[dt,
279+
dt.newbyteorder(native_code),
280+
dt.newbyteorder(swapped_code)]
281+
dt_codes.append(code_syns)
274282
return Recoder(dt_codes,
275283
fields=('code',
276284
'label',

0 commit comments

Comments
 (0)