tqchen commented on code in PR #668:
URL: https://github.com/apache/tvm-ffi/pull/668#discussion_r3590907019


##########
include/tvm/ffi/dtype.h:
##########
@@ -138,6 +138,158 @@ inline String DLDataTypeToString(DLDataType dtype) {
   return TypeTraits<String>::MoveFromAnyAfterCheck(&out);
 }
 
+/*!
+ * \brief Check whether a DLDataType is a floating-point type.
+ * \param dtype The DLDataType to check.
+ * \return True if dtype is a floating-point type, false otherwise.
+ */
+inline bool DTypeIsFloat(DLDataType dtype) {
+  switch (static_cast<int>(dtype.code)) {
+    case kDLFloat:
+    case kDLBfloat:
+    case kDLFloat8_e3m4:
+    case kDLFloat8_e4m3:
+    case kDLFloat8_e4m3b11fnuz:
+    case kDLFloat8_e4m3fn:
+    case kDLFloat8_e4m3fnuz:
+    case kDLFloat8_e5m2:
+    case kDLFloat8_e5m2fnuz:
+    case kDLFloat8_e8m0fnu:
+    case kDLFloat6_e2m3fn:
+    case kDLFloat6_e3m2fn:
+    case kDLFloat4_e2m1fn:
+      return true;
+    default:
+      return false;
+  }
+}
+
+/*!
+ * \brief Check whether a DLDataType is an integer type.
+ * \param dtype The DLDataType to check.
+ * \return True if dtype is a signed or unsigned integer type, false otherwise.
+ */
+inline bool DTypeIsInt(DLDataType dtype) {
+  switch (static_cast<int>(dtype.code)) {
+    case kDLInt:
+    case kDLUInt:
+      return true;
+    default:
+      return false;
+  }
+}
+
+/*!
+ * \brief Check whether a DLDataType is a boolean type.
+ * \param dtype The DLDataType to check.
+ * \return True if dtype is a boolean type, false otherwise.
+ */
+inline bool DTypeIsBool(DLDataType dtype) { return dtype.code == kDLBool; }

Review Comment:
   TVM_FFI_INLINE



##########
include/tvm/ffi/dtype.h:
##########
@@ -138,6 +138,158 @@ inline String DLDataTypeToString(DLDataType dtype) {
   return TypeTraits<String>::MoveFromAnyAfterCheck(&out);
 }
 
+/*!
+ * \brief Check whether a DLDataType is a floating-point type.
+ * \param dtype The DLDataType to check.
+ * \return True if dtype is a floating-point type, false otherwise.
+ */
+inline bool DTypeIsFloat(DLDataType dtype) {
+  switch (static_cast<int>(dtype.code)) {
+    case kDLFloat:
+    case kDLBfloat:
+    case kDLFloat8_e3m4:
+    case kDLFloat8_e4m3:
+    case kDLFloat8_e4m3b11fnuz:
+    case kDLFloat8_e4m3fn:
+    case kDLFloat8_e4m3fnuz:
+    case kDLFloat8_e5m2:
+    case kDLFloat8_e5m2fnuz:
+    case kDLFloat8_e8m0fnu:
+    case kDLFloat6_e2m3fn:
+    case kDLFloat6_e3m2fn:
+    case kDLFloat4_e2m1fn:
+      return true;
+    default:
+      return false;
+  }
+}
+
+/*!
+ * \brief Check whether a DLDataType is an integer type.
+ * \param dtype The DLDataType to check.
+ * \return True if dtype is a signed or unsigned integer type, false otherwise.
+ */
+inline bool DTypeIsInt(DLDataType dtype) {
+  switch (static_cast<int>(dtype.code)) {

Review Comment:
   this should not be a switch case, keep things inlined via TVM_FFI_INLINE 
likely helps downstream simplification



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to