numpy  2.0.0
src/multiarray/methods.c File Reference
#include <stdarg.h>
#include <Python.h>
#include "structmember.h"
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
#include "npy_config.h"
#include "npy_pycompat.h"
#include "npy_import.h"
#include "ufunc_override.h"
#include "common.h"
#include "ctors.h"
#include "calculation.h"
#include "convert_datatype.h"
#include "item_selection.h"
#include "conversion_utils.h"
#include "shape.h"
#include "methods.h"
#include <stdio.h>

Defines

#define PY_SSIZE_T_CLEAN
#define NPY_NO_DEPRECATED_API   NPY_API_VERSION
#define _MULTIARRAYMODULE
#define NPY_FORWARD_NDARRAY_METHOD(name)
#define _CHKTYPENUM(typ)   ((typ) ? (typ)->type_num : NPY_NOTYPE)

Functions

static int NpyArg_ParseKeywords (PyObject *keys, const char *format, char **kwlist,...)
static PyObject * get_forwarding_ndarray_method (const char *name)
static PyObject * forward_ndarray_method (PyArrayObject *self, PyObject *args, PyObject *kwds, PyObject *forwarding_callable)
static PyObject * array_take (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_fill (PyArrayObject *self, PyObject *args)
static PyObject * array_put (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_reshape (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_squeeze (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_view (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_argmax (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_argmin (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_max (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_min (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_ptp (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_swapaxes (PyArrayObject *self, PyObject *args)
NPY_NO_EXPORT PyObject * PyArray_GetField (PyArrayObject *self, PyArray_Descr *typed, int offset)
static PyObject * array_getfield (PyArrayObject *self, PyObject *args, PyObject *kwds)
NPY_NO_EXPORT int PyArray_SetField (PyArrayObject *self, PyArray_Descr *dtype, int offset, PyObject *val)
static PyObject * array_setfield (PyArrayObject *self, PyObject *args, PyObject *kwds)
NPY_NO_EXPORT PyObject * PyArray_Byteswap (PyArrayObject *self, npy_bool inplace)
static PyObject * array_byteswap (PyArrayObject *self, PyObject *args)
static PyObject * array_tolist (PyArrayObject *self, PyObject *args)
static PyObject * array_tobytes (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_tofile (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_toscalar (PyArrayObject *self, PyObject *args)
static PyObject * array_setscalar (PyArrayObject *self, PyObject *args)
NPY_NO_EXPORT const char * npy_casting_to_string (NPY_CASTING casting)
static PyObject * array_astype (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_wraparray (PyArrayObject *self, PyObject *args)
static PyObject * array_preparearray (PyArrayObject *self, PyObject *args)
static PyObject * array_getarray (PyArrayObject *self, PyObject *args)
static PyObject * array_copy (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_copy_keeporder (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_resize (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_repeat (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_choose (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_sort (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_partition (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_argsort (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_argpartition (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_searchsorted (PyArrayObject *self, PyObject *args, PyObject *kwds)
static void _deepcopy_call (char *iptr, char *optr, PyArray_Descr *dtype, PyObject *deepcopy, PyObject *visit)
static PyObject * array_deepcopy (PyArrayObject *self, PyObject *args)
static PyObject * _getlist_pkl (PyArrayObject *self)
static int _setlist_pkl (PyArrayObject *self, PyObject *list)
static PyObject * array_reduce (PyArrayObject *self, PyObject *NPY_UNUSED(args))
static PyObject * array_setstate (PyArrayObject *self, PyObject *args)
NPY_NO_EXPORT int PyArray_Dump (PyObject *self, PyObject *file, int protocol)
NPY_NO_EXPORT PyObject * PyArray_Dumps (PyObject *self, int protocol)
static PyObject * array_dump (PyArrayObject *self, PyObject *args)
static PyObject * array_dumps (PyArrayObject *self, PyObject *args)
static PyObject * array_sizeof (PyArrayObject *self)
static PyObject * array_transpose (PyArrayObject *self, PyObject *args)
static PyObject * array_mean (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_sum (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_cumsum (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_prod (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_cumprod (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_dot (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_any (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_all (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_stddev (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_variance (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_compress (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_nonzero (PyArrayObject *self, PyObject *args)
static PyObject * array_trace (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_clip (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_conjugate (PyArrayObject *self, PyObject *args)
static PyObject * array_diagonal (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_flatten (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_ravel (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_round (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_setflags (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_newbyteorder (PyArrayObject *self, PyObject *args)
static PyObject * array_complex (PyArrayObject *self, PyObject *NPY_UNUSED(args))

Variables

NPY_NO_EXPORT PyMethodDef array_methods []

Define Documentation

#define _CHKTYPENUM (   typ)    ((typ) ? (typ)->type_num : NPY_NOTYPE)
Value:
static PyObject *callable = NULL; \
        if (callable == NULL) { \
            callable = get_forwarding_ndarray_method(name); \
            if (callable == NULL) { \
                return NULL; \
            } \
        } \
        return forward_ndarray_method(self, args, kwds, callable)
Forwards an ndarray method to the function numpy.core._methods.<name>(...), caching the callable in a local static variable. Note that the initialization is not thread-safe, but relies on the CPython GIL to be correct.

Referenced by array_argmin(), and array_transpose().

#define NPY_NO_DEPRECATED_API   NPY_API_VERSION

Function Documentation

static void _deepcopy_call ( char *  iptr,
char *  optr,
PyArray_Descr dtype,
PyObject *  deepcopy,
PyObject *  visit 
) [static]
call deepcopy on this argument
static PyObject* _getlist_pkl ( PyArrayObject self) [static]
Convert Array to flat list (using getitem)
static int _setlist_pkl ( PyArrayObject self,
PyObject *  list 
) [static]
static PyObject* array_all ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_any ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_argmax ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_argmin ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_argpartition ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_argsort ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_astype ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
TODO: UNSAFE default for compatibility, I think
switching to SAME_KIND by default would be good.
If the memory layout matches and, data types are equivalent, and it's not a subtype if subok is False, then we can skip the copy.
If the requested dtype is flexible, adapt it
This steals the reference to dtype, so no DECREF of dtype
static PyObject* array_byteswap ( PyArrayObject self,
PyObject *  args 
) [static]

Referenced by array_newbyteorder().

static PyObject* array_choose ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_newbyteorder().

static PyObject* array_clip ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_newbyteorder().

static PyObject* array_compress ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

References PyArray_FLAGS.

Referenced by array_newbyteorder().

static PyObject* array_conjugate ( PyArrayObject self,
PyObject *  args 
) [static]

Referenced by array_newbyteorder().

static PyObject* array_copy ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_copy_keeporder ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
Separate from array_copy to make __copy__ preserve Fortran contiguity.

References NPY_QUICKSORT.

static PyObject* array_cumprod ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_cumsum ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_deepcopy ( PyArrayObject self,
PyObject *  args 
) [static]
static PyObject* array_diagonal ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_dot ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_dump ( PyArrayObject self,
PyObject *  args 
) [static]
static PyObject* array_dumps ( PyArrayObject self,
PyObject *  args 
) [static]
static PyObject* array_fill ( PyArrayObject self,
PyObject *  args 
) [static]

References NPY_RAISE, and PyArray_ClipmodeConverter().

Referenced by array_complex().

static PyObject* array_flatten ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_getarray ( PyArrayObject self,
PyObject *  args 
) [static]
convert to PyArray_Type
static PyObject* array_getfield ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_max ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_mean ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_min ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_newbyteorder ( PyArrayObject self,
PyObject *  args 
) [static]
static PyObject* array_nonzero ( PyArrayObject self,
PyObject *  args 
) [static]

References NPY_ARRAY_ALIGNED, and PyArray_CLEARFLAGS().

Referenced by array_complex().

static PyObject* array_partition ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_preparearray ( PyArrayObject self,
PyObject *  args 
) [static]
No need to create a new view
static PyObject* array_prod ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_ptp ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_put ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_ravel ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_reduce ( PyArrayObject self,
PyObject *  NPY_UNUSEDargs 
) [static]
version number of this pickle type. Increment if we need to
change the format. Be sure to handle the old versions in array_setstate.
Return a tuple of (callable object, arguments, object's state)
We will put everything in the object's state, so that on UnPickle
it can use the string object as memory without a copy
dummy data-type
Now fill in object's state. This is a tuple with

5 arguments

  1. an integer with the pickle version.
  2. a Tuple giving the shape
  3. a PyArray_Descr Object (with correct bytorder set)
  4. a npy_bool stating if Fortran or not
System Message: WARNING/2 (<string>, line 8) Enumerated list ends without a blank line; unexpected unindent.

5) a Python object representing the data (a string, or a list or any user-defined object).

Notice because Python does not describe a mechanism to write raw data to the pickle, this performs a copy to a string first

References PyArrayDescr_Type.

static PyObject* array_repeat ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_reshape ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_resize ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_round ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by array_complex().

static PyObject* array_searchsorted ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_setflags ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_setscalar ( PyArrayObject self,
PyObject *  args 
) [static]
If there is a tuple as a single argument, treat it as the argument
Special case of C-order flat indexing... :|
Convert the flat index into a multi-index
A multi-index tuple

References PyArray_PyIntAsIntp().

Referenced by array_complex().

static PyObject* array_setstate ( PyArrayObject self,
PyObject *  args 
) [static]
This will free any memory associated with a and
use the string in setstate as the (writeable) memory.
If we ever need another pickle format, increment the version
number. But we should still be able to handle the old versions. We've only got one right now.
Check that the string is not interned
byte-swap on pickle-read

References _array_fill_strides(), tagPyArrayObject_fields::dimensions, tagPyArrayObject_fields::flags, NPY_ARRAY_C_CONTIGUOUS, NPY_ARRAY_F_CONTIGUOUS, PyArray_DESCR, PyArray_DIMS, PyArray_STRIDES, PyDimMem_NEW, and tagPyArrayObject_fields::strides.

static PyObject* array_sizeof ( PyArrayObject self) [static]
object + dimension and strides
static PyObject* array_sort ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_squeeze ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

References PyArray_Squeeze().

static PyObject* array_stddev ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_sum ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]

References PyArray_Nonzero().

static PyObject* array_swapaxes ( PyArrayObject self,
PyObject *  args 
) [static]
static PyObject* array_take ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_tobytes ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_tofile ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
This should grow an order= keyword to be consistent
static PyObject* array_tolist ( PyArrayObject self,
PyObject *  args 
) [static]
static PyObject* array_toscalar ( PyArrayObject self,
PyObject *  args 
) [static]
If there is a tuple as a single argument, treat it as the argument
Special case of C-order flat indexing... :|
Convert the flat index into a multi-index
A multi-index tuple

Referenced by array_complex().

static PyObject* array_trace ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_transpose ( PyArrayObject self,
PyObject *  args 
) [static]
static PyObject* array_variance ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_view ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds 
) [static]
If user specified a positional argument, guess whether it
represents a type or a dtype for backward compatibility.
type specified?
static PyObject* array_wraparray ( PyArrayObject self,
PyObject *  args 
) [static]
default sub-type implementation
The type was set in __array_prepare__
static PyObject* forward_ndarray_method ( PyArrayObject self,
PyObject *  args,
PyObject *  kwds,
PyObject *  forwarding_callable 
) [static]
Forwards an ndarray method to a the Python function numpy.core._methods.<name>(...)
Combine 'self' and 'args' together into one tuple
Call the function and return
static PyObject* get_forwarding_ndarray_method ( const char *  name) [static]
Get a reference to the function we're calling
static int NpyArg_ParseKeywords ( PyObject *  keys,
const char *  format,
char **  kwlist,
  ... 
) [static]
NpyArg_ParseKeywords
Utility function that provides the keyword parsing functionality of PyArg_ParseTupleAndKeywords without having to have an args argument.
NPY_NO_EXPORT PyObject* PyArray_Byteswap ( PyArrayObject self,
npy_bool  inplace 
)
This doesn't change the descriptor just the actual data...

<

Use iterator

Referenced by PyArray_MoveInto().

NPY_NO_EXPORT int PyArray_Dump ( PyObject *  self,
PyObject *  file,
int  protocol 
)
NPY_NO_EXPORT PyObject* PyArray_Dumps ( PyObject *  self,
int  protocol 
)
NPY_NO_EXPORT PyObject* PyArray_GetField ( PyArrayObject self,
PyArray_Descr typed,
int  offset 
)
Get a subset of bytes from each element of the array
steals reference to typed, must not be NULL
check that we are not reinterpreting memory containing Objects.
only returns True or raises
NPY_NO_EXPORT int PyArray_SetField ( PyArrayObject self,
PyArray_Descr dtype,
int  offset,
PyObject *  val 
)
Set a subset of bytes from each element of the array
steals reference to dtype, must not be NULL
getfield returns a view we can write to

Variable Documentation