diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2018-09-25 11:56:33 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-09-25 12:07:36 -0700 |
commit | d5c5df164cedcd8ae43fff41256592818bc6c2de (patch) | |
tree | 0b07685ff599ad9bfe93a58386c67adb94e57c8e /tensorflow/python/ops | |
parent | df930015230c1195065e2fd01c61f527b8662efb (diff) |
Add "encoding" attribute to string length op, which controls how "string length" is defined:
* BYTE: The number of bytes in each string. (Default)
* UTF8: The number of UTF-8 encoded Unicode code points in each string.
RELNOTES: Add option to calculate string length in Unicode characters
PiperOrigin-RevId: 214478470
Diffstat (limited to 'tensorflow/python/ops')
-rw-r--r-- | tensorflow/python/ops/string_ops.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tensorflow/python/ops/string_ops.py b/tensorflow/python/ops/string_ops.py index 5d949467fd..046a48d192 100644 --- a/tensorflow/python/ops/string_ops.py +++ b/tensorflow/python/ops/string_ops.py @@ -36,10 +36,12 @@ from tensorflow.python.ops import math_ops # go/tf-wildcard-import # pylint: disable=wildcard-import +# pylint: disable=g-bad-import-order from tensorflow.python.ops.gen_string_ops import * from tensorflow.python.util import compat as util_compat from tensorflow.python.util import deprecation from tensorflow.python.util.tf_export import tf_export +# pylint: enable=g-bad-import-order # pylint: enable=wildcard-import @@ -328,6 +330,17 @@ def reduce_join(inputs, axis=None, reduce_join.__doc__ = deprecation.rewrite_argument_docstring( gen_string_ops.reduce_join.__doc__, "reduction_indices", "axis") + +# This wrapper provides backwards compatibility for code that predates the +# unit argument and that passed 'name' as a positional argument. +@tf_export("strings.length") +def string_length(input, name=None, unit="BYTE"): + return gen_string_ops.string_length(input, unit=unit, name=name) + + +string_length.__doc__ = gen_string_ops.string_length.__doc__ + + ops.NotDifferentiable("RegexReplace") ops.NotDifferentiable("StringToHashBucket") ops.NotDifferentiable("StringToHashBucketFast") |