def test_thumbnail(): """Test the image thumbnail for square data.""" np.random.seed(0) data = np.random.random((10, 2, 2)) data[:, 0, :] = 18 * data[:, 0, :] + 1 data[0, :, :] = [0, 0] data[-1, 0, :] = [20, 20] data[-1, 1, :] = [0, 0] layer = Vectors(data) layer._update_thumbnail() assert layer.thumbnail.shape == layer._thumbnail_shape
def test_big_thumbail(): """Test the image thumbnail with n_vectors > _max_vectors_thumbnail""" np.random.seed(0) n_vectors = int(1.5 * Vectors._max_vectors_thumbnail) data = np.random.random((n_vectors, 2, 2)) data[:, 0, :] = 18 * data[:, 0, :] + 1 data[0, :, :] = [0, 0] data[-1, 0, :] = [20, 20] data[-1, 1, :] = [0, 0] layer = Vectors(data) layer._update_thumbnail() assert layer.thumbnail.shape == layer._thumbnail_shape
class Vectors2DSuite: """Benchmarks for the Vectors layer with 2D data""" params = [2**i for i in range(4, 18, 2)] def setup(self, n): np.random.seed(0) self.data = np.random.random((n, 2, 2)) self.layer = Vectors(self.data) def time_create_layer(self, n): """Time to create an image layer.""" Vectors(self.data) def time_refresh(self, n): """Time to refresh view.""" self.layer.refresh() def time_set_view_slice(self, n): """Time to set view slice.""" self.layer._set_view_slice() def time_update_thumbnail(self, n): """Time to update thumbnail.""" self.layer._update_thumbnail() def time_get_value(self, n): """Time to get current value.""" self.layer.get_value((0, ) * 2) def time_width(self, n): """Time to update width.""" self.layer.width = 2 def time_length(self, n): """Time to update length.""" self.layer.length = 2 def mem_layer(self, n): """Memory used by layer.""" return self.layer def mem_data(self, n): """Memory used by raw data.""" return self.data