# file : src/relay/pass/pattern_util.h
template <typename T>
T GetScalarFromConstant(Expr expr) {
const auto* n = expr.as<ConstantNode>();
CHECK(n->is_scalar());
return static_cast<T*>(n->data->data)[0];
}
/*!
* \brief Construct an int type.
* \param bits The number of bits in the type.
* \param lanes The number of lanes.
* \return The constructed data type.
*/
static DataType Int(int bits, int lanes = 1) {
return DataType(kDLInt, bits, lanes);
}
/*!
* \brief Construct an uint type.
* \param bits The number of bits in the type.
* \param lanes The number of lanes
* \return The constructed data type.
*/
static DataType UInt(int bits, int lanes = 1) {
return DataType(kDLUInt, bits, lanes);
}
/*!
* \brief Construct an uint type.
* \param bits The number of bits in the type.
* \param lanes The number of lanes
* \return The constructed data type.
*/
static DataType Float(int bits, int lanes = 1) {
return DataType(kDLFloat, bits, lanes);
}
/*!
* \brief Construct a bool type.
* \param lanes The number of lanes
* \return The constructed data type.
*/
static DataType Bool(int lanes = 1) {
return DataType::UInt(1, lanes);
}