@@ -70,11 +70,11 @@ enum class Type_t {
70
70
// / \ingroup ov_element_cpp_api
71
71
class OPENVINO_API Type {
72
72
public:
73
- Type () = default ;
74
- Type (const Type&) = default ;
73
+ constexpr Type () = default;
74
+ constexpr Type (const Type&) = default;
75
75
constexpr Type (const Type_t t) : m_type{t} {}
76
76
explicit Type (const std::string& type);
77
- Type& operator =(const Type&) = default ;
77
+ constexpr Type& operator =(const Type&) = default ;
78
78
std::string c_type_string () const ;
79
79
size_t size () const ;
80
80
size_t hash () const ;
@@ -95,6 +95,8 @@ class OPENVINO_API Type {
95
95
// The name of this type, the enum name of this type
96
96
std::string get_type_name () const ;
97
97
friend OPENVINO_API std::ostream& operator <<(std::ostream&, const Type&);
98
+
99
+ OPENVINO_DEPRECATED (" This function is deprecated and will be removed in 2026.0." )
98
100
static std::vector<const Type*> get_known_types ();
99
101
100
102
// / \brief Checks whether this element type is merge-compatible with `t`.
@@ -137,129 +139,131 @@ using TypeVector = std::vector<Type>;
137
139
138
140
// / \brief undefined element type
139
141
// / \ingroup ov_element_cpp_api
140
- constexpr Type undefined (Type_t::undefined);
142
+ inline constexpr Type undefined (Type_t::undefined);
141
143
// / \brief dynamic element type
142
144
// / \ingroup ov_element_cpp_api
143
- constexpr Type dynamic (Type_t::dynamic);
145
+ inline constexpr Type dynamic (Type_t::dynamic);
144
146
// / \brief boolean element type
145
147
// / \ingroup ov_element_cpp_api
146
- constexpr Type boolean (Type_t::boolean);
148
+ inline constexpr Type boolean (Type_t::boolean);
147
149
// / \brief bf16 element type
148
150
// / \ingroup ov_element_cpp_api
149
- constexpr Type bf16 (Type_t::bf16 );
151
+ inline constexpr Type bf16 (Type_t::bf16 );
150
152
// / \brief f16 element type
151
153
// / \ingroup ov_element_cpp_api
152
- constexpr Type f16 (Type_t::f16 );
154
+ inline constexpr Type f16 (Type_t::f16 );
153
155
// / \brief f32 element type
154
156
// / \ingroup ov_element_cpp_api
155
- constexpr Type f32 (Type_t::f32 );
157
+ inline constexpr Type f32 (Type_t::f32 );
156
158
// / \brief f64 element type
157
159
// / \ingroup ov_element_cpp_api
158
- constexpr Type f64 (Type_t::f64 );
160
+ inline constexpr Type f64 (Type_t::f64 );
159
161
// / \brief i4 element type
160
162
// / \ingroup ov_element_cpp_api
161
- constexpr Type i4 (Type_t::i4);
163
+ inline constexpr Type i4 (Type_t::i4);
162
164
// / \brief i8 element type
163
165
// / \ingroup ov_element_cpp_api
164
- constexpr Type i8 (Type_t::i8 );
166
+ inline constexpr Type i8 (Type_t::i8 );
165
167
// / \brief i16 element type
166
168
// / \ingroup ov_element_cpp_api
167
- constexpr Type i16 (Type_t::i16 );
169
+ inline constexpr Type i16 (Type_t::i16 );
168
170
// / \brief i32 element type
169
171
// / \ingroup ov_element_cpp_api
170
- constexpr Type i32 (Type_t::i32 );
172
+ inline constexpr Type i32 (Type_t::i32 );
171
173
// / \brief i64 element type
172
174
// / \ingroup ov_element_cpp_api
173
- constexpr Type i64 (Type_t::i64 );
175
+ inline constexpr Type i64 (Type_t::i64 );
174
176
// / \brief binary element type
175
177
// / \ingroup ov_element_cpp_api
176
- constexpr Type u1 (Type_t::u1);
178
+ inline constexpr Type u1 (Type_t::u1);
177
179
// / \brief u2 element type
178
180
// / \ingroup ov_element_cpp_api
179
- constexpr Type u2 (Type_t::u2);
181
+ inline constexpr Type u2 (Type_t::u2);
180
182
// / \brief u3 element type
181
183
// / \ingroup ov_element_cpp_api
182
- constexpr Type u3 (Type_t::u3);
184
+ inline constexpr Type u3 (Type_t::u3);
183
185
// / \brief u4 element type
184
186
// / \ingroup ov_element_cpp_api
185
- constexpr Type u4 (Type_t::u4);
187
+ inline constexpr Type u4 (Type_t::u4);
186
188
// / \brief u6 element type
187
189
// / \ingroup ov_element_cpp_api
188
- constexpr Type u6 (Type_t::u6);
190
+ inline constexpr Type u6 (Type_t::u6);
189
191
// / \brief u8 element type
190
192
// / \ingroup ov_element_cpp_api
191
- constexpr Type u8 (Type_t::u8 );
193
+ inline constexpr Type u8 (Type_t::u8 );
192
194
// / \brief u16 element type
193
195
// / \ingroup ov_element_cpp_api
194
- constexpr Type u16 (Type_t::u16 );
196
+ inline constexpr Type u16 (Type_t::u16 );
195
197
// / \brief u32 element type
196
198
// / \ingroup ov_element_cpp_api
197
- constexpr Type u32 (Type_t::u32 );
199
+ inline constexpr Type u32 (Type_t::u32 );
198
200
// / \brief u64 element type
199
201
// / \ingroup ov_element_cpp_api
200
- constexpr Type u64 (Type_t::u64 );
202
+ inline constexpr Type u64 (Type_t::u64 );
201
203
// / \brief nf4 element type
202
204
// / \ingroup ov_element_cpp_api
203
- constexpr Type nf4 (Type_t::nf4);
205
+ inline constexpr Type nf4 (Type_t::nf4);
204
206
// / \brief f8e4m3 element type
205
207
// / \ingroup ov_element_cpp_api
206
- constexpr Type f8e4m3 (Type_t::f8e4m3);
208
+ inline constexpr Type f8e4m3 (Type_t::f8e4m3);
207
209
// / \brief f8e4m3 element type
208
210
// / \ingroup ov_element_cpp_api
209
- constexpr Type f8e5m2 (Type_t::f8e5m2);
211
+ inline constexpr Type f8e5m2 (Type_t::f8e5m2);
210
212
// / \brief string element type
211
213
// / \ingroup ov_element_cpp_api
212
- constexpr Type string (Type_t::string);
214
+ inline constexpr Type string (Type_t::string);
213
215
// / \brief f4e2m1 element type
214
216
// / \ingroup ov_element_cpp_api
215
- constexpr Type f4e2m1 (Type_t::f4e2m1);
217
+ inline constexpr Type f4e2m1 (Type_t::f4e2m1);
216
218
// / \brief f8e8m0 element type
217
219
// / \ingroup ov_element_cpp_api
218
- constexpr Type f8e8m0 (Type_t::f8e8m0);
220
+ inline constexpr Type f8e8m0 (Type_t::f8e8m0);
219
221
220
- template <typename T>
221
- Type from () {
222
- OPENVINO_THROW (" Unknown type" );
222
+ template <class T >
223
+ constexpr Type from () {
224
+ if constexpr (std::is_same_v<T, char > || std::is_same_v<T, bool >) {
225
+ return boolean;
226
+ } else if constexpr (std::is_same_v<T, ov::float16>) {
227
+ return f16 ;
228
+ } else if constexpr (std::is_same_v<T, float >) {
229
+ return f32 ;
230
+ } else if constexpr (std::is_same_v<T, double >) {
231
+ return f64 ;
232
+ } else if constexpr (std::is_same_v<T, int8_t >) {
233
+ return i8 ;
234
+ } else if constexpr (std::is_same_v<T, int16_t >) {
235
+ return i16 ;
236
+ } else if constexpr (std::is_same_v<T, int32_t >) {
237
+ return i32 ;
238
+ } else if constexpr (std::is_same_v<T, int64_t >) {
239
+ return i64 ;
240
+ } else if constexpr (std::is_same_v<T, uint8_t >) {
241
+ return u8 ;
242
+ } else if constexpr (std::is_same_v<T, uint16_t >) {
243
+ return u16 ;
244
+ } else if constexpr (std::is_same_v<T, uint32_t >) {
245
+ return u32 ;
246
+ } else if constexpr (std::is_same_v<T, uint64_t >) {
247
+ return u64 ;
248
+ } else if constexpr (std::is_same_v<T, ov::bfloat16>) {
249
+ return bf16 ;
250
+ } else if constexpr (std::is_same_v<T, ov::float8_e4m3>) {
251
+ return f8e4m3;
252
+ } else if constexpr (std::is_same_v<T, ov::float8_e5m2>) {
253
+ return f8e5m2;
254
+ } else if constexpr (std::is_same_v<T, std::string>) {
255
+ return string;
256
+ } else if constexpr (std::is_same_v<T, ov::float4_e2m1>) {
257
+ return f4e2m1;
258
+ } else if constexpr (std::is_same_v<T, ov::float8_e8m0>) {
259
+ return f8e8m0;
260
+ } else {
261
+ OPENVINO_THROW (" Unknown type" );
262
+ }
223
263
}
224
- template <>
225
- OPENVINO_API Type from<char >();
226
- template <>
227
- OPENVINO_API Type from<bool >();
228
- template <>
229
- OPENVINO_API Type from<float >();
230
- template <>
231
- OPENVINO_API Type from<double >();
232
- template <>
233
- OPENVINO_API Type from<int8_t >();
234
- template <>
235
- OPENVINO_API Type from<int16_t >();
236
- template <>
237
- OPENVINO_API Type from<int32_t >();
238
- template <>
239
- OPENVINO_API Type from<int64_t >();
240
- template <>
241
- OPENVINO_API Type from<uint8_t >();
242
- template <>
243
- OPENVINO_API Type from<uint16_t >();
244
- template <>
245
- OPENVINO_API Type from<uint32_t >();
246
- template <>
247
- OPENVINO_API Type from<uint64_t >();
248
- template <>
249
- OPENVINO_API Type from<ov::bfloat16>();
250
- template <>
251
- OPENVINO_API Type from<ov::float16>();
252
- template <>
253
- OPENVINO_API Type from<ov::float8_e4m3>();
254
- template <>
255
- OPENVINO_API Type from<ov::float8_e5m2>();
256
- template <>
257
- OPENVINO_API Type from<std::string>();
258
- template <>
259
- OPENVINO_API Type from<ov::float4_e2m1>();
260
- template <>
261
- OPENVINO_API Type from<ov::float8_e8m0>();
262
264
265
+ OPENVINO_DEPRECATED (
266
+ " This function is deprecated and will be removed in 2026.0. Use ov::fundamental_type_for<Type> instead" )
263
267
OPENVINO_API Type fundamental_type_for (const Type& type);
264
268
265
269
OPENVINO_API
@@ -281,12 +285,12 @@ template <>
281
285
class OPENVINO_API AttributeAdapter<ov::element::Type> : public ValueAccessor<std::string> {
282
286
public:
283
287
OPENVINO_RTTI (" AttributeAdapter<ov::element::Type>" );
284
- AttributeAdapter (ov::element::Type& value) : m_ref(value) {}
288
+ constexpr AttributeAdapter (ov::element::Type& value) : m_ref(value) {}
285
289
286
290
const std::string& get () override ;
287
291
void set (const std::string& value) override ;
288
292
289
- operator ov::element::Type&() {
293
+ constexpr operator ov::element::Type&() {
290
294
return m_ref;
291
295
}
292
296
0 commit comments