diff --git a/mlir/lib/Bindings/Python/IRAttributes.cpp b/mlir/lib/Bindings/Python/IRAttributes.cpp --- a/mlir/lib/Bindings/Python/IRAttributes.cpp +++ b/mlir/lib/Bindings/Python/IRAttributes.cpp @@ -113,15 +113,9 @@ /// A python-wrapped dense array attribute with an element type and a derived /// implementation class. template -class PyDenseArrayAttribute - : public PyConcreteAttribute> { +class PyDenseArrayAttribute : public PyConcreteAttribute { public: - static constexpr typename PyConcreteAttribute< - PyDenseArrayAttribute>::IsAFunctionTy isaFunction = - DerivedT::isaFunction; - static constexpr const char *pyClassName = DerivedT::pyClassName; - using PyConcreteAttribute< - PyDenseArrayAttribute>::PyConcreteAttribute; + using PyConcreteAttribute::PyConcreteAttribute; /// Iterator over the integer elements of a dense array. class PyDenseArrayIterator { @@ -158,33 +152,29 @@ EltTy getItem(intptr_t i) { return DerivedT::getElement(*this, i); } /// Bind the attribute class. - static void bindDerived(typename PyConcreteAttribute< - PyDenseArrayAttribute>::ClassTy &c) { + static void bindDerived(typename PyConcreteAttribute::ClassTy &c) { // Bind the constructor. c.def_static( "get", [](const std::vector &values, DefaultingPyMlirContext ctx) { MlirAttribute attr = DerivedT::getAttribute(ctx->get(), values.size(), values.data()); - return PyDenseArrayAttribute(ctx->getRef(), attr); + return DerivedT(ctx->getRef(), attr); }, py::arg("values"), py::arg("context") = py::none(), "Gets a uniqued dense array attribute"); // Bind the array methods. - c.def("__getitem__", - [](PyDenseArrayAttribute &arr, intptr_t i) { - if (i >= mlirDenseArrayGetNumElements(arr)) - throw py::index_error("DenseArray index out of range"); - return arr.getItem(i); - }); - c.def("__len__", [](const PyDenseArrayAttribute &arr) { - return mlirDenseArrayGetNumElements(arr); + c.def("__getitem__", [](DerivedT &arr, intptr_t i) { + if (i >= mlirDenseArrayGetNumElements(arr)) + throw py::index_error("DenseArray index out of range"); + return arr.getItem(i); }); - c.def("__iter__", [](const PyDenseArrayAttribute &arr) { - return PyDenseArrayIterator(arr); + c.def("__len__", [](const DerivedT &arr) { + return mlirDenseArrayGetNumElements(arr); }); - c.def("__add__", [](PyDenseArrayAttribute &arr, - py::list extras) { + c.def("__iter__", + [](const DerivedT &arr) { return PyDenseArrayIterator(arr); }); + c.def("__add__", [](DerivedT &arr, py::list extras) { std::vector values; intptr_t numOldElements = mlirDenseArrayGetNumElements(arr); values.reserve(numOldElements + py::len(extras)); @@ -194,7 +184,7 @@ values.push_back(pyTryCast(attr)); MlirAttribute attr = DerivedT::getAttribute(arr.getContext()->get(), values.size(), values.data()); - return PyDenseArrayAttribute(arr.getContext(), attr); + return DerivedT(arr.getContext(), attr); }); } };