diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2018-04-02 14:46:13 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-04-02 14:48:43 -0700 |
commit | 8f543ed7e3e2775aedb5c953f7f5cbff2139663a (patch) | |
tree | 06040261b7965ed031a6588eb1a0a15d4ea0e299 | |
parent | 817882c28fd6f0dbbbf35b6ac0764ccbd38430d0 (diff) |
Replaced calls to deprecated tensorflow::StringPiece methods with their
tensorflow::str_util equivalents.
This will allow the deprecated methods to be removed.
PiperOrigin-RevId: 191350894
21 files changed, 72 insertions, 53 deletions
diff --git a/tensorflow/c/c_api_test.cc b/tensorflow/c/c_api_test.cc index 028f146be3..ca80db23ed 100644 --- a/tensorflow/c/c_api_test.cc +++ b/tensorflow/c/c_api_test.cc @@ -53,7 +53,7 @@ Status TF_TensorToTensor(const TF_Tensor* src, Tensor* dst); 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/cc/saved_model/loader_test.cc b/tensorflow/cc/saved_model/loader_test.cc index 4c64d2cfe3..72b8bc1871 100644 --- a/tensorflow/cc/saved_model/loader_test.cc +++ b/tensorflow/cc/saved_model/loader_test.cc @@ -24,6 +24,7 @@ limitations under the License. #include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/io/path.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" namespace tensorflow { @@ -133,9 +134,9 @@ TEST_F(LoaderTest, NoTagMatch) { Status st = LoadSavedModel(session_options, run_options, export_dir, {"missing-tag"}, &bundle); EXPECT_FALSE(st.ok()); - EXPECT_TRUE(StringPiece(st.error_message()) - .contains("Could not find meta graph def matching supplied " - "tags: { missing-tag }")) + EXPECT_TRUE(str_util::StrContains( + st.error_message(), + "Could not find meta graph def matching supplied tags: { missing-tag }")) << st.error_message(); } @@ -149,9 +150,9 @@ TEST_F(LoaderTest, NoTagMatchMultiple) { Status st = LoadSavedModel(session_options, run_options, export_dir, {kSavedModelTagServe, "missing-tag"}, &bundle); EXPECT_FALSE(st.ok()); - EXPECT_TRUE( - StringPiece(st.error_message()) - .contains("Could not find meta graph def matching supplied tags: ")) + EXPECT_TRUE(str_util::StrContains( + st.error_message(), + "Could not find meta graph def matching supplied tags: ")) << st.error_message(); } @@ -169,7 +170,7 @@ TEST_F(LoaderTest, SessionCreationFailure) { Status st = LoadSavedModel(session_options, run_options, export_dir, {kSavedModelTagServe}, &bundle); EXPECT_FALSE(st.ok()); - EXPECT_TRUE(StringPiece(st.error_message()).contains(kInvalidTarget)) + EXPECT_TRUE(str_util::StrContains(st.error_message(), kInvalidTarget)) << st.error_message(); } diff --git a/tensorflow/cc/tutorials/example_trainer.cc b/tensorflow/cc/tutorials/example_trainer.cc index 3675d72ee3..5dbc4f5f6a 100644 --- a/tensorflow/cc/tutorials/example_trainer.cc +++ b/tensorflow/cc/tutorials/example_trainer.cc @@ -24,6 +24,7 @@ limitations under the License. #include "tensorflow/core/graph/default_device.h" #include "tensorflow/core/graph/graph_def_builder.h" #include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/platform/init_main.h" #include "tensorflow/core/platform/logging.h" @@ -166,7 +167,8 @@ namespace { bool ParseInt32Flag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, int32* dst) { - if (arg.Consume(flag) && arg.Consume("=")) { + if (tensorflow::str_util::ConsumePrefix(&arg, flag) && + tensorflow::str_util::ConsumePrefix(&arg, "=")) { char extra; return (sscanf(arg.data(), "%d%c", dst, &extra) == 1); } @@ -176,7 +178,7 @@ bool ParseInt32Flag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, bool ParseBoolFlag(tensorflow::StringPiece arg, tensorflow::StringPiece flag, bool* dst) { - if (arg.Consume(flag)) { + if (tensorflow::str_util::ConsumePrefix(&arg, flag)) { if (arg.empty()) { *dst = true; return true; diff --git a/tensorflow/compiler/xla/service/llvm_ir/llvm_util.cc b/tensorflow/compiler/xla/service/llvm_ir/llvm_util.cc index 2a282f3be7..ec04239b4f 100644 --- a/tensorflow/compiler/xla/service/llvm_ir/llvm_util.cc +++ b/tensorflow/compiler/xla/service/llvm_ir/llvm_util.cc @@ -34,6 +34,7 @@ limitations under the License. #include "tensorflow/core/lib/core/casts.h" #include "tensorflow/core/lib/core/errors.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/env.h" #include "tensorflow/core/platform/logging.h" @@ -762,7 +763,7 @@ void InitializeLLVMCommandLineOptions(const HloModuleConfig& config) { fake_argv_storage.push_back(""); for (const auto& it : options) { // Skip options the XLA backend itself consumes. - if (!tensorflow::StringPiece(it.first).starts_with("xla_")) { + if (!tensorflow::str_util::StartsWith(it.first, "xla_")) { if (it.second.empty()) { fake_argv_storage.push_back(it.first); } else { diff --git a/tensorflow/compiler/xla/tools/parser/hlo_parser_test.cc b/tensorflow/compiler/xla/tools/parser/hlo_parser_test.cc index 863081d654..adc8b1d620 100644 --- a/tensorflow/compiler/xla/tools/parser/hlo_parser_test.cc +++ b/tensorflow/compiler/xla/tools/parser/hlo_parser_test.cc @@ -18,6 +18,7 @@ limitations under the License. #include <string> #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/core/stringpiece.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" namespace xla { @@ -894,7 +895,7 @@ class HloParserTest : public ::testing::Test, public ::testing::WithParamInterface<TestData> { protected: static void ExpectHasSubstr(StringPiece s, StringPiece expected) { - EXPECT_TRUE(StringPiece(s).contains(expected)) + EXPECT_TRUE(tensorflow::str_util::StrContains(s, expected)) << "'" << s << "' does not contain '" << expected << "'"; } diff --git a/tensorflow/contrib/android/asset_manager_filesystem.cc b/tensorflow/contrib/android/asset_manager_filesystem.cc index fe2d13e636..513d519eab 100644 --- a/tensorflow/contrib/android/asset_manager_filesystem.cc +++ b/tensorflow/contrib/android/asset_manager_filesystem.cc @@ -229,9 +229,8 @@ string AssetManagerFileSystem::NormalizeDirectoryPath(const string& fname) { } string AssetManagerFileSystem::RemoveAssetPrefix(const string& name) { - string output(name); - StringPiece piece(output); - piece.Consume(prefix_); + StringPiece piece(name); + str_util::ConsumePrefix(&piece, prefix_); return piece.ToString(); } diff --git a/tensorflow/contrib/nccl/kernels/nccl_rewrite.cc b/tensorflow/contrib/nccl/kernels/nccl_rewrite.cc index a4de46a93f..4676e937e5 100644 --- a/tensorflow/contrib/nccl/kernels/nccl_rewrite.cc +++ b/tensorflow/contrib/nccl/kernels/nccl_rewrite.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 #include <forward_list> @@ -254,7 +255,7 @@ class NcclReplacePass : public GraphOptimizationPass { // Find reduction and broadcast ops and replace them with Send/Recv ops. for (Node* node : graph->op_nodes()) { StringPiece type = node->type_string(); - if (!type.starts_with("Nccl")) { + if (!str_util::StartsWith(type, "Nccl")) { continue; } if (type == "NcclReduce") { diff --git a/tensorflow/contrib/tensorboard/db/summary_file_writer_test.cc b/tensorflow/contrib/tensorboard/db/summary_file_writer_test.cc index c61b465596..cd3f712256 100644 --- a/tensorflow/contrib/tensorboard/db/summary_file_writer_test.cc +++ b/tensorflow/contrib/tensorboard/db/summary_file_writer_test.cc @@ -19,6 +19,7 @@ limitations under the License. #include "tensorflow/core/lib/core/refcount.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/io/record_reader.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/util/event.pb.h" @@ -58,7 +59,7 @@ class SummaryFileWriterTest : public ::testing::Test { TF_CHECK_OK(env_.GetChildren(testing::TmpDir(), &files)); bool found = false; for (const string& f : files) { - if (StringPiece(f).contains(test_name)) { + if (str_util::StrContains(f, test_name)) { if (found) { return errors::Unknown("Found more than one file for ", test_name); } diff --git a/tensorflow/core/distributed_runtime/base_rendezvous_mgr.cc b/tensorflow/core/distributed_runtime/base_rendezvous_mgr.cc index 049eec347c..bafd9bfc68 100644 --- a/tensorflow/core/distributed_runtime/base_rendezvous_mgr.cc +++ b/tensorflow/core/distributed_runtime/base_rendezvous_mgr.cc @@ -144,9 +144,9 @@ BaseRemoteRendezvous::~BaseRemoteRendezvous() { // Returns true if "device_name" is a valid full name of local device // of the "worker". This helper is purely based on the worker name // and device name and does no lookups in the worker->device_mgr. -static bool IsLocalDevice(const string& worker_name, +static bool IsLocalDevice(const StringPiece worker_name, const StringPiece device_name) { - return device_name.starts_with(worker_name); + return str_util::StartsWith(device_name, worker_name); } Status BaseRemoteRendezvous::Initialize(WorkerSession* session) { diff --git a/tensorflow/core/distributed_runtime/rpc/grpc_session.cc b/tensorflow/core/distributed_runtime/rpc/grpc_session.cc index 120a33f17b..3e79a40683 100644 --- a/tensorflow/core/distributed_runtime/rpc/grpc_session.cc +++ b/tensorflow/core/distributed_runtime/rpc/grpc_session.cc @@ -26,6 +26,7 @@ limitations under the License. #include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/lib/core/errors.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/mutex.h" #include "tensorflow/core/protobuf/master.pb.h" @@ -402,7 +403,7 @@ Status GrpcSession::Reset(const SessionOptions& options, class GrpcSessionFactory : public SessionFactory { public: bool AcceptsOptions(const SessionOptions& options) override { - return StringPiece(options.target).starts_with(kSchemePrefix); + return str_util::StartsWith(options.target, kSchemePrefix); } Session* NewSession(const SessionOptions& options) override { diff --git a/tensorflow/core/grappler/op_types.cc b/tensorflow/core/grappler/op_types.cc index e0ee49d157..e12e432a33 100644 --- a/tensorflow/core/grappler/op_types.cc +++ b/tensorflow/core/grappler/op_types.cc @@ -21,6 +21,7 @@ limitations under the License. #include "tensorflow/core/grappler/op_types.h" #include "tensorflow/core/grappler/utils.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/strings/str_util.h" namespace tensorflow { namespace grappler { @@ -409,7 +410,7 @@ bool ModifiesInputsInPlace(const NodeDef& node) { // Some nodes do in-place updates on regular tensor inputs. string op_name = node.op(); std::transform(op_name.begin(), op_name.end(), op_name.begin(), ::tolower); - if (StringPiece(op_name).contains("inplace")) { + if (str_util::StrContains(op_name, "inplace")) { return true; } return GetBoolAttr(node, "in_place") || GetBoolAttr(node, "inplace"); diff --git a/tensorflow/core/lib/wav/wav_io_test.cc b/tensorflow/core/lib/wav/wav_io_test.cc index d8a83fc464..9e41da6a20 100644 --- a/tensorflow/core/lib/wav/wav_io_test.cc +++ b/tensorflow/core/lib/wav/wav_io_test.cc @@ -19,6 +19,7 @@ limitations under the License. #include "tensorflow/core/lib/core/error_codes.pb.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/platform/types.h" @@ -203,7 +204,7 @@ TEST(WavIO, ChunkSizeOverflow) { wav_data_string, &decoded_audio, &decoded_sample_count, &decoded_channel_count, &decoded_sample_rate); EXPECT_FALSE(decode_status.ok()); - EXPECT_TRUE(StringPiece(decode_status.error_message()).contains("too large")) + EXPECT_TRUE(str_util::StrContains(decode_status.error_message(), "too large")) << decode_status.error_message(); } diff --git a/tensorflow/core/ops/math_grad_test.cc b/tensorflow/core/ops/math_grad_test.cc index 8dcd3e815f..da38a6bc24 100644 --- a/tensorflow/core/ops/math_grad_test.cc +++ b/tensorflow/core/ops/math_grad_test.cc @@ -19,6 +19,7 @@ limitations under the License. #include "tensorflow/core/framework/function_testlib.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/tensor_testutil.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/test.h" #include "tensorflow/core/public/session.h" @@ -362,7 +363,7 @@ class MathGradTest : public ::testing::Test { }; void HasError(const Status& s, const string& substr) { - EXPECT_TRUE(StringPiece(s.ToString()).contains(substr)) + EXPECT_TRUE(str_util::StrContains(s.ToString(), substr)) << s << ", expected substring " << substr; } diff --git a/tensorflow/core/ops/math_ops_test.cc b/tensorflow/core/ops/math_ops_test.cc index ca3772e6f8..8f974d5367 100644 --- a/tensorflow/core/ops/math_ops_test.cc +++ b/tensorflow/core/ops/math_ops_test.cc @@ -20,6 +20,7 @@ limitations under the License. #include "tensorflow/core/framework/tensor_shape.pb.h" #include "tensorflow/core/framework/tensor_testutil.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 { @@ -239,20 +240,21 @@ TEST(MathOpsTest, Select_ShapeFn) { // Expect an error when the shapes can't be merged. handle_data[2]->at(0).first = shape_proto({2, 2}); - EXPECT_TRUE(StringPiece(run_inference_for_handles().error_message()) - .contains("must be equal, but are 1 and 2")); + EXPECT_TRUE(str_util::StrContains(run_inference_for_handles().error_message(), + "must be equal, but are 1 and 2")); handle_data[2]->at(0).first = i1; // restore to valid // Expect an error when the types can't be merged. handle_data[2]->at(1).second = DT_INT64; - EXPECT_TRUE(StringPiece(run_inference_for_handles().error_message()) - .contains("pointing to different dtypes")); + EXPECT_TRUE(str_util::StrContains(run_inference_for_handles().error_message(), + "pointing to different dtypes")); handle_data[2]->at(1).second = DT_INT32; // restore to valid // Expect an error when different numbers of tensors are merged. handle_data[2]->push_back({i1, DT_FLOAT}); - EXPECT_TRUE(StringPiece(run_inference_for_handles().error_message()) - .contains("pointing to different numbers of tensors")); + EXPECT_TRUE( + str_util::StrContains(run_inference_for_handles().error_message(), + "pointing to different numbers of tensors")); handle_data[2]->pop_back(); // restore to valid. } diff --git a/tensorflow/core/platform/hadoop/hadoop_file_system_test.cc b/tensorflow/core/platform/hadoop/hadoop_file_system_test.cc index 6ba2f04d0f..b207d34749 100644 --- a/tensorflow/core/platform/hadoop/hadoop_file_system_test.cc +++ b/tensorflow/core/platform/hadoop/hadoop_file_system_test.cc @@ -18,6 +18,7 @@ limitations under the License. #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/gtl/stl_util.h" #include "tensorflow/core/lib/io/path.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/file_system.h" #include "tensorflow/core/platform/test.h" @@ -197,7 +198,7 @@ TEST_F(HadoopFileSystemTest, WriteWhileReading) { // Skip the test if we're not testing on HDFS. Hadoop's local filesystem // implementation makes no guarantees that writable files are readable while // being written. - if (!StringPiece(fname).starts_with("hdfs://")) { + if (!str_util::StartsWith(fname, "hdfs://")) { return; } diff --git a/tensorflow/core/profiler/internal/advisor/tfprof_advisor_test.cc b/tensorflow/core/profiler/internal/advisor/tfprof_advisor_test.cc index e968b9c97e..96b6cc30bd 100644 --- a/tensorflow/core/profiler/internal/advisor/tfprof_advisor_test.cc +++ b/tensorflow/core/profiler/internal/advisor/tfprof_advisor_test.cc @@ -16,6 +16,7 @@ limitations under the License. #include "tensorflow/core/profiler/internal/advisor/tfprof_advisor.h" #include "tensorflow/core/lib/io/path.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/test.h" @@ -82,8 +83,8 @@ TEST_F(TFProfAdvisorTest, OperationChecker) { (*options.mutable_checkers())[kCheckers[1]]; AdviceProto advice = advisor_->Advise(options); EXPECT_EQ(advice.checkers().at(kCheckers[1]).reports_size(), 1); - EXPECT_TRUE(StringPiece(advice.checkers().at(kCheckers[1]).reports(0)) - .contains("NCHW")); + EXPECT_TRUE(str_util::StrContains( + advice.checkers().at(kCheckers[1]).reports(0), "NCHW")); } TEST_F(TFProfAdvisorTest, UtilizationChecker) { @@ -91,16 +92,17 @@ TEST_F(TFProfAdvisorTest, UtilizationChecker) { (*options.mutable_checkers())[kCheckers[0]]; AdviceProto advice = advisor_->Advise(options); EXPECT_EQ(advice.checkers().at(kCheckers[0]).reports_size(), 1); - EXPECT_TRUE(StringPiece(advice.checkers().at(kCheckers[0]).reports(0)) - .contains("low utilization")); + EXPECT_TRUE(str_util::StrContains( + advice.checkers().at(kCheckers[0]).reports(0), "low utilization")); } TEST_F(TFProfAdvisorTest, ExpensiveOperationChecker) { AdvisorOptionsProto options; (*options.mutable_checkers())[kCheckers[2]]; AdviceProto advice = advisor_->Advise(options); - EXPECT_TRUE(StringPiece(advice.checkers().at(kCheckers[2]).reports(0)) - .contains("top 1 operation type: Conv2D")); + EXPECT_TRUE( + str_util::StrContains(advice.checkers().at(kCheckers[2]).reports(0), + "top 1 operation type: Conv2D")); } } // namespace tfprof diff --git a/tensorflow/core/util/tensor_bundle/tensor_bundle_test.cc b/tensorflow/core/util/tensor_bundle/tensor_bundle_test.cc index 08f1aa7125..7f166f0ec0 100644 --- a/tensorflow/core/util/tensor_bundle/tensor_bundle_test.cc +++ b/tensorflow/core/util/tensor_bundle/tensor_bundle_test.cc @@ -26,6 +26,7 @@ limitations under the License. #include "tensorflow/core/lib/core/status_test_util.h" #include "tensorflow/core/lib/io/path.h" #include "tensorflow/core/lib/io/table_builder.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" @@ -293,7 +294,7 @@ void VersionTest(const VersionDef& version, StringPiece expected_error) { BundleReader reader(Env::Default(), path); EXPECT_TRUE(errors::IsInvalidArgument(reader.status())); EXPECT_TRUE( - StringPiece(reader.status().error_message()).starts_with(expected_error)); + str_util::StartsWith(reader.status().error_message(), expected_error)); } } // namespace @@ -588,7 +589,7 @@ TEST(TensorBundleTest, Error) { TF_EXPECT_OK(writer.Add("foo", Constant_2x3(1.f))); EXPECT_FALSE(writer.Add("foo", Constant_2x3(2.f)).ok()); EXPECT_TRUE( - StringPiece(writer.status().ToString()).contains("duplicate key")); + str_util::StrContains(writer.status().ToString(), "duplicate key")); EXPECT_FALSE(writer.Finish().ok()); } { // Double finish @@ -598,7 +599,7 @@ TEST(TensorBundleTest, Error) { } { // Not found. BundleReader reader(Env::Default(), Prefix("nonexist")); - EXPECT_TRUE(StringPiece(reader.status().ToString()).contains("Not found")); + EXPECT_TRUE(str_util::StrContains(reader.status().ToString(), "Not found")); } } @@ -629,7 +630,7 @@ TEST(TensorBundleTest, Checksum) { BundleReader reader(Env::Default(), Prefix(prefix)); Status status = reader.Lookup(key, &val); EXPECT_TRUE(errors::IsDataLoss(status)); - EXPECT_TRUE(StringPiece(status.ToString()).contains(expected_msg)); + EXPECT_TRUE(str_util::StrContains(status.ToString(), expected_msg)); }; // Corrupts a float tensor. @@ -680,8 +681,8 @@ TEST(TensorBundleTest, Endianness) { BundleReader reader(Env::Default(), Prefix("end")); EXPECT_TRUE(errors::IsUnimplemented(reader.status())); - EXPECT_TRUE(StringPiece(reader.status().ToString()) - .contains("different endianness from the reader")); + EXPECT_TRUE(str_util::StrContains(reader.status().ToString(), + "different endianness from the reader")); } TEST(TensorBundleTest, TruncatedTensorContents) { diff --git a/tensorflow/examples/label_image/main.cc b/tensorflow/examples/label_image/main.cc index 63bc39de6c..baa65d3243 100644 --- a/tensorflow/examples/label_image/main.cc +++ b/tensorflow/examples/label_image/main.cc @@ -49,6 +49,7 @@ limitations under the License. #include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/core/threadpool.h" #include "tensorflow/core/lib/io/path.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/init_main.h" @@ -137,15 +138,15 @@ Status ReadTensorFromImageFile(const string& file_name, const int input_height, // Now try to figure out what kind of file it is and decode it. const int wanted_channels = 3; tensorflow::Output image_reader; - if (tensorflow::StringPiece(file_name).ends_with(".png")) { + if (tensorflow::str_util::EndsWith(file_name, ".png")) { image_reader = DecodePng(root.WithOpName("png_reader"), file_reader, DecodePng::Channels(wanted_channels)); - } else if (tensorflow::StringPiece(file_name).ends_with(".gif")) { + } else if (tensorflow::str_util::EndsWith(file_name, ".gif")) { // gif decoder returns 4-D tensor, remove the first dim image_reader = Squeeze(root.WithOpName("squeeze_first_dim"), DecodeGif(root.WithOpName("gif_reader"), file_reader)); - } else if (tensorflow::StringPiece(file_name).ends_with(".bmp")) { + } else if (tensorflow::str_util::EndsWith(file_name, ".bmp")) { image_reader = DecodeBmp(root.WithOpName("bmp_reader"), file_reader); } else { // Assume if it's neither a PNG nor a GIF then it must be a JPEG. diff --git a/tensorflow/examples/multibox_detector/main.cc b/tensorflow/examples/multibox_detector/main.cc index e38704fd98..96ea525a4e 100644 --- a/tensorflow/examples/multibox_detector/main.cc +++ b/tensorflow/examples/multibox_detector/main.cc @@ -30,6 +30,7 @@ limitations under the License. #include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/core/threadpool.h" #include "tensorflow/core/lib/io/path.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/stringprintf.h" #include "tensorflow/core/platform/init_main.h" #include "tensorflow/core/platform/logging.h" @@ -84,10 +85,10 @@ Status ReadTensorFromImageFile(const string& file_name, const int input_height, // Now try to figure out what kind of file it is and decode it. const int wanted_channels = 3; tensorflow::Output image_reader; - if (tensorflow::StringPiece(file_name).ends_with(".png")) { + if (tensorflow::str_util::EndsWith(file_name, ".png")) { image_reader = DecodePng(root.WithOpName("png_reader"), file_reader, DecodePng::Channels(wanted_channels)); - } else if (tensorflow::StringPiece(file_name).ends_with(".gif")) { + } else if (tensorflow::str_util::EndsWith(file_name, ".gif")) { image_reader = DecodeGif(root.WithOpName("gif_reader"), file_reader); } else { // Assume if it's neither a PNG nor a GIF then it must be a JPEG. @@ -131,7 +132,7 @@ Status ReadTensorFromImageFile(const string& file_name, const int input_height, Status SaveImage(const Tensor& tensor, const string& file_path) { LOG(INFO) << "Saving image to " << file_path; - CHECK(tensorflow::StringPiece(file_path).ends_with(".png")) + CHECK(tensorflow::str_util::EndsWith(file_path, ".png")) << "Only saving of png files is supported."; auto root = tensorflow::Scope::NewRootScope(); diff --git a/tensorflow/python/eager/python_eager_op_gen.cc b/tensorflow/python/eager/python_eager_op_gen.cc index 06185904e7..15d20bdd1a 100644 --- a/tensorflow/python/eager/python_eager_op_gen.cc +++ b/tensorflow/python/eager/python_eager_op_gen.cc @@ -117,7 +117,7 @@ class GenEagerPythonOp : public python_op_gen_internal::GenPythonOp { const string& function_name) : python_op_gen_internal::GenPythonOp(op_def, api_def, function_name) { op_name_ = function_name_; - op_name_.Consume("_"); + str_util::ConsumePrefix(&op_name_, "_"); } ~GenEagerPythonOp() override {} @@ -492,7 +492,7 @@ bool GenEagerPythonOp::GetEagerFunctionSetup(const string& indentation, strings::StrAppend(function_setup, indentation, " ", attr_api_name, " = ", default_value, "\n"); } - if (attr_type.starts_with("list(")) { + if (str_util::StartsWith(attr_type, "list(")) { ExpectListArg(indentation, attr_api_name, function_setup); } diff --git a/tensorflow/python/lib/core/py_seq_tensor.cc b/tensorflow/python/lib/core/py_seq_tensor.cc index 8247d354db..32ea737a99 100644 --- a/tensorflow/python/lib/core/py_seq_tensor.cc +++ b/tensorflow/python/lib/core/py_seq_tensor.cc @@ -20,6 +20,7 @@ limitations under the License. #include "tensorflow/core/framework/types.h" #include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/stringpiece.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/types.h" #include "tensorflow/python/lib/core/numpy.h" #include "tensorflow/python/lib/core/py_util.h" @@ -77,9 +78,9 @@ string PyRepr(PyObject* obj) { bool IsPyDimension(PyObject* obj) { const char* tp_name = obj->ob_type->tp_name; if (strcmp(tp_name, "Dimension") != 0) return false; - bool ret = - StringPiece(PyRepr(PyType(obj))) - .ends_with("tensorflow.python.framework.tensor_shape.Dimension'>"); + bool ret = str_util::EndsWith( + PyRepr(PyType(obj)), + "tensorflow.python.framework.tensor_shape.Dimension'>"); return ret; } |