Skip to content

Commit f6e2c00

Browse files
authored
Move operator<< and to_string for DALIDataType to the global namespace. (#5748)
Fix ADL for operator<< in gcc>=12 and clang. Signed-off-by: Michal Zientkiewicz <michalz@nvidia.com>
1 parent 058f183 commit f6e2c00

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

dali/pipeline/data/types.h

+19-18
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
#define DALI_REGISTER_TYPE_IMPL(...)
5353
#endif
5454

55+
inline std::string to_string(daliDataType_t dtype);
56+
inline std::ostream &operator<<(std::ostream &, daliDataType_t dtype);
57+
5558
namespace dali {
5659

5760
class TensorLayout;
@@ -90,9 +93,6 @@ inline Copier GetCopier() {
9093

9194
using DALIDataType = daliDataType_t;
9295

93-
inline std::string to_string(DALIDataType dtype);
94-
inline std::ostream &operator<<(std::ostream &, DALIDataType dtype);
95-
9696
constexpr auto GetBuiltinTypeName = daliDataTypeName;
9797
constexpr auto IsFloatingPoint = daliDataTypeIsFloatingPoint;
9898
constexpr auto IsIntegral = daliDataTypeIsIntegral;
@@ -412,14 +412,6 @@ inline std::string_view TypeName(DALIDataType dtype) {
412412
return "<unknown>";
413413
}
414414

415-
inline std::string to_string(DALIDataType dtype) {
416-
std::string_view name = TypeName(dtype);
417-
if (name == "<unknown>")
418-
return "unknown type: " + std::to_string(static_cast<int>(dtype));
419-
else
420-
return std::string(name);
421-
}
422-
423415
// Used to define a type for use in dali. Inserts the type into the
424416
// TypeTable w/ a unique id and creates a method to get the name of
425417
// the type as a string. This does not work for non-fundamental types,
@@ -465,8 +457,22 @@ DALI_REGISTER_TYPE(std::vector<float>, DALI_FLOAT_VEC);
465457
DALI_REGISTER_TYPE(std::vector<TensorLayout>, DALI_TENSOR_LAYOUT_VEC);
466458
DALI_REGISTER_TYPE(std::vector<DALIDataType>, DALI_DATA_TYPE_VEC);
467459

468-
inline std::ostream &operator<<(std::ostream &os, DALIDataType dtype) {
469-
std::string_view name = TypeName(dtype);
460+
#define DALI_INTEGRAL_TYPES uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
461+
#define DALI_NUMERIC_TYPES DALI_INTEGRAL_TYPES, float, double
462+
#define DALI_NUMERIC_TYPES_FP16 DALI_NUMERIC_TYPES, float16
463+
464+
} // namespace dali
465+
466+
inline std::string to_string(daliDataType_t dtype) {
467+
std::string_view name = dali::TypeName(dtype);
468+
if (name == "<unknown>")
469+
return "unknown type: " + std::to_string(static_cast<int>(dtype));
470+
else
471+
return std::string(name);
472+
}
473+
474+
inline std::ostream &operator<<(std::ostream &os, daliDataType_t dtype) {
475+
std::string_view name = dali::TypeName(dtype);
470476
if (name == "<unknown>") {
471477
// Use string concatenation so that the result is the same as in to_string, unaffected by
472478
// formatting & other settings in `os`.
@@ -476,10 +482,5 @@ inline std::ostream &operator<<(std::ostream &os, DALIDataType dtype) {
476482
}
477483
}
478484

479-
#define DALI_INTEGRAL_TYPES uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
480-
#define DALI_NUMERIC_TYPES DALI_INTEGRAL_TYPES, float, double
481-
#define DALI_NUMERIC_TYPES_FP16 DALI_NUMERIC_TYPES, float16
482-
483-
} // namespace dali
484485

485486
#endif // DALI_PIPELINE_DATA_TYPES_H_

0 commit comments

Comments
 (0)