This is an archive of the discontinued LLVM Phabricator instance.

[mlir][python] Make DenseBoolArrayAttr.get work with list of bools.
ClosedPublic

Authored by ingomueller-net on Aug 28 2023, 2:46 AM.

Details

Summary

This patch makes the getter function of DenseBoolArrayAttr work more
intuitively. Until now, it was implemented with a std::vector<int>
argument, which works in the typical situation where you call the pybind
function with a list of Python bools (like [True, False]). However, it
does *not* work if the elements of the list have to be cast to Bool
before (and that is the default behavior for lists of all other types).
The patch thus changes the signature to std::vector<bool>, which helps
pybind to make the function behave as expected for bools. The tests now
also contain a case where such a cast is happening. This also makes the
conversion of DenseBoolArrayAttr back to Python more intuitive:
instead of converting to 0 and 1, the elements are now converted to
False and True.

Diff Detail