Modify type-specific mappings to be explicit about long/long long rather than

relying on a specific definition meaning int64.

PiperOrigin-RevId: 321402137
Change-Id: I8f3e753725551bdba4eb0b2855e8515a3a7828b4
This commit is contained in:
A. Unique TensorFlower 2020-07-15 11:28:11 -07:00 committed by TensorFlower Gardener
parent ac988f3bb8
commit 2d3ab484dd
5 changed files with 78 additions and 9 deletions

View File

@ -395,8 +395,6 @@ MATCH_TYPE_AND_ENUM(int8, DT_INT8);
MATCH_TYPE_AND_ENUM(tstring, DT_STRING);
MATCH_TYPE_AND_ENUM(complex64, DT_COMPLEX64);
MATCH_TYPE_AND_ENUM(complex128, DT_COMPLEX128);
MATCH_TYPE_AND_ENUM(int64, DT_INT64);
MATCH_TYPE_AND_ENUM(uint64, DT_UINT64);
MATCH_TYPE_AND_ENUM(bool, DT_BOOL);
MATCH_TYPE_AND_ENUM(qint8, DT_QINT8);
MATCH_TYPE_AND_ENUM(quint8, DT_QUINT8);
@ -408,6 +406,59 @@ MATCH_TYPE_AND_ENUM(Eigen::half, DT_HALF);
MATCH_TYPE_AND_ENUM(ResourceHandle, DT_RESOURCE);
MATCH_TYPE_AND_ENUM(Variant, DT_VARIANT);
template <>
struct DataTypeToEnum<long> {
static DataType v() { return value; }
static DataType ref() { return MakeRefType(value); }
static constexpr DataType value = sizeof(long) == 4 ? DT_INT32 : DT_INT64;
};
template <>
struct IsValidDataType<long> {
static constexpr bool value = true;
};
template <>
struct EnumToDataType<DT_INT64> {
typedef tensorflow::int64 Type;
};
template <>
struct DataTypeToEnum<unsigned long> {
static DataType v() { return value; }
static DataType ref() { return MakeRefType(value); }
static constexpr DataType value =
sizeof(unsigned long) == 4 ? DT_UINT32 : DT_UINT64;
};
template <>
struct IsValidDataType<unsigned long> {
static constexpr bool value = true;
};
template <>
struct EnumToDataType<DT_UINT64> {
typedef tensorflow::uint64 Type;
};
template <>
struct DataTypeToEnum<long long> {
static DataType v() { return DT_INT64; }
static DataType ref() { return MakeRefType(DT_INT64); }
static constexpr DataType value = DT_INT64;
};
template <>
struct IsValidDataType<long long> {
static constexpr bool value = true;
};
template <>
struct DataTypeToEnum<unsigned long long> {
static DataType v() { return DT_UINT64; }
static DataType ref() { return MakeRefType(DT_UINT64); }
static constexpr DataType value = DT_UINT64;
};
template <>
struct IsValidDataType<unsigned long long> {
static constexpr bool value = true;
};
#undef MATCH_TYPE_AND_ENUM
// All types not specialized are marked invalid.

View File

@ -101,7 +101,7 @@ class KeyedSparseTensorColumn : public ColumnInterface<InternalType> {
private:
const Tensor& values_;
uint64 key_[2];
tensorflow::uint64 key_[2];
std::vector<int64> feature_counts_;
std::vector<int64> feature_start_indices_;
};
@ -201,7 +201,7 @@ class KeyedDenseTensorColumn : public ColumnInterface<InternalType> {
private:
const Tensor& tensor_;
uint64 key_[2];
tensorflow::uint64 key_[2];
};
// InternalType is int64 only when using HashCrosser.

View File

@ -21,8 +21,10 @@ limitations under the License.
namespace tensorflow {
inline uint64 StrongKeyedHash(const uint64 (&key)[2], const string& s) {
return highwayhash::StringHasher<highwayhash::SipHashState>()(key, s);
inline uint64 StrongKeyedHash(const tensorflow::uint64 (&key)[2],
const string& s) {
return highwayhash::StringHasher<highwayhash::SipHashState>()(
{key[0], key[1]}, s);
}
} // namespace tensorflow

View File

@ -32,7 +32,7 @@ namespace tensorflow {
// string input = "input string";
// uint64 hash_value = StrongKeyedHash(key, input);
//
uint64 StrongKeyedHash(const uint64 (&)[2], const string&);
uint64 StrongKeyedHash(const tensorflow::uint64 (&)[2], const string&);
} // namespace tensorflow

View File

@ -44,13 +44,29 @@ class XStatsBuilder {
void AddStatValue(const XStatMetadata& metadata, uint32 value) {
AddStat(metadata)->set_uint64_value(value);
}
void AddStatValue(const XStatMetadata& metadata, uint64 value) {
void AddStatValue(const XStatMetadata& metadata,
unsigned long value) { // NOLINT
if constexpr (sizeof(unsigned long) == 8) { // NOLINT
AddStat(metadata)->set_uint64_value(value);
} else {
AddStat(metadata)->set_uint32_value(value);
}
}
void AddStatValue(const XStatMetadata& metadata,
unsigned long long value) { // NOLINT
AddStat(metadata)->set_uint64_value(value);
}
void AddStatValue(const XStatMetadata& metadata, int32 value) {
AddStat(metadata)->set_int64_value(value);
}
void AddStatValue(const XStatMetadata& metadata, int64 value) {
void AddStatValue(const XStatMetadata& metadata, long value) { // NOLINT
if constexpr (sizeof(long) == 8) { // NOLINT
AddStat(metadata)->set_int64_value(value);
} else {
AddStat(metadata)->set_int32_value(value);
}
}
void AddStatValue(const XStatMetadata& metadata, long long value) { // NOLINT
AddStat(metadata)->set_int64_value(value);
}
void AddStatValue(const XStatMetadata& metadata, double value) {