File: benchmark_interpolation.py

package info (click to toggle)
skimage 0.25.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,720 kB
  • sloc: python: 60,007; cpp: 2,592; ansic: 1,591; xml: 1,342; javascript: 1,267; makefile: 168; sh: 20
file content (57 lines) | stat: -rw-r--r-- 2,199 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# See "Writing benchmarks" in the asv docs for more information.
# https://asv.readthedocs.io/en/latest/writing_benchmarks.html
import numpy as np
from skimage import transform


class InterpolationResize:
    param_names = ['new_shape', 'order', 'mode', 'dtype', 'anti_aliasing']
    params = [
        ((500, 800), (2000, 4000), (80, 80, 80), (150, 150, 150)),  # new_shape
        (0, 1, 3, 5),  # order
        ('symmetric',),  # mode
        (np.float64,),  # dtype
        (True,),  # anti_aliasing
    ]

    """Benchmark for filter routines in scikit-image."""

    def setup(self, new_shape, order, mode, dtype, anti_aliasing):
        ndim = len(new_shape)
        if ndim == 2:
            image = np.random.random((1000, 1000))
        else:
            image = np.random.random((100, 100, 100))
        self.image = image.astype(dtype, copy=False)

    def time_resize(self, new_shape, order, mode, dtype, anti_aliasing):
        transform.resize(
            self.image, new_shape, order=order, mode=mode, anti_aliasing=anti_aliasing
        )

    def time_rescale(self, new_shape, order, mode, dtype, anti_aliasing):
        scale = tuple(s2 / s1 for s2, s1 in zip(new_shape, self.image.shape))
        transform.rescale(
            self.image, scale, order=order, mode=mode, anti_aliasing=anti_aliasing
        )

    def peakmem_resize(self, new_shape, order, mode, dtype, anti_aliasing):
        transform.resize(
            self.image, new_shape, order=order, mode=mode, anti_aliasing=anti_aliasing
        )

    def peakmem_reference(self, *args):
        """Provide reference for memory measurement with empty benchmark.

        Peakmem benchmarks measure the maximum amount of RAM used by a
        function. However, this maximum also includes the memory used
        during the setup routine (as of asv 0.2.1; see [1]_).
        Measuring an empty peakmem function might allow us to disambiguate
        between the memory used by setup and the memory used by target (see
        other ``peakmem_`` functions below).

        References
        ----------
        .. [1]: https://asv.readthedocs.io/en/stable/writing_benchmarks.html#peak-memory
        """
        pass