Optimization: convert point slice indices to floats
@@ -1471,10 +1471,15 @@ class Points(Layer):
"""
# Get a list of the data for the points in this slice
not_disp = list(self._dims_not_displayed)
- indices = np.array(dims_indices)
+ # We want a numpy array so we can use fancy indexing with the non-displayed
+ # indices, but as dims_indices can (and often/always does) contain slice
+ # objects, the array has dtype=object which is then very slow for the
+ # arithmetic below. As Points._round_index is always False, we can safely
+ # convert to float to get a major performance improvement.
+ not_disp_indices = np.array(dims_indices)[not_disp].astype(float)
if len(self.data) > 0:
if self.out_of_slice_display is True and self.ndim > 2:
- distances = abs(self.data[:, not_disp] - indices[not_disp])
+ distances = abs(self.data[:, not_disp] - not_disp_indices)
sizes = self.size[:, not_disp] / 2
matches = np.all(distances <= sizes, axis=1)
size_match = sizes[matches]
@@ -1486,7 +1491,7 @@ class Points(Layer):
return slice_indices, scale
else:
data = self.data[:, not_disp]
- distances = np.abs(data - indices[not_disp])
+ distances = np.abs(data - not_disp_indices)
matches = np.all(distances <= 0.5, axis=1)
slice_indices = np.where(matches)[0].astype(int)
return slice_indices, 1
