-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tile utility function; speed up pointmass sampling
- Loading branch information
1 parent
08bad5c
commit 870dd96
Showing
4 changed files
with
155 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import numpy as np | ||
import tensorflow as tf | ||
|
||
from edward.util import get_dims, tile | ||
|
||
|
||
class test_tile_class(tf.test.TestCase): | ||
|
||
def _test(self, input, multiples): | ||
if isinstance(multiples, int) or isinstance(multiples, float): | ||
multiples_shape = [multiples] | ||
elif isinstance(multiples, tuple): | ||
multiples_shape = list(multiples) | ||
else: | ||
multiples_shape = multiples | ||
|
||
input_shape = get_dims(input) | ||
diff = len(input_shape) - len(multiples_shape) | ||
if diff < 0: | ||
input_shape = [1] * abs(diff) + input_shape | ||
elif diff > 0: | ||
multiples_shape = [1] * diff + multiples_shape | ||
|
||
val_true = [x * y for x, y in zip(input_shape, multiples_shape)] | ||
with self.test_session(): | ||
val_est = get_dims(tile(input, multiples)) | ||
assert val_est == val_true | ||
|
||
def test_0d(self): | ||
x = tf.constant(0) | ||
self._test(x, 2) | ||
self._test(x, (2, 1)) | ||
|
||
def test_1d(self): | ||
x = tf.constant([0, 1, 2]) | ||
self._test(x, 2) | ||
self._test(x, (2, 2)) | ||
self._test(x, (2, 1, 2)) | ||
x = tf.constant([1, 2, 3, 4]) | ||
self._test(x, (4, 1)) | ||
|
||
def test_2d(self): | ||
x = tf.constant([[1, 2], [3, 4]]) | ||
self._test(x, 2) | ||
self._test(x, (2, 1)) | ||
|
||
if __name__ == '__main__': | ||
tf.test.main() |