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

Defines

#define PY_SSIZE_T_CLEAN
#define NPY_NO_DEPRECATED_API   NPY_API_VERSION
#define _MULTIARRAYMODULE
#define _define_get(UPPER, lower)

Functions

static void _UpdateContiguousFlags (PyArrayObject *ap)
NPY_NO_EXPORT PyObject * PyArray_NewFlagsObject (PyObject *obj)
NPY_NO_EXPORT void PyArray_UpdateFlags (PyArrayObject *ret, int flagmask)
static void arrayflags_dealloc (PyArrayFlagsObject *self)
 _define_get (NPY_ARRAY_C_CONTIGUOUS, contiguous)
static PyObject * arrayflags_fnc_get (PyArrayFlagsObject *self)
static PyObject * arrayflags_farray_get (PyArrayFlagsObject *self)
static PyObject * arrayflags_num_get (PyArrayFlagsObject *self)
static int arrayflags_updateifcopy_set (PyArrayFlagsObject *self, PyObject *obj)
static int arrayflags_aligned_set (PyArrayFlagsObject *self, PyObject *obj)
static int arrayflags_writeable_set (PyArrayFlagsObject *self, PyObject *obj)
static PyObject * arrayflags_getitem (PyArrayFlagsObject *self, PyObject *ind)
static int arrayflags_setitem (PyArrayFlagsObject *self, PyObject *ind, PyObject *item)
static char * _torf_ (int flags, int val)
static PyObject * arrayflags_print (PyArrayFlagsObject *self)
static int arrayflags_compare (PyArrayFlagsObject *self, PyArrayFlagsObject *other)
static PyObject * arrayflags_richcompare (PyObject *self, PyObject *other, int cmp_op)
static PyObject * arrayflags_new (PyTypeObject *NPY_UNUSED(self), PyObject *args, PyObject *NPY_UNUSED(kwds))

Variables

static PyGetSetDef arrayflags_getsets []
static PyMappingMethods arrayflags_as_mapping
NPY_NO_EXPORT PyTypeObject PyArrayFlags_Type

Define Documentation

#define _define_get (   UPPER,
  lower 
)
Value:
static PyObject * \
    arrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \
    { \
        PyObject *item; \
        item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \
        Py_INCREF(item); \
        return item; \
    }
#define NPY_NO_DEPRECATED_API   NPY_API_VERSION

Function Documentation

_define_get ( NPY_ARRAY_C_CONTIGUOUS  ,
contiguous   
)
static char* _torf_ ( int  flags,
int  val 
) [static]
static void _UpdateContiguousFlags ( PyArrayObject ap) [static]
Check whether the given array is stored contiguously in memory. And update the passed in ap flags apropriately.
The traditional rule is that for an array to be flagged as C contiguous, the following must hold:
strides[-1] == itemsize strides[i] == shape[i+1] * strides[i + 1]
And for an array to be flagged as F contiguous, the obvious reversal:
strides[0] == itemsize strides[i] == shape[i - 1] * strides[i - 1]
According to these rules, a 0- or 1-dimensional array is either both C- and F-contiguous, or neither; and an array with 2+ dimensions can be C- or F- contiguous, or neither, but not both. Though there there are exceptions for arrays with zero or one item, in the first case the check is relaxed up to and including the first dimension with shape[i] == 0. In the second case <cite>strides == itemsize</cite> will can be true for all dimensions and both flags are set.
When NPY_RELAXED_STRIDES_CHECKING is set, we use a more accurate definition of C- and F-contiguity, in which all 0-sized arrays are contiguous (regardless of dimensionality), and if shape[i] == 1 then we ignore strides[i] (since it has no affect on memory layout). With these new rules, it is possible for e.g. a 10x1 array to be both C- and F-contiguous -- but, they break downstream code which assumes that for contiguous arrays strides[-1] (resp. strides[0]) always contains the itemsize.

<

not NPY_RELAXED_STRIDES_CHECKING
contiguous, if it got this far

<

not NPY_RELAXED_STRIDES_CHECKING
check if fortran contiguous

<

not NPY_RELAXED_STRIDES_CHECKING

<

not NPY_RELAXED_STRIDES_CHECKING

References NPY_ARRAY_C_CONTIGUOUS, NPY_ARRAY_F_CONTIGUOUS, PyArray_CLEARFLAGS(), PyArray_DIMS, PyArray_ENABLEFLAGS(), PyArray_ITEMSIZE, PyArray_NDIM, and PyArray_STRIDES.

Referenced by PyArray_UpdateFlags().

static int arrayflags_aligned_set ( PyArrayFlagsObject self,
PyObject *  obj 
) [static]
static int arrayflags_compare ( PyArrayFlagsObject self,
PyArrayFlagsObject other 
) [static]
static void arrayflags_dealloc ( PyArrayFlagsObject self) [static]
static PyObject* arrayflags_farray_get ( PyArrayFlagsObject self) [static]
static PyObject* arrayflags_fnc_get ( PyArrayFlagsObject self) [static]
static PyObject* arrayflags_getitem ( PyArrayFlagsObject self,
PyObject *  ind 
) [static]
static PyObject* arrayflags_new ( PyTypeObject *  NPY_UNUSEDself,
PyObject *  args,
PyObject *  NPY_UNUSEDkwds 
) [static]
static PyObject* arrayflags_num_get ( PyArrayFlagsObject self) [static]
static PyObject* arrayflags_print ( PyArrayFlagsObject self) [static]
static PyObject* arrayflags_richcompare ( PyObject *  self,
PyObject *  other,
int  cmp_op 
) [static]
static int arrayflags_setitem ( PyArrayFlagsObject self,
PyObject *  ind,
PyObject *  item 
) [static]
static int arrayflags_updateifcopy_set ( PyArrayFlagsObject self,
PyObject *  obj 
) [static]
relies on setflags order being write, align, uic

Referenced by arrayflags_writeable_set().

static int arrayflags_writeable_set ( PyArrayFlagsObject self,
PyObject *  obj 
) [static]
NPY_NO_EXPORT void PyArray_UpdateFlags ( PyArrayObject ret,
int  flagmask 
)
Update Several Flags at once.
Always update both, as its not trivial to guess one from the other
This is not checked by default WRITEABLE is not part of UPDATE_ALL

References _IsAligned(), _IsWriteable(), _UpdateContiguousFlags(), NPY_ARRAY_ALIGNED, NPY_ARRAY_C_CONTIGUOUS, NPY_ARRAY_F_CONTIGUOUS, NPY_ARRAY_WRITEABLE, PyArray_CLEARFLAGS(), and PyArray_ENABLEFLAGS().

Referenced by NpyIter_GetShape().


Variable Documentation

PyMappingMethods arrayflags_as_mapping [static]
Initial value:
 {
    (lenfunc)NULL,                       
    (binaryfunc)arrayflags_getitem,      
    (objobjargproc)arrayflags_setitem,   
}
PyGetSetDef arrayflags_getsets[] [static]