numpy  2.0.0
src/multiarray/shape.h File Reference

Go to the source code of this file.

Functions

NPY_NO_EXPORT PyObject * build_shape_string (npy_intp n, npy_intp *vals)
NPY_NO_EXPORT void PyArray_CreateMultiSortedStridePerm (int narrays, PyArrayObject **arrays, int ndim, int *out_strideperm)
NPY_NO_EXPORT PyObject * PyArray_SqueezeSelected (PyArrayObject *self, npy_bool *axis_flags)

Function Documentation

NPY_NO_EXPORT PyObject* build_shape_string ( npy_intp  n,
npy_intp vals 
)
Builds a string representation of the shape given in 'vals'. A negative value in 'vals' gets interpreted as newaxis.
See shape.h for parameters documentation
Negative dimension indicates "newaxis", which can be discarded for printing if it's a leading dimension. Find the first non-"newaxis" dimension.

Referenced by broadcast_strides().

NPY_NO_EXPORT void PyArray_CreateMultiSortedStridePerm ( int  narrays,
PyArrayObject **  arrays,
int  ndim,
int *  out_strideperm 
)
Creates a sorted stride perm matching the KEEPORDER behavior of the NpyIter object. Because this operates based on multiple input strides, the 'stride' member of the npy_stride_sort_item would be useless and we simply argsort a list of indices instead.
The caller should have already validated that 'ndim' matches for every array in the arrays list.
Initialize the strideperm values to the identity.
This is the same as the custom stable insertion sort in the NpyIter object, but sorting in the reverse order as in the iterator. The iterator sorts from smallest stride to biggest stride (Fortran order), whereas here we sort from biggest stride to smallest stride (C order).
Set swap even if it's not ambiguous already, because in the case of conflicts between different operands, C-order wins.
Only set swap if it's still ambiguous
A comparison has been done, so it's no longer ambiguous
If the comparison was unambiguous, either shift 'ipos' to 'i1' or stop looking for an insertion point
Insert out_strideperm[i0] into the right place

References NPY_CORDER, and PyArray_Newshape().

NPY_NO_EXPORT PyObject* PyArray_SqueezeSelected ( PyArrayObject self,
npy_bool axis_flags 
)
Just like PyArray_Squeeze, but allows the caller to select a subset of the size-one dimensions to squeeze out.
Verify that the axes requested are all of size one
If there were no axes to squeeze out, return the same array
If self isn't not a base class ndarray, call its __array_wrap__ method