aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/distributions
diff options
context:
space:
mode:
authorGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-08-09 10:33:18 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-08-09 10:33:18 -0700
commitf9eaa3c2990059b8210b0d8cc6829429c052d6db (patch)
treeafee848a7700cfc9aac1aa13fdcab85c7cd89b12 /tensorflow/contrib/distributions
parent799213b7aa0b0442b1d15a2ea6770913879e76dd (diff)
parent7462a25a2aed29f63ed3a047aec4ff363d8b6aad (diff)
Merge pull request #20477 from wdirons:fix_inverse_in_matrix_inverse_tril_test
PiperOrigin-RevId: 208069965
Diffstat (limited to 'tensorflow/contrib/distributions')
-rw-r--r--tensorflow/contrib/distributions/python/kernel_tests/bijectors/matrix_inverse_tril_test.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/tensorflow/contrib/distributions/python/kernel_tests/bijectors/matrix_inverse_tril_test.py b/tensorflow/contrib/distributions/python/kernel_tests/bijectors/matrix_inverse_tril_test.py
index 85d604e34a..49a9afe3f6 100644
--- a/tensorflow/contrib/distributions/python/kernel_tests/bijectors/matrix_inverse_tril_test.py
+++ b/tensorflow/contrib/distributions/python/kernel_tests/bijectors/matrix_inverse_tril_test.py
@@ -29,6 +29,17 @@ from tensorflow.python.platform import test
class MatrixInverseTriLBijectorTest(test.TestCase):
"""Tests the correctness of the Y = inv(tril) transformation."""
+ #The inverse of 0 is undefined, as the numbers above the main
+ #diagonal must be zero, we zero out these numbers after running inverse.
+ #See: https://github.com/numpy/numpy/issues/11445
+ def _inv(self, x):
+ y = np.linalg.inv(x)
+ #triu_indices only works on 2d arrays
+ #need to iterate over all the 2d arrays in a x-dimensional array.
+ for idx in np.ndindex(y.shape[0:-2]):
+ y[idx][np.triu_indices(y[idx].shape[-1], 1)] = 0
+ return y
+
@test_util.run_in_graph_and_eager_modes
def testComputesCorrectValues(self):
inv = bijectors.MatrixInverseTriL(validate_args=True)
@@ -98,7 +109,7 @@ class MatrixInverseTriLBijectorTest(test.TestCase):
[2., 3.]]],
[[[4., 0.],
[5., -6.]]]], dtype=np.float32)
- x_inv_ = np.linalg.inv(x_)
+ x_inv_ = self._inv(x_)
expected_fldj_ = -4. * np.sum(
np.log(np.abs(np.diagonal(x_, axis1=-2, axis2=-1))), axis=-1)