8000 Header cleanup by charris · Pull Request #102 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Header cleanup #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 34 additions & 31 deletions numpy/core/include/numpy/ndarrayobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ extern "C" CONFUSE_EMACS
#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, \
PyArray_DescrFromType(type), 0, 0, 0, NULL);

#define PyArray_FROM_OTF(m, type, flags) \
PyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \
(((flags) & NPY_ENSURECOPY) ? \
((flags) | NPY_DEFAULT) : (flags)), NULL)
#define PyArray_FROM_OTF(m, type, flags) \
PyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \
(((flags) & NPY_ARRAY_ENSURECOPY) ? \
((flags) | NPY_ARRAY_DEFAULT) : (flags)), NULL)

#define PyArray_FROMANY(m, type, min, max, flags) \
PyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \
(((flags) & NPY_ENSURECOPY) ? \
(flags) | NPY_DEFAULT : (flags)), NULL)
#define PyArray_FROMANY(m, type, min, max, flags) \
PyArray_FromAny(m, PyArray_DescrFromType(type), min, max, \
(((flags) & NPY_ARRAY_ENSURECOPY) ? \
(flags) | NPY_ARRAY_DEFAULT : (flags)), NULL)

#define PyArray_ZEROS(m, dims, type, fortran) \
PyArray_Zeros(m, dims, PyArray_DescrFromType(type), fortran)
Expand All @@ -113,7 +113,7 @@ extern "C" CONFUSE_EMACS

#define PyArray_ContiguousFromAny(op, type, min_depth, max_depth) \
PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
max_depth, NPY_DEFAULT, NULL)
max_depth, NPY_ARRAY_DEFAULT, NULL)

#define PyArray_EquivArrTypes(a1, a2) \
PyArray_EquivTypes(PyArray_DESCR(a1), PyArray_DESCR(a2))
Expand All @@ -126,7 +126,7 @@ extern "C" CONFUSE_EMACS

#define PyArray_SimpleNewFromData(nd, dims, typenum, data) \
PyArray_New(&PyArray_Type, nd, dims, typenum, NULL, \
data, 0, NPY_CARRAY, NULL)
data, 0, NPY_ARRAY_CARRAY, NULL)

#define PyArray_SimpleNewFromDescr(nd, dims, descr) \
PyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, \
Expand Down Expand Up @@ -160,34 +160,37 @@ extern "C" CONFUSE_EMACS
(l)*PyArray_STRIDES(obj)[3]))

#define PyArray_XDECREF_ERR(obj) \
if (obj && (PyArray_FLAGS(obj) & NPY_UPDATEIFCOPY)) { \
PyArray_FLAGS(PyArray_BASE(obj)) |= NPY_WRITEABLE; \
PyArray_FLAGS(obj) &= ~NPY_UPDATEIFCOPY; \
} \
if (obj && (PyArray_FLAGS(obj) & NPY_ARRAY_UPDATEIFCOPY)) { \
PyArray_FLAGS(PyArray_BASE(obj)) |= NPY_ARRAY_WRITEABLE; \
PyArray_FLAGS(obj) &= ~NPY_ARRAY_UPDATEIFCOPY; \
} \
Py_XDECREF(obj)

#define PyArray_DESCR_REPLACE(descr) do { \
PyArray_Descr *_new_; \
_new_ = PyArray_DescrNew(descr); \
Py_XDECREF(descr); \
descr = _new_; \
#define PyArray_DESCR_REPLACE(descr) do { \
PyArray_Descr *_new_; \
_new_ = PyArray_DescrNew(descr); \
Py_XDECREF(descr); \
descr = _new_; \
} while(0)

/* Copy should always return contiguous array */
#define PyArray_Copy(obj) PyArray_NewCopy(obj, NPY_CORDER)

#define PyArray_FromObject(op, type, min_depth, max_depth) \
PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
max_depth, NPY_BEHAVED | NPY_ENSUREARRAY, NULL)

#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth) \
PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
max_depth, NPY_DEFAULT | NPY_ENSUREARRAY, NULL)

