|
MLIR 22.0.0git
|
A CRTP base class for pseudo-containers willing to support Python-type slicing access on top of indexed access. More...
#include "Bindings/Python/NanobindUtils.h"
Public Member Functions | |
| Sliceable (intptr_t startIndex, intptr_t length, intptr_t step) | |
| ElementTy | getElement (intptr_t index) |
| Returns the index-th element in the slice, supports negative indices. | |
| intptr_t | size () |
| Returns the size of slice. | |
| std::vector< ElementTy > | dunderAdd (Derived &other) |
| Returns a new vector (mapped to Python list) containing elements from two slices. | |
Static Public Member Functions | |
| static void | bind (nanobind::module_ &m) |
| Binds the indexing and length methods in the Python class. | |
| static void | bindDerived (ClassTy &) |
| Hook for derived classes willing to bind more methods. | |
Protected Types | |
| using | ClassTy = nanobind::class_<Derived> |
| template<typename T, typename... Args> | |
| using | has_maybe_downcast = decltype(&T::maybeDownCast) |
| Trait to check if T provides a maybeDownCast method. | |
Protected Member Functions | |
| intptr_t | wrapIndex (intptr_t index) |
| Transforms index into a legal value to access the underlying sequence. | |
| intptr_t | linearizeIndex (intptr_t index) |
| Computes the linear index given the current slice properties. | |
| nanobind::object | getItem (intptr_t index) |
| Returns the element at the given slice index. | |
| nanobind::object | getItemSlice (PyObject *slice) |
| Returns a new instance of the pseudo-container restricted to the given slice. | |
A CRTP base class for pseudo-containers willing to support Python-type slicing access on top of indexed access.
Calling bind on this class will define __len__ as well as __getitem__ with integer and slice arguments.
This is intended for pseudo-containers that can refer to arbitrary slices of underlying storage indexed by a single integer. Indexing those with an integer produces an instance of ElementTy. Indexing those with a slice produces a new instance of Derived, which can be sliced further.
A derived class must provide the following:
The getRawNumElements() and getRawElement(intptr_t) callbacks must not throw.
A derived class may additionally define:
Definition at line 248 of file NanobindUtils.h.
|
protected |
Definition at line 250 of file NanobindUtils.h.
|
protected |
Trait to check if T provides a maybeDownCast method.
Note, you need the & to detect inherited members.
Definition at line 274 of file NanobindUtils.h.
|
inlineexplicit |
Definition at line 310 of file NanobindUtils.h.
|
inlinestatic |
Binds the indexing and length methods in the Python class.
Definition at line 346 of file NanobindUtils.h.
|
inlinestatic |
Hook for derived classes willing to bind more methods.
Definition at line 396 of file NanobindUtils.h.
|
inline |
Returns a new vector (mapped to Python list) containing elements from two slices.
The new vector is necessary because slices may not be contiguous or even come from the same original sequence.
Definition at line 333 of file NanobindUtils.h.
Referenced by mlir::Sliceable< PyOpResultList, PyOpResult >::bind().
|
inline |
Returns the index-th element in the slice, supports negative indices.
Throws if the index is out of bounds.
Definition at line 317 of file NanobindUtils.h.
Referenced by mlir::Sliceable< PyOpResultList, PyOpResult >::dunderAdd().
|
inlineprotected |
Returns the element at the given slice index.
Supports negative indices by taking elements in inverse order. Returns a nullptr object if out of bounds.
Definition at line 279 of file NanobindUtils.h.
|
inlineprotected |
Returns a new instance of the pseudo-container restricted to the given slice.
Returns a nullptr object on failure.
Definition at line 298 of file NanobindUtils.h.
|
inlineprotected |
Computes the linear index given the current slice properties.
Definition at line 263 of file NanobindUtils.h.
Referenced by mlir::Sliceable< PyOpResultList, PyOpResult >::getElement(), and mlir::Sliceable< PyOpResultList, PyOpResult >::getItem().
|
inline |
Returns the size of slice.
Definition at line 328 of file NanobindUtils.h.
|
inlineprotected |
Transforms index into a legal value to access the underlying sequence.
Returns <0 on failure.
Definition at line 254 of file NanobindUtils.h.
Referenced by mlir::Sliceable< PyOpResultList, PyOpResult >::getElement(), and mlir::Sliceable< PyOpResultList, PyOpResult >::getItem().