1# See "Writing benchmarks" in the asv docs for more information.
2# https://asv.readthedocs.io/en/latest/writing_benchmarks.html
3import numpy as np
4from skimage import transform
5
6
7class InterpolationResize:
8
9    param_names = ['new_shape', 'order', 'mode', 'dtype', 'anti_aliasing']
10    params = [
11        ((500, 800), (2000, 4000), (80, 80, 80), (150, 150, 150)),  # new_shape
12        (0, 1, 3, 5),    # order
13        ('symmetric',),  # mode
14        (np.float64, ),  # dtype
15        (True,),         # anti_aliasing
16    ]
17
18    """Benchmark for filter routines in scikit-image."""
19    def setup(self, new_shape, order, mode, dtype, anti_aliasing):
20        ndim = len(new_shape)
21        if ndim == 2:
22            image = np.random.random((1000, 1000))
23        else:
24            image = np.random.random((100, 100, 100))
25        self.image = image.astype(dtype, copy=False)
26
27    def time_resize(self, new_shape, order, mode, dtype, anti_aliasing):
28        transform.resize(self.image, new_shape, order=order, mode=mode,
29                         anti_aliasing=anti_aliasing)
30
31    def time_rescale(self, new_shape, order, mode, dtype, anti_aliasing):
32        scale = tuple(s2 / s1 for s2, s1 in zip(new_shape, self.image.shape))
33        transform.rescale(self.image, scale, order=order, mode=mode,
34                          anti_aliasing=anti_aliasing)
35
36    def peakmem_resize(self, new_shape, order, mode, dtype, anti_aliasing):
37        transform.resize(self.image, new_shape, order=order, mode=mode,
38                         anti_aliasing=anti_aliasing)
39
40    def peakmem_reference(self, *args):
41        """Provide reference for memory measurement with empty benchmark.
42
43        Peakmem benchmarks measure the maximum amount of RAM used by a
44        function. However, this maximum also includes the memory used
45        during the setup routine (as of asv 0.2.1; see [1]_).
46        Measuring an empty peakmem function might allow us to disambiguate
47        between the memory used by setup and the memory used by target (see
48        other ``peakmem_`` functions below).
49
50        References
51        ----------
52        .. [1]: https://asv.readthedocs.io/en/stable/writing_benchmarks.html#peak-memory
53        """  # noqa
54        pass
55