Exemple #1
0
 def testExecuteMultipleWithoutError(self):
     all_ops = []
     shape = [6, 5]
     seed = [42, 24]
     for compute_uv_ in True, False:
         for full_matrices_ in True, False:
             matrix1 = stateless_random_ops.stateless_random_normal(
                 shape, seed)
             matrix2 = stateless_random_ops.stateless_random_normal(
                 shape, seed)
             self.assertAllEqual(matrix1, matrix2)
             if compute_uv_:
                 s1, u1, v1 = linalg_ops.svd(matrix1,
                                             compute_uv=compute_uv_,
                                             full_matrices=full_matrices_)
                 s2, u2, v2 = linalg_ops.svd(matrix2,
                                             compute_uv=compute_uv_,
                                             full_matrices=full_matrices_)
                 all_ops += [s1, s2, u1, u2, v1, v2]
             else:
                 s1 = linalg_ops.svd(matrix1,
                                     compute_uv=compute_uv_,
                                     full_matrices=full_matrices_)
                 s2 = linalg_ops.svd(matrix2,
                                     compute_uv=compute_uv_,
                                     full_matrices=full_matrices_)
                 all_ops += [s1, s2]
     val = self.evaluate(all_ops)
     for i in range(0, len(val), 2):
         self.assertAllEqual(val[i], val[i + 1])
 def testConcurrentExecutesWithoutError(self):
   seed = [42, 24]
   matrix_shape = [5, 5]
   matrix1 = stateless_random_ops.stateless_random_normal(matrix_shape, seed)
   matrix2 = stateless_random_ops.stateless_random_normal(matrix_shape, seed)
   matrix1 = math_ops.matmul(matrix1, matrix1, adjoint_a=True)
   matrix2 = math_ops.matmul(matrix2, matrix2, adjoint_a=True)
   c1 = linalg_ops.cholesky(matrix1)
   c2 = linalg_ops.cholesky(matrix2)
   c1_val, c2_val = self.evaluate([c1, c2])
   self.assertAllClose(c1_val, c2_val)
Exemple #3
0
 def testConcurrentExecutesWithoutError(self):
   matrix_shape = [5, 5]
   seed = [42, 24]
   matrix1 = stateless_random_ops.stateless_random_normal(
       shape=matrix_shape, seed=seed)
   matrix2 = stateless_random_ops.stateless_random_normal(
       shape=matrix_shape, seed=seed)
   self.assertAllEqual(matrix1, matrix2)
   lu1, p1 = linalg_ops.lu(matrix1)
   lu2, p2 = linalg_ops.lu(matrix2)
   lu1_val, p1_val, lu2_val, p2_val = self.evaluate([lu1, p1, lu2, p2])
   self.assertAllEqual(lu1_val, lu2_val)
   self.assertAllEqual(p1_val, p2_val)
 def testConcurrentExecutesWithoutError(self):
   matrix_shape = [5, 5]
   seed = [42, 24]
   matrix1 = math_ops.cast(
       stateless_random_ops.stateless_random_normal(matrix_shape, seed=seed),
       dtypes.complex64)
   matrix2 = math_ops.cast(
       stateless_random_ops.stateless_random_normal(matrix_shape, seed=seed),
       dtypes.complex64)
   self.assertAllEqual(matrix1, matrix2)
   logm1 = gen_linalg_ops.matrix_logarithm(matrix1)
   logm2 = gen_linalg_ops.matrix_logarithm(matrix2)
   logm = self.evaluate([logm1, logm2])
   self.assertAllEqual(logm[0], logm[1])
Exemple #5
0
 def testConcurrentExecutesWithoutError(self):
     matrix_shape = [5, 5]
     seed = [42, 24]
     matrix1 = stateless_random_ops.stateless_random_normal(
         shape=matrix_shape, seed=seed)
     matrix2 = stateless_random_ops.stateless_random_normal(
         shape=matrix_shape, seed=seed)
     self.assertAllEqual(matrix1, matrix2)
     square1 = math_ops.matmul(matrix1, matrix1)
     square2 = math_ops.matmul(matrix2, matrix2)
     sqrt1 = gen_linalg_ops.matrix_square_root(square1)
     sqrt2 = gen_linalg_ops.matrix_square_root(square2)
     all_ops = [sqrt1, sqrt2]
     sqrt = self.evaluate(all_ops)
     self.assertAllClose(sqrt[0], sqrt[1])
 def testRandomNormalIsFinite(self):
   with self.session() as sess, self.test_scope():
     for dtype in self._random_types():
       seed_t = array_ops.placeholder(dtypes.int32, shape=[2])
       x = stateless.stateless_random_normal(
           shape=[10000], seed=seed_t, dtype=dtype)
       y = sess.run(x, {seed_t: [0x12345678, 0xabcdef1]})
       self.assertTrue(np.all(np.isfinite(y)))
 def testRandomNormalIsFinite(self):
   with self.cached_session() as sess, self.test_scope():
     for dtype in self._random_types():
       seed_t = array_ops.placeholder(dtypes.int32, shape=[2])
       x = stateless.stateless_random_normal(
           shape=[10000], seed=seed_t, dtype=dtype)
       y = sess.run(x, {seed_t: [0x12345678, 0xabcdef12]})
       self.assertTrue(np.all(np.isfinite(y)))
