From d5c5df164cedcd8ae43fff41256592818bc6c2de Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Tue, 25 Sep 2018 11:56:33 -0700 Subject: 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 --- tensorflow/python/ops/string_ops.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tensorflow/python/ops') 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") -- cgit v1.2.3