! * \brief Get the custom type name for a given type code. * \param str The string to parse. * \param scan The scan pointer. * \return The custom type name. */
| 39 | * \return The custom type name. |
| 40 | */ |
| 41 | inline int ParseCustomDataTypeCode(const std::string_view& str, const char** scan) { |
| 42 | TVM_FFI_ICHECK(str.substr(0, 6) == "custom") << "Not a valid custom datatype string"; |
| 43 | auto tmp = str.data(); |
| 44 | TVM_FFI_ICHECK(str.data() == tmp); |
| 45 | *scan = str.data() + 6; |
| 46 | TVM_FFI_ICHECK(str.data() == tmp); |
| 47 | if (**scan != '[') { |
| 48 | TVM_FFI_THROW(ValueError) << "expected opening brace after 'custom' type in" << str; |
| 49 | } |
| 50 | TVM_FFI_ICHECK(str.data() == tmp); |
| 51 | *scan += 1; |
| 52 | TVM_FFI_ICHECK(str.data() == tmp); |
| 53 | size_t custom_name_len = 0; |
| 54 | TVM_FFI_ICHECK(str.data() == tmp); |
| 55 | while (*scan + custom_name_len <= str.data() + str.length() && |
| 56 | *(*scan + custom_name_len) != ']') { |
| 57 | ++custom_name_len; |
| 58 | } |
| 59 | TVM_FFI_ICHECK(str.data() == tmp); |
| 60 | if (*(*scan + custom_name_len) != ']') { |
| 61 | TVM_FFI_THROW(ValueError) << "expected closing brace after 'custom' type in" << str; |
| 62 | } |
| 63 | TVM_FFI_ICHECK(str.data() == tmp); |
| 64 | *scan += custom_name_len + 1; |
| 65 | TVM_FFI_ICHECK(str.data() == tmp); |
| 66 | auto type_name = str.substr(7, custom_name_len); |
| 67 | TVM_FFI_ICHECK(str.data() == tmp); |
| 68 | static Function fget_custom_type_code = Function::GetGlobalRequired("dtype.get_custom_type_code"); |
| 69 | return fget_custom_type_code(std::string(type_name)).cast<int>(); |
| 70 | } |
| 71 | |
| 72 | /* |
| 73 | * \brief Convert a DLDataTypeCode to a string. |
no test coverage detected