FIX: early fix for dtype conversion from bool to other type PR #306, Issue #263

This commit is contained in:
kuantkid
2012-09-10 13:00:32 +08:00
parent 38f0ca3dbc
commit 61be60cace
2 changed files with 7 additions and 8 deletions
+1 -4
View File
@@ -157,10 +157,7 @@ def convert(image, dtype, force_copy=False, uniform=False):
if kind_in == 'b':
# from binary image, to float and to integer
if kind == 'f':
return dtype(image)
elif kind in 'ui':
return dtype(image) * dtype_range[dtype][1]
return dtype(image) * dtype_range[dtype][1]
if kind in 'ui':
imin = np.iinfo(dtype).min
+6 -4
View File
@@ -93,12 +93,14 @@ def test_bool():
img_[1, 1] = True
img8[1, 1] = True
funcs = (img_as_float, img_as_int, img_as_ubyte, img_as_uint, img_as_bool)
for func in funcs:
for (func, dt) in [(img_as_int, np.int16),
(img_as_float, np.float64),
(img_as_uint, np.uint16),
(img_as_ubyte, np.ubyte)]:
converted_ = func(img_)
assert np.sum(converted_) == 1
assert np.sum(converted_) == dtype_range[dt][1]
converted8 = func(img8)
assert np.sum(converted8) == 1
assert np.sum(converted8) == dtype_range[dt][1]
if __name__ == '__main__':
np.testing.run_module_suite()