24 nb::enum_<MlirSparseTensorLevelFormat>(m,
"LevelFormat", nb::is_arithmetic(),
32 nb::enum_<MlirSparseTensorLevelPropertyNondefault>(m,
"LevelProperty")
41 [](nb::object cls, std::vector<MlirSparseTensorLevelType> lvlTypes,
42 std::optional<MlirAffineMap> dimToLvl,
43 std::optional<MlirAffineMap> lvlToDim,
int posWidth,
int crdWidth,
44 std::optional<MlirAttribute> explicitVal,
45 std::optional<MlirAttribute> implicitVal, MlirContext context) {
47 context, lvlTypes.size(), lvlTypes.data(),
48 dimToLvl ? *dimToLvl : MlirAffineMap{nullptr},
49 lvlToDim ? *lvlToDim : MlirAffineMap{nullptr}, posWidth,
50 crdWidth, explicitVal ? *explicitVal : MlirAttribute{nullptr},
51 implicitVal ? *implicitVal : MlirAttribute{nullptr}));
53 nb::arg(
"cls"), nb::arg(
"lvl_types"), nb::arg(
"dim_to_lvl").none(),
54 nb::arg(
"lvl_to_dim").none(), nb::arg(
"pos_width"),
55 nb::arg(
"crd_width"), nb::arg(
"explicit_val").none() = nb::none(),
56 nb::arg(
"implicit_val").none() = nb::none(),
57 nb::arg(
"context").none() = nb::none(),
58 "Gets a sparse_tensor.encoding from parameters.")
62 const std::vector<MlirSparseTensorLevelPropertyNondefault>
64 unsigned n,
unsigned m) {
66 lvlFmt, properties.data(), properties.size(), n, m);
68 nb::arg(
"cls"), nb::arg(
"lvl_fmt"),
69 nb::arg(
"properties") =
70 std::vector<MlirSparseTensorLevelPropertyNondefault>(),
71 nb::arg(
"n") = 0, nb::arg(
"m") = 0,
72 "Builds a sparse_tensor.encoding.level_type from parameters.")
73 .def_property_readonly(
75 [](MlirAttribute
self) {
77 std::vector<MlirSparseTensorLevelType> ret;
79 for (
int l = 0; l < lvlRank; ++l)
83 .def_property_readonly(
85 [](MlirAttribute
self) -> std::optional<MlirAffineMap> {
91 .def_property_readonly(
93 [](MlirAttribute
self) -> std::optional<MlirAffineMap> {
99 .def_property_readonly(
"pos_width",
105 [](MlirAttribute
self) -> std::optional<MlirAttribute> {
112 .def_property_readonly(
114 [](MlirAttribute
self) -> std::optional<MlirAttribute> {
121 .def_property_readonly(
123 [](MlirAttribute
self) ->
unsigned {
128 .def_property_readonly(
130 [](MlirAttribute
self) ->
unsigned {
135 .def_property_readonly(
"lvl_formats_enum", [](MlirAttribute
self) {
137 std::vector<MlirSparseTensorLevelFormat> ret;
138 ret.reserve(lvlRank);
139 for (
int l = 0; l < lvlRank; l++)
146 m.doc() =
"MLIR SparseTensor dialect.";
NB_MODULE(_mlirDialectsSparseTensor, m)
static void populateDialectSparseTensorSubmodule(const nb::module_ &m)
Creates a custom subclass of mlir.ir.Attribute, implementing a casting constructor and type checking ...
pure_subclass & def_classmethod(const char *name, Func &&f, const Extra &...extra)
pure_subclass & def_property_readonly(const char *name, Func &&f, const Extra &...extra)
static bool mlirAffineMapIsNull(MlirAffineMap affineMap)
Checks whether an affine map is null.
MLIR_CAPI_EXPORTED MlirAffineMap mlirSparseTensorEncodingAttrGetDimToLvl(MlirAttribute attr)
Returns the dimension-to-level mapping of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGetImplicitVal(MlirAttribute attr)
Returns the implicit value of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED intptr_t mlirSparseTensorEncodingGetLvlRank(MlirAttribute attr)
Returns the level-rank of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGet(MlirContext ctx, intptr_t lvlRank, MlirSparseTensorLevelType const *lvlTypes, MlirAffineMap dimToLvl, MlirAffineMap lvlTodim, int posWidth, int crdWidth, MlirAttribute explicitVal, MlirAttribute implicitVal)
Creates a sparse_tensor.encoding attribute with the given parameters.
MLIR_CAPI_EXPORTED enum MlirSparseTensorLevelFormat mlirSparseTensorEncodingAttrGetLvlFmt(MlirAttribute attr, intptr_t lvl)
Returns a specified level-format of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED int mlirSparseTensorEncodingAttrGetCrdWidth(MlirAttribute attr)
Returns the coordinate bitwidth of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED MlirAffineMap mlirSparseTensorEncodingAttrGetLvlToDim(MlirAttribute attr)
Returns the level-to-dimension mapping of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirSparseTensorEncodingAttrGetExplicitVal(MlirAttribute attr)
Returns the explicit value of the sparse_tensor.encoding attribute.
MlirSparseTensorLevelFormat
@ MLIR_SPARSE_TENSOR_LEVEL_N_OUT_OF_M
@ MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED
@ MLIR_SPARSE_TENSOR_LEVEL_DENSE
@ MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED
@ MLIR_SPARSE_TENSOR_LEVEL_SINGLETON
MLIR_CAPI_EXPORTED unsigned mlirSparseTensorEncodingAttrGetStructuredN(MlirSparseTensorLevelType lvlType)
MLIR_CAPI_EXPORTED MlirSparseTensorLevelType mlirSparseTensorEncodingAttrBuildLvlType(enum MlirSparseTensorLevelFormat lvlFmt, const enum MlirSparseTensorLevelPropertyNondefault *properties, unsigned propSize, unsigned n, unsigned m)
MLIR_CAPI_EXPORTED unsigned mlirSparseTensorEncodingAttrGetStructuredM(MlirSparseTensorLevelType lvlType)
MLIR_CAPI_EXPORTED bool mlirAttributeIsASparseTensorEncodingAttr(MlirAttribute attr)
Checks whether the given attribute is a sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED MlirSparseTensorLevelType mlirSparseTensorEncodingAttrGetLvlType(MlirAttribute attr, intptr_t lvl)
Returns a specified level-type of the sparse_tensor.encoding attribute.
MLIR_CAPI_EXPORTED int mlirSparseTensorEncodingAttrGetPosWidth(MlirAttribute attr)
Returns the position bitwidth of the sparse_tensor.encoding attribute.
@ MLIR_SPARSE_PROPERTY_NON_UNIQUE
@ MLIR_SPARSE_PROPERTY_NON_ORDERED
@ MLIR_SPARSE_PROPERTY_SOA
static bool mlirAttributeIsNull(MlirAttribute attr)
Checks whether an attribute is null.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.