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 << "'";
}
#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 {
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();
}
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();
}
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();
}
#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"
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);
}
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;
#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"
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 {
#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 {
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 << "'";
}
}
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();
}
limitations under the License.
==============================================================================*/
+#include "tensorflow/core/lib/strings/str_util.h"
#if GOOGLE_CUDA
#include <forward_list>
// 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") {
#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"
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);
}
// 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) {
#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"
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 {
#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 {
// 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");
#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"
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();
}
#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"
};
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;
}
#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 {
// 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.
}
#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"
// 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;
}
#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"
(*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) {
(*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
#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"
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
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
}
{ // 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"));
}
}
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.
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) {
#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"
// 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.
#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"
// 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.
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();
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 {}
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);
}
#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"
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;
}