aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow
diff options
context:
space:
mode:
authorGravatar Yu-Cheng Ling <ycling@google.com>2018-05-31 15:50:55 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-05-31 15:53:48 -0700
commit6ca9a881ebd9bd3c7d4432dbddd779dafc8f936b (patch)
tree56c17e8259737e59c3e8d73884b67b7e95f6a2a2 /tensorflow
parent28f8cf5cf2281682f70f4674192f9f31d68c5ee1 (diff)
Refactoring: Extract CombineHashes function into a shared module
PiperOrigin-RevId: 198793295
Diffstat (limited to 'tensorflow')
-rw-r--r--tensorflow/contrib/lite/op_resolver.h4
-rw-r--r--tensorflow/contrib/lite/toco/tflite/export.h21
-rw-r--r--tensorflow/contrib/lite/util.cc10
-rw-r--r--tensorflow/contrib/lite/util.h2
4 files changed, 19 insertions, 18 deletions
diff --git a/tensorflow/contrib/lite/op_resolver.h b/tensorflow/contrib/lite/op_resolver.h
index 38a2706942..9d7e3f2085 100644
--- a/tensorflow/contrib/lite/op_resolver.h
+++ b/tensorflow/contrib/lite/op_resolver.h
@@ -18,6 +18,7 @@ limitations under the License.
#include <unordered_map>
#include "tensorflow/contrib/lite/context.h"
#include "tensorflow/contrib/lite/schema/schema_generated.h"
+#include "tensorflow/contrib/lite/util.h"
namespace tflite {
@@ -55,8 +56,7 @@ struct OperatorKeyHasher {
size_t operator()(const T& x) const {
size_t a = ValueHasher<typename T::first_type>()(x.first);
size_t b = ValueHasher<typename T::second_type>()(x.second);
- // Hash combinator used by TensorFlow core.
- return a ^ (b + 0x9e3779b97f4a7800ULL + (a << 10) + (a >> 4));
+ return CombineHashes({a, b});
}
};
} // namespace op_resolver_hasher
diff --git a/tensorflow/contrib/lite/toco/tflite/export.h b/tensorflow/contrib/lite/toco/tflite/export.h
index 90abfb94d8..098d2163e6 100644
--- a/tensorflow/contrib/lite/toco/tflite/export.h
+++ b/tensorflow/contrib/lite/toco/tflite/export.h
@@ -17,6 +17,7 @@ limitations under the License.
#include "tensorflow/contrib/lite/toco/model.h"
#include "tensorflow/contrib/lite/toco/tflite/operator.h"
+#include "tensorflow/contrib/lite/util.h"
namespace toco {
@@ -72,22 +73,10 @@ struct OperatorKey {
struct Hash {
size_t operator()(const OperatorKey& key) const {
- return CombineHashes({std::hash<size_t>()(static_cast<size_t>(key.type)),
- std::hash<std::string>()(key.custom_code),
- std::hash<int>()(key.version)});
- }
-
- private:
- // TODO(ycling): Refactoring and extract this function into a common
- // utility module.
- static size_t CombineHashes(std::initializer_list<size_t> hashes) {
- size_t result = 0;
- // Hash combiner used by TensorFlow core.
- for (size_t hash : hashes) {
- result = result ^ (hash + 0x9e3779b97f4a7800ULL + (result << 10) +
- (result >> 4));
- }
- return result;
+ return ::tflite::CombineHashes(
+ {std::hash<size_t>()(static_cast<size_t>(key.type)),
+ std::hash<std::string>()(key.custom_code),
+ std::hash<int>()(key.version)});
}
};
};
diff --git a/tensorflow/contrib/lite/util.cc b/tensorflow/contrib/lite/util.cc
index fb4af07d06..8ccb65c24f 100644
--- a/tensorflow/contrib/lite/util.cc
+++ b/tensorflow/contrib/lite/util.cc
@@ -38,4 +38,14 @@ bool EqualArrayAndTfLiteIntArray(const TfLiteIntArray* a, const int b_size,
return true;
}
+size_t CombineHashes(std::initializer_list<size_t> hashes) {
+ size_t result = 0;
+ // Hash combiner used by TensorFlow core.
+ for (size_t hash : hashes) {
+ result = result ^
+ (hash + 0x9e3779b97f4a7800ULL + (result << 10) + (result >> 4));
+ }
+ return result;
+}
+
} // namespace tflite
diff --git a/tensorflow/contrib/lite/util.h b/tensorflow/contrib/lite/util.h
index a34db35823..89d9b4f5cf 100644
--- a/tensorflow/contrib/lite/util.h
+++ b/tensorflow/contrib/lite/util.h
@@ -35,6 +35,8 @@ TfLiteIntArray* ConvertArrayToTfLiteIntArray(const int rank, const int* dims);
bool EqualArrayAndTfLiteIntArray(const TfLiteIntArray* a, const int b_size,
const int* b);
+size_t CombineHashes(std::initializer_list<size_t> hashes);
+
} // namespace tflite
#endif // TENSORFLOW_CONTRIB_LITE_UTIL_H_