def testShapeMismatch(self):
   c = np.random.randint(0, 2, 6).astype(np.bool).reshape(1, 3, 2)
   x = np.random.rand(1, 3, 2) * 100
   y = np.random.rand(2, 5, 3) * 100
   for t in [np.float32, np.float64, np.int32, np.int64, np.complex64]:
     xt = x.astype(t)
     yt = y.astype(t)
     with self.assertRaises(ValueError):
       tf.batch_select(c, xt, yt)
 def _compare(self, c, x, y, use_gpu):
   np_ans = np.concatenate(
       [x_i if c_i else y_i for c_i, x_i, y_i in zip(c, x, y)])
   with self.test_session(use_gpu=use_gpu):
     out = tf.batch_select(c, x, y)
     tf_ans = out.eval()
   self.assertAllEqual(np_ans, tf_ans)
   self.assertShapeEqual(np_ans, out)
 def _compareGradientY(self, c, x, y):
   with self.test_session():
     inx = tf.convert_to_tensor(x)
     iny = tf.convert_to_tensor(y)
     out = tf.batch_select(c, inx, iny)
     s = list(np.shape(c))
     jacob_t, jacob_n = tf.test.compute_gradient(iny,
                                                 s,
                                                 out,
                                                 s,
                                                 x_init_value=y)
   if x.dtype == np.float32:
     self.assertAllClose(jacob_t, jacob_n, rtol=1e-3, atol=1e-3)
   elif x.dtype == np.float64:
     self.assertAllClose(jacob_t, jacob_n, rtol=1e-5, atol=1e-5)