[all-commits] [llvm/llvm-project] 8dcb67: [mlir][python] Make DenseBoolArrayAttr.get work wi...

Ingo Müller via All-commits all-commits at lists.llvm.org
Mon Aug 28 08:15:24 PDT 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 8dcb67225b2ce871b54f7a0f172b58f15f05f7fa
  Author: Ingo Müller <ingomueller at google.com>
  Date:   2023-08-28 (Mon, 28 Aug 2023)

  Changed paths:
    M mlir/lib/Bindings/Python/IRAttributes.cpp
    M mlir/test/python/ir/attributes.py

  Log Message:
  [mlir][python] Make DenseBoolArrayAttr.get work with list of bools.

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`.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D158973

More information about the All-commits mailing list