#define PyArray_CopyFromObject(op, type, min_depth, max_depth) \
PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
max_depth, NPY_ENSURECOPY | NPY_DEFAULT | \
NPY_ENSUREARRAY, NULL)
#define PyArray_FromObject(op, type, min_depth, max_depth) \
PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
max_depth, NPY_ARRAY_BEHAVED | \
NPY_ARRAY_ENSUREARRAY, NULL)

#define PyArray_ContiguousFromObject(op, type, min_depth, max_depth) \
PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
max_depth, NPY_ARRAY_DEFAULT | \
NPY_ARRAY_ENSUREARRAY, NULL)

#define PyArray_CopyFromObject(op, type, min_depth, max_depth) \
PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth, \
max_depth, NPY_ARRAY_ENSURECOPY | \
NPY_ARRAY_DEFAULT | \
NPY_ARRAY_ENSUREARRAY, NULL)

#define PyArray_Cast(mp, type_num) \
PyArray_CastToType(mp, PyArray_DescrFromType(type_num), 0)
Expand Down
128 changes: 63 additions & 65 deletions numpy/core/include/numpy/ndarraytypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,112 +654,107 @@ typedef struct {
npy_int32 sec, us, ps, as;
} npy_timedeltastruct;

/* TO BE REMOVED - NOT USED INTERNALLY. */
#if PY_VERSION_HEX >= 0x03000000
#define PyDataType_GetDatetimeMetaData(descr) \
((descr->metadata == NULL) ? NULL : \
((PyArray_DatetimeMetaData *)(PyCapsule_GetPointer( \
PyDict_GetItemString( \
descr->metadata, NPY_METADATA_DTSTR), NULL))))
#else
#define PyDataType_GetDatetimeMetaData(descr) \
((descr->metadata == NULL) ? NULL : \
((PyArray_DatetimeMetaData *)(PyCObject_AsVoidPtr( \
PyDict_GetItemString(descr->metadata, NPY_METADATA_DTSTR)))))
#endif

typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);

/*
* Means c-style contiguous (last index varies the fastest). The data
* elements right after each other.
*/
#define NPY_CONTIGUOUS 0x0001
#define NPY_ARRAY_C_CONTIGUOUS 0x0001

/*
* set if array is a contiguous Fortran array: the first index varies
* Set if array is a contiguous Fortran array: the first index varies
* the fastest in memory (strides array is reverse of C-contiguous
* array)
*/
#define NPY_FORTRAN 0x0002

#define NPY_C_CONTIGUOUS NPY_CONTIGUOUS
#define NPY_F_CONTIGUOUS NPY_FORTRAN
#define NPY_ARRAY_F_CONTIGUOUS 0x0002

/*
* Note: all 0-d arrays are CONTIGUOUS and FORTRAN contiguous. If a
* 1-d array is CONTIGUOUS it is also FORTRAN contiguous
* Note: all 0-d arrays are C_CONTIGUOUS and F_CONTIGUOUS. If a
* 1-d array is C_CONTIGUOUS it is also F_CONTIGUOUS
*/

/*
* If set, the array owns the data: it will be free'd when the array
* is deleted.
*/
#define NPY_OWNDATA 0x0004
#define NPY_ARRAY_OWNDATA 0x0004

/*
* An array never has the next four set; they're only used as parameter
* flags to the the various FromAny functions
*/

/* Cause a cast to occur regardless of whether or not it is safe. */
#define NPY_FORCECAST 0x0010
#define NPY_ARRAY_FORCECAST 0x0010

/*
* Always copy the array. Returned arrays are always CONTIGUOUS,
* ALIGNED, and WRITEABLE.
*/
#define NPY_ENSURECOPY 0x0020
#define NPY_ARRAY_ENSURECOPY 0x0020
F438
/* Make sure the returned array is a base-class ndarray */
#define NPY_ENSUREARRAY 0x0040
#define NPY_ARRAY_ENSUREARRAY 0x0040

/*
* Make sure that the strides are in units of the element size Needed
* for some operations with record-arrays.
*/
#define NPY_ELEMENTSTRIDES 0x0080
#define NPY_ARRAY_ELEMENTSTRIDES 0x0080

