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 "numpy/npy_3kcompat.h"
#include "common.h"
#include "ctors.h"
#include "calculation.h"
#include "methods.h"
#include "convert_datatype.h"
#include <stdio.h>

Defines

#define PY_SSIZE_T_CLEAN
#define NPY_NO_DEPRECATED_API
#define _MULTIARRAYMODULE
#define NPY_NO_PREFIX
#define _ARET(x)   PyArray_Return((PyArrayObject *)(x))
#define _CHKTYPENUM(typ)   ((typ) ? (typ)->type_num : PyArray_NOTYPE)

Functions

static int NpyArg_ParseKeywords (PyObject *keys, const char *format, char **kwlist,...)
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)
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_ptp (PyArrayObject *self, PyObject *args, PyObject *kwds)
static PyObject * array_min (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, Bool inplace)
static PyObject * array_byteswap (PyArrayObject *self, PyObject *args)
static PyObject * array_tolist (PyArrayObject *self, PyObject *args)
static PyObject * array_tostring (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)
static PyObject * array_setasflat (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_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_argsort (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_transpose (PyArrayObject *self, PyObject *args)
static int _get_type_num_double (PyArray_Descr *dtype1, PyArray_Descr *dtype2)
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)

Variables

NPY_NO_EXPORT PyMethodDef array_methods []

Define Documentation

#define _ARET (   x)    PyArray_Return((PyArrayObject *)(x))
Should only be used if x is known to be an nd-array
#define _CHKTYPENUM (   typ)    ((typ) ? (typ)->type_num : PyArray_NOTYPE)
#define _MULTIARRAYMODULE
#define NPY_NO_DEPRECATED_API
#define NPY_NO_PREFIX
#define PY_SSIZE_T_CLEAN

Function Documentation

static void _deepcopy_call ( char *  iptr,
char *  optr,
PyArray_Descr *  dtype,
PyObject *  deepcopy,
PyObject *  visit 
) [static]

call deepcopy on this argument

static int _get_type_num_double ( PyArray_Descr *  dtype1,
PyArray_Descr *  dtype2 
) [static]
Return typenumber from dtype2 unless it is NULL, then return
NPY_DOUBLE if dtype1->type_num is integer or bool and dtype1->type_num otherwise.

For integer or bool data-types

Referenced by array_cumsum().

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]

Referenced by array_round().

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

Referenced by array_setflags().

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

Referenced by array_setflags().

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

Referenced by array_setflags().

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

Referenced by array_setflags().

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

Referenced by array_setflags().

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

References NPY_ARRAY_UPDATEIFCOPY.

Referenced by array_setflags().

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

Referenced by array_setflags().

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

Referenced by array_setflags().

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

Referenced by array_ravel(), and array_setflags().

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

Referenced by array_setflags().

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

Referenced by array_ravel().

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

Referenced by array_setflags().

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

Since blas-dot is exposed only on the Python side, we need to grab it from there

References PyArray_Nonzero().

Referenced by array_setflags().

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

Referenced by array_round().

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

Referenced by array_round().

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

Referenced by array_setflags().

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

Referenced by array_setflags().

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_setflags().

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

Referenced by array_setflags().

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

Referenced by array_newbyteorder().

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

Referenced by array_newbyteorder().

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

Referenced by array_newbyteorder().

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

No need to create a new view

References PyArray_Type.

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

Referenced by array_newbyteorder().

static PyObject* array_ptp ( PyArrayObject *  self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_put ( PyArrayObject *  self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_ravel ( PyArrayObject *  self,
PyObject *  args,
PyObject *  kwds 
) [static]
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 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 NPY_ANYORDER, and PyArray_ToString().

static PyObject* array_repeat ( PyArrayObject *  self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_reshape ( PyArrayObject *  self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_resize ( PyArrayObject *  self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_round ( PyArrayObject *  self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_searchsorted ( PyArrayObject *  self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_setasflat ( PyArrayObject *  self,
PyObject *  args 
) [static]
Sets the array values from another array as if they were flat

Referenced by array_setflags().

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

<

allows for flat setting as well as 1-d case
Call with a converted set of arguments

Referenced by array_setflags().

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

Referenced by array_round().

static PyObject* array_sort ( PyArrayObject *  self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_squeeze ( PyArrayObject *  self,
PyObject *  args 
) [static]
static PyObject* array_stddev ( PyArrayObject *  self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_sum ( PyArrayObject *  self,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_swapaxes ( PyArrayObject *  self,
PyObject *  args 
) [static]
static PyObject* array_take ( 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]

<

allows for flat getting as well as 1-d case

Referenced by array_setflags().

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

References _IsAligned(), and NPY_ARRAY_ALIGNED.

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__

Referenced by array_ravel().

NPY_NO_EXPORT const char* npy_casting_to_string ( NPY_CASTING  casting)
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,
Bool  inplace 
)
This doesn't change the descriptor just the actual data...

<

Use iterator

References PyArrayIterObject_tag::dataptr, and PyArray_ITER_NEXT.

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 
)
steals typed reference
Get a subset of bytes from each element of the array
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

Variable Documentation

NPY_NO_EXPORT PyMethodDef array_methods[]