numpy  2.0.0
src/multiarray/number.h File Reference

Go to the source code of this file.

Data Structures

struct  NumericOps

Functions

NPY_NO_EXPORT PyObject * array_int (PyArrayObject *v)
NPY_NO_EXPORT int PyArray_SetNumericOps (PyObject *dict)
NPY_NO_EXPORT PyObject * PyArray_GetNumericOps (void)
NPY_NO_EXPORT PyObject * PyArray_GenericBinaryFunction (PyArrayObject *m1, PyObject *m2, PyObject *op)
NPY_NO_EXPORT PyObject * PyArray_GenericUnaryFunction (PyArrayObject *m1, PyObject *op)
NPY_NO_EXPORT PyObject * PyArray_GenericReduceFunction (PyArrayObject *m1, PyObject *op, int axis, int rtype, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_GenericAccumulateFunction (PyArrayObject *m1, PyObject *op, int axis, int rtype, PyArrayObject *out)
NPY_NO_EXPORT int needs_right_binop_forward (PyObject *self, PyObject *other, const char *right_name, int is_inplace)

Variables

NPY_NO_EXPORT NumericOps n_ops
NPY_NO_EXPORT PyNumberMethods array_as_number

Function Documentation

If we still got an array which can hold references, stop because it could point back at 'v'.
NPY_NO_EXPORT int needs_right_binop_forward ( PyObject *  self,
PyObject *  other,
const char *  right_name,
int  inplace_op 
)
Check whether the operation needs to be forwarded to the right-hand binary operation.
This is the case when all of the following conditions apply:

  1. the other object defines __numpy_ufunc__
  2. the other object defines the right-hand operation __r*__
  3. Python hasn't already called the right-hand operation [occurs if the other object is a strict subclass provided the operation is not in-place]
An additional check is made in GIVE_UP_IF_HAS_RIGHT_BINOP macro below:

  1. other.__class__.__r*__ is not self.__class__.__r*__

    This is needed, because CPython does not call __rmul__ if the tp_number slots of the two objects are the same.

This always prioritizes the __r*__ routines over __numpy_ufunc__, independent of whether the other object is an ndarray subclass or not.
Quick cases
Bail out if Python would already have called the right-hand operation.
NPY_NO_EXPORT PyObject* PyArray_GenericAccumulateFunction ( PyArrayObject m1,
PyObject *  op,
int  axis,
int  rtype,
PyArrayObject out 
)

Referenced by PyArray_Prod(), and PyArray_Sum().

NPY_NO_EXPORT PyObject* PyArray_GenericBinaryFunction ( PyArrayObject m1,
PyObject *  m2,
PyObject *  op 
)
Catch priority inversion and punt, but only if it's guaranteed that we were called through m1 and the other guy is not an array at all. Note that some arrays need to pass through here even with priorities inverted, for example: float(17) * np.matrix(...)
See also:

System Message: WARNING/2 (<string>, line 12) Definition list ends without a blank line; unexpected unindent.
which should possibly be updated when this is.

Referenced by array_inplace_multiply(), PyArray_GenericInplaceUnaryFunction(), and PyArray_GenericUnaryFunction().

NPY_NO_EXPORT PyObject* PyArray_GenericReduceFunction ( PyArrayObject m1,
PyObject *  op,
int  axis,
int  rtype,
PyArrayObject out 
)
NPY_NO_EXPORT PyObject* PyArray_GetNumericOps ( void  )
Get dictionary showing number functions that all arrays will use
NPY_NO_EXPORT int PyArray_SetNumericOps ( PyObject *  dict)
Set internal structure with number functions that all arrays will use

Variable Documentation

NPY_NO_EXPORT PyNumberMethods array_as_number

*********** Implement Number Protocol ************************

System Message: WARNING/2 (<string>, line 1)
Title overline too short.

   Implement Number Protocol ****************************
 
NB: static objects initialized to zero

Referenced by array_bitwise_and(), array_bitwise_or(), array_bitwise_xor(), array_inplace_add(), array_inplace_multiply(), array_inplace_subtract(), array_invert(), PyArray_GenericInplaceUnaryFunction(), PyArray_GenericUnaryFunction(), PyArray_Max(), PyArray_Mean(), PyArray_Prod(), PyArray_Ptp(), and PyArray_Sum().