/*
* Array data is aligned on the appropiate memory address for the type
* stored according to how the compiler would align things (e.g., an
* array of integers (4 bytes each) starts on a memory address that's
* a multiple of 4)
*/
#define NPY_ALIGNED 0x0100
#define NPY_ARRAY_ALIGNED 0x0100

/* Array data has the native endianness */
#define NPY_NOTSWAPPED 0x0200
#define NPY_ARRAY_NOTSWAPPED 0x0200

/* Array data is writeable */
#define NPY_WRITEABLE 0x0400
#define NPY_ARRAY_WRITEABLE 0x0400

/*
* If this flag is set, then base contains a pointer to an array of
* the same size that should be updated with the current contents of
* this array when this array is deallocated
*/
#define NPY_UPDATEIFCOPY 0x1000
#define NPY_ARRAY_UPDATEIFCOPY 0x1000

#define NPY_ARRAY_BEHAVED (NPY_ARRAY_ALIGNED | \
NPY_ARRAY_WRITEABLE)
#define NPY_ARRAY_BEHAVED_NS (NPY_ARRAY_ALIGNED | \
NPY_ARRAY_WRITEABLE | \
NPY_ARRAY_NOTSWAPPED)
#define NPY_ARRAY_CARRAY (NPY_ARRAY_C_CONTIGUOUS | \
NPY_ARRAY_BEHAVED)
#define NPY_ARRAY_CARRAY_RO (NPY_ARRAY_C_CONTIGUOUS | \
NPY_ARRAY_ALIGNED)
#define NPY_ARRAY_FARRAY (NPY_ARRAY_F_CONTIGUOUS | \
NPY_ARRAY_BEHAVED)
#define NPY_ARRAY_FARRAY_RO (NPY_ARRAY_F_CONTIGUOUS | \
NPY_ARRAY_ALIGNED)
#define NPY_ARRAY_DEFAULT (NPY_ARRAY_CARRAY)
#define NPY_ARRAY_IN_ARRAY (NPY_ARRAY_CARRAY_RO)
#define NPY_ARRAY_OUT_ARRAY (NPY_ARRAY_CARRAY)
#define NPY_ARRAY_INOUT_ARRAY (NPY_ARRAY_CARRAY | \
NPY_ARRAY_UPDATEIFCOPY)
#define NPY_ARRAY_IN_FARRAY (NPY_ARRAY_FARRAY_RO)
#define NPY_ARRAY_OUT_FARRAY (NPY_ARRAY_FARRAY)
#define NPY_ARRAY_INOUT_FARRAY (NPY_ARRAY_FARRAY | \
NPY_ARRAY_UPDATEIFCOPY)

#define NPY_ARRAY_UPDATE_ALL (NPY_ARRAY_C_CONTIGUOUS | \
NPY_ARRAY_F_CONTIGUOUS | \
NPY_ARRAY_ALIGNED)

/* This flag is for the array interface */
#define NPY_ARR_HAS_DESCR 0x0800


#define NPY_BEHAVED (NPY_ALIGNED | NPY_WRITEABLE)
#define NPY_BEHAVED_NS (NPY_ALIGNED | NPY_WRITEABLE | NPY_NOTSWAPPED)
#define NPY_CARRAY (NPY_CONTIGUOUS | NPY_BEHAVED)
#define NPY_CARRAY_RO (NPY_CONTIGUOUS | NPY_ALIGNED)
#define NPY_FARRAY (NPY_FORTRAN | NPY_BEHAVED)
#define NPY_FARRAY_RO (NPY_FORTRAN | NPY_ALIGNED)
#define NPY_DEFAULT NPY_CARRAY
#define NPY_IN_ARRAY NPY_CARRAY_RO
#define NPY_OUT_ARRAY NPY_CARRAY
#define NPY_INOUT_ARRAY (NPY_CARRAY | NPY_UPDATEIFCOPY)
#define NPY_IN_FARRAY NPY_FARRAY_RO
#define NPY_OUT_FARRAY NPY_FARRAY
#define NPY_INOUT_FARRAY (NPY_FARRAY | NPY_UPDATEIFCOPY)

#define NPY_UPDATE_ALL (NPY_CONTIGUOUS | NPY_FORTRAN | NPY_ALIGNED)


