numpy  2.0.0
src/multiarray/multiarraymodule.c File Reference
#include "Python.h"
#include "structmember.h"
#include <numpy/npy_common.h>
#include "numpy/arrayobject.h"
#include "numpy/arrayscalars.h"
#include "numpy/npy_math.h"
#include "npy_config.h"
#include "npy_pycompat.h"
#include "npy_import.h"
#include "arraytypes.h"
#include "arrayobject.h"
#include "hashdescr.h"
#include "descriptor.h"
#include "calculation.h"
#include "number.h"
#include "scalartypes.h"
#include "numpymemoryview.h"
#include "convert_datatype.h"
#include "conversion_utils.h"
#include "nditer_pywrap.h"
#include "methods.h"
#include "_datetime.h"
#include "datetime_strings.h"
#include "datetime_busday.h"
#include "datetime_busdaycal.h"
#include "item_selection.h"
#include "shape.h"
#include "ctors.h"
#include "array_assign.h"
#include "common.h"
#include "ufunc_override.h"
#include "multiarraymodule.h"
#include "cblasfuncs.h"
#include "vdot.h"
#include "templ_common.h"
#include "compiled_base.h"
#include "mem_overlap.h"
#include <setjmp.h>
#include <signal.h>
#include "__multiarray_api.c"

Defines

#define PY_SSIZE_T_CLEAN
#define NPY_NO_DEPRECATED_API   NPY_API_VERSION
#define _MULTIARRAYMODULE
#define STRIDING_OK(op, order)
#define INNER_WHERE_LOOP(size)
#define _test_code()
#define SINGLE_INHERIT(child, parent)
#define DUAL_INHERIT(child, parent1, parent2)
#define INHERIT_INT(child, parent2)
#define DUAL_INHERIT_COMPARE(child, parent1, parent2)
#define DUAL_INHERIT2(child, parent1, parent2)
#define _addnew(key, val, one)
#define _addone(key, val)
#define RETVAL
#define ADDCONST(NAME)

Functions

