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

bethgelab / foolbox / 8137716344

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

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/tensorboard.py
1
"""Internal module for attacks that support logging to TensorBoard"""
2
from typing import Union, Callable, TypeVar, Any, cast
10✔
3
from typing_extensions import Literal
10✔
4
import eagerpy as ep
10✔
5
from functools import wraps
10✔
6

7

8
FuncType = Callable[..., None]
10✔
9
F = TypeVar("F", bound=FuncType)
10✔
10

11

12
def maybenoop(f: F) -> F:
10✔
13
    @wraps(f)
10✔
14
    def wrapper(self: "TensorBoard", *args: Any, **kwds: Any) -> None:
10✔
15
        if self.writer is None:
8✔
16
            return
8✔
17
        return f(self, *args, **kwds)
8✔
18

19
    return cast(F, wrapper)
10✔
20

21

22
class TensorBoard:
10✔
23
    """A custom TensorBoard class that accepts EagerPy tensors and that
24
    can be disabled by turned into a noop by passing logdir=False.
25

26
    This makes it possible to add tensorboard logging without any if
27
    statements and without any computational overhead if it's disabled.
28
    """
29

30
    def __init__(self, logdir: Union[Literal[False], None, str]):
10✔
31
        if logdir or (logdir is None):
8✔
32
            from tensorboardX import SummaryWriter
8✔
33

34
            self.writer = SummaryWriter(logdir=logdir)
8✔
35
        else:
36
            self.writer = None
8✔
37

38
    @maybenoop
10✔
39
    def close(self) -> None:
10✔
40
        self.writer.close()
8✔
41

42
    @maybenoop
10✔
43
    def scalar(self, tag: str, x: Union[int, float], step: int) -> None:
10✔
44
        self.writer.add_scalar(tag, x, step)
8✔
45

46
    @maybenoop
10✔
47
    def mean(self, tag: str, x: ep.Tensor, step: int) -> None:
10✔
48
        self.writer.add_scalar(tag, x.mean(axis=0).item(), step)
8✔
49

50
    @maybenoop
10✔
51
    def probability(self, tag: str, x: ep.Tensor, step: int) -> None:
10✔
52
        self.writer.add_scalar(tag, x.float32().mean(axis=0).item(), step)
8✔
53

54
    @maybenoop
10✔
55
    def conditional_mean(
10✔
56
        self, tag: str, x: ep.Tensor, cond: ep.Tensor, step: int
57
    ) -> None:
58
        cond_ = cond.numpy()
8✔
59
        if ~cond_.any():
8✔
60
            return
8✔
61
        x_ = x.numpy()
8✔
62
        x_ = x_[cond_]
8✔
63
        self.writer.add_scalar(tag, x_.mean(axis=0).item(), step)
8✔
64

65
    @maybenoop
10✔
66
    def probability_ratio(
10✔
67
        self, tag: str, x: ep.Tensor, y: ep.Tensor, step: int
68
    ) -> None:
69
        x_ = x.float32().mean(axis=0).item()
8✔
70
        y_ = y.float32().mean(axis=0).item()
8✔
71
        if y_ == 0:
8✔
72
            return
8✔
73
        self.writer.add_scalar(tag, x_ / y_, step)
8✔
74

75
    @maybenoop
10✔
76
    def histogram(
10✔
77
        self, tag: str, x: ep.Tensor, step: int, *, first: bool = True
78
    ) -> None:
79
        x = x.numpy()
8✔
80
        self.writer.add_histogram(tag, x, step)
8✔
81
        if first:
8✔
82
            self.writer.add_scalar(tag + "/0", x[0].item(), step)
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

© 2026 Coveralls, Inc