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

bethgelab / foolbox / 8140123939

04 Mar 2024 12:25PM UTC coverage: 98.477%. Remained the same
8140123939

push

github

web-flow
Increase package version (#724)

3492 of 3546 relevant lines covered (98.48%)

7.22 hits per line

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

100.0
/foolbox/models/numpy.py
1
from typing import TypeVar, Callable, Optional
10✔
2
import eagerpy as ep
10✔
3

4
from ..types import Bounds
10✔
5
from ..types import BoundsInput
10✔
6

7
from .base import Model
10✔
8

9

10
T = TypeVar("T")
10✔
11

12

13
class NumPyModel(Model):
10✔
14
    def __init__(
10✔
15
        self, model: Callable, bounds: BoundsInput, data_format: Optional[str] = None
16
    ):
17
        self._model = model
10✔
18
        self._bounds = Bounds(*bounds)
10✔
19
        if data_format is not None:
10✔
20
            if data_format not in ["channels_first", "channels_last"]:
10✔
21
                raise ValueError(
10✔
22
                    f"expected data_format to be 'channels_first' or 'channels_last', got {data_format}"
23
                )
24
        self._data_format = data_format
10✔
25

26
    @property
10✔
27
    def bounds(self) -> Bounds:
10✔
28
        return self._bounds
10✔
29

30
    def __call__(self, inputs: T) -> T:
10✔
31
        x, restore_type = ep.astensor_(inputs)
2✔
32
        y = self._model(x.numpy())
2✔
33
        z = ep.from_numpy(x, y)
2✔
34
        return restore_type(z)
2✔
35

36
    @property
10✔
37
    def data_format(self) -> str:
10✔
38
        if self._data_format is None:
10✔
39
            raise AttributeError(  # AttributeError -> hasattr returns False
10✔
40
                "please specify data_format when initializing the NumPyModel"
41
            )
42
        return self._data_format
2✔
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