Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move operator<< and to_string for daliDataType_t to the global namespace. #5748

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions dali/pipeline/data/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
#define DALI_REGISTER_TYPE_IMPL(...)
#endif

inline std::string to_string(daliDataType_t dtype);
inline std::ostream &operator<<(std::ostream &, daliDataType_t dtype);

namespace dali {

class TensorLayout;
Expand Down Expand Up @@ -90,9 +93,6 @@ inline Copier GetCopier() {

using DALIDataType = daliDataType_t;

inline std::string to_string(DALIDataType dtype);
inline std::ostream &operator<<(std::ostream &, DALIDataType dtype);

constexpr auto GetBuiltinTypeName = daliDataTypeName;
constexpr auto IsFloatingPoint = daliDataTypeIsFloatingPoint;
constexpr auto IsIntegral = daliDataTypeIsIntegral;
Expand Down Expand Up @@ -412,14 +412,6 @@ inline std::string_view TypeName(DALIDataType dtype) {
return "<unknown>";
}

inline std::string to_string(DALIDataType dtype) {
std::string_view name = TypeName(dtype);
if (name == "<unknown>")
return "unknown type: " + std::to_string(static_cast<int>(dtype));
else
return std::string(name);
}

// Used to define a type for use in dali. Inserts the type into the
// TypeTable w/ a unique id and creates a method to get the name of
// the type as a string. This does not work for non-fundamental types,
Expand Down Expand Up @@ -465,8 +457,22 @@ DALI_REGISTER_TYPE(std::vector<float>, DALI_FLOAT_VEC);
DALI_REGISTER_TYPE(std::vector<TensorLayout>, DALI_TENSOR_LAYOUT_VEC);
DALI_REGISTER_TYPE(std::vector<DALIDataType>, DALI_DATA_TYPE_VEC);

inline std::ostream &operator<<(std::ostream &os, DALIDataType dtype) {
std::string_view name = TypeName(dtype);
#define DALI_INTEGRAL_TYPES uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
#define DALI_NUMERIC_TYPES DALI_INTEGRAL_TYPES, float, double
#define DALI_NUMERIC_TYPES_FP16 DALI_NUMERIC_TYPES, float16

} // namespace dali

inline std::string to_string(daliDataType_t dtype) {
std::string_view name = dali::TypeName(dtype);
if (name == "<unknown>")
return "unknown type: " + std::to_string(static_cast<int>(dtype));
else
return std::string(name);
}

inline std::ostream &operator<<(std::ostream &os, daliDataType_t dtype) {
std::string_view name = dali::TypeName(dtype);
if (name == "<unknown>") {
// Use string concatenation so that the result is the same as in to_string, unaffected by
// formatting & other settings in `os`.
Expand All @@ -476,10 +482,5 @@ inline std::ostream &operator<<(std::ostream &os, DALIDataType dtype) {
}
}

#define DALI_INTEGRAL_TYPES uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
#define DALI_NUMERIC_TYPES DALI_INTEGRAL_TYPES, float, double
#define DALI_NUMERIC_TYPES_FP16 DALI_NUMERIC_TYPES, float16

} // namespace dali

#endif // DALI_PIPELINE_DATA_TYPES_H_
Loading