From: A. Unique TensorFlower Date: Fri, 6 Apr 2018 19:37:17 +0000 (-0700) Subject: Replaced calls to deprecated tensorflow::StringPiece methods with their X-Git-Tag: tflite-v0.1.7~16^2^2~88 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e8dedc2c0f00dd28a3398cceb5e3293faaabbb9f;p=platform%2Fupstream%2Ftensorflow.git Replaced calls to deprecated tensorflow::StringPiece methods with their tensorflow::str_util equivalents. This will allow the deprecated methods to be removed. PiperOrigin-RevId: 191925087 --- diff --git a/tensorflow/core/kernels/BUILD b/tensorflow/core/kernels/BUILD index a196fc5..1857d8d 100644 --- a/tensorflow/core/kernels/BUILD +++ b/tensorflow/core/kernels/BUILD @@ -2265,6 +2265,7 @@ tf_cc_tests( ":ops_util", "//tensorflow/core:core_cpu", "//tensorflow/core:framework", + "//tensorflow/core:lib", "//tensorflow/core:lib_internal", "//tensorflow/core:protos_all_cc", "//tensorflow/core:test", @@ -5905,6 +5906,7 @@ tf_cc_test( "//tensorflow/core:core_cpu", "//tensorflow/core:core_cpu_internal", "//tensorflow/core:framework", + "//tensorflow/core:lib", "//tensorflow/core:tensorflow", "//tensorflow/core:test", "//tensorflow/core:test_main", diff --git a/tensorflow/core/kernels/crop_and_resize_op_test.cc b/tensorflow/core/kernels/crop_and_resize_op_test.cc index a35e1b0..709082e 100644 --- a/tensorflow/core/kernels/crop_and_resize_op_test.cc +++ b/tensorflow/core/kernels/crop_and_resize_op_test.cc @@ -26,6 +26,7 @@ limitations under the License. #include "tensorflow/core/kernels/ops_testutil.h" #include "tensorflow/core/kernels/ops_util.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" namespace tensorflow { @@ -242,7 +243,7 @@ TEST_F(CropAndResizeOpTest, TestInvalidInputShape) { AddInputFromArray(TensorShape({2}), {4, 4}); Status s = RunOpKernel(); ASSERT_FALSE(s.ok()); - EXPECT_TRUE(StringPiece(s.ToString()).contains("input image must be 4-D")) + EXPECT_TRUE(str_util::StrContains(s.ToString(), "input image must be 4-D")) << s; } @@ -255,7 +256,7 @@ TEST_F(CropAndResizeOpTest, TestInvalidBoxIndexShape) { Status s = RunOpKernel(); ASSERT_FALSE(s.ok()); EXPECT_TRUE( - StringPiece(s.ToString()).contains("box_index has incompatible shape")) + str_util::StrContains(s.ToString(), "box_index has incompatible shape")) << s; } @@ -267,8 +268,8 @@ TEST_F(CropAndResizeOpTest, TestInvalidBoxIndex) { AddInputFromArray(TensorShape({2}), {3, 3}); Status s = RunOpKernel(); ASSERT_FALSE(s.ok()); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("box_index has values outside [0, batch_size)")) + EXPECT_TRUE(str_util::StrContains( + s.ToString(), "box_index has values outside [0, batch_size)")) << s; } diff --git a/tensorflow/core/kernels/decode_image_op.cc b/tensorflow/core/kernels/decode_image_op.cc index 912d04c..2cafa44 100644 --- a/tensorflow/core/kernels/decode_image_op.cc +++ b/tensorflow/core/kernels/decode_image_op.cc @@ -41,9 +41,9 @@ enum FileFormat { // Classify the contents of a file based on starting bytes (the magic number). FileFormat ClassifyFileFormat(StringPiece data) { // The 4th byte of JPEG is '\xe0' or '\xe1', so check just the first three - if (data.starts_with("\xff\xd8\xff")) return kJpgFormat; - if (data.starts_with("\x89PNG\r\n\x1a\n")) return kPngFormat; - if (data.starts_with("\x47\x49\x46\x38")) return kGifFormat; + if (str_util::StartsWith(data, "\xff\xd8\xff")) return kJpgFormat; + if (str_util::StartsWith(data, "\x89PNG\r\n\x1a\n")) return kPngFormat; + if (str_util::StartsWith(data, "\x47\x49\x46\x38")) return kGifFormat; return kUnknownFormat; } diff --git a/tensorflow/core/kernels/dynamic_partition_op_test.cc b/tensorflow/core/kernels/dynamic_partition_op_test.cc index 9a7ed0a..17eb4e2 100644 --- a/tensorflow/core/kernels/dynamic_partition_op_test.cc +++ b/tensorflow/core/kernels/dynamic_partition_op_test.cc @@ -30,6 +30,7 @@ limitations under the License. #include "tensorflow/core/kernels/ops_util.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test_benchmark.h" @@ -153,8 +154,8 @@ TEST_F(DynamicPartitionOpTest, Error_IndexOutOfRange) { {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}); AddInputFromArray(TensorShape({5}), {0, 2, 99, 2, 2}); Status s = RunOpKernel(); - EXPECT_TRUE( - StringPiece(s.ToString()).contains("partitions[2] = 99 is not in [0, 4)")) + EXPECT_TRUE(str_util::StrContains(s.ToString(), + "partitions[2] = 99 is not in [0, 4)")) << s; } diff --git a/tensorflow/core/kernels/dynamic_stitch_op_test.cc b/tensorflow/core/kernels/dynamic_stitch_op_test.cc index 6775893..7fa6e32 100644 --- a/tensorflow/core/kernels/dynamic_stitch_op_test.cc +++ b/tensorflow/core/kernels/dynamic_stitch_op_test.cc @@ -26,6 +26,7 @@ limitations under the License. #include "tensorflow/core/kernels/ops_testutil.h" #include "tensorflow/core/kernels/ops_util.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/test.h" @@ -88,9 +89,9 @@ TEST_F(DynamicStitchOpTest, Error_IndicesMultiDimensional) { AddInputFromArray(TensorShape({3}), {0, 40, 70}); AddInputFromArray(TensorShape({5}), {10, 60, 20, 30, 50}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("data[1].shape = [5] does not start with " - "indices[1].shape = [1,5]")) + EXPECT_TRUE(str_util::StrContains( + s.ToString(), + "data[1].shape = [5] does not start with indices[1].shape = [1,5]")) << s; } @@ -103,9 +104,9 @@ TEST_F(DynamicStitchOpTest, Error_DataNumDimsMismatch) { AddInputFromArray(TensorShape({3}), {0, 40, 70}); AddInputFromArray(TensorShape({1, 5}), {10, 60, 20, 30, 50}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("data[1].shape = [1,5] does not start with " - "indices[1].shape = [5]")) + EXPECT_TRUE(str_util::StrContains( + s.ToString(), + "data[1].shape = [1,5] does not start with indices[1].shape = [5]")) << s; } @@ -119,9 +120,10 @@ TEST_F(DynamicStitchOpTest, Error_DataDimSizeMismatch) { AddInputFromArray(TensorShape({4, 2}), {10, 11, 60, 61, 20, 21, 30, 31}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("Need data[0].shape[1:] = data[1].shape[1:], " - "got data[0].shape = [3,1], data[1].shape = [4,2]")) + EXPECT_TRUE( + str_util::StrContains(s.ToString(), + "Need data[0].shape[1:] = data[1].shape[1:], got " + "data[0].shape = [3,1], data[1].shape = [4,2]")) << s; } @@ -134,10 +136,9 @@ TEST_F(DynamicStitchOpTest, Error_DataAndIndicesSizeMismatch) { AddInputFromArray(TensorShape({3}), {0, 40, 70}); AddInputFromArray(TensorShape({4}), {10, 60, 20, 30}); Status s = RunOpKernel(); - EXPECT_TRUE( - StringPiece(s.ToString()) - .contains( - "data[1].shape = [4] does not start with indices[1].shape = [5]")) + EXPECT_TRUE(str_util::StrContains( + s.ToString(), + "data[1].shape = [4] does not start with indices[1].shape = [5]")) << s; } diff --git a/tensorflow/core/kernels/gather_op_test.cc b/tensorflow/core/kernels/gather_op_test.cc index 3edcb34..0409cad 100644 --- a/tensorflow/core/kernels/gather_op_test.cc +++ b/tensorflow/core/kernels/gather_op_test.cc @@ -31,6 +31,7 @@ limitations under the License. #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/gtl/array_slice.h" #include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test_benchmark.h" @@ -171,7 +172,7 @@ TEST_F(GatherOpTest, Error_IndexOutOfRange) { AddInputFromArray(TensorShape({}), {0}); Status s = RunOpKernel(); EXPECT_TRUE( - StringPiece(s.ToString()).contains("indices[2] = 99 is not in [0, 5)")) + str_util::StrContains(s.ToString(), "indices[2] = 99 is not in [0, 5)")) << s; } diff --git a/tensorflow/core/kernels/non_max_suppression_op_test.cc b/tensorflow/core/kernels/non_max_suppression_op_test.cc index 67d9217..9387fb1 100644 --- a/tensorflow/core/kernels/non_max_suppression_op_test.cc +++ b/tensorflow/core/kernels/non_max_suppression_op_test.cc @@ -24,6 +24,7 @@ limitations under the License. #include "tensorflow/core/kernels/ops_testutil.h" #include "tensorflow/core/kernels/ops_util.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" namespace tensorflow { @@ -147,7 +148,7 @@ TEST_F(NonMaxSuppressionOpTest, TestInconsistentBoxAndScoreShapes) { ASSERT_FALSE(s.ok()); EXPECT_TRUE( - StringPiece(s.ToString()).contains("scores has incompatible shape")) + str_util::StrContains(s.ToString(), "scores has incompatible shape")) << s; } @@ -160,7 +161,7 @@ TEST_F(NonMaxSuppressionOpTest, TestInvalidIOUThreshold) { ASSERT_FALSE(s.ok()); EXPECT_TRUE( - StringPiece(s.ToString()).contains("iou_threshold must be in [0, 1]")) + str_util::StrContains(s.ToString(), "iou_threshold must be in [0, 1]")) << s; } @@ -308,7 +309,7 @@ TEST_F(NonMaxSuppressionV2OpTest, TestInconsistentBoxAndScoreShapes) { ASSERT_FALSE(s.ok()); EXPECT_TRUE( - StringPiece(s.ToString()).contains("scores has incompatible shape")) + str_util::StrContains(s.ToString(), "scores has incompatible shape")) << s; } @@ -322,7 +323,7 @@ TEST_F(NonMaxSuppressionV2OpTest, TestInvalidIOUThreshold) { ASSERT_FALSE(s.ok()); EXPECT_TRUE( - StringPiece(s.ToString()).contains("iou_threshold must be in [0, 1]")) + str_util::StrContains(s.ToString(), "iou_threshold must be in [0, 1]")) << s; } diff --git a/tensorflow/core/kernels/quantize_and_dequantize_op_test.cc b/tensorflow/core/kernels/quantize_and_dequantize_op_test.cc index 5ffcc7d..e41df12 100644 --- a/tensorflow/core/kernels/quantize_and_dequantize_op_test.cc +++ b/tensorflow/core/kernels/quantize_and_dequantize_op_test.cc @@ -29,6 +29,7 @@ limitations under the License. #include "tensorflow/core/framework/types.pb.h" #include "tensorflow/core/kernels/ops_testutil.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test_benchmark.h" namespace tensorflow { @@ -379,8 +380,8 @@ TEST_F(QuantizeAndDequantizeTest, Invalid_range_given) { AddInputFromArray(TensorShape({}), {0.0}); // Max Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("Invalid range: input_min 1 > input_max 0")) + EXPECT_TRUE(str_util::StrContains(s.ToString(), + "Invalid range: input_min 1 > input_max 0")) << s; } @@ -401,8 +402,8 @@ TEST_F(QuantizeAndDequantizeTest, Invalid_range_given_V3) { AddInputFromArray(TensorShape({}), {8}); // num_bits Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("Invalid range: input_min 1 > input_max 0")) + EXPECT_TRUE(str_util::StrContains(s.ToString(), + "Invalid range: input_min 1 > input_max 0")) << s; } diff --git a/tensorflow/core/kernels/remote_fused_graph_rewriter_transform_test.cc b/tensorflow/core/kernels/remote_fused_graph_rewriter_transform_test.cc index d5b37b1..9217c25 100644 --- a/tensorflow/core/kernels/remote_fused_graph_rewriter_transform_test.cc +++ b/tensorflow/core/kernels/remote_fused_graph_rewriter_transform_test.cc @@ -27,6 +27,7 @@ limitations under the License. #include "tensorflow/core/kernels/remote_fused_graph_execute_op_test_utils.h" #include "tensorflow/core/kernels/remote_fused_graph_execute_utils.h" #include "tensorflow/core/lib/core/status_test_util.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/public/session.h" #include "tensorflow/tools/graph_transforms/transform_utils.h" @@ -181,7 +182,7 @@ class FuseRemoteGraphMultipleAddOpsRewriterTest : public ::testing::Test { int cluster_count = 0; for (const NodeDef& node_def : output_graph_def_.node()) { const string& name = node_def.name(); - if (StringPiece(name).starts_with(REMOTE_FUSED_GRAPH_NODE_NAME)) { + if (str_util::StartsWith(name, REMOTE_FUSED_GRAPH_NODE_NAME)) { ++cluster_count; RemoteFusedGraphExecuteInfo info; string serialized_proto; diff --git a/tensorflow/core/kernels/resize_bicubic_op_test.cc b/tensorflow/core/kernels/resize_bicubic_op_test.cc index 25a37d5..c23570d 100644 --- a/tensorflow/core/kernels/resize_bicubic_op_test.cc +++ b/tensorflow/core/kernels/resize_bicubic_op_test.cc @@ -18,6 +18,7 @@ limitations under the License. #include "tensorflow/core/framework/node_def_builder.h" #include "tensorflow/core/framework/tensor.h" #include "tensorflow/core/kernels/ops_testutil.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test_benchmark.h" @@ -218,9 +219,8 @@ TEST_F(ResizeBicubicOpTest, TestBicubic2x2To0x0) { AddInputFromArray(TensorShape({2}), {0, 0}); Status s = RunOpKernel(); - EXPECT_TRUE( - StringPiece(s.ToString()) - .contains("Invalid argument: output dimensions must be positive")) + EXPECT_TRUE(str_util::StrContains( + s.ToString(), "Invalid argument: output dimensions must be positive")) << s; } diff --git a/tensorflow/core/kernels/resize_bilinear_op_test.cc b/tensorflow/core/kernels/resize_bilinear_op_test.cc index a920e60..6d57892 100644 --- a/tensorflow/core/kernels/resize_bilinear_op_test.cc +++ b/tensorflow/core/kernels/resize_bilinear_op_test.cc @@ -25,6 +25,7 @@ limitations under the License. #include "tensorflow/core/kernels/ops_util.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/random/random.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" namespace tensorflow { @@ -457,9 +458,8 @@ TEST_F(ResizeBilinearOpTest, TestInvalidOutputSize) { AddInputFromArray(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4}); AddInputFromArray(TensorShape({2}), {0, 0}); Status s = RunOpKernel(); - EXPECT_TRUE( - StringPiece(s.ToString()) - .contains("Invalid argument: output dimensions must be positive")) + EXPECT_TRUE(str_util::StrContains( + s.ToString(), "Invalid argument: output dimensions must be positive")) << s; } @@ -467,8 +467,8 @@ TEST_F(ResizeBilinearOpTest, TestInvalidInputShape) { AddInputFromArray(TensorShape({2, 2, 1}), {1, 2, 3, 4}); AddInputFromArray(TensorShape({2}), {4, 4}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("Invalid argument: input must be 4-dimensional")) + EXPECT_TRUE(str_util::StrContains( + s.ToString(), "Invalid argument: input must be 4-dimensional")) << s; } @@ -476,8 +476,8 @@ TEST_F(ResizeBilinearOpTest, TestInvalidSizeDim) { AddInputFromArray(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4}); AddInputFromArray(TensorShape({2, 1}), {4, 4}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("Invalid argument: shape_t must be 1-dimensional")) + EXPECT_TRUE(str_util::StrContains( + s.ToString(), "Invalid argument: shape_t must be 1-dimensional")) << s; } @@ -485,8 +485,8 @@ TEST_F(ResizeBilinearOpTest, TestInvalidSizeElements) { AddInputFromArray(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4}); AddInputFromArray(TensorShape({3}), {4, 4, 1}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("Invalid argument: shape_t must have two elements")) + EXPECT_TRUE(str_util::StrContains( + s.ToString(), "Invalid argument: shape_t must have two elements")) << s; } diff --git a/tensorflow/core/kernels/roll_op_test.cc b/tensorflow/core/kernels/roll_op_test.cc index 90b6f8d..e431226 100644 --- a/tensorflow/core/kernels/roll_op_test.cc +++ b/tensorflow/core/kernels/roll_op_test.cc @@ -29,6 +29,7 @@ limitations under the License. #include "tensorflow/core/kernels/ops_testutil.h" #include "tensorflow/core/kernels/ops_util.h" #include "tensorflow/core/lib/io/path.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test_benchmark.h" @@ -372,7 +373,8 @@ TEST_F(RollOpTest, Error_InputMustBeVectorOrHigher) { AddInputFromArray(TensorShape({}), {1}); AddInputFromArray(TensorShape({}), {0}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()).contains("input must be 1-D or higher")) + EXPECT_TRUE( + str_util::StrContains(s.ToString(), "input must be 1-D or higher")) << s; } @@ -384,8 +386,8 @@ TEST_F(RollOpTest, Error_AxisMustBeScalarOrVector) { AddInputFromArray(TensorShape({}), {1}); AddInputFromArray(TensorShape({1, 2}), {0, 1}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("axis must be a scalar or a 1-D vector")) + EXPECT_TRUE(str_util::StrContains(s.ToString(), + "axis must be a scalar or a 1-D vector")) << s; } @@ -397,8 +399,8 @@ TEST_F(RollOpTest, Error_ShiftMustBeScalarOrVector) { AddInputFromArray(TensorShape({1, 2}), {0, 1}); AddInputFromArray(TensorShape({}), {1}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("shift must be a scalar or a 1-D vector")) + EXPECT_TRUE(str_util::StrContains(s.ToString(), + "shift must be a scalar or a 1-D vector")) << s; } @@ -410,8 +412,8 @@ TEST_F(RollOpTest, Error_ShiftAndAxisMustBeSameSize) { AddInputFromArray(TensorShape({1}), {1}); AddInputFromArray(TensorShape({2}), {0, 1}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("shift and axis must have the same size")) + EXPECT_TRUE(str_util::StrContains(s.ToString(), + "shift and axis must have the same size")) << s; } @@ -423,7 +425,7 @@ TEST_F(RollOpTest, Error_AxisOutOfRange) { AddInputFromArray(TensorShape({}), {1}); AddInputFromArray(TensorShape({}), {1}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()).contains("is out of range")) << s; + EXPECT_TRUE(str_util::StrContains(s.ToString(), "is out of range")) << s; } // isd - (inner shift dimension) The inner most dimension to be shifted. diff --git a/tensorflow/core/kernels/scatter_nd_op_test.cc b/tensorflow/core/kernels/scatter_nd_op_test.cc index ae81efa..c134a8d 100644 --- a/tensorflow/core/kernels/scatter_nd_op_test.cc +++ b/tensorflow/core/kernels/scatter_nd_op_test.cc @@ -28,6 +28,7 @@ limitations under the License. #include "tensorflow/core/kernels/ops_util.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test_benchmark.h" @@ -183,9 +184,8 @@ TEST_F(ScatterNdUpdateOpTest, Error_IndexOutOfRange) { AddInputFromArray(TensorShape({3, 3}), {100, 101, 102, 777, 778, 779, 10000, 10001, 10002}); Status s = RunOpKernel(); - EXPECT_TRUE( - StringPiece(s.ToString()) - .contains("Invalid indices: [2,0] = [99] does not index into [5,3]")) + EXPECT_TRUE(str_util::StrContains( + s.ToString(), "Invalid indices: [2,0] = [99] does not index into [5,3]")) << s; } @@ -198,10 +198,10 @@ TEST_F(ScatterNdUpdateOpTest, Error_WrongDimsIndices) { AddInputFromArray(TensorShape({3, 3}), {100, 101, 102, 777, 778, 779, 10000, 10001, 10002}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("The outermost dimension of updates and indices " - "must match. Got indices.shape [1,3,1], " - "updates.shape [3,3]")) + EXPECT_TRUE(str_util::StrContains( + s.ToString(), + "The outermost dimension of updates and indices must match. Got " + "indices.shape [1,3,1], updates.shape [3,3]")) << s; } @@ -216,10 +216,8 @@ TEST_F(ScatterNdUpdateOpTest, Error_MismatchedParamsAndUpdateDimensions) { TensorShape({3, 4}), {100, 101, 102, 103, 777, 778, 779, 780, 10000, 10001, 10002, 10004}); Status s = RunOpKernel(); - EXPECT_TRUE( - StringPiece(s.ToString()) - .contains("Must have updates.shape = indices.shape[:batch_dim]")) - + EXPECT_TRUE(str_util::StrContains( + s.ToString(), "Must have updates.shape = indices.shape[:batch_dim]")) << s; } @@ -233,10 +231,9 @@ TEST_F(ScatterNdUpdateOpTest, Error_MismatchedIndicesAndUpdateDimensions) { AddInputFromArray(TensorShape({2, 3}), {100, 101, 102, 10000, 10001, 10002}); Status s = RunOpKernel(); - EXPECT_TRUE( - StringPiece(s.ToString()) - .contains( - "The outermost dimension of updates and indices must match.")) + EXPECT_TRUE(str_util::StrContains( + s.ToString(), + "The outermost dimension of updates and indices must match.")) << s; } diff --git a/tensorflow/core/kernels/scatter_op_test.cc b/tensorflow/core/kernels/scatter_op_test.cc index 5b3537b..2ec8c42 100644 --- a/tensorflow/core/kernels/scatter_op_test.cc +++ b/tensorflow/core/kernels/scatter_op_test.cc @@ -28,6 +28,7 @@ limitations under the License. #include "tensorflow/core/kernels/ops_util.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test_benchmark.h" @@ -170,7 +171,7 @@ TEST_F(ScatterUpdateOpTest, Error_IndexOutOfRange) { {100, 101, 102, 777, 778, 779, 10000, 10001, 10002}); Status s = RunOpKernel(); EXPECT_TRUE( - StringPiece(s.ToString()).contains("indices[2] = 99 is not in [0, 5)")) + str_util::StrContains(s.ToString(), "indices[2] = 99 is not in [0, 5)")) << s; } @@ -183,8 +184,9 @@ TEST_F(ScatterUpdateOpTest, Error_WrongDimsIndices) { AddInputFromArray(TensorShape({3, 3}), {100, 101, 102, 777, 778, 779, 10000, 10001, 10002}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("Must have updates.shape = indices.shape + " + EXPECT_TRUE( + str_util::StrContains(s.ToString(), + "Must have updates.shape = indices.shape + " "params.shape[1:] or updates.shape = [], got ")) << s; } @@ -200,8 +202,9 @@ TEST_F(ScatterUpdateOpTest, Error_MismatchedParamsAndUpdateDimensions) { TensorShape({3, 4}), {100, 101, 102, 103, 777, 778, 779, 780, 10000, 10001, 10002, 10004}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("Must have updates.shape = indices.shape + " + EXPECT_TRUE( + str_util::StrContains(s.ToString(), + "Must have updates.shape = indices.shape + " "params.shape[1:] or updates.shape = [], got ")) << s; @@ -217,8 +220,9 @@ TEST_F(ScatterUpdateOpTest, Error_MismatchedIndicesAndUpdateDimensions) { AddInputFromArray(TensorShape({2, 3}), {100, 101, 102, 10000, 10001, 10002}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()) - .contains("Must have updates.shape = indices.shape + " + EXPECT_TRUE( + str_util::StrContains(s.ToString(), + "Must have updates.shape = indices.shape + " "params.shape[1:] or updates.shape = [], got ")) << s; } diff --git a/tensorflow/core/kernels/shape_op_test.cc b/tensorflow/core/kernels/shape_op_test.cc index a545fb1..9cd590a 100644 --- a/tensorflow/core/kernels/shape_op_test.cc +++ b/tensorflow/core/kernels/shape_op_test.cc @@ -26,6 +26,7 @@ limitations under the License. #include "tensorflow/core/framework/variant_op_registry.h" #include "tensorflow/core/kernels/ops_testutil.h" #include "tensorflow/core/kernels/ops_util.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/types.h" @@ -62,8 +63,8 @@ REGISTER_UNARY_VARIANT_DECODE_FUNCTION(KnownVecSize, "KNOWN VECTOR SIZE TYPE"); REGISTER_UNARY_VARIANT_SHAPE_FUNCTION(KnownVecSize, "KNOWN VECTOR SIZE TYPE", GetShapeFromKnownVecSize); -static void ExpectHasError(const Status& s, const string& substr) { - EXPECT_TRUE(StringPiece(s.ToString()).contains(substr)) +static void ExpectHasError(const Status& s, StringPiece substr) { + EXPECT_TRUE(str_util::StrContains(s.ToString(), substr)) << ">>" << s << "<<, expected substring >>" << substr << "<<"; } diff --git a/tensorflow/core/kernels/softmax_op.cc b/tensorflow/core/kernels/softmax_op.cc index e1712ac..e726089 100644 --- a/tensorflow/core/kernels/softmax_op.cc +++ b/tensorflow/core/kernels/softmax_op.cc @@ -15,6 +15,7 @@ limitations under the License. // See docs in ../ops/nn_ops.cc. +#include "tensorflow/core/lib/strings/str_util.h" #define EIGEN_USE_THREADS #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" @@ -55,7 +56,7 @@ template class SoftmaxOp : public OpKernel { public: explicit SoftmaxOp(OpKernelConstruction* context) : OpKernel(context) { - log_ = StringPiece(type_string()).starts_with("Log"); + log_ = str_util::StartsWith(type_string(), "Log"); } void Compute(OpKernelContext* context) override { diff --git a/tensorflow/core/kernels/softmax_op_gpu.cu.cc b/tensorflow/core/kernels/softmax_op_gpu.cu.cc index 130d693..b63dcbb 100644 --- a/tensorflow/core/kernels/softmax_op_gpu.cu.cc +++ b/tensorflow/core/kernels/softmax_op_gpu.cu.cc @@ -13,6 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ +#include "tensorflow/core/lib/strings/str_util.h" #if GOOGLE_CUDA #define EIGEN_USE_GPU @@ -128,7 +129,7 @@ template class SoftmaxOpGPU : public OpKernel { public: explicit SoftmaxOpGPU(OpKernelConstruction* context) : OpKernel(context) { - log_ = StringPiece(type_string()).starts_with("Log"); + log_ = str_util::StartsWith(type_string(), "Log"); } void Compute(OpKernelContext* context) override { diff --git a/tensorflow/core/kernels/sparse_dense_binary_op_shared_test.cc b/tensorflow/core/kernels/sparse_dense_binary_op_shared_test.cc index fe198af..29577eb 100644 --- a/tensorflow/core/kernels/sparse_dense_binary_op_shared_test.cc +++ b/tensorflow/core/kernels/sparse_dense_binary_op_shared_test.cc @@ -24,6 +24,7 @@ limitations under the License. #include "tensorflow/core/graph/graph.h" #include "tensorflow/core/graph/node_builder.h" #include "tensorflow/core/kernels/ops_testutil.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/platform/test_benchmark.h" @@ -32,7 +33,7 @@ namespace tensorflow { namespace { static void ExpectHasSubstr(StringPiece s, StringPiece expected) { - EXPECT_TRUE(StringPiece(s).contains(expected)) + EXPECT_TRUE(str_util::StrContains(s, expected)) << "'" << s << "' does not contain '" << expected << "'"; } diff --git a/tensorflow/core/kernels/summary_op_test.cc b/tensorflow/core/kernels/summary_op_test.cc index 3c46abb..9dcabcc 100644 --- a/tensorflow/core/kernels/summary_op_test.cc +++ b/tensorflow/core/kernels/summary_op_test.cc @@ -28,6 +28,7 @@ limitations under the License. #include "tensorflow/core/kernels/ops_util.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/histogram/histogram.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/logging.h" @@ -122,7 +123,7 @@ TEST_F(SummaryScalarOpTest, Error_MismatchedSize) { AddInputFromArray(TensorShape({2}), {"tag1", "tag2"}); AddInputFromArray(TensorShape({3}), {1.0f, -0.73f, 10000.0f}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()).contains("not the same shape")) << s; + EXPECT_TRUE(str_util::StrContains(s.ToString(), "not the same shape")) << s; } TEST_F(SummaryScalarOpTest, Error_WrongDimsTags) { @@ -133,7 +134,7 @@ TEST_F(SummaryScalarOpTest, Error_WrongDimsTags) { AddInputFromArray(TensorShape({2}), {1.0f, -0.73f}); Status s = RunOpKernel(); EXPECT_TRUE( - StringPiece(s.ToString()).contains("tags and values not the same shape")) + str_util::StrContains(s.ToString(), "tags and values not the same shape")) << s; } @@ -145,7 +146,7 @@ TEST_F(SummaryScalarOpTest, Error_WrongDimsValues) { AddInputFromArray(TensorShape({2, 1}), {1.0f, -0.73f}); Status s = RunOpKernel(); EXPECT_TRUE( - StringPiece(s.ToString()).contains("tags and values not the same shape")) + str_util::StrContains(s.ToString(), "tags and values not the same shape")) << s; } @@ -256,7 +257,7 @@ TEST_F(SummaryHistoOpTest, Error_WrongDimsTags) { AddInputFromArray(TensorShape({2, 1}), {"tag1", "tag2"}); AddInputFromArray(TensorShape({2}), {1.0f, -0.73f}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()).contains("tags must be scalar")) << s; + EXPECT_TRUE(str_util::StrContains(s.ToString(), "tags must be scalar")) << s; } TEST_F(SummaryHistoOpTest, Error_TooManyTagValues) { @@ -266,7 +267,7 @@ TEST_F(SummaryHistoOpTest, Error_TooManyTagValues) { AddInputFromArray(TensorShape({2}), {"tag1", "tag2"}); AddInputFromArray(TensorShape({2, 1}), {1.0f, -0.73f}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()).contains("tags must be scalar")) << s; + EXPECT_TRUE(str_util::StrContains(s.ToString(), "tags must be scalar")) << s; } // -------------------------------------------------------------------------- @@ -365,7 +366,7 @@ TEST_F(SummaryMergeOpTest, Error_MismatchedSize) { AddInputFromArray(TensorShape({2}), {s1.SerializeAsString(), s2.SerializeAsString()}); Status s = RunOpKernel(); - EXPECT_TRUE(StringPiece(s.ToString()).contains("Duplicate tag")) << s; + EXPECT_TRUE(str_util::StrContains(s.ToString(), "Duplicate tag")) << s; } } // namespace