1. # file : src/relay/pass/pattern_util.h
    2. template <typename T>
    3. T GetScalarFromConstant(Expr expr) {
    4. const auto* n = expr.as<ConstantNode>();
    5. CHECK(n->is_scalar());
    6. return static_cast<T*>(n->data->data)[0];
    7. }
    8. /*!
    9. * \brief Construct an int type.
    10. * \param bits The number of bits in the type.
    11. * \param lanes The number of lanes.
    12. * \return The constructed data type.
    13. */
    14. static DataType Int(int bits, int lanes = 1) {
    15. return DataType(kDLInt, bits, lanes);
    16. }
    17. /*!
    18. * \brief Construct an uint type.
    19. * \param bits The number of bits in the type.
    20. * \param lanes The number of lanes
    21. * \return The constructed data type.
    22. */
    23. static DataType UInt(int bits, int lanes = 1) {
    24. return DataType(kDLUInt, bits, lanes);
    25. }
    26. /*!
    27. * \brief Construct an uint type.
    28. * \param bits The number of bits in the type.
    29. * \param lanes The number of lanes
    30. * \return The constructed data type.
    31. */
    32. static DataType Float(int bits, int lanes = 1) {
    33. return DataType(kDLFloat, bits, lanes);
    34. }
    35. /*!
    36. * \brief Construct a bool type.
    37. * \param lanes The number of lanes
    38. * \return The constructed data type.
    39. */
    40. static DataType Bool(int lanes = 1) {
    41. return DataType::UInt(1, lanes);
    42. }