def test_indicators_to_sparse_ids_1d(self):
     indicators = (0, 0, 1, 0)
     sparse_ids = sparse_ops.indicators_to_sparse_ids(indicators)
     with self.cached_session():
         _assert_sparse_tensor_value(
             self,
             sparse_tensor.SparseTensorValue(
                 indices=((0, ), ),
                 values=(2, ),
                 dense_shape=(1, ),
             ), sparse_ids.eval())
 def test_string_indicators_to_sparse_ids(self):
     indicators = (
         (('', '', 'A', ''), ('', '', '', '')),
         (('B', '', '', 'C'), ('', '', 'D', '')),
     )
     sparse_ids = sparse_ops.indicators_to_sparse_ids(indicators)
     with self.cached_session():
         _assert_sparse_tensor_value(
             self,
             sparse_tensor.SparseTensorValue(
                 indices=((0, 0, 0), (1, 0, 0), (1, 0, 1), (1, 1, 0)),
                 values=(2, 0, 3, 2),
                 dense_shape=(2, 2, 2),
             ), sparse_ids.eval())
 def test_indicators_to_sparse_ids_unknown_rank(self):
     indicators_values = (
         ((0, 0, 1, 0), (0, 0, 0, 0)),
         ((1, 0, 0, 1), (0, 0, 1, 0)),
     )
     indicators = array_ops.placeholder(dtype=dtypes.int32)
     sparse_ids = sparse_ops.indicators_to_sparse_ids(indicators)
     with self.cached_session():
         _assert_sparse_tensor_value(
             self,
             sparse_tensor.SparseTensorValue(
                 indices=((0, 0, 0), (1, 0, 0), (1, 0, 1), (1, 1, 0)),
                 values=(2, 0, 3, 2),
                 dense_shape=(2, 2, 2),
             ), sparse_ids.eval(feed_dict={indicators: indicators_values}))
 def test_indicators_to_sparse_ids_ignore_value(self):
     indicators = (
         ((-1, -1, 10, -1), (-1, -1, -1, -1)),
         ((11, -1, -1, 12), (-1, -1, 13, -1)),
     )
     sparse_ids = sparse_ops.indicators_to_sparse_ids(indicators,
                                                      ignore_value=-1)
     with self.cached_session():
         _assert_sparse_tensor_value(
             self,
             sparse_tensor.SparseTensorValue(
                 indices=((0, 0, 0), (1, 0, 0), (1, 0, 1), (1, 1, 0)),
                 values=(2, 0, 3, 2),
                 dense_shape=(2, 2, 2),
             ), sparse_ids.eval())
 def test_int16_to_sparse_ids_2d(self):
     indicators = (
         (0, 0, 1, 0),
         (1, 0, 0, 1),
     )
     sparse_ids = sparse_ops.indicators_to_sparse_ids(indicators,
                                                      dtype=dtypes.int16)
     with self.cached_session():
         _assert_sparse_tensor_value(
             self,
             sparse_tensor.SparseTensorValue(
                 indices=((0, 0), (1, 0), (1, 1)),
                 values=np.array((2, 0, 3), dtype=np.int16),
                 dense_shape=(2, 2),
             ), sparse_ids.eval())
 def test_indicators_to_sparse_ids_3d(self):
     indicators = (
         ((0, 0, 1, 0, 0), (0, 0, 0, 0, 0)),
         ((1, 0, 0, 1, 0), (0, 0, 1, 0, 0)),
         ((0, 0, 0, 0, 0), (0, 0, 0, 0, 0)),
         ((1, 0, 0, 1, 1), (0, 0, 1, 0, 0)),
     )
     sparse_ids = sparse_ops.indicators_to_sparse_ids(indicators)
     with self.cached_session():
         _assert_sparse_tensor_value(
             self,
             sparse_tensor.SparseTensorValue(
                 indices=((0, 0, 0), (1, 0, 0), (1, 0, 1), (1, 1, 0),
                          (3, 0, 0), (3, 0, 1), (3, 0, 2), (3, 1, 0)),
                 values=(2, 0, 3, 2, 0, 3, 4, 2),
                 dense_shape=(4, 2, 3),
             ), sparse_ids.eval())