This is especially convenient when trying to resize the splat.
Reviewed By: jpienaar
Differential Revision: https://reviews.llvm.org/D146510
[](PyDenseElementsAttribute &self) -> bool {
return mlirDenseElementsAttrIsSplat(self);
})
+ .def("get_splat_value",
+ [](PyDenseElementsAttribute &self) -> PyAttribute {
+ if (!mlirDenseElementsAttrIsSplat(self)) {
+ throw SetPyError(
+ PyExc_ValueError,
+ "get_splat_value called on a non-splat attribute");
+ }
+ return PyAttribute(self.getContext(),
+ mlirDenseElementsAttrGetSplatValue(self));
+ })
.def_buffer(&PyDenseElementsAttribute::accessBuffer);
}
print(attr)
# CHECK: is_splat: True
print("is_splat:", attr.is_splat)
+ assert attr.get_splat_value() == element
# CHECK-LABEL: TEST: testGetDenseElementsSplatFloat
attr = DenseElementsAttr.get_splat(shaped_type, element)
# CHECK: dense<1.200000e+00> : tensor<2x3x4xf32>
print(attr)
+ assert attr.get_splat_value() == element
# CHECK-LABEL: TEST: testGetDenseElementsSplatErrors