array_utils.h

Typedefs

using PyArrayKeyTuple_t = nb::typed<nb::tuple, std::variant<nb::int_, nb::slice, nb::ellipsis>, nb::ellipsis>

Typed Python tuple, used as key when slicing an APyTypes array using a tuple. Python signature: tuple[int | slice | types.EllipsisType, ...]

using PyArrayKey_t = std::variant<nb::int_, nb::slice, nb::ellipsis, PyArrayKeyTuple_t>

Typed Python array key signature, used as key in the Python exposed __getitem__ and __setitem__ array methods. Python signature: int | slice | types.EllipsisType | tuple[int | slice | types.EllipsisType, ...]

using PyShapeTuple_t = nb::typed<nb::tuple, nb::int_, nb::ellipsis>

Typed Python tuple, used to denote the shape of array objects. Python signature: tuple[int, ...]

using PyShapeParam_t = std::variant<nanobind::int_, PyShapeTuple_t>

Typed Python shape parameter, used to denote shape in array functions. Python signature: int | tuple[int, ...]

Functions

template<typename INT_TYPE = std::size_t, bool allow_negative_dimensions = false>
static inline std::vector<INT_TYPE> cpp_shape_from_python_shape_like(const PyShapeParam_t &shape)

Create a C++ shape vector (std::vector<INT_TYPE>) from a Python shape object std::variant<nb::typed<nb::tuple, nb::int_, nb::ellipsis>, nanobind::int_>.

static inline std::vector<std::size_t> cpp_axes_from_python(const std::optional<PyShapeParam_t> &python_axes, std::size_t ndim)

Convert a Python tuple to a unique sorted list of dimensions (smaller than ndim)

static inline std::vector<std::size_t> get_normalized_axes(const PyShapeParam_t &axes, const std::size_t n_dim)

Converts the provided axes into a vector of positive indices.

Throws:

nb::value_error – if an axis value is out of bounds, if there are duplicate axes in the tuple or the axis don’t match.

template<typename RANDOM_ACCESS_CONST_ITERATOR, typename RANDOM_ACCESS_ITERATOR>
static inline void transpose_axes_and_copy_data(RANDOM_ACCESS_CONST_ITERATOR src, RANDOM_ACCESS_ITERATOR dst, const std::vector<std::size_t> &src_shape, const std::vector<std::size_t> &new_axis, std::size_t itemsize = 1)

Permutes the dimensions of the input data and copies it to the destination.

This function permutes the dimensions of the source data according to the provided permutation array and copies the permuted data to the destination. Assumunes that the sizes specified in src_shape and perm match the dimensionality of the data.

static inline APyFixed to_apyfixed(const nb::object &val)

Convert a value to APyFixed. The format of the result will be big enough to accommodate the result.

static inline std::vector<APyFixed> arange(const nb::object &start, const nb::object &stop, const nb::object &step)

Generate a vector of APyFixed object with evenly spaced values within a given range.