Skip to content

Commit

Permalink
Remove reference_video_tensor() fixture (#62)
Browse files Browse the repository at this point in the history
Summary:
This PR removes `reference_video_tensor()` because its unnecessary.

I assume the use of this fixture was used to cache the corresponding returned value. This is unnecessary for 2 reasons:

- The fixture wasn't even cached anyway, because its scope wasn't set to `"session"`. You can verify that by printing something within the fixture, and running tests with `pytest -s`. You'll see the print statement being executed each time, proving that no caching was involved.
- Getting the return value is dead cheap and doesn't need to be cached in the first place. Proof:

```py
[ins] In [1]: import test_utils
tes
[nav] In [2]: %timeit test_utils.NASA_VIDEO.to_tensor()
55.8 µs ± 3.76 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
```

Pull Request resolved: #62

Reviewed By: scotts

Differential Revision: D59449321

Pulled By: NicolasHug

fbshipit-source-id: a848654115054e1526204d697d1d14748808ef91
  • Loading branch information
NicolasHug authored and facebook-github-bot committed Jul 8, 2024
1 parent 85d8b79 commit 508eee1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
12 changes: 3 additions & 9 deletions test/samplers/video_clip_sampler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
VideoClipSampler,
)

from ..test_utils import ( # noqa: F401; see use in test_sampler
assert_tensor_equal,
reference_video_tensor,
)
from ..test_utils import assert_tensor_equal, NASA_VIDEO


@pytest.mark.parametrize(
Expand All @@ -33,15 +30,12 @@
),
],
)
def test_sampler(
sampler_args,
reference_video_tensor, # noqa: F811; linter does not see this as a use
):
def test_sampler(sampler_args):
torch.manual_seed(0)
desired_width, desired_height = 320, 240
video_args = VideoArgs(desired_width=desired_width, desired_height=desired_height)
sampler = VideoClipSampler(video_args, sampler_args)
clips = sampler(reference_video_tensor)
clips = sampler(NASA_VIDEO.to_tensor())
assert_tensor_equal(len(clips), sampler_args.clips_per_video)
clip = clips[0]
if isinstance(sampler_args, TimeBasedSamplerArgs):
Expand Down
6 changes: 0 additions & 6 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from dataclasses import dataclass

import numpy as np
import pytest

import torch

Expand Down Expand Up @@ -36,11 +35,6 @@ def _load_tensor_from_file(filename: str) -> torch.Tensor:
return torch.load(file_path, weights_only=True)


@pytest.fixture()
def reference_video_tensor() -> torch.Tensor:
return NASA_VIDEO.to_tensor()


@dataclass
class TestContainerFile:
filename: str
Expand Down

0 comments on commit 508eee1

Please sign in to comment.