Example #1
0
 def raise_zero_rank_error():
     msg = gen_string_ops.string_join([
         'len requires non-zero rank, got ',
         gen_string_ops.as_string(rank)
     ])
     with ops.control_dependencies([control_flow_ops.Assert(False, [msg])]):
         return constant_op.constant(0, dtype=dtypes.int32)
Example #2
0
def string_join(inputs, separator="", name=None):
    """Perform element-wise concatenation of a list of string tensors.

  Given a list of string tensors of same shape, performs element-wise
  concatenation of the strings of the same index in all tensors.


  >>> tf.strings.join(['abc','def']).numpy()
  b'abcdef'
  >>> tf.strings.join([['abc','123'],
  ...                  ['def','456'],
  ...                  ['ghi','789']]).numpy()
  array([b'abcdefghi', b'123456789'], dtype=object)
  >>> tf.strings.join([['abc','123'],
  ...                  ['def','456']],
  ...                  separator=" ").numpy()
  array([b'abc def', b'123 456'], dtype=object)

  Args:
    inputs: A list of `tf.Tensor` objects of same size and `tf.string` dtype.
    separator: A string added between each string being joined.
    name: A name for the operation (optional).

  Returns:
    A `tf.string` tensor.
  """
    return gen_string_ops.string_join(inputs, separator=separator, name=name)
Example #3
0
def _tf_dataset_len(s):
  l = cardinality.cardinality(s)
  msg = gen_string_ops.string_join([
      'len requires dataset with definitive cardinality, got ',
      gen_string_ops.as_string(l)
  ])
  # TODO (yongtang): UNKNOWN is treated as an error.
  # In case there are more UNKNOWN cases for dataset, we could
  # use dataset.reduce() to find out the length (in an expensive way).
  with ops.control_dependencies([
      control_flow_ops.Assert(
          math_ops.logical_and(
              math_ops.not_equal(l, cardinality.INFINITE),
              math_ops.not_equal(l, cardinality.UNKNOWN)), [msg])
  ]):
    l = array_ops.identity(l)

  return l
Example #4
0
 def raise_zero_rank_error():
   msg = gen_string_ops.string_join(
       ['len requires non-zero rank, got ',
        gen_string_ops.as_string(rank)])
   with ops.control_dependencies([control_flow_ops.Assert(False, [msg])]):
     return constant_op.constant(0, dtype=dtypes.int32)