Changed extern to constexpr for global element type (#3463)

* Changed extern to constexpr for global element type

* Fixed comments
This commit is contained in:
Ilya Churaev 2020-12-03 17:58:17 +03:00 committed by GitHub
parent 325a0a4f5e
commit e1c9d91ece
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 87 deletions

View File

@ -65,7 +65,7 @@ namespace ngraph
{ {
} }
Type(const Type&) = default; Type(const Type&) = default;
Type(const Type_t t) constexpr Type(const Type_t t)
: m_type{t} : m_type{t}
{ {
} }
@ -74,7 +74,6 @@ namespace ngraph
bool is_signed, bool is_signed,
bool is_quantized, bool is_quantized,
const std::string& cname); const std::string& cname);
~Type() {}
Type& operator=(const Type&) = default; Type& operator=(const Type&) = default;
const std::string& c_type_string() const; const std::string& c_type_string() const;
size_t size() const; size_t size() const;
@ -91,11 +90,6 @@ namespace ngraph
size_t bitwidth() const; size_t bitwidth() const;
// The name of this type, the enum name of this type // The name of this type, the enum name of this type
const std::string& get_type_name() const; const std::string& get_type_name() const;
bool operator==(const Type_t& other) const;
bool operator!=(const Type_t& other) const { return !(*this == other); }
bool operator==(const Type& other) const;
bool operator!=(const Type& other) const { return !(*this == other); }
bool operator<(const Type& other) const;
friend NGRAPH_API std::ostream& operator<<(std::ostream&, const Type&); friend NGRAPH_API std::ostream& operator<<(std::ostream&, const Type&);
/// \brief Checks whether this element type is merge-compatible with `t`. /// \brief Checks whether this element type is merge-compatible with `t`.
@ -124,58 +118,29 @@ namespace ngraph
static bool merge(element::Type& dst, const element::Type& t1, const element::Type& t2); static bool merge(element::Type& dst, const element::Type& t1, const element::Type& t2);
// \brief This allows switch(element_type) // \brief This allows switch(element_type)
operator Type_t() const { return m_type; } constexpr operator Type_t() const { return m_type; }
private: private:
Type_t m_type{Type_t::undefined}; Type_t m_type{Type_t::undefined};
}; };
typedef std::vector<Type> TypeVector; typedef std::vector<Type> TypeVector;
NGRAPH_DEPRECATED( constexpr Type undefined(Type_t::undefined);
"This global element type was deprecated. Please use Type_t::undefined instead.") constexpr Type dynamic(Type_t::dynamic);
extern NGRAPH_API const Type undefined; constexpr Type boolean(Type_t::boolean);
NGRAPH_DEPRECATED( constexpr Type bf16(Type_t::bf16);
"This global element type was deprecated. Please use Type_t::dynamic instead.") constexpr Type f16(Type_t::f16);
extern NGRAPH_API const Type dynamic; constexpr Type f32(Type_t::f32);
NGRAPH_DEPRECATED( constexpr Type f64(Type_t::f64);
"This global element type was deprecated. Please use Type_t::boolean instead.") constexpr Type i8(Type_t::i8);
extern NGRAPH_API const Type boolean; constexpr Type i16(Type_t::i16);
NGRAPH_DEPRECATED( constexpr Type i32(Type_t::i32);
"This global element type was deprecated. Please use Type_t::bf16 instead.") constexpr Type i64(Type_t::i64);
extern NGRAPH_API const Type bf16; constexpr Type u1(Type_t::u1);
NGRAPH_DEPRECATED( constexpr Type u8(Type_t::u8);
"This global element type was deprecated. Please use Type_t::f16 instead.") constexpr Type u16(Type_t::u16);
extern NGRAPH_API const Type f16; constexpr Type u32(Type_t::u32);
NGRAPH_DEPRECATED( constexpr Type u64(Type_t::u64);
"This global element type was deprecated. Please use Type_t::f32 instead.")
extern NGRAPH_API const Type f32;
NGRAPH_DEPRECATED(
"This global element type was deprecated. Please use Type_t::f64 instead.")
extern NGRAPH_API const Type f64;
NGRAPH_DEPRECATED("This global element type was deprecated. Please use Type_t::i8 instead.")
extern NGRAPH_API const Type i8;
NGRAPH_DEPRECATED(
"This global element type was deprecated. Please use Type_t::i16 instead.")
extern NGRAPH_API const Type i16;
NGRAPH_DEPRECATED(
"This global element type was deprecated. Please use Type_t::i32 instead.")
extern NGRAPH_API const Type i32;
NGRAPH_DEPRECATED(
"This global element type was deprecated. Please use Type_t::i64 instead.")
extern NGRAPH_API const Type i64;
NGRAPH_DEPRECATED("This global element type was deprecated. Please use Type_t::u1 instead.")
extern NGRAPH_API const Type u1;
NGRAPH_DEPRECATED("This global element type was deprecated. Please use Type_t::u8 instead.")
extern NGRAPH_API const Type u8;
NGRAPH_DEPRECATED(
"This global element type was deprecated. Please use Type_t::u16 instead.")
extern NGRAPH_API const Type u16;
NGRAPH_DEPRECATED(
"This global element type was deprecated. Please use Type_t::u32 instead.")
extern NGRAPH_API const Type u32;
NGRAPH_DEPRECATED(
"This global element type was deprecated. Please use Type_t::u64 instead.")
extern NGRAPH_API const Type u64;
template <typename T> template <typename T>
Type from() Type from()

View File

@ -26,25 +26,6 @@
using namespace ngraph; using namespace ngraph;
using namespace std; using namespace std;
NGRAPH_SUPPRESS_DEPRECATED_START
const element::Type element::undefined(element::Type_t::undefined);
const element::Type element::dynamic(element::Type_t::dynamic);
const element::Type element::boolean(element::Type_t::boolean);
const element::Type element::bf16(element::Type_t::bf16);
const element::Type element::f16(element::Type_t::f16);
const element::Type element::f32(element::Type_t::f32);
const element::Type element::f64(element::Type_t::f64);
const element::Type element::i8(element::Type_t::i8);
const element::Type element::i16(element::Type_t::i16);
const element::Type element::i32(element::Type_t::i32);
const element::Type element::i64(element::Type_t::i64);
const element::Type element::u1(element::Type_t::u1);
const element::Type element::u8(element::Type_t::u8);
const element::Type element::u16(element::Type_t::u16);
const element::Type element::u32(element::Type_t::u32);
const element::Type element::u64(element::Type_t::u64);
NGRAPH_SUPPRESS_DEPRECATED_END
constexpr DiscreteTypeInfo AttributeAdapter<element::Type>::type_info; constexpr DiscreteTypeInfo AttributeAdapter<element::Type>::type_info;
class TypeInfo class TypeInfo
@ -127,21 +108,6 @@ const std::string& element::Type::c_type_string() const
return get_type_info_map().at(m_type).m_cname; return get_type_info_map().at(m_type).m_cname;
} }
bool element::Type::operator==(const element::Type_t& other) const
{
return m_type == other;
}
bool element::Type::operator==(const element::Type& other) const
{
return m_type == other.m_type;
}
bool element::Type::operator<(const Type& other) const
{
return m_type < other.m_type;
}
size_t element::Type::size() const size_t element::Type::size() const
{ {
return std::ceil(static_cast<float>(bitwidth()) / 8.0f); return std::ceil(static_cast<float>(bitwidth()) / 8.0f);