NPY_NO_EXPORT double PyArray_GetPriority (PyObject *obj, double default_)
NPY_NO_EXPORT int PyArray_MultiplyIntList (int *l1, int n)
NPY_NO_EXPORT npy_intp PyArray_MultiplyList (npy_intp *l1, int n)
NPY_NO_EXPORT npy_intp PyArray_OverflowMultiplyList (npy_intp *l1, int n)
NPY_NO_EXPORT void * PyArray_GetPtr (PyArrayObject *obj, npy_intp *ind)
NPY_NO_EXPORT int PyArray_CompareLists (npy_intp *l1, npy_intp *l2, int n)
NPY_NO_EXPORT int PyArray_AsCArray (PyObject **op, void *ptr, npy_intp *dims, int nd, PyArray_Descr *typedescr)
NPY_NO_EXPORT int PyArray_As1D (PyObject **op, char **ptr, int *d1, int typecode)
NPY_NO_EXPORT int PyArray_As2D (PyObject **op, char ***ptr, int *d1, int *d2, int typecode)
NPY_NO_EXPORT int PyArray_Free (PyObject *op, void *ptr)
NPY_NO_EXPORT PyArrayObjectPyArray_ConcatenateArrays (int narrays, PyArrayObject **arrays, int axis)
NPY_NO_EXPORT PyArrayObjectPyArray_ConcatenateFlattenedArrays (int narrays, PyArrayObject **arrays, NPY_ORDER order)
NPY_NO_EXPORT PyObject * PyArray_Concatenate (PyObject *op, int axis)
static int _signbit_set (PyArrayObject *arr)
NPY_NO_EXPORT NPY_SCALARKIND PyArray_ScalarKind (int typenum, PyArrayObject **arr)
NPY_NO_EXPORT int PyArray_CanCoerceScalar (int thistype, int neededtype, NPY_SCALARKIND scalar)
static PyArrayObjectnew_array_for_sum (PyArrayObject *ap1, PyArrayObject *ap2, PyArrayObject *out, int nd, npy_intp dimensions[], int typenum)
NPY_NO_EXPORT PyObject * PyArray_InnerProduct (PyObject *op1, PyObject *op2)
NPY_NO_EXPORT PyObject * PyArray_MatrixProduct (PyObject *op1, PyObject *op2)
NPY_NO_EXPORT PyObject * PyArray_MatrixProduct2 (PyObject *op1, PyObject *op2, PyArrayObject *out)
NPY_NO_EXPORT PyObject * PyArray_CopyAndTranspose (PyObject *op)
static PyArrayObject_pyarray_correlate (PyArrayObject *ap1, PyArrayObject *ap2, int typenum, int mode, int *inverted)
static int _pyarray_revert (PyArrayObject *ret)
NPY_NO_EXPORT PyObject * PyArray_Correlate2 (PyObject *op1, PyObject *op2, int mode)
NPY_NO_EXPORT PyObject * PyArray_Correlate (PyObject *op1, PyObject *op2, int mode)
static PyObject * array_putmask (PyObject *NPY_UNUSED(module), PyObject *args, PyObject *kwds)
static int _equivalent_fields (PyObject *field1, PyObject *field2)
static int _equivalent_subarrays (PyArray_ArrayDescr *sub1, PyArray_ArrayDescr *sub2)
NPY_NO_EXPORT unsigned char PyArray_EquivTypes (PyArray_Descr *type1, PyArray_Descr *type2)
NPY_NO_EXPORT unsigned char PyArray_EquivTypenums (int typenum1, int typenum2)
static NPY_STEALS_REF_TO_ARG (1)
static PyObject * _array_fromobject (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kws)
static PyObject * array_copyto (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
static PyObject * array_empty (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
static PyObject * array_empty_like (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
static PyObject * array_scalar (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
static PyObject * array_zeros (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
static PyObject * array_count_nonzero (PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
static PyObject * array_fromstring (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds)
static PyObject * array_fromfile (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds)
static PyObject * array_fromiter (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds)
static PyObject * array_frombuffer (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *keywds)
static PyObject * array_concatenate (PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
static PyObject * array_innerproduct (PyObject *NPY_UNUSED(dummy), PyObject *args)
static PyObject * array_matrixproduct (PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
static PyObject * array_vdot (PyObject *NPY_UNUSED(dummy), PyObject *args)
static PyObject * array_matmul (PyObject *NPY_UNUSED(m), PyObject *args, PyObject *kwds)
static int einsum_sub_op_from_str (PyObject *args, PyObject **str_obj, char **subscripts, PyArrayObject **op)
static int einsum_list_to_subscripts (PyObject *obj, char *subscripts, int subsize)
static int einsum_sub_op_from_lists (PyObject *args, char *subscripts, int subsize, PyArrayObject **op)
static PyObject * array_einsum (PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
static PyObject * array_fastCopyAndTranspose (PyObject *NPY_UNUSED(dummy), PyObject *args)
static PyObject * array_correlate (PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
static PyObject * array_correlate2 (PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
static PyObject * array_arange (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kws)
NPY_NO_EXPORT unsigned int PyArray_GetNDArrayCVersion (void)
NPY_NO_EXPORT unsigned int PyArray_GetNDArrayCFeatureVersion (void)
static PyObject * array__get_ndarray_c_version (PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
NPY_NO_EXPORT int PyArray_GetEndianness (void)
static PyObject * array__reconstruct (PyObject *NPY_UNUSED(dummy), PyObject *args)
static PyObject * array_set_string_function (PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
static PyObject * array_set_ops_function (PyObject *NPY_UNUSED(self), PyObject *NPY_UNUSED(args), PyObject *kwds)
static PyObject * array_set_datetimeparse_function (PyObject *NPY_UNUSED(self), PyObject *NPY_UNUSED(args), PyObject *NPY_UNUSED(kwds))
NPY_NO_EXPORT PyObject * PyArray_Where (PyObject *condition, PyObject *x, PyObject *y)
static PyObject * array_where (PyObject *NPY_UNUSED(ignored), PyObject *args)
static PyObject * array_lexsort (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
static PyObject * array_can_cast_safely (PyObject *NPY_UNUSED(self), PyObject *args, PyObject *kwds)
static PyObject * array_promote_types (PyObject *NPY_UNUSED(dummy), PyObject *args)
static PyObject * array_min_scalar_type (PyObject *NPY_UNUSED(dummy), PyObject *args)
static PyObject * array_result_type (PyObject *NPY_UNUSED(dummy), PyObject *args)
static PyObject * array_datetime_data (PyObject *NPY_UNUSED(dummy), PyObject *args)
static PyObject * new_buffer (PyObject *NPY_UNUSED(dummy), PyObject *args)
static PyObject * buffer_buffer (PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
static void _SigSegv_Handler (int signum)
static PyObject * as_buffer (PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
static PyObject * format_longfloat (PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
static PyObject * compare_chararrays (PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
static PyObject * _vec_string_with_args (PyArrayObject *char_array, PyArray_Descr *type, PyObject *method, PyObject *args)
static PyObject * _vec_string_no_args (PyArrayObject *char_array, PyArray_Descr *type, PyObject *method)
static PyObject * _vec_string (PyObject *NPY_UNUSED(dummy), PyObject *args, PyObject *kwds)
NPY_NO_EXPORT void _PyArray_SigintHandler (int signum)
NPY_NO_EXPORT void * _PyArray_GetSigintBuf (void)
static PyObject * test_interrupt (PyObject *NPY_UNUSED(self), PyObject *args)
static PyObject * array_shares_memory_impl (PyObject *args, PyObject *kwds, Py_ssize_t default_max_work, int raise_exceptions)
static PyObject * array_shares_memory (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
static PyObject * array_may_share_memory (PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kwds)
static int setup_scalartypes (PyObject *NPY_UNUSED(dict))
static void set_flaginfo (PyObject *d)
static int intern_strings (void)
PyMODINIT_FUNC initmultiarray (void)

Variables

NPY_NO_EXPORT int NPY_NUMUSERTYPES = 0
NPY_NO_EXPORT PyTypeObject PyBigArray_Type
jmp_buf _NPY_SIGSEGV_BUF
static NPY_TLS int sigint_buf_init = 0
static NPY_TLS NPY_SIGJMP_BUF _NPY_SIGINT_BUF
static struct PyMethodDef array_module_methods []
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_array = NULL
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_array_prepare = NULL
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_array_wrap = NULL
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_array_finalize = NULL
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_buffer = NULL
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_ufunc = NULL
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_order = NULL
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_copy = NULL
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_dtype = NULL
NPY_VISIBILITY_HIDDEN PyObject * npy_ma_str_ndmin = NULL

Define Documentation

#define _addnew (   key,
  val,
  one 
)
Value:
PyDict_SetItemString(newd, #key, s=PyInt_FromLong(val));    \
    Py_DECREF(s);                                               \
    PyDict_SetItemString(newd, #one, s=PyInt_FromLong(val));    \
    Py_DECREF(s)
#define _addone (   key,
  val 
)
Value:
PyDict_SetItemString(newd, #key, s=PyInt_FromLong(val));    \
    Py_DECREF(s)
#define _test_code ( )
Value:
{ \
        test = *((char*)memptr); \
        if (!ro) { \
            *((char *)memptr) = '\0'; \
            *((char *)memptr) = test; \
        } \
        test = *((char*)memptr+size-1); \
        if (!ro) { \
            *((char *)memptr+size-1) = '\0'; \
            *((char *)memptr+size-1) = test; \
        } \
    }
#define ADDCONST (   NAME)
Value:
s = PyInt_FromLong(NPY_##NAME);             \
    PyDict_SetItemString(d, #NAME, s);          \
    Py_DECREF(s)

Referenced by setup_scalartypes().

#define DUAL_INHERIT (   child,
  parent1,
  parent2 
)
Value:
Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type;       \
    Py##child##ArrType_Type.tp_bases =                                  \
        Py_BuildValue("(OO)", &Py##parent2##ArrType_Type,               \
                      &Py##parent1##_Type);                             \
    if (PyType_Ready(&Py##child##ArrType_Type) < 0) {                   \
        PyErr_Print();                                                  \
        PyErr_Format(PyExc_SystemError,                                 \
                     "could not initialize Py%sArrType_Type",           \
                     #child);                                           \
        return -1;                                                      \
    }                                                                   \
    Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;
#define DUAL_INHERIT2 (   child,
  parent1,
  parent2 
)
Value:
Py##child##ArrType_Type.tp_base = &Py##parent1##_Type;              \
    Py##child##ArrType_Type.tp_bases =                                  \
        Py_BuildValue("(OO)", &Py##parent1##_Type,                      \
                      &Py##parent2##ArrType_Type);                      \
    Py##child##ArrType_Type.tp_richcompare =                            \
        Py##parent1##_Type.tp_richcompare;                              \
    DUAL_INHERIT_COMPARE(child, parent1, parent2)                       \
    Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;       \
    if (PyType_Ready(&Py##child##ArrType_Type) < 0) {                   \
        PyErr_Print();                                                  \
        PyErr_Format(PyExc_SystemError,                                 \
                     "could not initialize Py%sArrType_Type",           \
                     #child);                                           \
        return -1;                                                      \
    }
#define DUAL_INHERIT_COMPARE (   child,
  parent1,
  parent2 
)
Value:
Py##child##ArrType_Type.tp_compare =                                \
        Py##parent1##_Type.tp_compare;
#define INHERIT_INT (   child,
  parent2 
)
Value:
Py##child##ArrType_Type.tp_flags |= Py_TPFLAGS_INT_SUBCLASS;        \
    DUAL_INHERIT(child, Int, parent2);
#define INNER_WHERE_LOOP (   size)
Value:
do { \
        npy_intp i; \
        for (i = 0; i < n; i++) { \
            if (*csrc) { \
                memcpy(dst, xsrc, size); \
            } \
            else { \
                memcpy(dst, ysrc, size); \
            } \
            dst += size; \
            xsrc += xstride; \
            ysrc += ystride; \
            csrc += cstride; \
        } \
    } while(0)
inner loop with constant size memcpy arguments this allows the compiler to replace function calls while still handling the alignment requirements of the platform.

Referenced by array_correlate().

#define NPY_NO_DEPRECATED_API   NPY_API_VERSION
Id:
multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp
#define RETVAL
Initialization function for the module
#define SINGLE_INHERIT (   child,
  parent 
)
Value:
Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type;        \
    if (PyType_Ready(&Py##child##ArrType_Type) < 0) {                   \
        PyErr_Print();                                                  \
        PyErr_Format(PyExc_SystemError,                                 \
                     "could not initialize Py%sArrType_Type",           \
                     #child);                                           \
        return -1;                                                      \
    }

Referenced by array_shares_memory().

#define STRIDING_OK (   op,
  order 
)
Value:
((order) == NPY_ANYORDER || \
                 (order) == NPY_KEEPORDER || \
                 ((order) == NPY_CORDER && PyArray_IS_C_CONTIGUOUS(op)) || \
                 ((order) == NPY_FORTRANORDER && PyArray_IS_F_CONTIGUOUS(op)))

Function Documentation

static PyObject* _array_fromobject ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  kws 
) [static]
super-fast path for ndarray argument calls
get dtype which can be positional
array(ndarray)
fast path for copy=False rest default (np.asarray)
order does not matter for contiguous 1d arrays
copy=False with default dtype, order and ndim
fast exit if simple call
One more chance
order == NPY_ANYORDER &&
create a new array from the same data with ones in the shape steals a reference to ret

References NPY_BOOL, NPY_SAME_KIND_CASTING, PyArray_AssignArray(), PyArray_CastingConverter(), PyArray_Converter(), PyArray_DescrFromType(), PyArray_FromAny(), and PyArray_Type.

static int _equivalent_fields ( PyObject *  field1,
PyObject *  field2 
) [static]
Compare the field dictionaries for two types.
Return 1 if the contents are the same, 0 if not.

References NPY_FALSE, NPY_KEEPORDER, and NPY_TRUE.

static int _equivalent_subarrays ( PyArray_ArrayDescr sub1,
PyArray_ArrayDescr sub2 
) [static]
Compare the subarray data for two types. Return 1 if they are the same, 0 if not.
static PyArrayObject* _pyarray_correlate ( PyArrayObject ap1,
PyArrayObject ap2,
int  typenum,
int  mode,
int *  inverted 
) [static]
Implementation which is common between PyArray_Correlate and PyArray_Correlate2.
inverted is set to 1 if computed correlate(ap2, ap1), 0 otherwise
Need to choose an output array that can hold a sum -- use priority to determine which subtype.

References _pyarray_revert(), NPY_ARRAY_DEFAULT, PyArray_Conjugate(), PyArray_DescrFromType(), PyArray_FromAny(), PyArray_ISCOMPLEX, and PyArray_ObjectType().

static int _pyarray_revert ( PyArrayObject ret) [static]
Revert a one dimensional array in-place
Return 0 on success, other value on failure
Optimization for unstructured dtypes
First reverse the whole array byte by byte...
...then swap in place every item

References PyArray_PutMask(), and PyArray_Type.

Referenced by _pyarray_correlate().

NPY_NO_EXPORT void _PyArray_SigintHandler ( int  signum)
jump buffer may be uninitialized as SIGINT allowing functions are usually run in other threads than the master thread that receives the signal
sending SIGINT to the worker threads to cancel them is job of the application

References array_busday_count(), array_busday_offset(), array_is_busday(), as_buffer(), buffer_buffer(), format_longfloat(), and new_buffer().

static int _signbit_set ( PyArrayObject arr) [static]

<

points to the npy_byte to test

References NPY_NOTYPE.

Referenced by PyArray_Concatenate().

static void _SigSegv_Handler ( int  signum) [static]
static PyObject* _vec_string_no_args ( PyArrayObject char_array,
PyArray_Descr type,
PyObject *  method 
) [static]
This is a faster version of _vec_string_args to use when there are no additional arguments to the string method. This doesn't require a broadcast iterator (and broadcast iterators don't work with 1 argument anyway).
static PyObject* _vec_string_with_args ( PyArrayObject char_array,
PyArray_Descr type,
PyObject *  method,
PyObject *  args 
) [static]
Steals ref to arg
static PyObject* array__get_ndarray_c_version ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args,
PyObject *  kwds 
) [static]

References PyArray_Where().

static PyObject* array__reconstruct ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args 
) [static]
static PyObject* array_arange ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  kws 
) [static]
static PyObject* array_can_cast_safely ( PyObject *  NPY_UNUSEDself,
PyObject *  args,
PyObject *  kwds 
) [static]
If the first parameter is an object or scalar, use CanCastArrayTo
Otherwise use CanCastTypeTo

Referenced by _vec_string().

static PyObject* array_concatenate ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by _vec_string().

static PyObject* array_copyto ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  kwds 
) [static]
Get the boolean where mask
static PyObject* array_correlate ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args,
PyObject *  kwds 
) [static]

References INNER_WHERE_LOOP.

Referenced by _vec_string().

static PyObject* array_correlate2 ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by _vec_string().

static PyObject* array_count_nonzero ( PyObject *  NPY_UNUSEDself,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_datetime_data ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args 
) [static]
static PyObject* array_einsum ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args,
PyObject *  kwds 
) [static]
einsum('i,j', a, b), einsum('i,j->ij', a, b)
einsum(a, [0], b, [1]), einsum(a, [0], b, [1], [0,1])
Get the keyword arguments
If no output was supplied, possibly convert to a scalar
out is a borrowed reference

Referenced by _vec_string().

static PyObject* array_empty ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_empty_like ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  kwds 
) [static]
steals the reference to dtype if it's not NULL
static PyObject* array_fastCopyAndTranspose ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args 
) [static]
static PyObject* array_frombuffer ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  keywds 
) [static]

Referenced by _vec_string().

static PyObject* array_fromfile ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  keywds 
) [static]

Referenced by _vec_string().

static PyObject* array_fromiter ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  keywds 
) [static]

References NPY_KEEPORDER, and NPY_SAFE_CASTING.

Referenced by _vec_string().

static PyObject* array_fromstring ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  keywds 
) [static]

Referenced by _vec_string().

static PyObject* array_innerproduct ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args 
) [static]

Referenced by _vec_string().

static PyObject* array_lexsort ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* array_matmul ( PyObject *  NPY_UNUSEDm,
PyObject *  args,
PyObject *  kwds 
) [static]
matmul
Implements the protocol used by the '&#64;' operator defined in PEP 364. Not in the NUMPY API at this time, maybe later.
in1: Left hand side operand in2: Right hand side operand out: Either NULL, or an array into which the output should be placed.
Returns NULL on error. Returns NotImplemented on priority override.
matmul is not currently implemented for object arrays
Scalars are rejected
Use einsum for the stacked cases. This is a quick implementation to avoid setting up the proper iterators. Einsum broadcasts, so we need to check dimensions before the call.
vector vector
vector matrix
matrix vector
matrix * matrix
If no output was supplied, possibly convert to a scalar

Referenced by _vec_string().

static PyObject* array_matrixproduct ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by _vec_string().

static PyObject* array_may_share_memory ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by _vec_string().

static PyObject* array_min_scalar_type ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args 
) [static]

Referenced by _vec_string().

static PyObject* array_promote_types ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args 
) [static]

Referenced by _vec_string().

static PyObject* array_putmask ( PyObject *  NPY_UNUSEDmodule,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by _vec_string().

static PyObject* array_result_type ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args 
) [static]

Referenced by _vec_string().

static PyObject* array_scalar ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  kwds 
) [static]
This function is needed for supporting Pickles of numpy scalar objects.
free dptr which contains zeros

References NPY_SSIZE_T_PYFMT, PyArray_DescrConverter(), and PyArray_FromIter().

static PyObject* array_set_datetimeparse_function ( PyObject *  NPY_UNUSEDself,
PyObject *  NPY_UNUSEDargs,
PyObject *  NPY_UNUSEDkwds 
) [static]
static PyObject* array_set_ops_function ( PyObject *  NPY_UNUSEDself,
PyObject *  NPY_UNUSEDargs,
PyObject *  kwds 
) [static]
Should probably ensure that objects are at least callable
Leave this to the caller for now --- error will be raised later when use is attempted
static PyObject* array_set_string_function ( PyObject *  NPY_UNUSEDself,
PyObject *  args,
PyObject *  kwds 
) [static]
reset the array_repr function to built-in
static PyObject* array_shares_memory ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  kwds 
) [static]

References SINGLE_INHERIT.

Referenced by _vec_string().

static PyObject* array_shares_memory_impl ( PyObject *  args,
PyObject *  kwds,
Py_ssize_t  default_max_work,
int  raise_exceptions 
) [static]
Use FromAny to enable checking overlap for objects exposing array
interfaces etc.
noop
Don't know, so say yes
Don't know, so say yes
Doesn't happen usually
static PyObject* array_vdot ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args 
) [static]
Conjugating dot product using the BLAS for vectors. Flattens both op1 and op2 before dotting.
array scalar output

References dot_alignment_error().

Referenced by _vec_string().

static PyObject* array_where ( PyObject *  NPY_UNUSEDignored,
PyObject *  args 
) [static]
static PyObject* array_zeros ( PyObject *  NPY_UNUSEDignored,
PyObject *  args,
PyObject *  kwds 
) [static]
static PyObject* as_buffer ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args,
PyObject *  kwds 
) [static]
Try to dereference the start and end of the memory region Catch segfault and report error if it occurs

Referenced by _PyArray_SigintHandler().

static PyObject* buffer_buffer ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by _PyArray_SigintHandler().

static PyObject* compare_chararrays ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args,
PyObject *  kwds 
) [static]

References _NPY_SIGINT_BUF.

Referenced by _PyArray_GetSigintBuf().

static int einsum_list_to_subscripts ( PyObject *  obj,
char *  subscripts,
int  subsize 
) [static]
Converts a list of subscripts to a string.
Returns -1 on error, the number of characters placed in subscripts otherwise.
Ellipsis
Subscript
Invalid
static int einsum_sub_op_from_lists ( PyObject *  args,
char *  subscripts,
int  subsize,
PyArrayObject **  op 
) [static]
Fills in the subscripts, with maximum size subsize, and op, with the values in the tuple 'args'.
Returns -1 on error, number of operands placed in op otherwise.
Set the operands to NULL
Get the operands and build the subscript string
Comma between the subscripts for each operand
Add the '->' to the string if provided
NULL-terminate the subscripts string
static int einsum_sub_op_from_str ( PyObject *  args,
PyObject **  str_obj,
char **  subscripts,
PyArrayObject **  op 
) [static]
Get the subscripts string
Set the operands to NULL
Get the operands
static PyObject* format_longfloat ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args,
PyObject *  kwds 
) [static]

Referenced by _PyArray_SigintHandler().

PyMODINIT_FUNC initmultiarray ( void  )
Create the module and add the functions
Initialize access to the PyDateTime API
Add some symbolic constants to the module
Before calling PyType_Ready, initialize the tp_hash slot in PyArray_Type to work around mingw32 not being able initialize static structure slots with functions from the Python C_API.
FIXME There is no error handling here
Initialize types in numpymemoryview.c
PyExc_Exception should catch all the standard errors that are now raised instead of the string exception "multiarray.error" This is for backward compatibility with existing code.
FIXME There is no error handling here
Business day calendar object
static int intern_strings ( void  ) [static]
static PyArrayObject* new_array_for_sum ( PyArrayObject ap1,
PyArrayObject ap2,
PyArrayObject out,
int  nd,
npy_intp  dimensions[],
int  typenum 
) [static]
Make a new empty array, of the passed size, of a type that takes the priority of ap1 and ap2 into account.
Need to choose an output array that can hold a sum -- use priority to determine which subtype.
verify that out is usable
static PyObject* new_buffer ( PyObject *  NPY_UNUSEDdummy,
PyObject *  args 
) [static]

Referenced by _PyArray_SigintHandler().

static NPY_STEALS_REF_TO_ARG ( ) [static]
  • END C-API FUNCTIONS *
NPY_RELAXED_STRIDES_CHECKING: If the strides logic is changed, the order specific stride setting is not necessary.
steals a reference to arr --- so don't increment here
NPY_NO_EXPORT int PyArray_As1D ( PyObject **  op,
char **  ptr,
int *  d1,
int  typecode 
)
Deprecated --- Use PyArray_AsCArray instead
Convert to a 1D C-array
2008-07-14, 1.5
NPY_NO_EXPORT int PyArray_As2D ( PyObject **  op,
char ***  ptr,
int *  d1,
int *  d2,
int  typecode 
)
Convert to a 2D C-array
2008-07-14, 1.5
NPY_NO_EXPORT int PyArray_AsCArray ( PyObject **  op,
void *  ptr,
npy_intp dims,
int  nd,
PyArray_Descr typedescr 
)
simulates a C-style 1-3 dimensional array which can be accesed using ptr[i] or ptr[i][j] or ptr[i][j][k] -- requires pointer allocation for 2-d and 3-d.
For 2-d and up, ptr is NOT equivalent to a statically defined 2-d or 3-d array. In particular, it cannot be passed into a function that requires a true pointer to a fixed-size array.
Simulate a C-array
steals a reference to typedescr -- can be NULL
NPY_NO_EXPORT int PyArray_CanCoerceScalar ( int  thistype,
int  neededtype,
NPY_SCALARKIND  scalar 
)
Determines whether the data type 'thistype', with
scalar kind 'scalar', can be coerced into 'neededtype'.
If 'thistype' is not a scalar, it must be safely castable
The lookup table gives us exactly what we need for this comparison, which PyArray_ScalarKind would not.
The rule is that positive scalars can be coerced to a signed ints, but negative scalars cannot be coerced to unsigned ints.

System Message: ERROR/3 (<string>, line 7) Unexpected indentation.

<blockquote>

_npy_scalar_kinds_table[int]==NEGINT > POSINT,
so 1 is returned, but
_npy_scalar_kinds_table[uint]==POSINT < NEGINT,
so 0 is returned, as required.

</blockquote>

References PyArray_Dims::len, NPY_ARRAY_ALIGNED, NPY_MAXDIMS, PyArray_DescrFromType(), PyArray_FromAny(), PyArray_MatrixProduct2(), PyArray_NDIM, PyArray_ObjectType(), and PyArray_Transpose().

NPY_NO_EXPORT int PyArray_CompareLists ( npy_intp l1,
npy_intp l2,
int  n 
)
Compare Lists

References NPY_ARRAY_CARRAY, PyArray_DATA, and PyArray_FromAny().

Referenced by PyArray_ArgMax(), and PyArray_TakeFrom().

NPY_NO_EXPORT PyObject* PyArray_Concatenate ( PyObject *  op,
int  axis 
)
Concatenate <blockquote> Concatenate an arbitrary Python sequence into an array. op is a python object supporting the sequence interface. Its elements will be concatenated together to form a single multidimensional array. If axis is NPY_MAXDIMS or bigger, then each sequence object will be flattened before concatenation</blockquote>
Convert the input list into arrays
'narrays' was set to how far we got in the conversion

References _npy_scalar_kinds_table, _signbit_set(), NPY_INTNEG_SCALAR, and NPY_INTPOS_SCALAR.

NPY_NO_EXPORT PyArrayObject* PyArray_ConcatenateArrays ( int  narrays,
PyArrayObject **  arrays,
int  axis 
)
Concatenates a list of ndarrays.
All the arrays must have the same 'ndim'
Handle standard Python negative indexing
Figure out the final concatenated shape starting from the first array's shape.
Build up the size of the concatenation axis
Validate that the rest of the dimensions match
Get the priority subtype for the array
Get the resulting dtype from combining all the arrays
Figure out the permutation to apply to the strides to match the memory layout of the input arrays, using ambiguity resolution rules matching that of the NpyIter.
Allocate the array for the result. This steals the 'dtype' reference.
Create a view which slides through ret for assigning the successive input arrays.
Set the dimension to match the input array's
Copy the data for this array
Slide to the start of the next window
Concatenates a list of ndarrays, flattening each in the specified order.
Figure out the final concatenated shape starting from the first array's shape.
Check for overflow
Get the priority subtype for the array
Get the resulting dtype from combining all the arrays
Allocate the array for the result. This steals the 'dtype' reference.
Create a view which slides through ret for assigning the successive input arrays.
Adjust the window dimensions for this array
Copy the data for this array
Slide to the start of the next window
NPY_NO_EXPORT PyObject* PyArray_CopyAndTranspose ( PyObject *  op)
Copy and Transpose <blockquote> Could deprecate this function, as there isn't a speed benefit over calling Transpose and then Copy.</blockquote>
Make sure we have an array
Set up the transpose operation
Do the transpose (always returns a view)
TODO: Change this to NPY_KEEPORDER for NumPy 2.0
NPY_NO_EXPORT PyObject* PyArray_Correlate ( PyObject *  op1,
PyObject *  op2,
int  mode 
)
Numeric.correlate(a1,a2,mode)
NPY_NO_EXPORT PyObject* PyArray_Correlate2 ( PyObject *  op1,
PyObject *  op2,
int  mode 
)
correlate(a1,a2,mode) <blockquote> This function computes the usual correlation (correlate(a1, a2) != correlate(a2, a1), and conjugate the second argument for complex inputs</blockquote>
If we inverted input orders, we need to reverse the output array (i.e. ret = ret[::-1])
NPY_NO_EXPORT unsigned char PyArray_EquivTypenums ( int  typenum1,
int  typenum2 
)

References NPY_MAXDIMS.

NPY_NO_EXPORT unsigned char PyArray_EquivTypes ( PyArray_Descr type1,
PyArray_Descr type2 
)
This function returns true if the two typecodes are
equivalent (same basic kind and same itemsize).

References npy_ma_str_order.

NPY_NO_EXPORT int PyArray_Free ( PyObject *  op,
void *  ptr 
)
End Deprecated
Free pointers created if As2D is called
Returns the built-in (at compilation time) C API version
NPY_NO_EXPORT unsigned int PyArray_GetNDArrayCVersion ( void  )
Included at the very first so not auto-grabbed and thus not labeled.
NPY_NO_EXPORT double PyArray_GetPriority ( PyObject *  obj,
double  default_ 
)
Get Priority from object

Referenced by _ctype_negative().

NPY_NO_EXPORT void* PyArray_GetPtr ( PyArrayObject obj,
npy_intp ind 
)
Produce a pointer into array
NPY_NO_EXPORT PyObject* PyArray_InnerProduct ( PyObject *  op1,
PyObject *  op2 
)
Could perhaps be redone to not make contiguous arrays
Numeric.innerproduct(a,v)

References PyArray_NDIM.

NPY_NO_EXPORT PyObject* PyArray_MatrixProduct ( PyObject *  op1,
PyObject *  op2 
)
Numeric.matrixproduct(a,v)
just like inner product but does the swapaxes stuff on the fly
NPY_NO_EXPORT PyObject* PyArray_MatrixProduct2 ( PyObject *  op1,
PyObject *  op2,
PyArrayObject out 
)
Numeric.matrixproduct2(a,v,out)
just like inner product but does the swapaxes stuff on the fly
Choose which subtype to return
Ensure that multiarray.dot(<Nx0>,<0xM>) -> zeros((N,M))
only for OBJECT arrays

Referenced by PyArray_CanCoerceScalar().

NPY_NO_EXPORT int PyArray_MultiplyIntList ( int *  l1,
int  n 
)
Multiply a List of ints
Multiply a List
Multiply a List of Non-negative numbers with over-flow detection.
ScalarKind <blockquote> Returns the scalar kind of a type number, with an optional tweak based on the scalar value itself. If no scalar is provided, it returns INTPOS_SCALAR for both signed and unsigned integers, otherwise it checks the sign of any signed integer to choose INTNEG_SCALAR when appropriate.</blockquote>
Signed integer types are INTNEG in the table
NPY_NO_EXPORT PyObject* PyArray_Where ( PyObject *  condition,
PyObject *  x,
PyObject *  y 
)
Where
Get the result from the iterator object array
constant sizes so compiler replaces memcpy
copyswap is faster than memcpy even if we are native

Referenced by array__get_ndarray_c_version().

static void set_flaginfo ( PyObject *  d) [static]
place a flag dictionary in d
static int setup_scalartypes ( PyObject *  NPY_UNUSEDdict) [static]
Establish scalar-type hierarchy <blockquote>
For dual inheritance we need to make sure that the objects being inherited from have the tp->mro object initialized. This is not necessarily true for the basic type objects of Python (it is checked for single inheritance but not dual in PyType_Ready).
Thus, we call PyType_Ready on the standard Python Types, here. </blockquote>
In Py3K, int is no longer a fixed-width integer type, so don't inherit numpy.int_ from it.

Docutils System Messages

System Message: ERROR/3 (<string>, line 1); backlink Unknown target name: "numpy.int".
Datetime doesn't fit in any category
Timedelta is an integer with an associated unit
fprintf(stderr,
"tp_free = p, PyObject_Del = p, int_tp_free = p, base.tp_free = pn",
PyIntArrType_Type.tp_free, PyObject_Del, PyInt_Type.tp_free, PySignedIntegerArrType_Type.tp_free);
Clean up string and unicode array types so they act more like strings -- get their tables from the standard types.

References ADDCONST.

Referenced by test_interrupt().

static PyObject* test_interrupt ( PyObject *  NPY_UNUSEDself,
PyObject *  args 
) [static]

Variable Documentation

struct PyMethodDef array_module_methods[] [static]
NPY_VISIBILITY_HIDDEN PyObject* npy_ma_str_array = NULL
NPY_VISIBILITY_HIDDEN PyObject* npy_ma_str_array_finalize = NULL
NPY_VISIBILITY_HIDDEN PyObject* npy_ma_str_array_prepare = NULL
NPY_VISIBILITY_HIDDEN PyObject* npy_ma_str_array_wrap = NULL
NPY_VISIBILITY_HIDDEN PyObject* npy_ma_str_buffer = NULL
NPY_VISIBILITY_HIDDEN PyObject* npy_ma_str_copy = NULL
NPY_VISIBILITY_HIDDEN PyObject* npy_ma_str_dtype = NULL
NPY_VISIBILITY_HIDDEN PyObject* npy_ma_str_ndmin = NULL
NPY_VISIBILITY_HIDDEN PyObject* npy_ma_str_order = NULL

Referenced by PyArray_EquivTypes().

NPY_VISIBILITY_HIDDEN PyObject* npy_ma_str_ufunc = NULL
Internal APIs

<

for npy_mul_with_overflow_intp
Only here for API compatibility
NPY_TLS int sigint_buf_init = 0 [static]