Commit d927cb65 by Eric Junyuan Xie Committed by Tianqi Chen

add hash function for tuple (#141)

parent 97811fa4
......@@ -7,6 +7,7 @@
#define NNVM_BASE_H_
#include <dmlc/base.h>
#include <dmlc/common.h>
#include <dmlc/any.h>
#include <dmlc/memory.h>
#include <dmlc/logging.h>
......
......@@ -581,4 +581,34 @@ inline bool Tuple<ValueType>::Load(TStream *strm) {
} // namespace nnvm
namespace std {
/*! \brief hash function for Tuple. */
template<typename T>
struct hash<nnvm::Tuple<T> > {
/*! \brief hash a Tuple into unsigned int */
size_t operator()(const nnvm::Tuple<T>& val) const {
std::hash<uint32_t> hash_uint;
size_t res = hash_uint(val.ndim());
for (uint32_t i = 0; i < val.ndim(); ++i) {
res = dmlc::HashCombine(res, val[i]);
}
return res;
}
};
/*! \brief hash function for TShape. */
template<>
struct hash<nnvm::TShape> {
/*! \brief hash a TShape into unsigned int */
size_t operator()(const nnvm::TShape& val) const {
std::hash<uint32_t> hash_uint;
size_t res = hash_uint(val.ndim());
for (uint32_t i = 0; i < val.ndim(); ++i) {
res = dmlc::HashCombine(res, val[i]);
}
return res;
}
};
} // namespace std
#endif // NNVM_TUPLE_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment