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 "numpy/npy_3kcompat.h"
#include "common.h"
#include "number.h"
#include "calculation.h"

Defines

#define PY_SSIZE_T_CLEAN
#define _MULTIARRAYMODULE
#define NPY_NO_PREFIX
#define _check_axis   PyArray_CheckAxis
#define PyAO   PyArrayObject

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 *ap, 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 _check_axis   PyArray_CheckAxis
FIXME: just remove _check_axis ?

Referenced by PyArray_Prod(), and PyArray_Sum().

#define _MULTIARRAYMODULE
#define NPY_NO_PREFIX
#define PY_SSIZE_T_CLEAN
#define PyAO   PyArrayObject

Referenced by PyArray_Prod(), and PyArray_Sum().


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]

Referenced by PyArray_Any().

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

NPY_NO_EXPORT PyObject* PyArray_ArgMin ( PyArrayObject ap,
int  axis,
PyArrayObject out 
)
ArgMin
NPY_NO_EXPORT PyObject* PyArray_Clip ( PyArrayObject self,
PyObject *  min,
PyObject *  max,
PyArrayObject out 
)
Clip

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
Side-effect of PyArray_FromAny
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, and PyArray_PromoteTypes().

NPY_NO_EXPORT PyObject* PyArray_Conjugate ( PyArrayObject self,
PyArrayObject out 
)
Conjugate
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_Max ( PyArrayObject ap,
int  axis,
PyArrayObject out 
)
Max
NPY_NO_EXPORT PyObject* PyArray_Mean ( PyArrayObject self,
int  axis,
int  rtype,
PyArrayObject out 
)
Mean
NPY_NO_EXPORT PyObject* PyArray_Min ( PyArrayObject ap,
int  axis,
PyArrayObject out 
)
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
NPY_NO_EXPORT PyObject * PyArray_Round ( PyArrayObject a,
int  decimals,
PyArrayObject out 
)
Round

new.real = a.real.round(decimals)
new.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