55 [](std::vector<MlirSparseTensorLevelType> lvlTypes,
56 std::optional<PyAffineMap> dimToLvl,
57 std::optional<PyAffineMap> lvlToDim,
int posWidth,
int crdWidth,
58 std::optional<PyAttribute> explicitVal,
59 std::optional<PyAttribute> implicitVal,
64 context.
get()->get(), lvlTypes.size(), lvlTypes.data(),
65 dimToLvl ? *dimToLvl : MlirAffineMap{nullptr},
66 lvlToDim ? *lvlToDim : MlirAffineMap{nullptr}, posWidth,
67 crdWidth, explicitVal ? *explicitVal : MlirAttribute{nullptr},
68 implicitVal ? *implicitVal : MlirAttribute{nullptr}));
70 nb::arg(
"lvl_types"), nb::arg(
"dim_to_lvl").none(),
71 nb::arg(
"lvl_to_dim").none(), nb::arg(
"pos_width"),
72 nb::arg(
"crd_width"), nb::arg(
"explicit_val") = nb::none(),
73 nb::arg(
"implicit_val") = nb::none(), nb::arg(
"context") = nb::none(),
74 "Gets a sparse_tensor.encoding from parameters.");
79 const std::vector<PySparseTensorLevelPropertyNondefault> &properties,
80 unsigned n,
unsigned m) {
81 std::vector<MlirSparseTensorLevelPropertyNondefault> props;
82 props.reserve(properties.size());
83 for (
auto prop : properties) {
92 nb::arg(
"properties") =
93 std::vector<PySparseTensorLevelPropertyNondefault>(),
94 nb::arg(
"n") = 0, nb::arg(
"m") = 0,
95 "Builds a sparse_tensor.encoding.level_type from parameters.");
97 c.def_prop_ro(
"lvl_types", [](
const EncodingAttr &self) {
99 std::vector<MlirSparseTensorLevelType> ret;
100 ret.reserve(lvlRank);
101 for (
int l = 0; l < lvlRank; ++l)
107 "dim_to_lvl", [](
EncodingAttr &self) -> std::optional<PyAffineMap> {
115 "lvl_to_dim", [](
EncodingAttr &self) -> std::optional<PyAffineMap> {
125 c.def_prop_ro(
"explicit_val",
127 -> std::optional<nb::typed<nb::object, PyAttribute>> {
130 if (mlirAttributeIsNull(ret))
135 c.def_prop_ro(
"implicit_val",
137 -> std::optional<nb::typed<nb::object, PyAttribute>> {
140 if (mlirAttributeIsNull(ret))
145 c.def_prop_ro(
"structured_n", [](
const EncodingAttr &self) ->
unsigned {
151 c.def_prop_ro(
"structured_m", [](
const EncodingAttr &self) ->
unsigned {
157 c.def_prop_ro(
"lvl_formats_enum", [](
const EncodingAttr &self) {
159 std::vector<PySparseTensorLevelFormat> ret;
160 ret.reserve(lvlRank);
162 for (
int l = 0; l < lvlRank; l++)
171 nb::enum_<PySparseTensorLevelFormat>(m,
"LevelFormat", nb::is_arithmetic(),
178 nb::enum_<PySparseTensorLevelPropertyNondefault>(m,
"LevelProperty")
191 m.doc() =
"MLIR SparseTensor dialect.";
NB_MODULE(_mlirDialectsSparseTensor, m)
ReferrentTy * get() const
PyMlirContextRef & getContext()
Accesses the context reference.
Used in function arguments when None should resolve to the current context manager set instance.
PyAttribute(PyMlirContextRef contextRef, MlirAttribute attr)
static void bind(nanobind::module_ &m, PyType_Slot *slots=nullptr)
nanobind::class_< EncodingAttr, PyAttribute > ClassTy
PyConcreteAttribute()=default
bool(*)(MlirAttribute) IsAFunctionTy
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 MlirStringRef mlirSparseTensorEncodingAttrGetName(void)
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.
MlirSparseTensorLevelPropertyNondefault
@ MLIR_SPARSE_PROPERTY_NON_UNIQUE
@ MLIR_SPARSE_PROPERTY_NON_ORDERED
@ MLIR_SPARSE_PROPERTY_SOA
The OpAsmOpInterface, see OpAsmInterface.td for more details.
static void populateDialectSparseTensorSubmodule(nb::module_ &m)
PySparseTensorLevelPropertyNondefault
PySparseTensorLevelFormat
Include the generated interface declarations.
A pointer to a sized fragment of a string, not necessarily null-terminated.
static constexpr const char * pyClassName
static constexpr IsAFunctionTy isaFunction
static void bindDerived(ClassTy &c)
static const MlirStringRef name