• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bethgelab / foolbox / 7618398226

22 Jan 2024 10:53PM UTC coverage: 98.47%. Remained the same
7618398226

push

github

web-flow
Bump pillow from 10.1.0 to 10.2.0 in /tests (#718)

Bumps [pillow](https://github.com/python-pillow/Pillow) from 10.1.0 to 10.2.0.
- [Release notes](https://github.com/python-pillow/Pillow/releases)
- [Changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst)
- [Commits](https://github.com/python-pillow/Pillow/compare/10.1.0...10.2.0)

---
updated-dependencies:
- dependency-name: pillow
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

3475 of 3529 relevant lines covered (98.47%)

7.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/foolbox/plot.py
1
from typing import Tuple, Any, Optional
10✔
2
import numpy as np
10✔
3
import eagerpy as ep
10✔
4

5

6
def images(
10✔
7
    images: Any,
8
    *,
9
    n: Optional[int] = None,
10
    data_format: Optional[str] = None,
11
    bounds: Tuple[float, float] = (0, 1),
12
    ncols: Optional[int] = None,
13
    nrows: Optional[int] = None,
14
    figsize: Optional[Tuple[float, float]] = None,
15
    scale: float = 1,
16
    **kwargs: Any,
17
) -> None:
18
    import matplotlib.pyplot as plt
8✔
19

20
    x: ep.Tensor = ep.astensor(images)
8✔
21
    if x.ndim != 4:
8✔
22
        raise ValueError(
8✔
23
            "expected images to have four dimensions: (N, C, H, W) or (N, H, W, C)"
24
        )
25
    if n is not None:
8✔
26
        x = x[:n]
8✔
27
    if data_format is None:
8✔
28
        channels_first = x.shape[1] == 1 or x.shape[1] == 3
8✔
29
        channels_last = x.shape[-1] == 1 or x.shape[-1] == 3
8✔
30
        if channels_first == channels_last:
8✔
31
            raise ValueError("data_format ambigous, please specify it explicitly")
8✔
32
    else:
33
        channels_first = data_format == "channels_first"
8✔
34
        channels_last = data_format == "channels_last"
8✔
35
        if not channels_first and not channels_last:
8✔
36
            raise ValueError(
8✔
37
                "expected data_format to be 'channels_first' or 'channels_last'"
38
            )
39
    assert channels_first != channels_last
8✔
40
    x_np = x.numpy()
8✔
41
    if channels_first:
8✔
42
        x_np = np.transpose(x_np, axes=(0, 2, 3, 1))
8✔
43
    min_, max_ = bounds
8✔
44
    x_np = (x_np - min_) / (max_ - min_)
8✔
45

46
    if nrows is None and ncols is None:
8✔
47
        nrows = 1
8✔
48
    if ncols is None:
8✔
49
        assert nrows is not None
8✔
50
        ncols = (len(x_np) + nrows - 1) // nrows
8✔
51
    elif nrows is None:
8✔
52
        nrows = (len(x_np) + ncols - 1) // ncols
8✔
53
    if figsize is None:
8✔
54
        figsize = (ncols * scale, nrows * scale)
8✔
55
    fig, axes = plt.subplots(
8✔
56
        ncols=ncols,
57
        nrows=nrows,
58
        figsize=figsize,
59
        squeeze=False,
60
        constrained_layout=True,
61
        **kwargs,
62
    )
63

64
    for row in range(nrows):
8✔
65
        for col in range(ncols):
8✔
66
            ax = axes[row][col]
8✔
67
            ax.set_xticks([])
8✔
68
            ax.set_yticks([])
8✔
69
            ax.axis("off")
8✔
70
            i = row * ncols + col
8✔
71
            if i < len(x):
8✔
72
                if x_np.shape[-1] == 1:
8✔
73
                    ax.imshow(x_np[i][:, :, 0])
8✔
74
                else:
75
                    ax.imshow(x_np[i])
8✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc