Skip to content

Commit dc5a398

Browse files
committed
Fix visualization of unsigned integer attributes
1 parent a3d0f7a commit dc5a398

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

ml3d/vis/visualizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def _convert_to_numpy(self, ary):
141141
elif isinstance(ary, np.ndarray):
142142
if len(ary.shape) == 2 and ary.shape[0] == 1:
143143
ary = ary[0] # "1D" array as 2D: [[1, 2, 3,...]]
144-
if ary.dtype.name.startswith('int'):
144+
if np.issubdtype(ary.dtype, np.integer):
145145
return np.array(ary, dtype='float32')
146146
else:
147147
return ary

tests/test_visualizer.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import numpy as np
2+
import pytest
3+
4+
from ml3d.vis.visualizer import Model
5+
6+
7+
@pytest.mark.parametrize("dtype", [np.uint8, np.uint16, np.uint32, np.uint64])
8+
def test_unsigned_integer_attributes_are_converted_to_float32(dtype):
9+
values = np.array([0, 1, 2], dtype=dtype)
10+
11+
converted = Model()._convert_to_numpy(values)
12+
13+
assert converted.dtype == np.float32
14+
np.testing.assert_array_equal(converted, values)

0 commit comments

Comments
 (0)