Skip to content
Snippets Groups Projects
Commit 7ac8496b authored by Olivier BICHLER's avatar Olivier BICHLER
Browse files

Added auto format_as() generation with EnumStrings

parent 8494bb90
No related branches found
No related tags found
3 merge requests!414Update version 0.5.1 -> 0.6.0,!408[Add] Dropout Operator,!359Improve scheduling
......@@ -97,8 +97,4 @@ constexpr const char* const EnumStrings<Aidge::DataFormat>::data[] = {
};
}
namespace Aidge {
inline auto format_as(DataFormat df) { return EnumStrings<DataFormat>::data[static_cast<int>(df)]; }
} // namespace Aidge
#endif /* AIDGE_CORE_DATA_DATAFORMAT_H_ */
......@@ -180,10 +180,4 @@ const char* const EnumStrings<Aidge::DataType>::data[]
"UInt5", "UInt6", "UInt7", "UInt8", "UInt16", "UInt32", "UInt64", "Any"};
}
namespace Aidge {
inline auto format_as(DataType dt) {
return EnumStrings<DataType>::data[static_cast<int>(dt)];
}
} // namespace Aidge
#endif /* AIDGE_CORE_DATA_DATATYPE_H_ */
......@@ -118,8 +118,4 @@ const char* const EnumStrings<Aidge::Elts_t::EltType>::data[]
= {"Data", "Token", "Undef"};
}
namespace Aidge {
inline auto format_as(Elts_t::EltType elt) { return EnumStrings<Aidge::Elts_t::EltType>::data[static_cast<int>(elt)]; }
}
#endif /* AIDGE_ELTS_H_ */
......@@ -148,4 +148,29 @@ class Interpolation {
};
} // namespace Aidge
/**
* @brief EnumStrings specialization for Interpolation::CoordinateTransformation.
*/
template <>
const char* const EnumStrings<Aidge::Interpolation::CoordinateTransformation>::data[] = {
"HalfPixel",
"HalfPixelSymmetric",
"PytorchHalfPixel",
"AlignCorners",
"Asymmetric"
};
/**
* @brief EnumStrings specialization for Interpolation::Mode.
*/
template <>
const char* const EnumStrings<Aidge::Interpolation::Mode>::data[] = {
"Cubic",
"Linear",
"RoundPreferFloor",
"RoundPreferCeil",
"Floor",
"Ceil"
};
#endif
......@@ -193,4 +193,12 @@ inline std::shared_ptr<Node> BitShift(const BitShift_Op::BitShiftDirection direc
#undef LIST_BITSHIFT_ATTR
/**
* @brief EnumStrings specialization for BitShift_Op::BitShiftDirection.
*/
template <>
const char* const EnumStrings<Aidge::BitShift_Op::BitShiftDirection>::data[] = {
"left", "right"
};
#endif /* AIDGE_CORE_OPERATOR_BITSHIFT_H_ */
......@@ -209,4 +209,12 @@ std::shared_ptr<Node> DepthToSpace(const std::uint32_t blockSize,
#undef LIST_DEPTHTOSPACE_ATTR
/**
* @brief EnumStrings specialization for DepthToSpace_Op::Mode.
*/
template <>
const char* const EnumStrings<Aidge::DepthToSpace_Op::Mode>::data[] = {
"DCR", "CRD"
};
#endif //AIDGE_CORE_OPERATOR_DEPTHTOSPACE_H_
......@@ -223,4 +223,20 @@ std::shared_ptr<Node> GridSample(
#undef LIST_GRIDSAMPLE_ATTR
/**
* @brief EnumStrings specialization for GridSample_Op::Mode.
*/
template <>
const char* const EnumStrings<Aidge::GridSample_Op::Mode>::data[] = {
"Linear", "Nearest", "Cubic"
};
/**
* @brief EnumStrings specialization for GridSample_Op::PaddingMode.
*/
template <>
const char* const EnumStrings<Aidge::GridSample_Op::PaddingMode>::data[] = {
"Zeros", "Border", "Reflection"
};
#endif /* AIDGE_CORE_OPERATOR_GRIDSAMPLE_H_ */
......@@ -260,16 +260,6 @@ private:
} // namespace Aidge
// Formatter specialization for Log::Level
template <>
struct fmt::formatter<Aidge::Log::Level> : formatter<const char*> {
template <typename FormatContext>
auto format(const Aidge::Log::Level& level, FormatContext& ctx) const {
const char* name = EnumStrings<Aidge::Log::Level>::data[static_cast<int>(level)];
return formatter<const char*>::format(name, ctx);
}
};
namespace {
template <>
const char* const EnumStrings<Aidge::Log::Level>::data[] = {
......
......@@ -12,6 +12,8 @@
#ifndef AIDGE_CORE_UTILS_LOGGER_ENUMSTRING_H_
#define AIDGE_CORE_UTILS_LOGGER_ENUMSTRING_H_
#include <fmt/format.h>
namespace {
// This is the type that will hold all the strings. Each enumerate type will
// declare its own specialization.
......@@ -20,4 +22,9 @@ template <typename T> struct EnumStrings {
};
}
namespace Aidge {
template <class T, typename std::enable_if<std::is_enum<T>::value>::type* = nullptr>
inline auto format_as(T elt) { return EnumStrings<T>::data[static_cast<int>(elt)]; }
}
#endif /* AIDGE_CORE_UTILS_LOGGER_ENUMSTRING_H_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment