numpy  2.0.0
src/multiarray/calculation.c File Reference
#include <Python.h>
#include "structmember.h"
#include "numpy/arrayobject.h"
#include "npy_config.h"
#include "npy_pycompat.h"
#include "common.h"
#include "number.h"
#include "calculation.h"
#include "array_assign.h"

Defines

#define PY_SSIZE_T_CLEAN
#define NPY_NO_DEPRECATED_API   NPY_API_VERSION
#define _MULTIARRAYMODULE

Functions

static double power_of_ten (int n)
NPY_NO_EXPORT PyObject * PyArray_ArgMax (PyArrayObject *op, int axis, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_ArgMin (PyArrayObject *op, int axis, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_Max (PyArrayObject *ap, int axis, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_Min (PyArrayObject *ap, int axis, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_Ptp (PyArrayObject *ap, int axis, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_Std (PyArrayObject *self, int axis, int rtype, PyArrayObject *out, int variance)
NPY_NO_EXPORT PyObject * __New_PyArray_Std (PyArrayObject *self, int axis, int rtype, PyArrayObject *out, int variance, int num)
NPY_NO_EXPORT PyObject * PyArray_Sum (PyArrayObject *self, int axis, int rtype, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_Prod (PyArrayObject *self, int axis, int rtype, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_CumSum (PyArrayObject *self, int axis, int rtype, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_CumProd (PyArrayObject *self, int axis, int rtype, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_Round (PyArrayObject *a, int decimals, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_Mean (PyArrayObject *self, int axis, int rtype, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_Any (PyArrayObject *self, int axis, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_All (PyArrayObject *self, int axis, PyArrayObject *out)
static PyObject * _GenericBinaryOutFunction (PyArrayObject *m1, PyObject *m2, PyArrayObject *out, PyObject *op)
static PyObject * _slow_array_clip (PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_Clip (PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_Conjugate (PyArrayObject *self, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_Trace (PyArrayObject *self, int offset, int axis1, int axis2, int rtype, PyArrayObject *out)

Define Documentation

#define NPY_NO_DEPRECATED_API   NPY_API_VERSION

Function Documentation

NPY_NO_EXPORT PyObject* __New_PyArray_Std ( PyArrayObject self,
int  axis,
int  rtype,
PyArrayObject out,
int  variance,
int  num 
)
Compute and reshape mean
Compute x = x - mx
Compute x * x
Compute add.reduce(x*x,axis)
sqrt()
static PyObject* _GenericBinaryOutFunction ( PyArrayObject m1,
PyObject *  m2,
PyArrayObject out,
PyObject *  op 
) [static]
static PyObject* _slow_array_clip ( PyArrayObject self,
PyObject *  min,
PyObject *  max,
PyArrayObject out 
) [static]

Referenced by PyArray_Clip().

static double power_of_ten ( int  n) [static]
NPY_NO_EXPORT PyObject* PyArray_All ( PyArrayObject self,
int  axis,
PyArrayObject out 
)
All
NPY_NO_EXPORT PyObject* PyArray_Any ( PyArrayObject self,
int  axis,
PyArrayObject out 
)
Any
NPY_NO_EXPORT PyObject* PyArray_ArgMax ( PyArrayObject op,
int  axis,
PyArrayObject out 
)
ArgMax
We need to permute the array so that axis is placed at the end. And all other dimensions are shifted left.
Will get native-byte order contiguous copy.
Trigger the UPDATEIFCOPY if necessary

References PyArray_Dims::len, NPY_ARRAY_CARRAY, NPY_ARRAY_UPDATEIFCOPY, NPY_BEGIN_THREADS_DEF, NPY_BEGIN_THREADS_DESCR, NPY_END_THREADS_DESCR, NPY_INTP, NPY_MAXDIMS, PyArray_Dims::ptr, PyArray_CheckAxis(), PyArray_CompareLists(), PyArray_ContiguousFromAny, PyArray_DATA, PyArray_DESCR, PyArray_DescrFromType(), PyArray_DIMS, PyArray_FromArray(), PyArray_NDIM, PyArray_New(), PyArray_SIZE, and PyArray_Transpose().

NPY_NO_EXPORT PyObject* PyArray_ArgMin ( PyArrayObject op,
int  axis,
PyArrayObject out 
)
ArgMin
We need to permute the array so that axis is placed at the end. And all other dimensions are shifted left.
Will get native-byte order contiguous copy.
Trigger the UPDATEIFCOPY if necessary
NPY_NO_EXPORT PyObject* PyArray_Clip ( PyArrayObject self,
PyObject *  min,
PyObject *  max,
PyArrayObject out 
)
Clip
Treat None the same as NULL
Use the fast scalar clip function
First we need to figure out the correct type
Steal the reference
Use the scalar descriptor only if it is of a bigger KIND than the input array (and then find the type that matches both).
Convert max to an array
If we are unsigned, then make sure min is not < 0 This is to match the behavior of _slow_array_clip
We allow min and max to go beyond the limits for other data-types in which case they are interpreted as their modular counterparts.
Convert min to an array
Check to see if input is single-segment, aligned, and in native byteorder
At this point, newin is a single-segment, aligned, and correct byte-order array of the correct type
if ingood == 0, then it is a copy, otherwise, it is the original input.
If we have already made a copy of the data, then use that as the output array
Now, we know newin is a usable array for fastclip, we need to make sure the output array is available and usable
Input is good at this point
Do we still not have a suitable output array? Create one, now
make sure the shape of the output array is the same
Now we can call the fast-clip function
Clean up temporary variables
Copy back into out if out was not already a nice array.

References _slow_array_clip(), _PyArray_Descr::f, PyArray_ArrFuncs::fastclip, PyArray_DESCR, and PyArray_PromoteTypes().

Referenced by array_cumprod().

NPY_NO_EXPORT PyObject* PyArray_Conjugate ( PyArrayObject self,
PyArrayObject out 
)
Conjugate

Referenced by _pyarray_correlate(), and array_dot().

NPY_NO_EXPORT PyObject* PyArray_CumProd ( PyArrayObject self,
int  axis,
int  rtype,
PyArrayObject out 
)
CumProd
NPY_NO_EXPORT PyObject* PyArray_CumSum ( PyArrayObject self,
int  axis,
int  rtype,
PyArrayObject out 
)
CumSum

References PyArray_ISCOMPLEX, and PyArray_SIZE.

NPY_NO_EXPORT PyObject* PyArray_Mean ( PyArrayObject self,
int  axis,
int  rtype,
PyArrayObject out 
)
NPY_NO_EXPORT PyObject* PyArray_Min ( PyArrayObject ap,
int  axis,
PyArrayObject out 
)
Min

References PyArray_CheckAxis(), PyArray_Max(), and PyArray_Min().

Referenced by PyArray_Min().

NPY_NO_EXPORT PyObject* PyArray_Prod ( PyArrayObject self,
int  axis,
int  rtype,
PyArrayObject out 
)
NPY_NO_EXPORT PyObject* PyArray_Ptp ( PyArrayObject ap,
int  axis,
PyArrayObject out 
)
Ptp

References n_ops, and NumericOps::subtract.

NPY_NO_EXPORT PyObject * PyArray_Round ( PyArrayObject a,
int  decimals,
PyArrayObject out 
)
Round
arr.real = a.real.round(decimals)
arr.imag = a.imag.round(decimals)
do the most common case first
NPY_NO_EXPORT PyObject* PyArray_Std ( PyArrayObject self,
int  axis,
int  rtype,
PyArrayObject out,
int  variance 
)
Set variance to 1 to by-pass square-root calculation and return variance
Std
NPY_NO_EXPORT PyObject* PyArray_Sum ( PyArrayObject self,
int  axis,
int  rtype,
PyArrayObject out 
)
NPY_NO_EXPORT PyObject* PyArray_Trace ( PyArrayObject self,
int  offset,
int  axis1,
int  axis2,
int  rtype,
PyArrayObject out 
)
Trace