/*
Expand Down Expand Up @@ -794,12 +789,12 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
#define PyArray_CHKFLAGS(m, FLAGS) \
((((PyArrayObject *)(m))->flags & (FLAGS)) == (FLAGS))

#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_CONTIGUOUS)
#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, NPY_WRITEABLE)
#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, NPY_ALIGNED)
#define PyArray_ISCONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS)
#define PyArray_ISWRITEABLE(m) PyArray_CHKFLAGS(m, NPY_ARRAY_WRITEABLE)
#define PyArray_ISALIGNED(m) PyArray_CHKFLAGS(m, NPY_ARRAY_ALIGNED)

#define PyArray_IS_C_CONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_C_CONTIGUOUS)
#define PyArray_IS_F_CONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_F_CONTIGUOUS)
#define PyArray_IS_C_CONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS)
#define PyArray_IS_F_CONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS)

#if NPY_ALLOW_THREADS
#define NPY_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
Expand Down Expand Up @@ -1236,7 +1231,6 @@ PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter);

/* The default array type */
#define NPY_DEFAULT_TYPE NPY_DOUBLE
#define PyArray_DEFAULT NPY_DEFAULT_TYPE

/*
* All sorts of useful ways to look into a PyArrayObject. These are
Expand All @@ -1245,15 +1239,15 @@ PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter);
*/

#define PyArray_NDIM(obj) (((PyArrayObject *)(obj))->nd)
#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || \
PyArray_CHKFLAGS(m, NPY_CONTIGUOUS) || \
PyArray_CHKFLAGS(m, NPY_FORTRAN))
#define PyArray_ISONESEGMENT(m) (PyArray_NDIM(m) == 0 || \
PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS) || \
PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS))

#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, NPY_FORTRAN) && \
#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) && \
(PyArray_NDIM(m) > 1))

#define PyArray_FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, NPY_FORTRAN) ? \
NPY_FORTRAN : 0))
#define PyArray_FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) ? \
NPY_ARRAY_F_CONTIGUOUS : 0))

#define FORTRAN_IF PyArray_FORTRAN_IF
#define PyArray_DATA(obj) ((void *)(((PyArrayObject *)(obj))->data))
Expand Down Expand Up @@ -1395,12 +1389,12 @@ PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter);
#define PyArray_FLAGSWAP(m, flags) (PyArray_CHKFLAGS(m, flags) && \
PyArray_ISNOTSWAPPED(m))

#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, NPY_CARRAY)
#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_CARRAY_RO)
#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, NPY_FARRAY)
#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_FARRAY_RO)
#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, NPY_BEHAVED)
#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, NPY_ALIGNED)
#define PyArray_ISCARRAY(m) PyArray_FLAGSWAP(m, NPY_ARRAY_CARRAY)
#define PyArray_ISCARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_CARRAY_RO)
#define PyArray_ISFARRAY(m) PyArray_FLAGSWAP(m, NPY_ARRAY_FARRAY)
#define PyArray_ISFARRAY_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_FARRAY_RO)
#define PyArray_ISBEHAVED(m) PyArray_FLAGSWAP(m, NPY_ARRAY_BEHAVED)
#define PyArray_ISBEHAVED_RO(m) PyArray_FLAGSWAP(m, NPY_ARRAY_ALIGNED)


#define PyDataType_ISNOTSWAPPED(d) PyArray_ISNBO(((PyArray_Descr *)(d))->byteorder)
Expand Down Expand Up @@ -1430,7 +1424,7 @@ typedef struct {

int flags; /*
* how should be data interpreted. Valid
* flags are CONTIGUOUS (1), FORTRAN (2),
* flags are CONTIGUOUS (1), F_CONTIGUOUS (2),
* ALIGNED (0x100), NOTSWAPPED (0x200), and
* WRITEABLE (0x400). ARR_HAS_DESCR (0x800)
* states that arrdescr field is present in
Expand All @@ -1452,4 +1446,8 @@ typedef struct {
*/
} PyArrayInterface;

#ifndef NPY_NO_DEPRECATED_API
#include "npy_deprecated_api.h"
#endif

#endif /* NPY_ARRAYTYPES_H */
Loading
0