Updated cc/ to use tstring.

This is a part of a larger migration effort for tensorflow::tstring.
See: https://github.com/tensorflow/community/pull/91
PiperOrigin-RevId: 262918772
This commit is contained in:
Dero Gharibian 2019-08-12 07:29:31 -07:00 committed by TensorFlower Gardener
parent d9fbce7831
commit bf10ecf080
4 changed files with 12 additions and 12 deletions

View File

@ -200,10 +200,10 @@ TEST(CCOpTest, TemplatedConst) {
test::ExpectTensorEqual<float>( test::ExpectTensorEqual<float>(
out, test::AsTensor<float>({3.f, 2.f, -1.f, 0.f}, {2, 2})); out, test::AsTensor<float>({3.f, 2.f, -1.f, 0.f}, {2, 2}));
auto c2 = ops::Const<string>(root, {{"this"}, {"is"}, {"a"}, {"constant"}}); auto c2 = ops::Const<tstring>(root, {{"this"}, {"is"}, {"a"}, {"constant"}});
test::GetTensor(root, c2, &out); test::GetTensor(root, c2, &out);
test::ExpectTensorEqual<string>( test::ExpectTensorEqual<tstring>(
out, test::AsTensor<string>({"this", "is", "a", "constant"}, {4, 1})); out, test::AsTensor<tstring>({"this", "is", "a", "constant"}, {4, 1}));
} }
TEST(CCOpTest, EmptyConst) { TEST(CCOpTest, EmptyConst) {

View File

@ -111,7 +111,7 @@ class Input {
Initializer(const T& v) { // NOLINT(runtime/explicit) Initializer(const T& v) { // NOLINT(runtime/explicit)
typedef typename RealType<T>::type RealT; typedef typename RealType<T>::type RealT;
Tensor t(DataTypeToEnum<RealT>::v(), TensorShape()); Tensor t(DataTypeToEnum<RealT>::v(), TensorShape());
t.flat<T>()(0) = RealT(v); t.flat<RealT>()(0) = RealT(v);
tensor = t; tensor = t;
} }
@ -125,7 +125,7 @@ class Input {
typedef typename RealType<T>::type RealT; typedef typename RealType<T>::type RealT;
Tensor t(DataTypeToEnum<RealT>::v(), shape); Tensor t(DataTypeToEnum<RealT>::v(), shape);
for (int64 i = 0; i < t.NumElements(); ++i) { for (int64 i = 0; i < t.NumElements(); ++i) {
t.flat<T>()(i) = RealT(v); t.flat<RealT>()(i) = RealT(v);
} }
tensor = t; tensor = t;
} }
@ -170,7 +170,7 @@ class Input {
// START_SKIP_DOXYGEN // START_SKIP_DOXYGEN
template <typename T, bool = std::is_convertible<T, string>::value> template <typename T, bool = std::is_convertible<T, string>::value>
struct RealType { struct RealType {
typedef string type; typedef tstring type;
}; };
template <typename T> template <typename T>

View File

@ -97,7 +97,7 @@ TEST(ConstOpTest, WithExplicitShape) {
auto d = ops::Const(root, {"1", "2", "3", "4", "5", "6"}, {2, 3}); auto d = ops::Const(root, {"1", "2", "3", "4", "5", "6"}, {2, 3});
TF_CHECK_OK(root.status()); TF_CHECK_OK(root.status());
EXPECT_EQ(d.op().output_type(0), DT_STRING); EXPECT_EQ(d.op().output_type(0), DT_STRING);
ExpectNodeEqual<string>(d.node(), {"1", "2", "3", "4", "5", "6"}, {2, 3}); ExpectNodeEqual<tstring>(d.node(), {"1", "2", "3", "4", "5", "6"}, {2, 3});
} }
TEST(ConstOpTest, FromProto) { TEST(ConstOpTest, FromProto) {
@ -144,7 +144,7 @@ TEST(ConstOpTest, TemplatedConst) {
auto c1 = ops::Const<int>(root, {1, 2}); auto c1 = ops::Const<int>(root, {1, 2});
ExpectTypeAndShape(c1.node(), DT_INT32, {2}); ExpectTypeAndShape(c1.node(), DT_INT32, {2});
auto c2 = ops::Const<string>(root, {{"this"}, {"is"}, {"a"}, {"constant"}}); auto c2 = ops::Const<tstring>(root, {{"this"}, {"is"}, {"a"}, {"constant"}});
ExpectTypeAndShape(c2.node(), DT_STRING, {4, 1}); ExpectTypeAndShape(c2.node(), DT_STRING, {4, 1});
} }

View File

@ -63,8 +63,8 @@ class LoaderTest : public ::testing::Test {
bundle.session->Run({}, {"filename_tensor:0"}, {}, &path_outputs)); bundle.session->Run({}, {"filename_tensor:0"}, {}, &path_outputs));
ASSERT_EQ(1, path_outputs.size()); ASSERT_EQ(1, path_outputs.size());
test::ExpectTensorEqual<string>( test::ExpectTensorEqual<tstring>(
test::AsTensor<string>({"foo.txt"}, TensorShape({})), path_outputs[0]); test::AsTensor<tstring>({"foo.txt"}, TensorShape({})), path_outputs[0]);
} }
void CheckSavedModelBundle(const string& export_dir, void CheckSavedModelBundle(const string& export_dir,
@ -78,14 +78,14 @@ class LoaderTest : public ::testing::Test {
const string output_name = const string output_name =
signature_def.outputs().at(kRegressOutputs).name(); signature_def.outputs().at(kRegressOutputs).name();
std::vector<string> serialized_examples; std::vector<tstring> serialized_examples;
for (float x : {0, 1, 2, 3}) { for (float x : {0, 1, 2, 3}) {
serialized_examples.push_back(MakeSerializedExample(x)); serialized_examples.push_back(MakeSerializedExample(x));
} }
// Validate the half plus two behavior. // Validate the half plus two behavior.
Tensor input = Tensor input =
test::AsTensor<string>(serialized_examples, TensorShape({4})); test::AsTensor<tstring>(serialized_examples, TensorShape({4}));
std::vector<Tensor> outputs; std::vector<Tensor> outputs;
TF_ASSERT_OK(bundle.session->Run({{input_name, input}}, {output_name}, {}, TF_ASSERT_OK(bundle.session->Run({{input_name, input}}, {output_name}, {},
&outputs)); &outputs));