Skip to content

Commit 133624a

Browse files
author
Jeff Niu
committed
[mlir][python] Fix build on windows
Reviewed By: stella.stamenova, ashay-github Differential Revision: https://reviews.llvm.org/D131906
1 parent c228410 commit 133624a

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

mlir/lib/Bindings/Python/IRAttributes.cpp

+14-24
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,9 @@ static T pyTryCast(py::handle object) {
113113
/// A python-wrapped dense array attribute with an element type and a derived
114114
/// implementation class.
115115
template <typename EltTy, typename DerivedT>
116-
class PyDenseArrayAttribute
117-
: public PyConcreteAttribute<PyDenseArrayAttribute<EltTy, DerivedT>> {
116+
class PyDenseArrayAttribute : public PyConcreteAttribute<DerivedT> {
118117
public:
119-
static constexpr typename PyConcreteAttribute<
120-
PyDenseArrayAttribute<EltTy, DerivedT>>::IsAFunctionTy isaFunction =
121-
DerivedT::isaFunction;
122-
static constexpr const char *pyClassName = DerivedT::pyClassName;
123-
using PyConcreteAttribute<
124-
PyDenseArrayAttribute<EltTy, DerivedT>>::PyConcreteAttribute;
118+
using PyConcreteAttribute<DerivedT>::PyConcreteAttribute;
125119

126120
/// Iterator over the integer elements of a dense array.
127121
class PyDenseArrayIterator {
@@ -158,33 +152,29 @@ class PyDenseArrayAttribute
158152
EltTy getItem(intptr_t i) { return DerivedT::getElement(*this, i); }
159153

160154
/// Bind the attribute class.
161-
static void bindDerived(typename PyConcreteAttribute<
162-
PyDenseArrayAttribute<EltTy, DerivedT>>::ClassTy &c) {
155+
static void bindDerived(typename PyConcreteAttribute<DerivedT>::ClassTy &c) {
163156
// Bind the constructor.
164157
c.def_static(
165158
"get",
166159
[](const std::vector<EltTy> &values, DefaultingPyMlirContext ctx) {
167160
MlirAttribute attr =
168161
DerivedT::getAttribute(ctx->get(), values.size(), values.data());
169-
return PyDenseArrayAttribute<EltTy, DerivedT>(ctx->getRef(), attr);
162+
return DerivedT(ctx->getRef(), attr);
170163
},
171164
py::arg("values"), py::arg("context") = py::none(),
172165
"Gets a uniqued dense array attribute");
173166
// Bind the array methods.
174-
c.def("__getitem__",
175-
[](PyDenseArrayAttribute<EltTy, DerivedT> &arr, intptr_t i) {
176-
if (i >= mlirDenseArrayGetNumElements(arr))
177-
throw py::index_error("DenseArray index out of range");
178-
return arr.getItem(i);
179-
});
180-
c.def("__len__", [](const PyDenseArrayAttribute<EltTy, DerivedT> &arr) {
181-
return mlirDenseArrayGetNumElements(arr);
167+
c.def("__getitem__", [](DerivedT &arr, intptr_t i) {
168+
if (i >= mlirDenseArrayGetNumElements(arr))
169+
throw py::index_error("DenseArray index out of range");
170+
return arr.getItem(i);
182171
});
183-
c.def("__iter__", [](const PyDenseArrayAttribute<EltTy, DerivedT> &arr) {
184-
return PyDenseArrayIterator(arr);
172+
c.def("__len__", [](const DerivedT &arr) {
173+
return mlirDenseArrayGetNumElements(arr);
185174
});
186-
c.def("__add__", [](PyDenseArrayAttribute<EltTy, DerivedT> &arr,
187-
py::list extras) {
175+
c.def("__iter__",
176+
[](const DerivedT &arr) { return PyDenseArrayIterator(arr); });
177+
c.def("__add__", [](DerivedT &arr, py::list extras) {
188178
std::vector<EltTy> values;
189179
intptr_t numOldElements = mlirDenseArrayGetNumElements(arr);
190180
values.reserve(numOldElements + py::len(extras));
@@ -194,7 +184,7 @@ class PyDenseArrayAttribute
194184
values.push_back(pyTryCast<EltTy>(attr));
195185
MlirAttribute attr = DerivedT::getAttribute(arr.getContext()->get(),
196186
values.size(), values.data());
197-
return PyDenseArrayAttribute<EltTy, DerivedT>(arr.getContext(), attr);
187+
return DerivedT(arr.getContext(), attr);
198188
});
199189
}
200190
};

0 commit comments

Comments
 (0)