Exemple #8
0
 def _random_normal(self, *args, **kwargs):
     if self._use_stateless:
         c_seed = self._stateless_seed_offset + kwargs['seed']
         kwargs['seed'] = math_ops.cast(
             array_ops.stack([c_seed, self._global_step]), dtypes.int32)
         return stateless_random_ops.stateless_random_normal(
             *args, **kwargs)
     else:
         return random_ops.random_normal(*args, **kwargs)
Exemple #9
0
 def testConcurrentExecutesWithoutError(self):
   seed = [42, 24]
   all_ops = []
   for full_matrices_ in True, False:
     for rows_ in 4, 5:
       for cols_ in 4, 5:
         matrix_shape = [rows_, cols_]
         matrix1 = stateless_random_ops.stateless_random_normal(
             matrix_shape, seed)
         matrix2 = stateless_random_ops.stateless_random_normal(
             matrix_shape, seed)
         self.assertAllEqual(matrix1, matrix2)
         q1, r1 = linalg_ops.qr(matrix1, full_matrices=full_matrices_)
         q2, r2 = linalg_ops.qr(matrix2, full_matrices=full_matrices_)
         all_ops += [q1, q2, r1, r2]
   val = self.evaluate(all_ops)
   for i in range(0, len(val), 2):
     self.assertAllClose(val[i], val[i + 1])
Exemple #10
0
 def testConcurrent(self):
     seed = [42, 24]
     matrix_shape = [3, 3]
     all_ops = []
     for adjoint_ in False, True:
         lhs1 = stateless_random_ops.stateless_random_normal(matrix_shape,
                                                             seed=seed)
         lhs2 = stateless_random_ops.stateless_random_normal(matrix_shape,
                                                             seed=seed)
         rhs1 = stateless_random_ops.stateless_random_normal(matrix_shape,
                                                             seed=seed)
         rhs2 = stateless_random_ops.stateless_random_normal(matrix_shape,
                                                             seed=seed)
         s1 = linalg_ops.matrix_solve(lhs1, rhs1, adjoint=adjoint_)
         s2 = linalg_ops.matrix_solve(lhs2, rhs2, adjoint=adjoint_)
         all_ops += [s1, s2]
     val = self.evaluate(all_ops)
     for i in range(0, len(all_ops), 2):
         self.assertAllEqual(val[i], val[i + 1])
Exemple #11
0
 def testThrowDeterminismError(self):
   shape = [6, 5]
   seed = [42, 24]
   matrix1 = stateless_random_ops.stateless_random_normal(shape, seed)
   with test_util.deterministic_ops():
     if test_util.is_gpu_available(cuda_only=True):
       with self.assertRaisesRegex(
           errors_impl.UnimplementedError, "Determinism is not yet supported "
           "for Svd."):
         self.evaluate(linalg_ops.svd(matrix1))
 def testDistributionOfStatelessRandomNormal(self):
   """Use Anderson-Darling test to test distribution appears normal."""
   with self.cached_session() as sess, self.test_scope():
     for dtype in self._random_types():
       seed_t = array_ops.placeholder(dtypes.int32, shape=[2])
       n = 1000
       x = stateless.stateless_random_normal(
           shape=[n], seed=seed_t, dtype=dtype)
       y = sess.run(x, {seed_t: [25252, 314159]})
       # The constant 2.492 is the 5% critical value for the Anderson-Darling
       # test where the mean and variance are known. This test is probabilistic
       # so to avoid flakiness the seed is fixed.
       self.assertTrue(self._anderson_darling(y.astype(float)) < 2.492)
 def f(x):
   return xla.compile(
       lambda x: stateless.stateless_random_normal([], seed=x), [x])