Skip to content

Commit 0d2ac49

Browse files
committed
BF - work round numpy 1.5.1 bug for zeros_like
Michael spotted a test error for the working_type function, and complex values. This turned out to be an obscure bug in ones_like, zeros_like for numpy 1.5.1. Work round this bug in working_type function.
1 parent f1e32ea commit 0d2ac49

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

nibabel/volumeutils.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -783,13 +783,16 @@ def working_type(in_type, slope=1.0, inter=0.0):
783783
Numpy type resulting from applying `inter` and `slope` to array of type
784784
`in_type`.
785785
"""
786-
in_type = np.dtype(in_type).type
787-
# What do these cast into?
788-
val = np.atleast_1d(in_type(1))
786+
val = np.array([1], dtype=in_type)
787+
slope = np.array(slope)
788+
inter = np.array(inter)
789+
# Don't use real values to avoid overflows. Promote to 1D to avoid scalar
790+
# casting rules. Don't use ones_like, zeros_like because of a bug in numpy
791+
# <= 1.5.1 in converting complex192 / complex256 scalars.
789792
if inter != 0:
790-
val = val + np.atleast_1d(np.zeros_like(inter))
793+
val = val + np.array([0], dtype=inter.dtype)
791794
if slope != 1:
792-
val = val + np.atleast_1d(np.ones_like(slope))
795+
val = val / np.array([1], dtype=slope.dtype)
793796
return val.dtype.type
794797

795798

0 commit comments

Comments
 (0)