Commit 563cd58
committed
[MLIR] Fix construction of
This change fixes the construction of MLIR attributes from `numpy` arrays for a Boolean `dtype`. This happened when calling `jax.mlir.ir_attribute` and the problem occurred in `_numpy_array_attribute`: that function *first* bit-packed the Booleans and *then* determined the `dtype` from the result, which is `uint8` at that point rather than `bool`. The fix thus consists of a simple swapping of lines. Note that the virtually equivalent `_numpy_array_constant` already used the right order.
The change extends and improves the tests for the FFI primitive, which uses `jax.mlir.ir_attribute` under the hood. The previous tests use a flawed comparison to verify the round-tripped type: it checked whether the *Python* type of the created MLIR attribute is the expected one. However, that is not enough: two `DenseElementAttr`s with different element types pass that check but really should not. That check would not have caught the bug fixed in this change (plus it didn't test the variant with `bool`s). The new version uses strings instead, which is not only more precise but also more concise in building the expected values. In addition to this improvement, the change adds instances of the corresponding FFI test for essentially all attribute types I could find.
PiperOrigin-RevId: 834770477i1 attributes from numpy arrays and add tests.1 parent ecd0b33 commit 563cd58
2 files changed
+56
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
| 367 | + | |
367 | 368 | | |
368 | 369 | | |
369 | 370 | | |
370 | 371 | | |
371 | | - | |
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
97 | 139 | | |
98 | 140 | | |
99 | 141 | | |
100 | 142 | | |
101 | 143 | | |
102 | 144 | | |
103 | 145 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
111 | 150 | | |
112 | 151 | | |
113 | 152 | | |
| |||
0 commit comments