def testDegenerate(self):
     for use_gpu in False, True:
         with self.test_session(use_gpu=use_gpu):
             for dtype in (tf.bool, ):
                 # A large number is needed to get Eigen to die
                 x = tf.zeros((0, 9938), dtype=dtype)
                 y = tf.reduce_nnz(x, [0])
                 self.assertAllEqual(y.eval(), np.zeros(9938))
Example #2
0
 def testDegenerate(self):
   for use_gpu in False, True:
     with self.test_session(use_gpu=use_gpu):
       for dtype in (tf.bool,):
         # A large number is needed to get Eigen to die
         x = tf.zeros((0, 9938), dtype=dtype)
         y = tf.reduce_nnz(x, [0])
         self.assertAllEqual(y.eval(), np.zeros(9938))
 def _compare(self,
              x,
              reduction_axes,
              keep_dims,
              use_gpu=False,
              feed_dict=None):
     np_ans = (x != 0).astype(np.int32)
     if reduction_axes is None:
         np_ans = np.sum(np_ans, keepdims=keep_dims)
     else:
         reduction_axes = np.array(reduction_axes).astype(np.int32)
         for ra in reduction_axes.ravel()[::-1]:
             np_ans = np.sum(np_ans, axis=ra, keepdims=keep_dims)
     with self.test_session(use_gpu=use_gpu) as sess:
         tf_ans = tf.reduce_nnz(x, reduction_axes, keep_dims)
         out = sess.run(tf_ans, feed_dict)
     self.assertAllClose(np_ans, out)
     self.assertShapeEqual(np_ans, tf_ans)
Example #4
0
 def _compare(self,
              x,
              reduction_axes,
              keep_dims,
              use_gpu=False,
              feed_dict=None):
   np_ans = (x != 0).astype(np.int32)
   if reduction_axes is None:
     np_ans = np.sum(np_ans, keepdims=keep_dims)
   else:
     reduction_axes = np.array(reduction_axes).astype(np.int32)
     for ra in reduction_axes.ravel()[::-1]:
       np_ans = np.sum(np_ans, axis=ra, keepdims=keep_dims)
   with self.test_session(use_gpu=use_gpu) as sess:
     tf_ans = tf.reduce_nnz(x, reduction_axes, keep_dims)
     out = sess.run(tf_ans, feed_dict)
   self.assertAllClose(np_ans, out)
   self.assertShapeEqual(np_ans, tf_ans)