forked from tancik/fourier-feature-networks
-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_fourier_feature_transform.py
46 lines (25 loc) · 1.07 KB
/
test_fourier_feature_transform.py
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
import pytest
import torch
from fourier_feature_transform import GaussianFourierFeatureTransform
def test_basic_tensor():
x = torch.randn((1, 2, 256, 256))
x = GaussianFourierFeatureTransform(2, 50, 10)(x)
assert x.shape == (1, 100, 256, 256)
def test_nonsquare_tensor():
x = torch.randn((1, 2, 256, 257))
x = GaussianFourierFeatureTransform(2, 50, 10)(x)
assert x.shape == (1, 100, 256, 257)
def test_one_width_height():
x = torch.randn((1, 2, 1, 1))
x = GaussianFourierFeatureTransform(2, 50, 10)(x)
assert x.shape == (1, 100, 1, 1)
def test_wrong_num_dims():
x = torch.randn((1, 2, 1))
with pytest.raises(AssertionError) as excinfo:
_ = GaussianFourierFeatureTransform(3, 50, 10)(x)
assert "Expected 4D input (got 3D input)" in str(excinfo.value)
def test_mismatched_input_channels():
x = torch.randn((1, 2, 1, 1))
with pytest.raises(AssertionError) as excinfo:
_ = GaussianFourierFeatureTransform(3, 50, 10)(x)
assert "Expected input to have 3 channels (got 2 channels)" in str(excinfo.value)