[Mlir-commits] [mlir] [MLIR, Python] Support converting boolean numpy arrays to and from mlir attributes (PR #113064)
Jacques Pienaar
llvmlistbot at llvm.org
Wed Oct 30 10:51:05 PDT 2024
================
@@ -326,6 +326,78 @@ def testGetDenseElementsF64():
print(np.array(attr))
+### 1 bit/boolean integer arrays
+# CHECK-LABEL: TEST: testGetDenseElementsI1Signless
+ at run
+def testGetDenseElementsI1Signless():
+ with Context():
+ array = np.array([True], dtype=np.bool_)
+ attr = DenseElementsAttr.get(array)
+ # CHECK: dense<true> : tensor<1xi1>
+ print(attr)
+ # CHECK: {{\[}} True]
+ print(np.array(attr))
+
+ array = np.array([[True, False, True], [True, True, False]], dtype=np.bool_)
+ attr = DenseElementsAttr.get(array)
+ # CHECK: dense<{{\[}}[true, false, true], [true, true, false]]> : tensor<2x3xi1>
+ print(attr)
+ # CHECK: {{\[}}[ True False True]
+ # CHECK: {{\[}} True True False]]
+ print(np.array(attr))
+
+ array = np.array(
+ [[True, True, False, False], [True, False, True, False]], dtype=np.bool_
+ )
+ attr = DenseElementsAttr.get(array)
+ # CHECK: dense<{{\[}}[true, true, false, false], [true, false, true, false]]> : tensor<2x4xi1>
+ print(attr)
+ # CHECK: {{\[}}[ True True False False]
+ # CHECK: {{\[}} True False True False]]
+ print(np.array(attr))
+
+ array = np.array(
+ [
+ [True, True, False, False],
+ [True, False, True, False],
+ [False, False, False, False],
+ [True, True, True, True],
+ [True, False, False, True],
+ ],
+ dtype=np.bool_,
+ )
+ attr = DenseElementsAttr.get(array)
+ # CHECK: dense<{{\[}}[true, true, false, false], [true, false, true, false], [false, false, false, false], [true, true, true, true], [true, false, false, true]]> : tensor<5x4xi1>
+ print(attr)
+ # CHECK: {{\[}}[ True True False False]
----------------
jpienaar wrote:
You could also use the LITERAL modifier to avoid the escaping regex.
https://github.com/llvm/llvm-project/pull/113064
More information about the Mlir-commits
mailing list