Merge pull request #311 from stefanv/dtype_bool_fast

ENH: Bool dtype conversion speed improvements.
This commit is contained in:
Tony S Yu
2012-09-13 18:35:27 -07:00
+6 -3
View File
@@ -155,11 +155,14 @@ def convert(image, dtype, force_copy=False, uniform=False):
if kind_in in "fi":
sign_loss()
prec_loss()
return dtype(image)
return image > dtype_in(dtype_range[dtype_in][1] / 2)
if kind_in == 'b':
# from binary image, to float and to integer
return dtype(image) * dtype(dtype_range[dtype][1])
result = dtype(image)
if kind != 'f':
result *= dtype(dtype_range[dtype][1])
return result
if kind in 'ui':
imin = np.iinfo(dtype).min