From 645a554a41ef5524e7ec65beeb7976c066886da6 Mon Sep 17 00:00:00 2001 From: Shanqing Cai Date: Sun, 11 Sep 2016 10:03:45 -0800 Subject: Update OSS protobuf git depedency version to 3.0.2 3.0.2 is the latest release. Add a level of indirection to the int64 type in 1) core/example/feature_util.h, feature_util.cc and the places where the type is used 2) tools/proto_text/gen_proto_text_functions_lib.cc and its tests. This is for dealing with the variability of "int64" type definition among different platforms. On some systems, int64 is "long int", while on others it is "long long int". See GitHub Issue for more details: https://github.com/tensorflow/tensorflow/issues/3626. This change list fixes the issue and eliminates the need to stick to an old (3.0.0-beta-2) commit of protobuf. Change: 132814372 --- tensorflow/core/example/feature_util.cc | 9 +++++---- tensorflow/core/example/feature_util.h | 15 ++++++++------- tensorflow/core/example/feature_util_test.cc | 27 ++++++++++++++------------- 3 files changed, 27 insertions(+), 24 deletions(-) (limited to 'tensorflow/core/example') diff --git a/tensorflow/core/example/feature_util.cc b/tensorflow/core/example/feature_util.cc index ddd2435a95..6f3cc6c6c5 100644 --- a/tensorflow/core/example/feature_util.cc +++ b/tensorflow/core/example/feature_util.cc @@ -28,7 +28,8 @@ namespace internal { } // namespace internal template <> -bool ExampleHasFeature(const string& name, const Example& example) { +bool ExampleHasFeature(const string& name, + const Example& example) { auto it = example.features().feature().find(name); return (it != example.features().feature().end()) && (it->second.kind_case() == Feature::KindCase::kInt64List); @@ -49,14 +50,14 @@ bool ExampleHasFeature(const string& name, const Example& example) { } template <> -const protobuf::RepeatedField& GetFeatureValues( +const protobuf::RepeatedField& GetFeatureValues( const string& name, const Example& example) { return example.features().feature().at(name).int64_list().value(); } template <> -protobuf::RepeatedField* GetFeatureValues(const string& name, - Example* example) { +protobuf::RepeatedField* GetFeatureValues( + const string& name, Example* example) { return internal::ExampleFeature(name, example) .mutable_int64_list() ->mutable_value(); diff --git a/tensorflow/core/example/feature_util.h b/tensorflow/core/example/feature_util.h index 048930d235..4004411cb1 100644 --- a/tensorflow/core/example/feature_util.h +++ b/tensorflow/core/example/feature_util.h @@ -73,8 +73,8 @@ template struct RepeatedFieldTrait; template <> -struct RepeatedFieldTrait { - using Type = protobuf::RepeatedField; +struct RepeatedFieldTrait { + using Type = protobuf::RepeatedField; }; template <> @@ -95,7 +95,7 @@ struct FeatureTrait; template struct FeatureTrait::value>::type> { - using Type = int64; + using Type = protobuf_int64; }; template @@ -178,7 +178,8 @@ void AppendFeatureValues(std::initializer_list container, } template <> -bool ExampleHasFeature(const string& name, const Example& example); +bool ExampleHasFeature(const string& name, + const Example& example); template <> bool ExampleHasFeature(const string& name, const Example& example); @@ -187,12 +188,12 @@ template <> bool ExampleHasFeature(const string& name, const Example& example); template <> -const protobuf::RepeatedField& GetFeatureValues( +const protobuf::RepeatedField& GetFeatureValues( const string& name, const Example& example); template <> -protobuf::RepeatedField* GetFeatureValues(const string& name, - Example* example); +protobuf::RepeatedField* GetFeatureValues( + const string& name, Example* example); template <> const protobuf::RepeatedField& GetFeatureValues( diff --git a/tensorflow/core/example/feature_util_test.cc b/tensorflow/core/example/feature_util_test.cc index 9e1d645118..eb7b90af1b 100644 --- a/tensorflow/core/example/feature_util_test.cc +++ b/tensorflow/core/example/feature_util_test.cc @@ -32,7 +32,7 @@ TEST(GetFeatureValuesInt64Test, ReadsASingleValue) { .mutable_int64_list() ->add_value(42); - auto tag = GetFeatureValues("tag", example); + auto tag = GetFeatureValues("tag", example); ASSERT_EQ(1, tag.size()); EXPECT_EQ(42, tag.Get(0)); @@ -41,7 +41,7 @@ TEST(GetFeatureValuesInt64Test, ReadsASingleValue) { TEST(GetFeatureValuesInt64Test, WritesASingleValue) { Example example; - GetFeatureValues("tag", &example)->Add(42); + GetFeatureValues("tag", &example)->Add(42); ASSERT_EQ(1, example.features().feature().at("tag").int64_list().value_size()); @@ -53,7 +53,7 @@ TEST(GetFeatureValuesInt64Test, CheckUntypedFieldExistence) { EXPECT_FALSE(ExampleHasFeature("tag", example)); - GetFeatureValues("tag", &example)->Add(0); + GetFeatureValues("tag", &example)->Add(0); EXPECT_TRUE(ExampleHasFeature("tag", example)); } @@ -62,12 +62,12 @@ TEST(GetFeatureValuesInt64Test, CheckTypedFieldExistence) { Example example; GetFeatureValues("tag", &example)->Add(3.14); - ASSERT_FALSE(ExampleHasFeature("tag", example)); + ASSERT_FALSE(ExampleHasFeature("tag", example)); - GetFeatureValues("tag", &example)->Add(42); + GetFeatureValues("tag", &example)->Add(42); - EXPECT_TRUE(ExampleHasFeature("tag", example)); - auto tag_ro = GetFeatureValues("tag", example); + EXPECT_TRUE(ExampleHasFeature("tag", example)); + auto tag_ro = GetFeatureValues("tag", example); ASSERT_EQ(1, tag_ro.size()); EXPECT_EQ(42, tag_ro.Get(0)); } @@ -78,9 +78,9 @@ TEST(GetFeatureValuesInt64Test, CopyIterableToAField) { std::copy(values.begin(), values.end(), protobuf::RepeatedFieldBackInserter( - GetFeatureValues("tag", &example))); + GetFeatureValues("tag", &example))); - auto tag_ro = GetFeatureValues("tag", example); + auto tag_ro = GetFeatureValues("tag", example); ASSERT_EQ(3, tag_ro.size()); EXPECT_EQ(1, tag_ro.Get(0)); EXPECT_EQ(2, tag_ro.Get(1)); @@ -114,7 +114,7 @@ TEST(GetFeatureValuesFloatTest, WritesASingleValue) { TEST(GetFeatureValuesFloatTest, CheckTypedFieldExistence) { Example example; - GetFeatureValues("tag", &example)->Add(42); + GetFeatureValues("tag", &example)->Add(42); ASSERT_FALSE(ExampleHasFeature("tag", example)); GetFeatureValues("tag", &example)->Add(3.14); @@ -151,7 +151,7 @@ TEST(GetFeatureValuesStringTest, WritesASingleValue) { TEST(GetFeatureValuesBytesTest, CheckTypedFieldExistence) { Example example; - GetFeatureValues("tag", &example)->Add(42); + GetFeatureValues("tag", &example)->Add(42); ASSERT_FALSE(ExampleHasFeature("tag", example)); *GetFeatureValues("tag", &example)->Add() = "FOO"; @@ -190,9 +190,10 @@ TEST(AppendFeatureValuesTest, FloatValuesUsingInitializerList) { TEST(AppendFeatureValuesTest, Int64ValuesUsingInitializerList) { Example example; - AppendFeatureValues({1, 2, 3}, "tag", &example); + std::vector values{1, 2, 3}; + AppendFeatureValues(values, "tag", &example); - auto tag_ro = GetFeatureValues("tag", example); + auto tag_ro = GetFeatureValues("tag", example); ASSERT_EQ(3, tag_ro.size()); EXPECT_EQ(1, tag_ro.Get(0)); EXPECT_EQ(2, tag_ro.Get(1)); -- cgit v1.2.3