23#include "llvm/ADT/ScopeExit.h"
24#include "llvm/Support/raw_ostream.h"
27using namespace nanobind::literals;
38 R
"(Gets a DenseElementsAttr from a Python buffer or array.
40When `type` is not provided, then some limited type inferencing is done based
41on the buffer format. Support presently exists for 8/16/32/64 signed and
42unsigned integers and float16/float32/float64. DenseElementsAttrs of these
43types can also be converted back to a corresponding buffer.
45For conversions outside of these types, a `type=` must be explicitly provided
46and the buffer contents must be bit-castable to the MLIR internal
49 * Integer types (except for i1): the buffer must be byte aligned to the
51 * Floating point types: Must be bit-castable to the given floating point
53 * i1 (bool): Bit packed into 8bit words where the bit pattern matches a
54 row major ordering. An arbitrary Numpy `bool_` array can be bit packed to
55 this specification with: `np.packbits(ary, axis=None, bitorder='little')`.
57If a single element buffer is passed (or for i1, a single byte with value 0
58or 255), then a splat will be created.
61 array: The array or buffer to convert.
62 signless: If inferring an appropriate MLIR type, use signless types for
63 integers (defaults True).
64 type: Skips inference of the MLIR element type and uses this instead. The
65 storage size must be consistent with the actual contents of the buffer.
66 shape: Overrides the shape of the buffer when constructing the MLIR
67 shaped type. This is needed when the physical and logical shape differ (as
69 context: Explicit context, if not from context manager.
72 DenseElementsAttr on success.
75 ValueError: If the type of the buffer or array cannot be matched to an MLIR
76 type or if the buffer does not meet expectations.
80 R
"(Gets a DenseElementsAttr from a Python list of attributes.
82Note that it can be expensive to construct attributes individually.
83For a large number of elements, consider using a Python buffer or array instead.
86 attrs: A list of attributes.
87 type: The desired shape and type of the resulting DenseElementsAttr.
88 If not provided, the element type is determined based on the type
89 of the 0th attribute and the shape is `[len(attrs)]`.
90 context: Explicit context, if not from context manager.
93 DenseElementsAttr on success.
96 ValueError: If the type of the attributes does not match the type
97 specified by `shaped_type`.
101 R
"(Gets a DenseResourceElementsAttr from a Python buffer or array.
103This function does minimal validation or massaging of the data, and it is
104up to the caller to ensure that the buffer meets the characteristics
107The backing buffer and any user objects will be retained for the lifetime
108of the resource blob. This is typically bounded to the context but the
109resource can have a shorter lifespan depending on how it is used in
110subsequent processing.
113 buffer: The array or buffer to convert.
114 name: Name to provide to the resource (may be changed upon collision).
115 type: The explicit ShapedType to construct the attribute with.
116 context: Explicit context, if not from context manager.
119 DenseResourceElementsAttr on success.
122 ValueError: If the type of the buffer or array cannot be matched to an MLIR
123 type or if the buffer does not meet expectations.
134 std::unique_ptr<Py_buffer,
void (*)(Py_buffer *)> owned_view_in)
136 shape(std::move(shape_in)),
strides(std::move(strides_in)),
139 for (ssize_t i = 0; i <
ndim; ++i) {
145 int flags = PyBUF_STRIDES | PyBUF_FORMAT;
146 auto *view =
new Py_buffer();
147 if (PyObject_GetBuffer(
ptr(), view, flags) != 0) {
149 throw nb::python_error();
156 static const char *
format() {
return "?"; }
160 static const char *
format() {
return "b"; }
164 static const char *
format() {
return "B"; }
168 static const char *
format() {
return "h"; }
172 static const char *
format() {
return "H"; }
176 static const char *
format() {
return "i"; }
180 static const char *
format() {
return "I"; }
184 static const char *
format() {
return "q"; }
188 static const char *
format() {
return "Q"; }
192 static const char *
format() {
return "f"; }
196 static const char *
format() {
return "d"; }
206 nb::arg(
"affine_map"),
"Gets an attribute wrapping an AffineMap.");
212 "Returns the value of the AffineMap attribute");
222 nb::arg(
"integer_set"),
"Gets an attribute wrapping an IntegerSet.");
225nb::typed<nb::object, PyAttribute>
228 if (PyArrayAttribute::PyArrayAttributeIterator::nextIndex >=
230 PyArrayAttribute::PyArrayAttributeIterator::attr.
get())) {
231 PyErr_SetNone(PyExc_StopIteration);
236 this->PyArrayAttribute::PyArrayAttributeIterator::attr
239 PyArrayAttribute::PyArrayAttributeIterator::attr.
get(),
240 PyArrayAttribute::PyArrayAttributeIterator::nextIndex++))
245 nb::class_<PyArrayAttributeIterator>(m,
"ArrayAttributeIterator")
259 mlirAttributes.reserve(nb::len(attributes));
260 for (
auto attribute : attributes) {
264 context->
get(), mlirAttributes.size(), mlirAttributes.data());
267 nb::arg(
"attributes"), nb::arg(
"context") = nb::none(),
268 "Gets a uniqued Array attribute");
271 intptr_t i) -> nb::typed<nb::object, PyAttribute> {
273 throw nb::index_error(
"ArrayAttribute index out of range");
284 std::vector<MlirAttribute> attributes;
286 attributes.reserve(numOldElements + nb::len(extras));
287 for (
intptr_t i = 0; i < numOldElements; ++i)
288 attributes.push_back(arr.
getItem(i));
289 for (nb::handle attr : extras)
292 arr.
getContext()->
get(), attributes.size(), attributes.data());
302 if (mlirAttributeIsNull(attr))
306 nb::arg(
"type"), nb::arg(
"value"), nb::arg(
"loc") = nb::none(),
307 "Gets an uniqued float point attribute associated to a type");
314 if (mlirAttributeIsNull(attr))
318 nb::arg(
"type"), nb::arg(
"value"), nb::arg(
"context") = nb::none(),
319 "Gets an uniqued float point attribute associated to a type");
327 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
328 "Gets an uniqued float point attribute associated to a f32 type");
336 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
337 "Gets an uniqued float point attribute associated to a f64 type");
339 "Returns the value of the float attribute");
341 "Converts the value of the float attribute to a Python float");
347 [](
PyType &type, nb::object value) {
350 int64_t intValue = nb::cast<int64_t>(value);
359 if (bitWidth <= 64) {
360 int64_t intValue = nb::cast<int64_t>(value);
366 unsigned numWords = std::ceil(
static_cast<double>(bitWidth) / 64);
367 std::vector<uint64_t> words(numWords, 0);
370 nb::object mask = nb::int_(0xFFFFFFFFFFFFFFFFULL);
371 nb::object shift = nb::int_(64);
372 nb::object current = value;
377 nb::object zero = nb::int_(0);
378 if (nb::cast<bool>(current < zero)) {
379 nb::object twoToTheBitWidth = nb::int_(1) << nb::int_(bitWidth);
380 current = current + twoToTheBitWidth;
384 for (
unsigned i = 0; i < numWords; ++i) {
385 words[i] = nb::cast<uint64_t>(current & mask);
386 current = current >> shift;
393 nb::arg(
"type"), nb::arg(
"value"),
394 "Gets an uniqued integer attribute associated to a type");
395 c.def_prop_ro(
"value", toPyInt,
"Returns the value of the integer attribute");
396 c.def(
"__int__", toPyInt,
397 "Converts the value of the integer attribute to a Python int");
398 c.def_prop_ro_static(
403 nb::sig(
"def static_typeid(/) -> TypeID"));
411 if (bitWidth <= 64) {
421 std::vector<uint64_t> words(numWords);
426 nb::object
result = nb::int_(0);
427 nb::object shift = nb::int_(64);
428 for (
unsigned i = numWords; i > 0; --i) {
436 bool signBitSet = (words[numWords - 1] >> ((bitWidth - 1) % 64)) & 1;
438 nb::object twoToTheBitWidth = nb::int_(1) << nb::int_(bitWidth);
453 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
454 "Gets an uniqued bool attribute");
456 "Returns the value of the bool attribute");
458 "Converts the value of the bool attribute to a Python bool");
465 throw std::runtime_error(
"SymbolRefAttr must be composed of at least "
469 for (
size_t i = 1; i < symbols.size(); ++i) {
470 referenceAttrs.push_back(
475 referenceAttrs.size(),
476 referenceAttrs.data()));
482 [](
const std::vector<std::string> &symbols,
486 nb::arg(
"symbols"), nb::arg(
"context") = nb::none(),
487 "Gets a uniqued SymbolRef attribute from a list of symbol names");
491 std::vector<std::string> symbols = {
500 "Returns the value of the SymbolRef attribute as a list[str]");
511 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
512 "Gets a uniqued FlatSymbolRef attribute");
517 return nb::str(stringRef.
data, stringRef.
length);
519 "Returns the value of the FlatSymbolRef attribute as a string");
525 [](
const std::string &dialectNamespace,
const nb_buffer &buffer,
531 static_cast<char *
>(bufferInfo.
ptr), type);
534 nb::arg(
"dialect_namespace"), nb::arg(
"buffer"), nb::arg(
"type"),
535 nb::arg(
"context") = nb::none(),
537 nb::sig(
"def get(dialect_namespace: str, buffer: typing_extensions.Buffer, type: Type, context: Context | None = None) -> OpaqueAttr"),
539 "Gets an Opaque attribute.");
544 return nb::str(stringRef.
data, stringRef.
length);
546 "Returns the dialect namespace for the Opaque attribute as a string");
551 return nb::bytes(stringRef.
data, stringRef.
length);
553 "Returns the data for the Opaqued attributes as `bytes`");
558 std::optional<PyType> explicitType,
560 const size_t numAttributes = nb::len(attributes);
561 if (numAttributes == 0)
562 throw nb::value_error(
"Attributes list must be non-empty.");
570 llvm::raw_string_ostream os(message);
571 os <<
"Expected a static ShapedType for the shaped_type parameter: "
572 << nb::cast<std::string>(nb::repr(nb::cast(*explicitType)));
573 throw nb::value_error(message.c_str());
575 shapedType = *explicitType;
585 mlirAttributes.reserve(numAttributes);
586 for (
const nb::handle &attribute : attributes) {
589 mlirAttributes.push_back(mlirAttribute);
593 llvm::raw_string_ostream os(message);
594 os <<
"All attributes must be of the same type and match "
595 <<
"the type parameter: expected="
596 << nb::cast<std::string>(nb::repr(nb::cast(shapedType)))
597 <<
", but got=" << nb::cast<std::string>(nb::repr(nb::cast(attrType)));
598 throw nb::value_error(message.c_str());
603 shapedType, mlirAttributes.size(), mlirAttributes.data());
610 const std::optional<PyType> &explicitType,
611 std::optional<std::vector<int64_t>> explicitShape,
614 int flags = PyBUF_ND;
616 flags |= PyBUF_FORMAT;
619 if (PyObject_GetBuffer(array.ptr(), &view, flags) != 0) {
620 throw nb::python_error();
622 llvm::scope_exit freeBuffer([&]() { PyBuffer_Release(&view); });
624 MlirContext context = contextWrapper->
get();
625 MlirAttribute attr = getAttributeFromBuffer(
626 view, signless, explicitType, std::move(explicitShape), context);
627 if (mlirAttributeIsNull(attr)) {
628 throw std::invalid_argument(
629 "DenseElementsAttr could not be constructed from the given buffer. "
630 "This may mean that the Python buffer layout does not match that "
631 "MLIR expected layout and is a bug.");
639 auto contextWrapper =
643 std::string message =
"Illegal element type for DenseElementsAttr: ";
644 message.append(nb::cast<std::string>(nb::repr(nb::cast(elementAttr))));
645 throw nb::value_error(message.c_str());
649 std::string message =
650 "Expected a static ShapedType for the shaped_type parameter: ";
651 message.append(nb::cast<std::string>(nb::repr(nb::cast(shapedType))));
652 throw nb::value_error(message.c_str());
657 std::string message =
658 "Shaped element type and attribute type must be equal: shaped=";
659 message.append(nb::cast<std::string>(nb::repr(nb::cast(shapedType))));
660 message.append(
", element=");
661 message.append(nb::cast<std::string>(nb::repr(nb::cast(elementAttr))));
662 throw nb::value_error(message.c_str());
665 MlirAttribute elements =
681 return bufferInfo<float>(shapedType);
685 return bufferInfo<double>(shapedType);
689 return bufferInfo<uint16_t>(shapedType,
"e");
693 return bufferInfo<int64_t>(shapedType);
700 return bufferInfo<int32_t>(shapedType);
704 return bufferInfo<uint32_t>(shapedType);
711 return bufferInfo<int64_t>(shapedType);
715 return bufferInfo<uint64_t>(shapedType);
722 return bufferInfo<int8_t>(shapedType);
726 return bufferInfo<uint8_t>(shapedType);
733 return bufferInfo<int16_t>(shapedType);
737 return bufferInfo<uint16_t>(shapedType);
745 return getBooleanBufferFromBitpackedAttribute();
750 throw std::invalid_argument(
751 "unsupported data type for conversion to Python buffer");
755#if PY_VERSION_HEX < 0x03090000
756 PyTypeObject *tp =
reinterpret_cast<PyTypeObject *
>(c.ptr());
757 tp->tp_as_buffer->bf_getbuffer = PyDenseElementsAttribute::bf_getbuffer;
758 tp->tp_as_buffer->bf_releasebuffer =
759 PyDenseElementsAttribute::bf_releasebuffer;
764 nb::arg(
"signless") =
true, nb::arg(
"type") = nb::none(),
765 nb::arg(
"shape") = nb::none(), nb::arg(
"context") = nb::none(),
767 nb::sig(
"def get(array: typing_extensions.Buffer, signless: bool = True, type: Type | None = None, shape: Sequence[int] | None = None, context: Context | None = None) -> DenseElementsAttr"),
771 nb::arg(
"attrs"), nb::arg(
"type") = nb::none(),
772 nb::arg(
"context") = nb::none(),
775 nb::arg(
"shaped_type"), nb::arg(
"element_attr"),
776 "Gets a DenseElementsAttr where all values are the same")
777 .def_prop_ro(
"is_splat",
781 .def(
"get_splat_value",
783 -> nb::typed<nb::object, PyAttribute> {
785 throw nb::value_error(
786 "get_splat_value called on a non-splat attribute");
793bool PyDenseElementsAttribute::isUnsignedIntegerFormat(
794 std::string_view format) {
797 char code = format[0];
798 return code ==
'I' || code ==
'B' || code ==
'H' || code ==
'L' ||
802bool PyDenseElementsAttribute::isSignedIntegerFormat(std::string_view format) {
805 char code = format[0];
806 return code ==
'i' || code ==
'b' || code ==
'h' || code ==
'l' ||
810MlirType PyDenseElementsAttribute::getShapedType(
811 std::optional<MlirType> bulkLoadElementType,
812 std::optional<std::vector<int64_t>> explicitShape, Py_buffer &view) {
815 shape.append(explicitShape->begin(), explicitShape->end());
817 shape.append(view.shape, view.shape + view.ndim);
822 throw std::invalid_argument(
"Shape can only be specified explicitly "
823 "when the type is not a shaped type.");
825 return *bulkLoadElementType;
829 *bulkLoadElementType, encodingAttr);
832MlirAttribute PyDenseElementsAttribute::getAttributeFromBuffer(
833 Py_buffer &view,
bool signless, std::optional<PyType> explicitType,
834 const std::optional<std::vector<int64_t>> &explicitShape,
835 MlirContext &context) {
840 std::optional<MlirType> bulkLoadElementType;
842 bulkLoadElementType = *explicitType;
844 std::string_view format(view.format);
847 assert(view.itemsize == 4 &&
"mismatched array itemsize");
849 }
else if (format ==
"d") {
851 assert(view.itemsize == 8 &&
"mismatched array itemsize");
853 }
else if (format ==
"e") {
855 assert(view.itemsize == 2 &&
"mismatched array itemsize");
857 }
else if (format ==
"?") {
860 return getBitpackedAttributeFromBooleanBuffer(view, explicitShape,
862 }
else if (isSignedIntegerFormat(format)) {
863 if (view.itemsize == 4) {
867 }
else if (view.itemsize == 8) {
871 }
else if (view.itemsize == 1) {
875 }
else if (view.itemsize == 2) {
880 }
else if (isUnsignedIntegerFormat(format)) {
881 if (view.itemsize == 4) {
883 bulkLoadElementType = signless
886 }
else if (view.itemsize == 8) {
888 bulkLoadElementType = signless
891 }
else if (view.itemsize == 1) {
895 }
else if (view.itemsize == 2) {
897 bulkLoadElementType = signless
902 if (!bulkLoadElementType) {
903 throw std::invalid_argument(
904 std::string(
"unimplemented array format conversion from format: ") +
905 std::string(format));
909 MlirType type = getShapedType(bulkLoadElementType, explicitShape, view);
913MlirAttribute PyDenseElementsAttribute::getBitpackedAttributeFromBooleanBuffer(
914 Py_buffer &view, std::optional<std::vector<int64_t>> explicitShape,
915 MlirContext &context) {
916 if (llvm::endianness::native != llvm::endianness::little) {
919 throw nb::type_error(
"Constructing a bit-packed MLIR attribute is "
920 "unsupported on big-endian systems");
922 nb::ndarray<uint8_t, nb::numpy, nb::ndim<1>, nb::c_contig> unpackedArray(
923 static_cast<uint8_t *
>(view.buf),
924 {static_cast<size_t>(view.len)});
926 nb::module_ numpy = nb::module_::import_(
"numpy");
927 nb::object packbitsFunc = numpy.attr(
"packbits");
928 nb::object packedBooleans =
929 packbitsFunc(nb::cast(unpackedArray),
"bitorder"_a =
"little");
930 nb_buffer_info pythonBuffer = nb::cast<nb_buffer>(packedBooleans).request();
933 std::move(explicitShape), view);
934 assert(pythonBuffer.
itemsize == 1 &&
"Packbits must return uint8");
942std::unique_ptr<nb_buffer_info>
943PyDenseElementsAttribute::getBooleanBufferFromBitpackedAttribute()
const {
944 if (llvm::endianness::native != llvm::endianness::little) {
947 throw nb::type_error(
"Constructing a numpy array from a MLIR attribute "
948 "is unsupported on big-endian systems");
952 int64_t numBitpackedBytes = llvm::divideCeil(numBooleans, 8);
953 uint8_t *bitpackedData =
static_cast<uint8_t *
>(
955 nb::ndarray<uint8_t, nb::numpy, nb::ndim<1>, nb::c_contig> packedArray(
957 {
static_cast<size_t>(numBitpackedBytes)});
959 nb::module_ numpy = nb::module_::import_(
"numpy");
960 nb::object unpackbitsFunc = numpy.attr(
"unpackbits");
961 nb::object equalFunc = numpy.attr(
"equal");
962 nb::object reshapeFunc = numpy.attr(
"reshape");
963 nb::object unpackedBooleans =
964 unpackbitsFunc(nb::cast(packedArray),
"bitorder"_a =
"little");
971 unpackedBooleans = unpackedBooleans[nb::slice(
972 nb::int_(0), nb::int_(numBooleans), nb::int_(1))];
973 unpackedBooleans = equalFunc(unpackedBooleans, 1);
977 std::vector<intptr_t> shape(rank);
978 for (intptr_t i = 0; i < rank; ++i) {
981 unpackedBooleans = reshapeFunc(unpackedBooleans, shape);
985 nb_buffer pythonBuffer = nb::cast<nb_buffer>(unpackedBooleans);
986 return std::make_unique<nb_buffer_info>(pythonBuffer.request());
991#if PY_VERSION_HEX >= 0x03090000
993 reinterpret_cast<void *
>(PyDenseElementsAttribute::bf_getbuffer)},
994 {Py_bf_releasebuffer,
995 reinterpret_cast<void *
>(PyDenseElementsAttribute::bf_releasebuffer)},
1000 int PyDenseElementsAttribute::bf_getbuffer(PyObject *obj,
1003 view->obj =
nullptr;
1004 std::unique_ptr<nb_buffer_info> info;
1006 auto *attr = nb::cast<PyDenseElementsAttribute *>(nb::handle(obj));
1007 info = attr->accessBuffer();
1008 }
catch (nb::python_error &e) {
1010 nb::chain_error(PyExc_BufferError,
"Error converting attribute to buffer");
1012 }
catch (std::exception &e) {
1013 nb::chain_error(PyExc_BufferError,
1014 "Error converting attribute to buffer: %s", e.what());
1019 view->buf = info->ptr;
1020 view->itemsize = info->itemsize;
1021 view->len = info->itemsize;
1022 for (
auto s : info->shape) {
1025 view->readonly = info->readonly;
1026 if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) {
1027 view->format =
const_cast<char *
>(info->format);
1029 if ((flags & PyBUF_STRIDES) == PyBUF_STRIDES) {
1030 view->ndim =
static_cast<int>(info->ndim);
1031 view->strides = info->strides.data();
1032 view->shape = info->shape.data();
1034 view->suboffsets =
nullptr;
1035 view->internal = info.release();
1040 void PyDenseElementsAttribute::bf_releasebuffer(PyObject *,
1042 delete reinterpret_cast<nb_buffer_info *
>(view->internal);
1047 throw nb::index_error(
"attempt to access out of bounds element");
1056 "dense int elements attribute");
1100 throw nb::type_error(
"Unsupported integer type");
1108#if PY_VERSION_HEX < 0x030d0000
1109#define Py_IsFinalizing _Py_IsFinalizing
1115 std::optional<size_t> alignment,
bool isMutable,
1118 throw std::invalid_argument(
1119 "Constructing a DenseResourceElementsAttr requires a ShapedType.");
1124 int flags = PyBUF_STRIDES;
1125 std::unique_ptr<Py_buffer> view = std::make_unique<Py_buffer>();
1126 if (PyObject_GetBuffer(buffer.ptr(), view.get(), flags) != 0) {
1127 throw nb::python_error();
1132 llvm::scope_exit freeBuffer([&]() {
1134 PyBuffer_Release(view.get());
1137 if (!PyBuffer_IsContiguous(view.get(),
'A')) {
1138 throw std::invalid_argument(
"Contiguous buffer is required.");
1142 size_t inferredAlignment;
1144 inferredAlignment = *alignment;
1146 inferredAlignment = view->strides[view->ndim - 1];
1149 auto deleter = [](
void *userData,
const void *data,
size_t size,
1153 assert(Py_IsInitialized() &&
"expected interpreter to be initialized");
1154 Py_buffer *ownedView =
static_cast<Py_buffer *
>(userData);
1155 nb::gil_scoped_acquire gil;
1156 PyBuffer_Release(ownedView);
1160 size_t rawBufferSize = view->len;
1163 isMutable, deleter,
static_cast<void *
>(view.get()));
1164 if (mlirAttributeIsNull(attr)) {
1165 throw std::invalid_argument(
1166 "DenseResourceElementsAttr could not be constructed from the given "
1168 "This may mean that the Python buffer layout does not match that "
1169 "MLIR expected layout and is a bug.");
1178 nb::arg(
"array"), nb::arg(
"name"), nb::arg(
"type"),
1179 nb::arg(
"alignment") = nb::none(), nb::arg(
"is_mutable") =
false,
1180 nb::arg(
"context") = nb::none(),
1182 nb::sig(
"def get_from_buffer(array: typing_extensions.Buffer, name: str, type: Type, alignment: int | None = None, is_mutable: bool = False, context: Context | None = None) -> DenseResourceElementsAttr"),
1192 return !mlirAttributeIsNull(
1203 mlirNamedAttributes.reserve(attributes.size());
1204 for (std::pair<nb::handle, nb::handle> it : attributes) {
1205 auto &mlirAttr = nb::cast<PyAttribute &>(it.second);
1206 auto name = nb::cast<std::string>(it.first);
1212 MlirAttribute attr =
1214 mlirNamedAttributes.data());
1217 nb::arg(
"value") = nb::dict(), nb::arg(
"context") = nb::none(),
1218 "Gets an uniqued dict attribute");
1219 c.def(
"__getitem__",
1221 const std::string &
name) -> nb::typed<nb::object, PyAttribute> {
1222 MlirAttribute attr =
1224 if (mlirAttributeIsNull(attr))
1225 throw nb::key_error(
"attempt to access a non-existent attribute");
1229 if (index < 0 || index >= self.
dunderLen()) {
1230 throw nb::index_error(
"attempt to access out of bounds attribute");
1241 throw nb::index_error(
"attempt to access out of bounds element");
1257 throw nb::type_error(
"Unsupported floating-point type");
1271 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
1272 "Gets a uniqued Type attribute");
1287 nb::arg(
"context") = nb::none(),
"Create a Unit attribute.");
1293 [](
int64_t offset,
const std::vector<int64_t> &strides,
1296 ctx->
get(), offset, strides.size(), strides.data());
1299 nb::arg(
"offset"), nb::arg(
"strides"), nb::arg(
"context") = nb::none(),
1300 "Gets a strided layout attribute.");
1302 "get_fully_dynamic",
1305 std::vector<int64_t> strides(rank);
1306 llvm::fill(strides, dynamic);
1308 ctx->
get(), dynamic, strides.size(), strides.data());
1311 nb::arg(
"rank"), nb::arg(
"context") = nb::none(),
1312 "Gets a strided layout attribute with dynamic offset and strides of "
1320 "Returns the value of the float point attribute");
1325 std::vector<int64_t> strides(size);
1326 for (
intptr_t i = 0; i < size; i++) {
1331 "Returns the value of the float point attribute");
1350 std::string(
"Can't cast unknown element type DenseArrayAttr (") +
1351 nb::cast<std::string>(nb::repr(nb::cast(pyAttribute))) +
")";
1352 throw nb::type_error(msg.c_str());
1362 "Can't cast unknown element type DenseIntOrFPElementsAttr (") +
1363 nb::cast<std::string>(nb::repr(nb::cast(pyAttribute))) +
")";
1364 throw nb::type_error(msg.c_str());
1372 std::string msg = std::string(
"Can't cast unknown attribute type Attr (") +
1373 nb::cast<std::string>(nb::repr(nb::cast(pyAttribute))) +
1375 throw nb::type_error(msg.c_str());
1383 std::string msg = std::string(
"Can't cast unknown SymbolRef attribute (") +
1384 nb::cast<std::string>(nb::repr(nb::cast(pyAttribute))) +
1386 throw nb::type_error(msg.c_str());
1393 MlirAttribute attr =
1397 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
1398 "Gets a uniqued string attribute");
1402 MlirAttribute attr =
1406 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
1407 "Gets a uniqued string attribute");
1410 [](
PyType &type,
const std::string &value) {
1411 MlirAttribute attr =
1415 nb::arg(
"type"), nb::arg(
"value"),
1416 "Gets a uniqued string attribute associated to a type");
1421 return nb::str(stringRef.
data, stringRef.
length);
1423 "Returns the value of the string attribute");
1428 return nb::bytes(stringRef.
data, stringRef.
length);
1430 "Returns the value of the string attribute as `bytes`");
1436 PyDenseBoolArrayAttribute::PyDenseArrayIterator::bind(m);
1438 PyDenseI8ArrayAttribute::PyDenseArrayIterator::bind(m);
1440 PyDenseI16ArrayAttribute::PyDenseArrayIterator::bind(m);
1442 PyDenseI32ArrayAttribute::PyDenseArrayIterator::bind(m);
1444 PyDenseI64ArrayAttribute::PyDenseArrayIterator::bind(m);
1446 PyDenseF32ArrayAttribute::PyDenseArrayIterator::bind(m);
1448 PyDenseF64ArrayAttribute::PyDenseArrayIterator::bind(m);
1461 nb::cast<nb::callable>(
1469 nb::cast<nb::callable>(
static const char kDenseElementsAttrGetDocstring[]
static const char kDenseResourceElementsAttrGetFromBufferDocstring[]
static const char kDenseElementsAttrGetFromListDocstring[]
MlirContext mlirAttributeGetContext(MlirAttribute attribute)
MlirType mlirAttributeGetType(MlirAttribute attribute)
std::string str() const
Converts the diagnostic to a string.
ReferrentTy * get() const
PyMlirContextRef & getContext()
Accesses the context reference.
Used in function arguments when None should resolve to the current context manager set instance.
Used in function arguments when None should resolve to the current context manager set instance.
static PyMlirContext & resolve()
static void bindDerived(ClassTy &c)
MlirAffineMap get() const
nanobind::typed< nanobind::object, PyAttribute > dunderNext()
PyArrayAttributeIterator & dunderIter()
static void bind(nanobind::module_ &m)
MlirAttribute getItem(intptr_t i) const
static void bindDerived(ClassTy &c)
Wrapper around the generic MlirAttribute.
PyAttribute(PyMlirContextRef contextRef, MlirAttribute attr)
MlirAttribute get() const
Bool Attribute subclass - BoolAttr.
static constexpr IsAFunctionTy isaFunction
static void bindDerived(ClassTy &c)
static void bind(nanobind::module_ &m, PyType_Slot *slots=nullptr)
nanobind::class_< PyAffineMapAttribute, PyAttribute > ClassTy
static PyDenseElementsAttribute getSplat(const PyType &shapedType, PyAttribute &elementAttr)
std::unique_ptr< nb_buffer_info > accessBuffer()
intptr_t dunderLen() const
static PyType_Slot slots[]
static void bindDerived(ClassTy &c)
static PyDenseElementsAttribute getFromList(const nanobind::list &attributes, std::optional< PyType > explicitType, DefaultingPyMlirContext contextWrapper)
static PyDenseElementsAttribute getFromBuffer(const nb_buffer &array, bool signless, const std::optional< PyType > &explicitType, std::optional< std::vector< int64_t > > explicitShape, DefaultingPyMlirContext contextWrapper)
Refinement of PyDenseElementsAttribute for attributes containing floating-point values.
static constexpr IsAFunctionTy isaFunction
static void bindDerived(ClassTy &c)
nanobind::float_ dunderGetItem(intptr_t pos) const
Refinement of the PyDenseElementsAttribute for attributes containing integer (and boolean) values.
static void bindDerived(ClassTy &c)
nanobind::int_ dunderGetItem(intptr_t pos) const
Returns the element at the given linear position.
static constexpr IsAFunctionTy isaFunction
static PyDenseResourceElementsAttribute getFromBuffer(const nb_buffer &buffer, const std::string &name, const PyType &type, std::optional< size_t > alignment, bool isMutable, DefaultingPyMlirContext contextWrapper)
static void bindDerived(ClassTy &c)
static const MlirStringRef name
static void bindDerived(ClassTy &c)
intptr_t dunderLen() const
bool dunderContains(const std::string &name) const
static const MlirStringRef name
static constexpr IsAFunctionTy isaFunction
static void bindDerived(ClassTy &c)
Float Point Attribute subclass - FloatAttr.
static void bindDerived(ClassTy &c)
static PyGlobals & get()
Most code should get the globals via this static accessor.
void registerTypeCaster(MlirTypeID mlirTypeID, nanobind::callable typeCaster, bool replace=false)
Adds a user-friendly type caster.
Integer Attribute subclass - IntegerAttr.
static constexpr IsAFunctionTy isaFunction
static void bindDerived(ClassTy &c)
static void bindDerived(ClassTy &c)
MlirIntegerSet get() const
static PyMlirContextRef forContext(MlirContext context)
Returns a context reference for the singleton PyMlirContext wrapper for the given context.
MlirContext get()
Accesses the underlying MlirContext.
PyMlirContextRef getRef()
Gets a strong reference to this context, which will ensure it is kept alive for the life of the refer...
Represents a Python MlirNamedAttr, carrying an optional owned name.
static void bindDerived(ClassTy &c)
Strided layout attribute subclass.
static void bindDerived(ClassTy &c)
static void bindDerived(ClassTy &c)
static void bindDerived(ClassTy &c)
static PySymbolRefAttribute fromList(const std::vector< std::string > &symbols, PyMlirContext &context)
static constexpr IsAFunctionTy isaFunction
static void bindDerived(ClassTy &c)
A TypeID provides an efficient and unique identifier for a specific C++ type.
Wrapper around the generic MlirType.
nanobind::typed< nanobind::object, PyType > maybeDownCast()
Unit Attribute subclass. Unit attributes don't have values.
static void bindDerived(ClassTy &c)
mlir::Diagnostic & unwrap(MlirDiagnostic diagnostic)
MLIR_CAPI_EXPORTED MlirAttribute mlirAffineMapAttrGet(MlirAffineMap map)
Creates an affine map attribute wrapping the given map.
MLIR_CAPI_EXPORTED MlirAttribute mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace, intptr_t dataLength, const char *data, MlirType type)
Creates an opaque attribute in the given context associated with the dialect identified by its namesp...
MLIR_CAPI_EXPORTED MlirAttribute mlirFloatAttrDoubleGetChecked(MlirLocation loc, MlirType type, double value)
Same as "mlirFloatAttrDoubleGet", but if the type is not valid for a construction of a FloatAttr,...
MLIR_CAPI_EXPORTED uint8_t mlirDenseElementsAttrGetUInt8Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED int64_t mlirStridedLayoutAttrGetOffset(MlirAttribute attr)
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapAttrGetValue(MlirAttribute attr)
Returns the affine map wrapped in the given affine map attribute.
MLIR_CAPI_EXPORTED int64_t mlirStridedLayoutAttrGetStride(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED int8_t mlirDenseElementsAttrGetInt8Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirAttribute mlirStridedLayoutAttrGet(MlirContext ctx, int64_t offset, intptr_t numStrides, const int64_t *strides)
MLIR_CAPI_EXPORTED unsigned mlirIntegerAttrGetValueNumWords(MlirAttribute attr)
Returns the number of 64-bit words that make up the integer attribute's underlying APInt value.
MLIR_CAPI_EXPORTED MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol)
Creates a flat symbol reference attribute in the given context referencing a symbol identified by the...
MLIR_CAPI_EXPORTED uint64_t mlirDenseElementsAttrGetIndexValue(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED const void * mlirDenseElementsAttrGetRawData(MlirAttribute attr)
Returns the raw data of the given dense elements attribute.
MLIR_CAPI_EXPORTED MlirTypeID mlirIntegerAttrGetTypeID(void)
Returns the typeID of an Integer attribute.
MLIR_CAPI_EXPORTED int16_t mlirDenseElementsAttrGetInt16Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolRefAttrGetRootReference(MlirAttribute attr)
Returns the string reference to the root referenced symbol.
MLIR_CAPI_EXPORTED MlirTypeID mlirDenseIntOrFPElementsAttrGetTypeID(void)
Returns the typeID of an DenseIntOrFPElements attribute.
MLIR_CAPI_EXPORTED bool mlirAttributeIsAInteger(MlirAttribute attr)
Checks whether the given attribute is an integer attribute.
MLIR_CAPI_EXPORTED intptr_t mlirDictionaryAttrGetNumElements(MlirAttribute attr)
Returns the number of attributes contained in a dictionary attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirIntegerSetAttrGet(MlirIntegerSet set)
Creates an integer set attribute wrapping the given set.
MLIR_CAPI_EXPORTED uint16_t mlirDenseElementsAttrGetUInt16Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED uint64_t mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED bool mlirBoolAttrGetValue(MlirAttribute attr)
Returns the value stored in the given bool attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirIntegerAttrGet(MlirType type, int64_t value)
Creates an integer attribute of the given type with the given integer value.
MLIR_CAPI_EXPORTED bool mlirDenseElementsAttrGetBoolValue(MlirAttribute attr, intptr_t pos)
Returns the pos-th value (flat contiguous indexing) of a specific type contained by the given dense e...
MLIR_CAPI_EXPORTED MlirAttribute mlirDictionaryAttrGet(MlirContext ctx, intptr_t numElements, MlirNamedAttribute const *elements)
Creates a dictionary attribute containing the given list of elements in the provided context.
MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, void *data, size_t dataLength, size_t dataAlignment, bool dataIsMutable, void(*deleter)(void *userData, const void *data, size_t size, size_t align), void *userData)
Unlike the typed accessors below, constructs the attribute with a raw data buffer and no type/alignme...
MLIR_CAPI_EXPORTED MlirAttribute mlirSymbolRefAttrGetNestedReference(MlirAttribute attr, intptr_t pos)
Returns pos-th reference nested in the given symbol reference attribute.
MLIR_CAPI_EXPORTED void mlirIntegerAttrGetValueWords(MlirAttribute attr, uint64_t *words)
Copies the 64-bit words making up the integer attribute's APInt value into the provided buffer.
MLIR_CAPI_EXPORTED int64_t mlirIntegerAttrGetValueInt(MlirAttribute attr)
Returns the value stored in the given integer attribute, assuming the value is of signless type and f...
MLIR_CAPI_EXPORTED intptr_t mlirSymbolRefAttrGetNumNestedReferences(MlirAttribute attr)
Returns the number of references nested in the given symbol reference attribute.
MLIR_CAPI_EXPORTED MlirType mlirTypeAttrGetValue(MlirAttribute attr)
Returns the type stored in the given type attribute.
MLIR_CAPI_EXPORTED bool mlirDenseElementsAttrIsSplat(MlirAttribute attr)
Checks whether the given dense elements attribute contains a single replicated value (splat).
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrGet(MlirType shapedType, intptr_t numElements, MlirAttribute const *elements)
Creates a dense elements attribute with the given Shaped type and elements in the same context as the...
MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueAttrGetData(MlirAttribute attr)
Returns the raw data as a string reference.
MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeGetNull(void)
Returns an empty attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirBoolAttrGet(MlirContext ctx, int value)
Creates a bool attribute in the given context with the given value.
MLIR_CAPI_EXPORTED int64_t mlirIntegerAttrGetValueSInt(MlirAttribute attr)
Returns the value stored in the given integer attribute, assuming the value is of signed type and fit...
MLIR_CAPI_EXPORTED int64_t mlirDenseElementsAttrGetInt64Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirNamedAttribute mlirDictionaryAttrGetElement(MlirAttribute attr, intptr_t pos)
Returns pos-th element of the given dictionary attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGetElement(MlirAttribute attr, intptr_t pos)
Returns pos-th element stored in the given array attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirDictionaryAttrGetElementByName(MlirAttribute attr, MlirStringRef name)
Returns the dictionary attribute element with the given name or NULL if the given name does not exist...
MLIR_CAPI_EXPORTED MlirTypeID mlirSymbolRefAttrGetTypeID(void)
Returns the typeID of an SymbolRef attribute.
MLIR_CAPI_EXPORTED MlirTypeID mlirDenseArrayAttrGetTypeID(void)
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrGetSplatValue(MlirAttribute attr)
Returns the single replicated value (splat) of a specific type contained by the given dense elements ...
MLIR_CAPI_EXPORTED float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED int64_t mlirElementsAttrGetNumElements(MlirAttribute attr)
Gets the total number of elements in the given elements attribute.
MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueAttrGetDialectNamespace(MlirAttribute attr)
Returns the namespace of the dialect with which the given opaque attribute is associated.
MLIR_CAPI_EXPORTED int32_t mlirDenseElementsAttrGetInt32Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirStringRef mlirStringAttrGetValue(MlirAttribute attr)
Returns the attribute values as a string reference.
MLIR_CAPI_EXPORTED double mlirFloatAttrGetValueDouble(MlirAttribute attr)
Returns the value stored in the given floating point attribute, interpreting the value as double.
MLIR_CAPI_EXPORTED uint64_t mlirIntegerAttrGetValueUInt(MlirAttribute attr)
Returns the value stored in the given integer attribute, assuming the value is of unsigned type and f...
MLIR_CAPI_EXPORTED MlirAttribute mlirUnitAttrGet(MlirContext ctx)
Creates a unit attribute in the given context.
MLIR_CAPI_EXPORTED double mlirDenseElementsAttrGetDoubleValue(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED intptr_t mlirStridedLayoutAttrGetNumStrides(MlirAttribute attr)
MLIR_CAPI_EXPORTED MlirAttribute mlirFloatAttrDoubleGet(MlirContext ctx, MlirType type, double value)
Creates a floating point attribute in the given context with the given double value and double-precis...
MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGet(MlirContext ctx, intptr_t numElements, MlirAttribute const *elements)
Creates an array element containing the given list of elements in the given context.
MLIR_CAPI_EXPORTED bool mlirAttributeIsAFloat(MlirAttribute attr)
Checks whether the given attribute is a floating point attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol, intptr_t numReferences, MlirAttribute const *references)
Creates a symbol reference attribute in the given context referencing a symbol identified by the give...
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrSplatGet(MlirType shapedType, MlirAttribute element)
Creates a dense elements attribute with the given Shaped type containing a single replicated element ...
MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrGet(MlirContext ctx, MlirStringRef str)
Creates a string attribute in the given context containing the given string.
MLIR_CAPI_EXPORTED MlirAttribute mlirTypeAttrGet(MlirType type)
Creates a type attribute wrapping the given type in the same context as the type.
MLIR_CAPI_EXPORTED intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr)
Returns the number of elements stored in the given array attribute.
MLIR_CAPI_EXPORTED unsigned mlirIntegerAttrGetValueBitWidth(MlirAttribute attr)
Returns the bit width of the integer attribute's underlying APInt value.
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrRawBufferGet(MlirType shapedType, size_t rawBufferSize, const void *rawBuffer)
Creates a dense elements attribute with the given Shaped type and elements populated from a packed,...
MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrTypedGet(MlirType type, MlirStringRef str)
Creates a string attribute in the given context containing the given string.
MLIR_CAPI_EXPORTED MlirAttribute mlirIntegerAttrGetFromWords(MlirType type, unsigned numWords, const uint64_t *words)
Creates an integer attribute of the given type from an array of 64-bit words.
MLIR_CAPI_EXPORTED MlirStringRef mlirFlatSymbolRefAttrGetValue(MlirAttribute attr)
Returns the referenced symbol as a string reference.
MLIR_CAPI_EXPORTED uint32_t mlirDenseElementsAttrGetUInt32Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirType mlirRankedTensorTypeGet(intptr_t rank, const int64_t *shape, MlirType elementType, MlirAttribute encoding)
Creates a tensor type of a fixed rank with the given shape, element type, and optional encoding in th...
MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsSignless(MlirType type)
Checks whether the given integer type is signless.
MLIR_CAPI_EXPORTED bool mlirTypeIsAInteger(MlirType type)
Checks whether the given type is an integer type.
MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetDimSize(MlirType type, intptr_t dim)
Returns the dim-th dimension of the given ranked shaped type.
MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeGet(MlirContext ctx, unsigned bitwidth)
Creates a signless integer type of the given bitwidth in the context.
MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsUnsigned(MlirType type)
Checks whether the given integer type is unsigned.
MLIR_CAPI_EXPORTED unsigned mlirIntegerTypeGetWidth(MlirType type)
Returns the bitwidth of an integer type.
MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetRank(MlirType type)
Returns the rank of the given ranked shaped type.
MLIR_CAPI_EXPORTED MlirType mlirF64TypeGet(MlirContext ctx)
Creates a f64 type in the given context.
MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeSignedGet(MlirContext ctx, unsigned bitwidth)
Creates a signed integer type of the given bitwidth in the context.
MLIR_CAPI_EXPORTED MlirType mlirF16TypeGet(MlirContext ctx)
Creates an f16 type in the given context.
MLIR_CAPI_EXPORTED bool mlirTypeIsAF64(MlirType type)
Checks whether the given type is an f64 type.
MLIR_CAPI_EXPORTED bool mlirTypeIsAF16(MlirType type)
Checks whether the given type is an f16 type.
MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsSigned(MlirType type)
Checks whether the given integer type is signed.
MLIR_CAPI_EXPORTED MlirType mlirShapedTypeGetElementType(MlirType type)
Returns the element type of the shaped type.
MLIR_CAPI_EXPORTED bool mlirShapedTypeHasStaticShape(MlirType type)
Checks whether the given shaped type has a static shape.
MLIR_CAPI_EXPORTED MlirType mlirF32TypeGet(MlirContext ctx)
Creates an f32 type in the given context.
MLIR_CAPI_EXPORTED bool mlirTypeIsAShaped(MlirType type)
Checks whether the given type is a Shaped type.
MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeUnsignedGet(MlirContext ctx, unsigned bitwidth)
Creates an unsigned integer type of the given bitwidth in the context.
MLIR_CAPI_EXPORTED bool mlirTypeIsAF32(MlirType type)
Checks whether the given type is an f32 type.
MLIR_CAPI_EXPORTED bool mlirTypeIsAIndex(MlirType type)
Checks whether the given type is an index type.
MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetDynamicStrideOrOffset(void)
Returns the value indicating a dynamic stride or offset in a shaped type.
MLIR_CAPI_EXPORTED MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name, MlirAttribute attr)
Associates an attribute with the name. Takes ownership of neither.
MLIR_CAPI_EXPORTED MlirStringRef mlirIdentifierStr(MlirIdentifier ident)
Gets the string value of the identifier.
MLIR_CAPI_EXPORTED MlirContext mlirTypeGetContext(MlirType type)
Gets the context that a type was created with.
MLIR_CAPI_EXPORTED bool mlirTypeEqual(MlirType t1, MlirType t2)
Checks if two types are equal.
MLIR_CAPI_EXPORTED MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str)
Gets an identifier with the given string value.
nb::object denseIntOrFPElementsAttributeCaster(PyAttribute &pyAttribute)
nb::object symbolRefOrFlatSymbolRefAttributeCaster(PyAttribute &pyAttribute)
nb::object integerOrBoolAttributeCaster(PyAttribute &pyAttribute)
MlirStringRef toMlirStringRef(const std::string &s)
static T pyTryCast(nanobind::handle object)
nb::object denseArrayAttributeCaster(PyAttribute &pyAttribute)
MLIR_PYTHON_API_EXPORTED void populateIRAttributes(nanobind::module_ &m)
Include the generated interface declarations.
A pointer to a sized fragment of a string, not necessarily null-terminated.
const char * data
Pointer to the first symbol.
size_t length
Length of the fragment.
Custom exception that allows access to error diagnostic information.
Instantiate the python dense array classes.
static constexpr IsAFunctionTy isaFunction
static constexpr IsAFunctionTy isaFunction
static constexpr IsAFunctionTy isaFunction
static constexpr IsAFunctionTy isaFunction
static constexpr IsAFunctionTy isaFunction
static constexpr IsAFunctionTy isaFunction
static constexpr IsAFunctionTy isaFunction
RAII object that captures any error diagnostics emitted to the provided context.
std::vector< PyDiagnostic::DiagnosticInfo > take()
SmallVector< ssize_t, 4 > strides
nb_buffer_info(void *ptr, ssize_t itemsize, const char *format, ssize_t ndim, SmallVector< ssize_t, 4 > shape_in, SmallVector< ssize_t, 4 > strides_in, bool readonly=false, std::unique_ptr< Py_buffer, void(*)(Py_buffer *)> owned_view_in=std::unique_ptr< Py_buffer, void(*)(Py_buffer *)>(nullptr, nullptr))
SmallVector< ssize_t, 4 > shape
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()