-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix the mistake of offset and add test for value
- Loading branch information
1 parent
691a2a8
commit 81b1986
Showing
2 changed files
with
26 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
import pytest | ||
|
||
import numpy as np | ||
import tensorflow as tf | ||
|
||
from ..positional_encode import PositionalEncode | ||
|
||
|
||
def test_output_shape(): | ||
layer = PositionalEncode() | ||
@pytest.fixture(scope='module') | ||
def layer(): | ||
return PositionalEncode() | ||
|
||
|
||
def test_output_shape(layer): | ||
inputs = tf.zeros([5, 4, 3]) | ||
outputs = layer(inputs) | ||
assert outputs.shape.as_list() == inputs.shape.as_list() | ||
|
||
|
||
def test_output_val(layer, sess): | ||
inputs = tf.constant([ | ||
[[1., 2., 3., 4.]], | ||
[[5., 6., 7., 8.]], | ||
]) | ||
outputs = layer(inputs) | ||
inputs_val, outputs_val = sess.run([inputs, outputs]) | ||
np.testing.assert_array_almost_equal( | ||
outputs_val[:, 0], | ||
inputs_val[:, 0] + np.array([ | ||
[0., 1., 0., 1.] # sin0, cos0, sin0, | ||
for _ in range(len(inputs_val)) | ||
]), | ||
) |