#include <c10/util/ArrayRef.h>
#include <c10/util/Half.h>
+#include <c10/util/Optional.h>
#include <c10/util/typeid.h>
#include <cstdint>
#undef DEFINE_CASE
}
-static inline ScalarType typeMetaToScalarType(caffe2::TypeMeta dtype) {
+static inline c10::optional<ScalarType> tryTypeMetaToScalarType(caffe2::TypeMeta dtype) {
#define DEFINE_IF(ctype, name, _) \
if (dtype == caffe2::TypeMeta::Make<ctype>()) { \
- return ScalarType::name; \
+ return {ScalarType::name}; \
}
AT_FORALL_SCALAR_TYPES_WITH_COMPLEX(DEFINE_IF)
#undef DEFINE_IF
if (dtype == caffe2::TypeMeta()) {
- return ScalarType::Undefined;
+ return {ScalarType::Undefined};
+ }
+ return c10::nullopt;
+}
+
+static inline ScalarType typeMetaToScalarType(caffe2::TypeMeta dtype) {
+ if (auto scalar_type = tryTypeMetaToScalarType(dtype)) {
+ return *scalar_type;
}
AT_ERROR("Unsupported TypeMeta in ATen: ", dtype, " (please report this error)");
}
static inline bool operator==(ScalarType t, caffe2::TypeMeta m) {
- return typeMetaToScalarType(m) == t;
+ if (auto mt = tryTypeMetaToScalarType(m)) {
+ return (*mt) == t;
+ }
+ return false;
}
static inline bool operator==(caffe2::TypeMeta m, ScalarType t) {
- return typeMetaToScalarType(m) == t;
+ return t == m;
}
#define DEFINE_CONSTANT(_,name,_2) \