diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-08-19 06:01:10 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-08-19 06:01:10 +0000 |
commit | b9ce9390471f4f0989c6e4605d04ef0e5d1f5494 (patch) | |
tree | d005120cdb78d06ff2b3e4489bfea202a61f2ee4 | |
parent | 262dff23c6053efb7c28ca4dc7ccb294b7e25a4d (diff) | |
download | numpy-b9ce9390471f4f0989c6e4605d04ef0e5d1f5494.tar.gz |
Fix white-space issues.
-rw-r--r-- | numpy/core/include/numpy/arrayobject.h | 12 | ||||
-rw-r--r-- | numpy/core/include/numpy/ndarrayobject.h | 34 | ||||
-rw-r--r-- | numpy/core/include/numpy/noprefix.h | 90 | ||||
-rw-r--r-- | numpy/core/include/numpy/old_defines.h | 182 | ||||
-rw-r--r-- | numpy/core/include/numpy/oldnumeric.h | 4 | ||||
-rw-r--r-- | numpy/core/include/numpy/ufuncobject.h | 38 | ||||
-rw-r--r-- | numpy/core/numerictypes.py | 9 | ||||
-rw-r--r-- | numpy/core/src/_isnan.c | 9 | ||||
-rw-r--r-- | numpy/core/src/_signbit.c | 6 | ||||
-rw-r--r-- | numpy/core/src/_sortmodule.c.src | 34 | ||||
-rw-r--r-- | numpy/core/src/arraymethods.c | 474 | ||||
-rw-r--r-- | numpy/core/src/arrayobject.c | 560 | ||||
-rw-r--r-- | numpy/core/src/arraytypes.inc.src | 533 | ||||
-rw-r--r-- | numpy/core/src/multiarraymodule.c | 1455 | ||||
-rw-r--r-- | numpy/core/src/scalarmathmodule.c.src | 92 | ||||
-rw-r--r-- | numpy/core/src/scalartypes.inc.src | 4 | ||||
-rw-r--r-- | numpy/core/src/ucsnarrow.c | 18 | ||||
-rw-r--r-- | numpy/core/src/ufuncobject.c | 814 | ||||
-rw-r--r-- | numpy/core/src/umathmodule.c.src | 10 |
19 files changed, 2189 insertions, 2189 deletions
diff --git a/numpy/core/include/numpy/arrayobject.h b/numpy/core/include/numpy/arrayobject.h index b57ac3399..cea108543 100644 --- a/numpy/core/include/numpy/arrayobject.h +++ b/numpy/core/include/numpy/arrayobject.h @@ -6,7 +6,7 @@ long double is present on platform. CHAR_BIT -- number of bits in a char (usually 8) (should be in limits.h) - + */ #ifndef Py_ARRAYOBJECT_H @@ -15,5 +15,13 @@ #ifdef NPY_NO_PREFIX #include "noprefix.h" #endif -#endif + +/* Add signal handling macros */ + +#define NPY_SIG_ON +#define NPY_SIG_OFF +#define NPY_SIG_CHECK + + +#endif diff --git a/numpy/core/include/numpy/ndarrayobject.h b/numpy/core/include/numpy/ndarrayobject.h index bd0fe56a4..9551cd7bc 100644 --- a/numpy/core/include/numpy/ndarrayobject.h +++ b/numpy/core/include/numpy/ndarrayobject.h @@ -77,7 +77,7 @@ typedef unsigned char npy_bool; #endif #ifndef Py_USING_UNICODE -#error Must use Python with unicode enabled. +#error Must use Python with unicode enabled. #endif @@ -205,7 +205,7 @@ typedef enum { NPY_WRAP=1, NPY_RAISE=2 } NPY_CLIPMODE; - + /* Define bit-width array types and typedefs */ #define NPY_MAX_INT8 127 @@ -684,17 +684,15 @@ typedef int Py_ssize_t; /* Data buffer */ #define PyDataMem_NEW(size) ((char *)malloc(size)) - /* #define PyArrayMem_NEW(size) PyMem_NEW(char, size)*/ #define PyDataMem_FREE(ptr) free(ptr) - /* #define PyArrayMem_FREE(ptr) PyMem_Free(ptr) */ #define PyDataMem_RENEW(ptr,size) ((char *)realloc(ptr,size)) -#define NPY_USE_PYMEM 0 +#define NPY_USE_PYMEM 1 #if NPY_USE_PYMEM == 1 -#define PyArray_malloc PyObject_Malloc -#define PyArray_free PyObject_Free -#define PyArray_realloc PyObject_Realloc +#define PyArray_malloc PyMem_Malloc +#define PyArray_free PyMem_Free +#define PyArray_realloc PyMem_Realloc #else #define PyArray_malloc malloc #define PyArray_free free @@ -759,11 +757,11 @@ typedef struct { PyArray_CopySwapFunc *copyswap; /* Function to compare items */ - /* Can be NULL + /* Can be NULL */ PyArray_CompareFunc *compare; - /* Function to select largest + /* Function to select largest Can be NULL */ PyArray_ArgFunc *argmax; @@ -773,8 +771,8 @@ typedef struct { PyArray_DotFunc *dotfunc; /* Function to scan an ASCII file and - place a single value plus possible separator - Can be NULL + place a single value plus possible separator + Can be NULL */ PyArray_ScanFunc *scanfunc; @@ -790,7 +788,7 @@ typedef struct { /* Used for arange. Can be NULL.*/ PyArray_FillFunc *fill; - /* Function to fill arrays with scalar values + /* Function to fill arrays with scalar values Can be NULL*/ PyArray_FillWithScalarFunc *fillwithscalar; @@ -958,7 +956,7 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *); #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_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 @@ -972,7 +970,7 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *); /* So that ufunc buffers are aligned */ #define NPY_MIN_BUFSIZE ((int)sizeof(cdouble)) #define NPY_MAX_BUFSIZE (((int)sizeof(cdouble))*1000000) -#define NPY_BUFSIZE 10000 +#define NPY_BUFSIZE 10000 /* #define NPY_BUFSIZE 80*/ #define PyArray_MAX(a,b) (((a)>(b))?(a):(b)) @@ -1003,8 +1001,8 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *); #define NPY_ALLOW_C_API __save__ = PyGILState_Ensure(); #define NPY_DISABLE_C_API PyGILState_Release(__save__); #else -#define NPY_BEGIN_ALLOW_THREADS -#define NPY_END_ALLOW_THREADS +#define NPY_BEGIN_ALLOW_THREADS +#define NPY_END_ALLOW_THREADS #define NPY_BEGIN_THREADS_DEF #define NPY_BEGIN_THREADS #define NPY_END_THREADS @@ -1376,7 +1374,7 @@ typedef struct { int flags; /* how should be data interpreted. Valid flags are CONTIGUOUS (1), FORTRAN (2), ALIGNED (0x100), NOTSWAPPED (0x200), and - WRITEABLE (0x400). + WRITEABLE (0x400). ARR_HAS_DESCR (0x800) states that arrdescr field is present in structure */ npy_intp *shape; /* A length-nd array of shape information */ diff --git a/numpy/core/include/numpy/noprefix.h b/numpy/core/include/numpy/noprefix.h index 7fecb9270..8614e870d 100644 --- a/numpy/core/include/numpy/noprefix.h +++ b/numpy/core/include/numpy/noprefix.h @@ -1,7 +1,7 @@ #ifndef NPY_NOPREFIX_H #define NPY_NOPREFIX_H -/* You can directly include noprefix.h as a backward +/* You can directly include noprefix.h as a backward compatibility measure*/ #ifndef NPY_NO_PREFIX #include "ndarrayobject.h" @@ -58,10 +58,10 @@ compatibility measure*/ #define SIZEOF_INTP NPY_SIZEOF_INTP #define SIZEOF_UINTP NPY_SIZEOF_UINTP -#define LONGLONG_FMT NPY_LONGLONG_FMT -#define ULONGLONG_FMT NPY_ULONGLONG_FMT +#define LONGLONG_FMT NPY_LONGLONG_FMT +#define ULONGLONG_FMT NPY_ULONGLONG_FMT #define LONGLONG_SUFFIX NPY_LONGLONG_SUFFIX -#define ULONGLONG_SUFFIX NPY_ULONGLONG_SUFFIX(x) +#define ULONGLONG_SUFFIX NPY_ULONGLONG_SUFFIX(x) #define MAX_INT8 127 #define MIN_INT8 -128 @@ -99,16 +99,16 @@ compatibility measure*/ #define MAX_ULONGLONG NPY_MAX_ULONGLONG #define SIZEOF_LONGDOUBLE NPY_SIZEOF_LONGDOUBLE -#define SIZEOF_LONGLONG NPY_SIZEOF_LONGLONG -#define BITSOF_BOOL NPY_BITSOF_BOOL -#define BITSOF_CHAR NPY_BITSOF_CHAR -#define BITSOF_SHORT NPY_BITSOF_SHORT -#define BITSOF_INT NPY_BITSOF_INT -#define BITSOF_LONG NPY_BITSOF_LONG -#define BITSOF_LONGLONG NPY_BITSOF_LONGLONG -#define BITSOF_FLOAT NPY_BITSOF_FLOAT -#define BITSOF_DOUBLE NPY_BITSOF_DOUBLE -#define BITSOF_LONGDOUBLE NPY_BITSOF_LONGDOUBLE +#define SIZEOF_LONGLONG NPY_SIZEOF_LONGLONG +#define BITSOF_BOOL NPY_BITSOF_BOOL +#define BITSOF_CHAR NPY_BITSOF_CHAR +#define BITSOF_SHORT NPY_BITSOF_SHORT +#define BITSOF_INT NPY_BITSOF_INT +#define BITSOF_LONG NPY_BITSOF_LONG +#define BITSOF_LONGLONG NPY_BITSOF_LONGLONG +#define BITSOF_FLOAT NPY_BITSOF_FLOAT +#define BITSOF_DOUBLE NPY_BITSOF_DOUBLE +#define BITSOF_LONGDOUBLE NPY_BITSOF_LONGDOUBLE #define PyArray_UCS4 npy_ucs4 #define _pya_malloc PyArray_malloc @@ -116,11 +116,11 @@ compatibility measure*/ #define _pya_realloc PyArray_realloc #define BEGIN_THREADS_DEF NPY_BEGIN_THREADS_DEF -#define BEGIN_THREADS NPY_BEGIN_THREADS -#define END_THREADS NPY_END_THREADS -#define ALLOW_C_API_DEF NPY_ALLOW_C_API_DEF -#define ALLOW_C_API NPY_ALLOW_C_API -#define DISABLE_C_API NPY_DISABLE_C_API +#define BEGIN_THREADS NPY_BEGIN_THREADS +#define END_THREADS NPY_END_THREADS +#define ALLOW_C_API_DEF NPY_ALLOW_C_API_DEF +#define ALLOW_C_API NPY_ALLOW_C_API +#define DISABLE_C_API NPY_DISABLE_C_API #define PY_FAIL NPY_FAIL #define PY_SUCCEED NPY_SUCCEED @@ -136,31 +136,31 @@ compatibility measure*/ #define LONGDOUBLE_FMT NPY_LONGDOUBLE_FMT #define CONTIGUOUS NPY_CONTIGUOUS -#define FORTRAN NPY_FORTRAN -#define OWNDATA NPY_OWNDATA -#define FORCECAST NPY_FORCECAST -#define ENSURECOPY NPY_ENSURECOPY -#define ENSUREARRAY NPY_ENSUREARRAY -#define ELEMENTSTRIDES NPY_ELEMENTSTRIDES -#define ALIGNED NPY_ALIGNED -#define NOTSWAPPED NPY_NOTSWAPPED -#define WRITEABLE NPY_WRITEABLE -#define UPDATEIFCOPY NPY_UPDATEIFCOPY -#define ARR_HAS_DESCR NPY_ARR_HAS_DESCR -#define BEHAVED NPY_BEHAVED -#define BEHAVED_NS NPY_BEHAVED_NS -#define CARRAY NPY_CARRAY -#define CARRAY_RO NPY_CARRAY_RO -#define FARRAY NPY_FARRAY -#define FARRAY_RO NPY_FARRAY_RO -#define DEFAULT NPY_DEFAULT -#define IN_ARRAY NPY_IN_ARRAY -#define OUT_ARRAY NPY_OUT_ARRAY -#define INOUT_ARRAY NPY_INOUT_ARRAY -#define IN_FARRAY NPY_IN_FARRAY -#define OUT_FARRAY NPY_OUT_FARRAY -#define INOUT_FARRAY NPY_INOUT_FARRAY -#define UPDATE_ALL NPY_UPDATE_ALL +#define FORTRAN NPY_FORTRAN +#define OWNDATA NPY_OWNDATA +#define FORCECAST NPY_FORCECAST +#define ENSURECOPY NPY_ENSURECOPY +#define ENSUREARRAY NPY_ENSUREARRAY +#define ELEMENTSTRIDES NPY_ELEMENTSTRIDES +#define ALIGNED NPY_ALIGNED +#define NOTSWAPPED NPY_NOTSWAPPED +#define WRITEABLE NPY_WRITEABLE +#define UPDATEIFCOPY NPY_UPDATEIFCOPY +#define ARR_HAS_DESCR NPY_ARR_HAS_DESCR +#define BEHAVED NPY_BEHAVED +#define BEHAVED_NS NPY_BEHAVED_NS +#define CARRAY NPY_CARRAY +#define CARRAY_RO NPY_CARRAY_RO +#define FARRAY NPY_FARRAY +#define FARRAY_RO NPY_FARRAY_RO +#define DEFAULT NPY_DEFAULT +#define IN_ARRAY NPY_IN_ARRAY +#define OUT_ARRAY NPY_OUT_ARRAY +#define INOUT_ARRAY NPY_INOUT_ARRAY +#define IN_FARRAY NPY_IN_FARRAY +#define OUT_FARRAY NPY_OUT_FARRAY +#define INOUT_FARRAY NPY_INOUT_FARRAY +#define UPDATE_ALL NPY_UPDATE_ALL #define OWN_DATA NPY_OWNDATA #define BEHAVED_FLAGS NPY_BEHAVED @@ -186,4 +186,4 @@ compatibility measure*/ #define REFCOUNT PyArray_REFCOUNT #define MAX_ELSIZE NPY_MAX_ELSIZE -#endif +#endif diff --git a/numpy/core/include/numpy/old_defines.h b/numpy/core/include/numpy/old_defines.h index 1c270e04b..4ccb815ed 100644 --- a/numpy/core/include/numpy/old_defines.h +++ b/numpy/core/include/numpy/old_defines.h @@ -13,45 +13,45 @@ #define PyArray_TYPES NPY_TYPES #define PyArray_BOOL NPY_BOOL -#define PyArray_BYTE NPY_BYTE -#define PyArray_UBYTE NPY_UBYTE -#define PyArray_SHORT NPY_SHORT -#define PyArray_USHORT NPY_USHORT -#define PyArray_INT NPY_INT -#define PyArray_UINT NPY_UINT -#define PyArray_LONG NPY_LONG -#define PyArray_ULONG NPY_ULONG -#define PyArray_LONGLONG NPY_LONGLONG -#define PyArray_ULONGLONG NPY_ULONGLONG -#define PyArray_FLOAT NPY_FLOAT -#define PyArray_DOUBLE NPY_DOUBLE -#define PyArray_LONGDOUBLE NPY_LONGDOUBLE -#define PyArray_CFLOAT NPY_CFLOAT -#define PyArray_CDOUBLE NPY_CDOUBLE -#define PyArray_CLONGDOUBLE NPY_CLONGDOUBLE -#define PyArray_OBJECT NPY_OBJECT -#define PyArray_STRING NPY_STRING -#define PyArray_UNICODE NPY_UNICODE -#define PyArray_VOID NPY_VOID -#define PyArray_NTYPES NPY_NTYPES -#define PyArray_NOTYPE NPY_NOTYPE -#define PyArray_CHAR NPY_CHAR -#define PyArray_USERDEF NPY_USERDEF +#define PyArray_BYTE NPY_BYTE +#define PyArray_UBYTE NPY_UBYTE +#define PyArray_SHORT NPY_SHORT +#define PyArray_USHORT NPY_USHORT +#define PyArray_INT NPY_INT +#define PyArray_UINT NPY_UINT +#define PyArray_LONG NPY_LONG +#define PyArray_ULONG NPY_ULONG +#define PyArray_LONGLONG NPY_LONGLONG +#define PyArray_ULONGLONG NPY_ULONGLONG +#define PyArray_FLOAT NPY_FLOAT +#define PyArray_DOUBLE NPY_DOUBLE +#define PyArray_LONGDOUBLE NPY_LONGDOUBLE +#define PyArray_CFLOAT NPY_CFLOAT +#define PyArray_CDOUBLE NPY_CDOUBLE +#define PyArray_CLONGDOUBLE NPY_CLONGDOUBLE +#define PyArray_OBJECT NPY_OBJECT +#define PyArray_STRING NPY_STRING +#define PyArray_UNICODE NPY_UNICODE +#define PyArray_VOID NPY_VOID +#define PyArray_NTYPES NPY_NTYPES +#define PyArray_NOTYPE NPY_NOTYPE +#define PyArray_CHAR NPY_CHAR +#define PyArray_USERDEF NPY_USERDEF #define PyArray_NUMUSERTYPES NPY_NUMUSERTYPES #define PyArray_INTP NPY_INTP #define PyArray_UINTP NPY_UINTP -#define PyArray_INT8 NPY_INT8 -#define PyArray_UINT8 NPY_UINT8 -#define PyArray_INT16 NPY_INT16 -#define PyArray_UINT16 NPY_UINT16 -#define PyArray_INT32 NPY_INT32 -#define PyArray_UINT32 NPY_UINT32 +#define PyArray_INT8 NPY_INT8 +#define PyArray_UINT8 NPY_UINT8 +#define PyArray_INT16 NPY_INT16 +#define PyArray_UINT16 NPY_UINT16 +#define PyArray_INT32 NPY_INT32 +#define PyArray_UINT32 NPY_UINT32 #ifdef NPY_INT64 -#define PyArray_INT64 NPY_INT64 -#define PyArray_UINT64 NPY_UINT64 +#define PyArray_INT64 NPY_INT64 +#define PyArray_UINT64 NPY_UINT64 #endif #ifdef NPY_INT128 @@ -86,36 +86,36 @@ #define PyArray_TYPECHAR NPY_TYPECHAR -#define PyArray_BOOLLTR NPY_BOOLLTR -#define PyArray_BYTELTR NPY_BYTELTR -#define PyArray_UBYTELTR NPY_UBYTELTR -#define PyArray_SHORTLTR NPY_SHORTLTR -#define PyArray_USHORTLTR NPY_USHORTLTR -#define PyArray_INTLTR NPY_INTLTR -#define PyArray_UINTLTR NPY_UINTLTR -#define PyArray_LONGLTR NPY_LONGLTR -#define PyArray_ULONGLTR NPY_ULONGLTR -#define PyArray_LONGLONGLTR NPY_LONGLONGLTR -#define PyArray_ULONGLONGLTR NPY_ULONGLONGLTR -#define PyArray_FLOATLTR NPY_FLOATLTR -#define PyArray_DOUBLELTR NPY_DOUBLELTR -#define PyArray_LONGDOUBLELTR NPY_LONGDOUBLELTR -#define PyArray_CFLOATLTR NPY_CFLOATLTR -#define PyArray_CDOUBLELTR NPY_CDOUBLELTR -#define PyArray_CLONGDOUBLELTR NPY_CLONGDOUBLELTR -#define PyArray_OBJECTLTR NPY_OBJECTLTR -#define PyArray_STRINGLTR NPY_STRINGLTR -#define PyArray_STRINGLTR2 NPY_STRINGLTR2 -#define PyArray_UNICODELTR NPY_UNICODELTR -#define PyArray_VOIDLTR NPY_VOIDLTR -#define PyArray_CHARLTR NPY_CHARLTR -#define PyArray_INTPLTR NPY_INTPLTR -#define PyArray_UINTPLTR NPY_UINTPLTR -#define PyArray_GENBOOLLTR NPY_GENBOOLLTR -#define PyArray_SIGNEDLTR NPY_SIGNEDLTR -#define PyArray_UNSIGNEDLTR NPY_UNSIGNEDLTR -#define PyArray_FLOATINGLTR NPY_FLOATINGLTR -#define PyArray_COMPLEXLTR NPY_COMPLEXLTR +#define PyArray_BOOLLTR NPY_BOOLLTR +#define PyArray_BYTELTR NPY_BYTELTR +#define PyArray_UBYTELTR NPY_UBYTELTR +#define PyArray_SHORTLTR NPY_SHORTLTR +#define PyArray_USHORTLTR NPY_USHORTLTR +#define PyArray_INTLTR NPY_INTLTR +#define PyArray_UINTLTR NPY_UINTLTR +#define PyArray_LONGLTR NPY_LONGLTR +#define PyArray_ULONGLTR NPY_ULONGLTR +#define PyArray_LONGLONGLTR NPY_LONGLONGLTR +#define PyArray_ULONGLONGLTR NPY_ULONGLONGLTR +#define PyArray_FLOATLTR NPY_FLOATLTR +#define PyArray_DOUBLELTR NPY_DOUBLELTR +#define PyArray_LONGDOUBLELTR NPY_LONGDOUBLELTR +#define PyArray_CFLOATLTR NPY_CFLOATLTR +#define PyArray_CDOUBLELTR NPY_CDOUBLELTR +#define PyArray_CLONGDOUBLELTR NPY_CLONGDOUBLELTR +#define PyArray_OBJECTLTR NPY_OBJECTLTR +#define PyArray_STRINGLTR NPY_STRINGLTR +#define PyArray_STRINGLTR2 NPY_STRINGLTR2 +#define PyArray_UNICODELTR NPY_UNICODELTR +#define PyArray_VOIDLTR NPY_VOIDLTR +#define PyArray_CHARLTR NPY_CHARLTR +#define PyArray_INTPLTR NPY_INTPLTR +#define PyArray_UINTPLTR NPY_UINTPLTR +#define PyArray_GENBOOLLTR NPY_GENBOOLLTR +#define PyArray_SIGNEDLTR NPY_SIGNEDLTR +#define PyArray_UNSIGNEDLTR NPY_UNSIGNEDLTR +#define PyArray_FLOATINGLTR NPY_FLOATINGLTR +#define PyArray_COMPLEXLTR NPY_COMPLEXLTR #define PyArray_QUICKSORT NPY_QUICKSORT #define PyArray_HEAPSORT NPY_HEAPSORT @@ -123,35 +123,35 @@ #define PyArray_SORTKIND NPY_SORTKIND #define PyArray_NSORTS NPY_NSORTS -#define PyArray_NOSCALAR NPY_NOSCALAR -#define PyArray_BOOL_SCALAR NPY_BOOL_SCALAR -#define PyArray_INTPOS_SCALAR NPY_INTPOS_SCALAR -#define PyArray_INTNEG_SCALAR NPY_INTNEG_SCALAR -#define PyArray_FLOAT_SCALAR NPY_FLOAT_SCALAR -#define PyArray_COMPLEX_SCALAR NPY_COMPLEX_SCALAR -#define PyArray_OBJECT_SCALAR NPY_OBJECT_SCALAR -#define PyArray_SCALARKIND NPY_SCALARKIND -#define PyArray_NSCALARKINDS NPY_NSCALARKINDS - -#define PyArray_ANYORDER NPY_ANYORDER +#define PyArray_NOSCALAR NPY_NOSCALAR +#define PyArray_BOOL_SCALAR NPY_BOOL_SCALAR +#define PyArray_INTPOS_SCALAR NPY_INTPOS_SCALAR +#define PyArray_INTNEG_SCALAR NPY_INTNEG_SCALAR +#define PyArray_FLOAT_SCALAR NPY_FLOAT_SCALAR +#define PyArray_COMPLEX_SCALAR NPY_COMPLEX_SCALAR +#define PyArray_OBJECT_SCALAR NPY_OBJECT_SCALAR +#define PyArray_SCALARKIND NPY_SCALARKIND +#define PyArray_NSCALARKINDS NPY_NSCALARKINDS + +#define PyArray_ANYORDER NPY_ANYORDER #define PyArray_CORDER NPY_CORDER -#define PyArray_FORTRANORDER NPY_FORTRANORDER -#define PyArray_ORDER NPY_ORDER - -#define PyDescr_ISBOOL PyDataType_ISBOOL -#define PyDescr_ISUNSIGNED PyDataType_ISUNSIGNED -#define PyDescr_ISSIGNED PyDataType_ISSIGNED -#define PyDescr_ISINTEGER PyDataType_ISINTEGER -#define PyDescr_ISFLOAT PyDataType_ISFLOAT -#define PyDescr_ISNUMBER PyDataType_ISNUMBER -#define PyDescr_ISSTRING PyDataType_ISSTRING -#define PyDescr_ISCOMPLEX PyDataType_ISCOMPLEX -#define PyDescr_ISPYTHON PyDataType_ISPYTHON -#define PyDescr_ISFLEXIBLE PyDataType_ISFLEXIBLE -#define PyDescr_ISUSERDEF PyDataType_ISUSERDEF -#define PyDescr_ISEXTENDED PyDataType_ISEXTENDED -#define PyDescr_ISOBJECT PyDataType_ISOBJECT -#define PyDescr_HASFIELDS PyDataType_HASFIELDS +#define PyArray_FORTRANORDER NPY_FORTRANORDER +#define PyArray_ORDER NPY_ORDER + +#define PyDescr_ISBOOL PyDataType_ISBOOL +#define PyDescr_ISUNSIGNED PyDataType_ISUNSIGNED +#define PyDescr_ISSIGNED PyDataType_ISSIGNED +#define PyDescr_ISINTEGER PyDataType_ISINTEGER +#define PyDescr_ISFLOAT PyDataType_ISFLOAT +#define PyDescr_ISNUMBER PyDataType_ISNUMBER +#define PyDescr_ISSTRING PyDataType_ISSTRING +#define PyDescr_ISCOMPLEX PyDataType_ISCOMPLEX +#define PyDescr_ISPYTHON PyDataType_ISPYTHON +#define PyDescr_ISFLEXIBLE PyDataType_ISFLEXIBLE +#define PyDescr_ISUSERDEF PyDataType_ISUSERDEF +#define PyDescr_ISEXTENDED PyDataType_ISEXTENDED +#define PyDescr_ISOBJECT PyDataType_ISOBJECT +#define PyDescr_HASFIELDS PyDataType_HASFIELDS #define PyArray_LITTLE NPY_LITTLE #define PyArray_BIG NPY_BIG @@ -163,6 +163,6 @@ #define PyArray_OPPBYTE NPY_OPPBYTE #define NPY_REFCOUNT PyArray_REFCOUNT -#define PyArray_MAX_ELSIZE NPY_MAX_ELSIZE +#define PyArray_MAX_ELSIZE NPY_MAX_ELSIZE #define PyArray_USE_PYMEM NPY_USE_PYMEM diff --git a/numpy/core/include/numpy/oldnumeric.h b/numpy/core/include/numpy/oldnumeric.h index fd0553de8..780d58227 100644 --- a/numpy/core/include/numpy/oldnumeric.h +++ b/numpy/core/include/numpy/oldnumeric.h @@ -16,7 +16,3 @@ #define OWN_DATA NPY_OWNDATA #define SAVESPACE 0 #define SAVESPACEBIT 0 - - - - diff --git a/numpy/core/include/numpy/ufuncobject.h b/numpy/core/include/numpy/ufuncobject.h index 2446f5431..544e1d68c 100644 --- a/numpy/core/include/numpy/ufuncobject.h +++ b/numpy/core/include/numpy/ufuncobject.h @@ -38,7 +38,7 @@ typedef struct { #define UFUNC_SHIFT_DIVIDEBYZERO 0 #define UFUNC_SHIFT_OVERFLOW 2 #define UFUNC_SHIFT_UNDERFLOW 4 -#define UFUNC_SHIFT_INVALID 6 +#define UFUNC_SHIFT_INVALID 6 /* platform-dependent code translates floating point @@ -48,28 +48,28 @@ typedef struct { #define UFUNC_FPE_OVERFLOW 2 #define UFUNC_FPE_UNDERFLOW 4 #define UFUNC_FPE_INVALID 8 - + #define UFUNC_ERR_DEFAULT 0 /* Default error mode */ /* Only internal -- not exported, yet*/ typedef struct { - /* Multi-iterator portion --- needs to be present in this order + /* Multi-iterator portion --- needs to be present in this order to work with PyArray_Broadcast */ PyObject_HEAD int numiter; npy_intp size; npy_intp index; int nd; - npy_intp dimensions[NPY_MAXDIMS]; + npy_intp dimensions[NPY_MAXDIMS]; PyArrayIterObject *iters[NPY_MAXARGS]; /* End of Multi-iterator portion */ /* The ufunc */ PyUFuncObject *ufunc; - + /* The error handling */ int errormask; /* Integer showing desired error handling */ - PyObject *errobj; /* currently a tuple with + PyObject *errobj; /* currently a tuple with (string, func or None) */ @@ -85,7 +85,7 @@ typedef struct { int leftover; int ninnerloops; int lastdim; - + /* Whether or not to swap */ int swap[NPY_MAXARGS]; @@ -102,16 +102,16 @@ typedef struct { /* usually points to buffer but when a cast is to be done it switches for that argument to castbuf. */ - char *bufptr[NPY_MAXARGS]; + char *bufptr[NPY_MAXARGS]; /* Steps filled in from iters or sizeof(item) - depending on loop method. + depending on loop method. */ npy_intp steps[NPY_MAXARGS]; int obj; /* This loop uses object arrays */ - int notimplemented; /* The loop caused notimplemented */ - int objfunc; /* This loop calls object functions + int notimplemented; /* The loop caused notimplemented */ + int objfunc; /* This loop calls object functions (an inner-loop function with argument types */ } PyUFuncLoopObject; @@ -218,9 +218,9 @@ typedef struct { | ((IEEE_STATUS_UNF & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \ | ((IEEE_STATUS_INV & fpstatus) ? UFUNC_FPE_INVALID : 0); \ } - + /* MS Windows -----------------------------------------------------*/ -#elif defined(_MSC_VER) +#elif defined(_MSC_VER) #include <float.h> @@ -237,11 +237,11 @@ typedef struct { #define isinf(x) ((_fpclass((double)(x)) == _FPCLASS_PINF) || \ (_fpclass((double)(x)) == _FPCLASS_NINF)) #define isfinite(x) (_finite((double) x)) - + /* Solaris --------------------------------------------------------*/ /* --------ignoring SunOS ieee_flags approach, someone else can ** deal with that! */ -#elif defined(sun) || defined(__BSD__) || defined(__OpenBSD__) +#elif defined(sun) || defined(__BSD__) || defined(__OpenBSD__) #include <ieeefp.h> #define UFUNC_CHECK_STATUS(ret) { \ @@ -254,7 +254,7 @@ typedef struct { | ((FP_X_INV & fpstatus) ? UFUNC_FPE_INVALID : 0); \ (void) fpsetsticky(0); \ } - + #elif defined(linux) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__MINGW32__) #if defined(__GLIBC__) || defined(__APPLE__) || defined(__MINGW32__) @@ -276,7 +276,7 @@ typedef struct { #define generate_divbyzero_error() feraiseexcept(FE_DIVBYZERO) #define generate_overflow_error() feraiseexcept(FE_OVERFLOW) - + #elif defined(_AIX) #include <float.h> @@ -298,7 +298,7 @@ typedef struct { #else -#define NO_FLOATING_POINT_SUPPORT +#define NO_FLOATING_POINT_SUPPORT #define UFUNC_CHECK_STATUS(ret) { \ ret = 0; \ } @@ -319,7 +319,7 @@ static void generate_divbyzero_error(void) { return; else /* should never be called */ numeric_zero2 += 1; - return; + return; } #endif diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index 38ba262ea..8fcbd213e 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -374,11 +374,14 @@ def obj2sctype(rep, default=None): return _python_type(rep) if isinstance(rep, ndarray): return rep.dtype.type - res = sctypeDict.get(rep, default) - return res + try: + res = dtype(rep) + except: + return default + return res.type -# This dictionary allows look up based on any alias for an array type +# This dictionary allows look up based on any alias for an array data-type class _typedict(dict): def __getitem__(self, obj): return dict.__getitem__(self, obj2sctype(obj)) diff --git a/numpy/core/src/_isnan.c b/numpy/core/src/_isnan.c index f5965fbc7..3257c4ef2 100644 --- a/numpy/core/src/_isnan.c +++ b/numpy/core/src/_isnan.c @@ -1,6 +1,6 @@ /* Adapted from cephes */ -static int +static int isnan(double x) { union @@ -9,7 +9,7 @@ isnan(double x) unsigned short s[4]; unsigned int i[2]; } u; - + u.d = x; #if SIZEOF_INT == 4 @@ -39,9 +39,8 @@ isnan(double x) return 1; } #endif - + #endif /* SIZEOF_INT */ - + return 0; } - diff --git a/numpy/core/src/_signbit.c b/numpy/core/src/_signbit.c index d128cb1fb..48a808ac7 100644 --- a/numpy/core/src/_signbit.c +++ b/numpy/core/src/_signbit.c @@ -1,6 +1,6 @@ /* Adapted from cephes */ -static int +static int signbit(double x) { union @@ -9,7 +9,7 @@ signbit(double x) short s[4]; int i[2]; } u; - + u.d = x; #if SIZEOF_INT == 4 @@ -27,6 +27,6 @@ signbit(double x) #else return u.s[3] < 0; #endif - + #endif /* SIZEOF_INT */ } diff --git a/numpy/core/src/_sortmodule.c.src b/numpy/core/src/_sortmodule.c.src index dae2c6045..7dcf64829 100644 --- a/numpy/core/src/_sortmodule.c.src +++ b/numpy/core/src/_sortmodule.c.src @@ -2,12 +2,12 @@ /* The purpose of this module is to add faster sort functions that are type-specific. This is done by altering the - function table for the builtin descriptors. + function table for the builtin descriptors. - These sorting functions are copied almost directly from numarray - with a few modifications (complex comparisons compare the imaginary + These sorting functions are copied almost directly from numarray + with a few modifications (complex comparisons compare the imaginary part if the real parts are equal, for example), and the names - are changed. + are changed. The original sorting code is due to Charles R. Harris who wrote it for numarray. @@ -15,13 +15,13 @@ /* Quick sort is usually the fastest, but the worst case scenario can be slower than the merge and heap sorts. The merge sort requires - extra memory and so for large arrays may not be useful. - + extra memory and so for large arrays may not be useful. + The merge sort is *stable*, meaning that equal components are unmoved from their entry versions, so it can be used to - implement lexigraphic sorting on multiple keys. + implement lexigraphic sorting on multiple keys. - The heap sort is included for completeness. + The heap sort is included for completeness. */ @@ -159,7 +159,7 @@ static int static int @TYPE@_heapsort(@type@ *start, intp n, void *unused) { - + @type@ tmp, *a; intp i,j,l; @@ -287,7 +287,7 @@ static int pl = start; pr = pl + num - 1; pw = (@type@ *) PyDataMem_NEW(((1+num/2))*sizeof(@type@)); - + if (!pw) { PyErr_NoMemory(); return -1; @@ -298,7 +298,7 @@ static int return 0; } -static void +static void @TYPE@_amergesort0(intp *pl, intp *pr, @type@ *v, intp *pw) { @type@ vp; @@ -345,7 +345,7 @@ static int pl = tosort; pr = pl + num - 1; pw = PyDimMem_NEW((1+num/2)); - + if (!pw) { PyErr_NoMemory(); return -1; @@ -362,7 +362,7 @@ static int #comp=strncmp,PyArray_CompareUCS4# #type=char *, PyArray_UCS4 *# */ -static void +static void @TYPE@_amergesort0(intp *pl, intp *pr, @type@*v, intp *pw, int elsize) { @type@ vp; @@ -413,7 +413,7 @@ static int pl = tosort; pr = pl + num - 1; pw = PyDimMem_NEW((1+num/2)); - + if (!pw) { PyErr_NoMemory(); return -1; @@ -424,8 +424,8 @@ static int return 0; } /**end repeat**/ - -static void + +static void add_sortfuncs(void) { PyArray_Descr *descr; @@ -465,7 +465,7 @@ init_sort(void) { PyObject *m; m = Py_InitModule("_sort", methods); - + import_array(); add_sortfuncs(); } diff --git a/numpy/core/src/arraymethods.c b/numpy/core/src/arraymethods.c index b2e630498..9cbe5b455 100644 --- a/numpy/core/src/arraymethods.c +++ b/numpy/core/src/arraymethods.c @@ -6,16 +6,16 @@ static char doc_take[] = "a.take(indices, axis=None). Selects the elements "\ "in indices from array a along the given axis."; static PyObject * -array_take(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_take(PyArrayObject *self, PyObject *args, PyObject *kwds) { int dimension=MAX_DIMS; PyObject *indices; PyArrayObject *out=NULL; NPY_CLIPMODE mode=NPY_RAISE; static char *kwlist[] = {"indices", "axis", "out", "mode", NULL}; - + dimension=0; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&O&O&", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&O&O&", kwlist, &indices, PyArray_AxisConverter, &dimension, PyArray_OutputConverter, @@ -23,7 +23,7 @@ array_take(PyArrayObject *self, PyObject *args, PyObject *kwds) PyArray_ClipmodeConverter, &mode)) return NULL; - + return _ARET(PyArray_TakeFrom(self, indices, dimension, out, mode)); } @@ -46,12 +46,12 @@ static char doc_put[] = "a.put(values, indices, mode) sets a.flat[n] = v[n] "\ "will repeat."; static PyObject * -array_put(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_put(PyArrayObject *self, PyObject *args, PyObject *kwds) { PyObject *indices, *values; NPY_CLIPMODE mode=NPY_RAISE; static char *kwlist[] = {"values", "indices", "mode", NULL}; - + if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O&", kwlist, &values, &indices, PyArray_ClipmodeConverter, @@ -64,12 +64,12 @@ static char doc_putmask[] = "a.putmask(values, mask) sets a.flat[n] = v[n] "\ "for each n where mask.flat[n] is TRUE. v can be scalar."; static PyObject * -array_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) { PyObject *mask, *values; static char *kwlist[] = {"values", "mask", NULL}; - + if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO", kwlist, &values, &mask)) return NULL; @@ -77,20 +77,20 @@ array_putmask(PyArrayObject *self, PyObject *args, PyObject *kwds) } static char doc_reshape[] = \ - "self.reshape(d1, d2, ..., dn, order='C') \n" - "Return a new array from this one. \n" - "\n The new array must have the same number of elements as self. " + "self.reshape(d1, d2, ..., dn, order='C') \n" + "Return a new array from this one. \n" + "\n The new array must have the same number of elements as self. " "Also\n always returns a view or raises a ValueError if that is \n" "impossible."; static PyObject * -array_reshape(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_reshape(PyArrayObject *self, PyObject *args, PyObject *kwds) { PyArray_Dims newshape; PyObject *ret; PyArray_ORDER order=PyArray_CORDER; int n; - + if (kwds != NULL) { PyObject *ref; ref = PyDict_GetItemString(kwds, "order"); @@ -101,15 +101,15 @@ array_reshape(PyArrayObject *self, PyObject *args, PyObject *kwds) n = PyTuple_Size(args); if (n <= 1) { - if (!PyArg_ParseTuple(args, "O&", PyArray_IntpConverter, + if (!PyArg_ParseTuple(args, "O&", PyArray_IntpConverter, &newshape)) return NULL; } else { if (!PyArray_IntpConverter(args, &newshape)) { if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "invalid shape"); - } + } goto fail; } } @@ -143,13 +143,13 @@ array_view(PyArrayObject *self, PyObject *args) if (otype) { if (PyType_Check(otype) && \ - PyType_IsSubtype((PyTypeObject *)otype, + PyType_IsSubtype((PyTypeObject *)otype, &PyArray_Type)) { - return PyArray_View(self, NULL, + return PyArray_View(self, NULL, (PyTypeObject *)otype); } else { - if (PyArray_DescrConverter(otype, &type) == PY_FAIL) + if (PyArray_DescrConverter(otype, &type) == PY_FAIL) return NULL; } } @@ -159,76 +159,76 @@ array_view(PyArrayObject *self, PyObject *args) static char doc_argmax[] = "a.argmax(axis=None, out=None)"; static PyObject * -array_argmax(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_argmax(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, PyArray_AxisConverter, &axis, PyArray_OutputConverter, &out)) - return NULL; - + return NULL; + return _ARET(PyArray_ArgMax(self, axis, out)); } static char doc_argmin[] = "a.argmin(axis=None, out=None)"; static PyObject * -array_argmin(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_argmin(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, PyArray_AxisConverter, &axis, PyArray_OutputConverter, &out)) - return NULL; - + return NULL; + return _ARET(PyArray_ArgMin(self, axis, out)); } static char doc_max[] = "a.max(axis=None)"; static PyObject * -array_max(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_max(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, PyArray_AxisConverter, &axis, PyArray_OutputConverter, &out)) - return NULL; - + return NULL; + return PyArray_Max(self, axis, out); } static char doc_ptp[] = "a.ptp(axis=None) a.max(axis)-a.min(axis)"; static PyObject * -array_ptp(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_ptp(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, PyArray_AxisConverter, &axis, PyArray_OutputConverter, &out)) - return NULL; - + return NULL; + return PyArray_Ptp(self, axis, out); } @@ -236,19 +236,19 @@ array_ptp(PyArrayObject *self, PyObject *args, PyObject *kwds) static char doc_min[] = "a.min(axis=None)"; static PyObject * -array_min(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_min(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, PyArray_AxisConverter, &axis, PyArray_OutputConverter, &out)) - return NULL; - + return NULL; + return PyArray_Min(self, axis, out); } @@ -286,15 +286,15 @@ PyArray_GetField(PyArrayObject *self, PyArray_Descr *typed, int offset) Py_DECREF(typed); return NULL; } - ret = PyArray_NewFromDescr(self->ob_type, + ret = PyArray_NewFromDescr(self->ob_type, typed, self->nd, self->dimensions, - self->strides, + self->strides, self->data + offset, self->flags, (PyObject *)self); if (ret == NULL) return NULL; Py_INCREF(self); - ((PyArrayObject *)ret)->base = (PyObject *)self; + ((PyArrayObject *)ret)->base = (PyObject *)self; PyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL); return ret; @@ -307,11 +307,11 @@ array_getfield(PyArrayObject *self, PyObject *args, PyObject *kwds) PyArray_Descr *dtype; int offset = 0; static char *kwlist[] = {"dtype", "offset", 0}; - + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|i", kwlist, PyArray_DescrConverter, &dtype, &offset)) return NULL; - + return _ARET(PyArray_GetField(self, dtype, offset)); } @@ -328,7 +328,7 @@ PyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype, { PyObject *ret=NULL; int retval = 0; - + if (offset < 0 || (offset + dtype->elsize) > self->descr->elsize) { PyErr_Format(PyExc_ValueError, "Need 0 <= offset <= %d for requested type " \ @@ -337,7 +337,7 @@ PyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype, Py_DECREF(dtype); return -1; } - ret = PyArray_NewFromDescr(self->ob_type, + ret = PyArray_NewFromDescr(self->ob_type, dtype, self->nd, self->dimensions, self->strides, self->data + offset, self->flags, (PyObject *)self); @@ -345,7 +345,7 @@ PyArray_SetField(PyArrayObject *self, PyArray_Descr *dtype, Py_INCREF(self); ((PyArrayObject *)ret)->base = (PyObject *)self; - PyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL); + PyArray_UpdateFlags((PyArrayObject *)ret, UPDATE_ALL); retval = PyArray_CopyObject((PyArrayObject *)ret, val); Py_DECREF(ret); return retval; @@ -358,7 +358,7 @@ array_setfield(PyArrayObject *self, PyObject *args, PyObject *kwds) int offset = 0; PyObject *value; static char *kwlist[] = {"value", "dtype", "offset", 0}; - + if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&|i", kwlist, &value, PyArray_DescrConverter, &dtype, &offset)) return NULL; @@ -406,13 +406,13 @@ PyArray_Byteswap(PyArrayObject *self, Bool inplace) } Py_DECREF(it); } - + Py_INCREF(self); return (PyObject *)self; } else { PyObject *new; - if ((ret = (PyArrayObject *)PyArray_NewCopy(self,-1)) == NULL) + if ((ret = (PyArrayObject *)PyArray_NewCopy(self,-1)) == NULL) return NULL; new = PyArray_Byteswap(ret, TRUE); Py_DECREF(new); @@ -425,13 +425,13 @@ static char doc_byteswap[] = "m.byteswap(False) Swap the bytes in"\ " is TRUE, byteswap in-place and return a reference to self."; static PyObject * -array_byteswap(PyArrayObject *self, PyObject *args) +array_byteswap(PyArrayObject *self, PyObject *args) { Bool inplace=FALSE; - + if (!PyArg_ParseTuple(args, "|O&", PyArray_BoolConverter, &inplace)) return NULL; - + return PyArray_Byteswap(self, inplace); } @@ -439,9 +439,9 @@ static char doc_tolist[] = "m.tolist(). Copy the data portion of the array"\ " to a hierarchical python list and return that list."; static PyObject * -array_tolist(PyArrayObject *self, PyObject *args) +array_tolist(PyArrayObject *self, PyObject *args) { - if (!PyArg_ParseTuple(args, "")) return NULL; + if (!PyArg_ParseTuple(args, "")) return NULL; return PyArray_ToList(self); } @@ -453,7 +453,7 @@ array_tostring(PyArrayObject *self, PyObject *args, PyObject *kwds) { NPY_ORDER order=NPY_CORDER; static char *kwlist[] = {"order", NULL}; - + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kwlist, PyArray_OrderConverter, &order)) return NULL; @@ -471,8 +471,8 @@ array_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds) char *sep=""; char *format=""; static char *kwlist[] = {"file", "sep", "format", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ss", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ss", kwlist, &file, &sep, &format)) return NULL; if (PyString_Check(file) || PyUnicode_Check(file)) { @@ -503,7 +503,7 @@ static char doc_toscalar[] = "m.item(). Copy the first data point of "\ static PyObject * array_toscalar(PyArrayObject *self, PyObject *args) { if (!PyArg_ParseTuple(args, "")) return NULL; - if (self->nd == 0 || PyArray_SIZE(self) == 1) + if (self->nd == 0 || PyArray_SIZE(self) == 1) return self->descr->f->getitem(self->data, self); else { PyErr_SetString(PyExc_ValueError, "can only convert an" \ @@ -517,14 +517,14 @@ static char doc_cast[] = "m.astype(t). Cast array m to type t. \n\n"\ " object of type int, float, or complex."; static PyObject * -array_cast(PyArrayObject *self, PyObject *args) +array_cast(PyArrayObject *self, PyObject *args) { PyArray_Descr *descr=NULL; PyObject *obj; - + if (!PyArg_ParseTuple(args, "O&", PyArray_DescrConverter, &descr)) return NULL; - + if (descr == self->descr) { obj = _ARET(PyArray_NewCopy(self,0)); Py_XDECREF(descr); @@ -534,7 +534,7 @@ array_cast(PyArrayObject *self, PyObject *args) return PyArray_FromArray(self, descr, NPY_FORCECAST); } return _ARET(PyArray_CastToType(self, descr, 0)); -} +} /* default sub-type implementation */ @@ -546,7 +546,7 @@ array_wraparray(PyArrayObject *self, PyObject *args) { PyObject *arr; PyObject *ret; - + if (PyTuple_Size(args) < 1) { PyErr_SetString(PyExc_TypeError, "only accepts 1 argument"); @@ -557,13 +557,13 @@ array_wraparray(PyArrayObject *self, PyObject *args) PyErr_SetString(PyExc_TypeError, "can only be called with ndarray object"); return NULL; - } + } Py_INCREF(PyArray_DESCR(arr)); - ret = PyArray_NewFromDescr(self->ob_type, + ret = PyArray_NewFromDescr(self->ob_type, PyArray_DESCR(arr), PyArray_NDIM(arr), - PyArray_DIMS(arr), + PyArray_DIMS(arr), PyArray_STRIDES(arr), PyArray_DATA(arr), PyArray_FLAGS(arr), (PyObject *)self); if (ret == NULL) return NULL; @@ -576,14 +576,14 @@ array_wraparray(PyArrayObject *self, PyObject *args) static char doc_array_getarray[] = "m.__array__(|dtype) just returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array."; static PyObject * -array_getarray(PyArrayObject *self, PyObject *args) +array_getarray(PyArrayObject *self, PyObject *args) { PyArray_Descr *newtype=NULL; PyObject *ret; - + if (!PyArg_ParseTuple(args, "|O&", PyArray_DescrConverter, &newtype)) return NULL; - + /* convert to PyArray_Type */ if (!PyArray_CheckExact(self)) { PyObject *new; @@ -592,13 +592,13 @@ array_getarray(PyArrayObject *self, PyObject *args) if (!PyType_IsSubtype(self->ob_type, &PyArray_Type)) { subtype = &PyArray_Type; } - + Py_INCREF(PyArray_DESCR(self)); - new = PyArray_NewFromDescr(subtype, + new = PyArray_NewFromDescr(subtype, PyArray_DESCR(self), PyArray_NDIM(self), - PyArray_DIMS(self), - PyArray_STRIDES(self), + PyArray_DIMS(self), + PyArray_STRIDES(self), PyArray_DATA(self), PyArray_FLAGS(self), NULL); if (new == NULL) return NULL; @@ -609,7 +609,7 @@ array_getarray(PyArrayObject *self, PyObject *args) else { Py_INCREF(self); } - + if ((newtype == NULL) || \ PyArray_EquivTypes(self->descr, newtype)) { return (PyObject *)self; @@ -628,12 +628,12 @@ static char doc_copy[] = "m.copy(|order). Return a copy of the array.\n"\ "only if m is already in fortran order."; static PyObject * -array_copy(PyArrayObject *self, PyObject *args) +array_copy(PyArrayObject *self, PyObject *args) { PyArray_ORDER fortran=PyArray_CORDER; if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter, &fortran)) return NULL; - + return PyArray_NewCopy(self, fortran); } @@ -643,14 +643,14 @@ static char doc_resize[] = "self.resize(new_shape, refcheck=True, order=False). "arrays\n Returns None."; static PyObject * -array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds) { PyArray_Dims newshape; PyObject *ret; int n; int refcheck = 1; PyArray_ORDER fortran=PyArray_ANYORDER; - + if (kwds != NULL) { PyObject *ref; ref = PyDict_GetItemString(kwds, "refcheck"); @@ -661,24 +661,24 @@ array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds) } } ref = PyDict_GetItemString(kwds, "order"); - if (ref != NULL || + if (ref != NULL || (PyArray_OrderConverter(ref, &fortran) == PY_FAIL)) return NULL; } n = PyTuple_Size(args); if (n <= 1) { - if (!PyArg_ParseTuple(args, "O&", PyArray_IntpConverter, + if (!PyArg_ParseTuple(args, "O&", PyArray_IntpConverter, &newshape)) return NULL; } else { if (!PyArray_IntpConverter(args, &newshape)) { if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "invalid shape"); - } - return NULL; + } + return NULL; } - } + } ret = PyArray_Resize(self, &newshape, refcheck, fortran); PyDimMem_FREE(newshape.ptr); if (ret == NULL) return NULL; @@ -697,11 +697,11 @@ array_repeat(PyArrayObject *self, PyObject *args, PyObject *kwds) { PyObject *repeats; int axis=MAX_DIMS; static char *kwlist[] = {"repeats", "axis", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&", kwlist, &repeats, PyArray_AxisConverter, &axis)) return NULL; - + return _ARET(PyArray_Repeat(self, repeats, axis)); } @@ -714,13 +714,13 @@ static char doc_choose[] = "a.choose(b0, b1, ..., bn, out=None, mode='raise')\n" "an integer array with entries from 0 to n+1."; static PyObject * -array_choose(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_choose(PyArrayObject *self, PyObject *args, PyObject *kwds) { PyObject *choices; int n; PyArrayObject *out=NULL; NPY_CLIPMODE clipmode=NPY_RAISE; - + n = PyTuple_Size(args); if (n <= 1) { if (!PyArg_ParseTuple(args, "O", &choices)) @@ -730,33 +730,33 @@ array_choose(PyArrayObject *self, PyObject *args, PyObject *kwds) choices = args; } if (kwds && PyDict_Check(kwds)) { - if (PyArray_OutputConverter(PyDict_GetItemString(kwds, + if (PyArray_OutputConverter(PyDict_GetItemString(kwds, "out"), &out) == PY_FAIL) return NULL; - if (PyArray_ClipmodeConverter(PyDict_GetItemString(kwds, - "mode"), + if (PyArray_ClipmodeConverter(PyDict_GetItemString(kwds, + "mode"), &clipmode) == PY_FAIL) return NULL; } - + return _ARET(PyArray_Choose(self, choices, out, clipmode)); } static char doc_sort[] = "a.sort(axis=-1,kind='quicksort') sorts in place along axis. Return is None and kind can be 'quicksort', 'mergesort', or 'heapsort'"; static PyObject * -array_sort(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_sort(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=-1; int val; PyArray_SORTKIND which=PyArray_QUICKSORT; static char *kwlist[] = {"axis", "kind", NULL}; - + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO&", kwlist, &axis, PyArray_SortkindConverter, &which)) return NULL; - + val = PyArray_Sort(self, axis, which); if (val < 0) return NULL; Py_INCREF(Py_None); @@ -768,16 +768,16 @@ static char doc_argsort[] = "a.argsort(axis=-1,kind='quicksort')\n"\ " given axis; kind can be 'quicksort', 'mergesort', or 'heapsort'"; static PyObject * -array_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_argsort(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=-1; PyArray_SORTKIND which=PyArray_QUICKSORT; static char *kwlist[] = {"axis", "kind", NULL}; - + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iO&", kwlist, &axis, PyArray_SortkindConverter, &which)) return NULL; - + return _ARET(PyArray_ArgSort(self, axis, which)); } @@ -790,12 +790,12 @@ static char doc_searchsorted[] = "a.searchsorted(v)\n"\ " in ascending order."; static PyObject * -array_searchsorted(PyArrayObject *self, PyObject *args) +array_searchsorted(PyArrayObject *self, PyObject *args) { PyObject *values; - + if (!PyArg_ParseTuple(args, "O", &values)) return NULL; - + return _ARET(PyArray_SearchSorted(self, values)); } @@ -811,7 +811,7 @@ _deepcopy_call(char *iptr, char *optr, PyArray_Descr *dtype, otemp = (PyObject **)optr; Py_XINCREF(*itemp); /* call deepcopy on this argument */ - res = PyObject_CallFunctionObjArgs(deepcopy, + res = PyObject_CallFunctionObjArgs(deepcopy, *itemp, visit, NULL); Py_XDECREF(*itemp); Py_XDECREF(*otemp); @@ -822,7 +822,7 @@ _deepcopy_call(char *iptr, char *optr, PyArray_Descr *dtype, PyArray_Descr *new; int offset, pos=0; while (PyDict_Next(dtype->fields, &pos, &key, &value)) { - if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, + if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) return; _deepcopy_call(iptr + offset, optr + offset, new, deepcopy, visit); @@ -833,7 +833,7 @@ _deepcopy_call(char *iptr, char *optr, PyArray_Descr *dtype, static char doc_deepcopy[] = "Used if copy.deepcopy is called on an array."; static PyObject * -array_deepcopy(PyArrayObject *self, PyObject *args) +array_deepcopy(PyArrayObject *self, PyObject *args) { PyObject* visit; char *optr; @@ -929,15 +929,15 @@ array_reduce(PyArrayObject *self, PyObject *args) obj = PyObject_GetAttrString(mod, "_reconstruct"); Py_DECREF(mod); PyTuple_SET_ITEM(ret, 0, obj); - PyTuple_SET_ITEM(ret, 1, + PyTuple_SET_ITEM(ret, 1, Py_BuildValue("ONc", (PyObject *)self->ob_type, Py_BuildValue("(N)", PyInt_FromLong(0)), /* dummy data-type */ 'b')); - - /* Now fill in object's state. This is a tuple with + + /* Now fill in object's state. This is a tuple with 5 arguments 1) an integer with the pickle version. @@ -947,7 +947,7 @@ array_reduce(PyArrayObject *self, PyObject *args) 5) a Python object representing the data (a string, or a list or any user-defined object). - Notice because Python does not describe a mechanism to write + Notice because Python does not describe a mechanism to write raw data to the pickle, this performs a copy to a string first */ @@ -956,7 +956,7 @@ array_reduce(PyArrayObject *self, PyObject *args) Py_DECREF(ret); return NULL; } PyTuple_SET_ITEM(state, 0, PyInt_FromLong(version)); - PyTuple_SET_ITEM(state, 1, PyObject_GetAttrString((PyObject *)self, + PyTuple_SET_ITEM(state, 1, PyObject_GetAttrString((PyObject *)self, "shape")); descr = self->descr; Py_INCREF(descr); @@ -986,12 +986,12 @@ static char doc_setstate[] = "a.__setstate__(tuple) for unpickling."; 1) a Tuple giving the shape 2) a PyArray_Descr Object 3) a Bool stating if Fortran or not - 4) a binary string with the data (or a list if Object array) + 4) a binary string with the data (or a list if Object array) */ static size_t _array_fill_strides(intp *, intp *, int, size_t, int, int *); -static int _IsAligned(PyArrayObject *); +static int _IsAligned(PyArrayObject *); static PyArray_Descr * _array_typedescr_fromstr(char *); @@ -1007,7 +1007,7 @@ array_setstate(PyArrayObject *self, PyObject *args) int len; intp size, dimensions[MAX_DIMS]; int nd; - + /* This will free any memory associated with a and use the string in setstate as the (writeable) memory. */ @@ -1017,7 +1017,7 @@ array_setstate(PyArrayObject *self, PyObject *args) PyErr_Clear(); version = 0; if (!PyArg_ParseTuple(args, "(O!O!iO)", &PyTuple_Type, - &shape, &PyArrayDescr_Type, &typecode, + &shape, &PyArrayDescr_Type, &typecode, &fortran, &rawdata)) { return NULL; } @@ -1050,14 +1050,14 @@ array_setstate(PyArrayObject *self, PyObject *args) if (typecode->hasobject || typecode->f->listpickle) { if (!PyList_Check(rawdata)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "object pickle not returning list"); return NULL; } } else { if (!PyString_Check(rawdata)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "pickle not returning string"); return NULL; } @@ -1066,7 +1066,7 @@ array_setstate(PyArrayObject *self, PyObject *args) return NULL; if ((len != (self->descr->elsize * size))) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "buffer size does not" \ " match array size"); return NULL; @@ -1083,7 +1083,7 @@ array_setstate(PyArrayObject *self, PyObject *args) self->flags &= ~UPDATEIFCOPY; if (self->dimensions != NULL) { - PyDimMem_FREE(self->dimensions); + PyDimMem_FREE(self->dimensions); self->dimensions = NULL; } @@ -1096,7 +1096,7 @@ array_setstate(PyArrayObject *self, PyObject *args) self->strides = self->dimensions + nd; memcpy(self->dimensions, dimensions, sizeof(intp)*nd); (void) _array_fill_strides(self->strides, dimensions, nd, - (size_t) self->descr->elsize, + (size_t) self->descr->elsize, (fortran ? FORTRAN : CONTIGUOUS), &(self->flags)); } @@ -1122,7 +1122,7 @@ array_setstate(PyArrayObject *self, PyObject *args) } else { self->descr = PyArray_DescrNew(typecode); - if (self->descr->byteorder == PyArray_BIG) + if (self->descr->byteorder == PyArray_BIG) self->descr->byteorder = PyArray_LITTLE; else if (self->descr->byteorder == PyArray_LITTLE) self->descr->byteorder = PyArray_BIG; @@ -1142,7 +1142,7 @@ array_setstate(PyArrayObject *self, PyObject *args) } else { self->data = PyDataMem_NEW(PyArray_NBYTES(self)); - if (self->data == NULL) { + if (self->data == NULL) { self->nd = 0; self->data = PyDataMem_NEW(self->descr->elsize); if (self->dimensions) PyDimMem_FREE(self->dimensions); @@ -1151,14 +1151,14 @@ array_setstate(PyArrayObject *self, PyObject *args) if (self->descr->hasobject) memset(self->data, 0, PyArray_NBYTES(self)); self->flags |= OWNDATA; self->base = NULL; - if (_setlist_pkl(self, rawdata) < 0) + if (_setlist_pkl(self, rawdata) < 0) return NULL; } PyArray_UpdateFlags(self, UPDATE_ALL); - + Py_INCREF(Py_None); - return Py_None; + return Py_None; } /*OBJECT_API*/ @@ -1177,7 +1177,7 @@ PyArray_Dump(PyObject *self, PyObject *file, int protocol) if (file==NULL) return -1; } else Py_INCREF(file); - ret = PyObject_CallMethod(cpick, "dump", "OOi", self, + ret = PyObject_CallMethod(cpick, "dump", "OOi", self, file, protocol); Py_XDECREF(ret); Py_DECREF(file); @@ -1251,7 +1251,7 @@ static char doc_transpose[] = "a.transpose(*axes)\n\n" ; static PyObject * -array_transpose(PyArrayObject *self, PyObject *args) +array_transpose(PyArrayObject *self, PyObject *args) { PyObject *shape=Py_None; int n; @@ -1261,7 +1261,7 @@ array_transpose(PyArrayObject *self, PyObject *args) n = PyTuple_Size(args); if (n > 1) shape = args; else if (n == 1) shape = PyTuple_GET_ITEM(args, 0); - + if (shape == Py_None) ret = PyArray_Transpose(self, NULL); else { @@ -1269,7 +1269,7 @@ array_transpose(PyArrayObject *self, PyObject *args) ret = PyArray_Transpose(self, &permute); PyDimMem_FREE(permute.ptr); } - + return _ARET(ret); } @@ -1289,15 +1289,15 @@ static char doc_mean[] = "a.mean(axis=None, dtype=None)\n\n"\ #define _CHKTYPENUM(typ) ((typ) ? (typ)->type_num : PyArray_NOTYPE) static PyObject * -array_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_mean(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArray_Descr *dtype=NULL; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "dtype", "out", NULL}; - + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist, - PyArray_AxisConverter, + PyArray_AxisConverter, &axis, PyArray_DescrConverter2, &dtype, PyArray_OutputConverter, @@ -1331,20 +1331,20 @@ static char doc_sum[] = "a.sum(axis=None, dtype=None)\n\n"\ "array([1, 5])"; static PyObject * -array_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArray_Descr *dtype=NULL; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "dtype", "out", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist, - PyArray_AxisConverter, + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist, + PyArray_AxisConverter, &axis, PyArray_DescrConverter2, &dtype, PyArray_OutputConverter, &out)) return NULL; - + return PyArray_Sum(self, axis, _CHKTYPENUM(dtype), out); } @@ -1352,40 +1352,40 @@ array_sum(PyArrayObject *self, PyObject *args, PyObject *kwds) static char doc_cumsum[] = "a.cumsum(axis=None, dtype=None, out=None)"; static PyObject * -array_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_cumsum(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArray_Descr *dtype=NULL; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "dtype", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist, - PyArray_AxisConverter, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist, + PyArray_AxisConverter, &axis, PyArray_DescrConverter2, &dtype, PyArray_OutputConverter, &out)) return NULL; - + return PyArray_CumSum(self, axis, _CHKTYPENUM(dtype), out); } static char doc_prod[] = "a.prod(axis=None, dtype=None)"; static PyObject * -array_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArray_Descr *dtype=NULL; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "dtype", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist, - PyArray_AxisConverter, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist, + PyArray_AxisConverter, &axis, PyArray_DescrConverter2, &dtype, PyArray_OutputConverter, &out)) return NULL; - + return PyArray_Prod(self, axis, _CHKTYPENUM(dtype), out); } @@ -1393,20 +1393,20 @@ array_prod(PyArrayObject *self, PyObject *args, PyObject *kwds) static char doc_cumprod[] = "a.cumprod(axis=None, dtype=None)"; static PyObject * -array_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArray_Descr *dtype=NULL; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "dtype", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist, - PyArray_AxisConverter, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist, + PyArray_AxisConverter, &axis, PyArray_DescrConverter2, &dtype, PyArray_OutputConverter, &out)) return NULL; - + return PyArray_CumProd(self, axis, _CHKTYPENUM(dtype), out); } @@ -1414,37 +1414,37 @@ array_cumprod(PyArrayObject *self, PyObject *args, PyObject *kwds) static char doc_any[] = "a.any(axis=None, out=None)"; static PyObject * -array_any(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_any(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, PyArray_AxisConverter, &axis, PyArray_OutputConverter, &out)) - return NULL; - + return NULL; + return PyArray_Any(self, axis, out); } static char doc_all[] = "a.all(axis=None)"; static PyObject * -array_all(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_all(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&", kwlist, PyArray_AxisConverter, &axis, PyArray_OutputConverter, &out)) - return NULL; + return NULL; return PyArray_All(self, axis, out); } @@ -1458,54 +1458,54 @@ static char doc_stddev[] = "a.std(axis=None, dtype=None, out=None)\n" "For multidimensional arrays, std is computed by default along the first axis.\n"; static PyObject * -array_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_stddev(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArray_Descr *dtype=NULL; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "dtype", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist, - PyArray_AxisConverter, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist, + PyArray_AxisConverter, &axis, PyArray_DescrConverter2, &dtype, PyArray_OutputConverter, &out)) return NULL; - + return PyArray_Std(self, axis, _CHKTYPENUM(dtype), out, 0); } static char doc_variance[] = "a.var(axis=None, dtype=None)"; static PyObject * -array_variance(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_variance(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; PyArray_Descr *dtype=NULL; PyArrayObject *out=NULL; static char *kwlist[] = {"axis", "dtype", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist, - PyArray_AxisConverter, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O&O&", kwlist, + PyArray_AxisConverter, &axis, PyArray_DescrConverter2, &dtype, PyArray_OutputConverter, &out)) return NULL; - + return PyArray_Std(self, axis, _CHKTYPENUM(dtype), out, 1); } static char doc_compress[] = "a.compress(condition=, axis=None, out=None)"; static PyObject * -array_compress(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_compress(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis=MAX_DIMS; - PyObject *condition; + PyObject *condition; PyArrayObject *out=NULL; static char *kwlist[] = {"condition", "axis", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&O&", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&O&", kwlist, &condition, PyArray_AxisConverter, &axis, PyArray_OutputConverter, @@ -1539,20 +1539,20 @@ static char doc_trace[] = "a.trace(offset=0, axis1=0, axis2=1, dtype=None, out=N "axis1 and axis2."; static PyObject * -array_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis1=0, axis2=1, offset=0; PyArray_Descr *dtype=NULL; PyArrayObject *out=NULL; static char *kwlist[] = {"offset", "axis1", "axis2", "dtype", "out", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iiiO&O&", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iiiO&O&", kwlist, &offset, &axis1, &axis2, PyArray_DescrConverter2, &dtype, PyArray_OutputConverter, &out)) return NULL; - - return _ARET(PyArray_Trace(self, offset, axis1, axis2, + + return _ARET(PyArray_Trace(self, offset, axis1, axis2, _CHKTYPENUM(dtype), out)); } @@ -1562,18 +1562,18 @@ array_trace(PyArrayObject *self, PyObject *args, PyObject *kwds) static char doc_clip[] = "a.clip(min=, max=, out=None)"; static PyObject * -array_clip(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_clip(PyArrayObject *self, PyObject *args, PyObject *kwds) { PyObject *min, *max; PyArrayObject *out=NULL; static char *kwlist[] = {"min", "max", "out", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O&", kwlist, - &min, &max, + &min, &max, PyArray_OutputConverter, - &out)) + &out)) return NULL; - + return _ARET(PyArray_Clip(self, min, max, out)); } @@ -1582,14 +1582,14 @@ static char doc_conj[] = "a.conj()"; static char doc_conjugate[] = "a.conjugate()"; static PyObject * -array_conjugate(PyArrayObject *self, PyObject *args) +array_conjugate(PyArrayObject *self, PyObject *args) { PyArrayObject *out=NULL; if (!PyArg_ParseTuple(args, "|O&", PyArray_OutputConverter, &out)) return NULL; - + return PyArray_Conjugate(self, out); } @@ -1597,15 +1597,15 @@ array_conjugate(PyArrayObject *self, PyObject *args) static char doc_diagonal[] = "a.diagonal(offset=0, axis1=0, axis2=1)"; static PyObject * -array_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_diagonal(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis1=0, axis2=1, offset=0; static char *kwlist[] = {"offset", "axis1", "axis2", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iii", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iii", kwlist, &offset, &axis1, &axis2)) return NULL; - + return _ARET(PyArray_Diagonal(self, offset, axis1, axis2)); } @@ -1616,9 +1616,9 @@ array_flatten(PyArrayObject *self, PyObject *args) { PyArray_ORDER fortran=PyArray_CORDER; - if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter, + if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter, &fortran)) return NULL; - + return PyArray_Flatten(self, fortran); } @@ -1628,8 +1628,8 @@ static PyObject * array_ravel(PyArrayObject *self, PyObject *args) { PyArray_ORDER fortran=PyArray_CORDER; - - if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter, + + if (!PyArg_ParseTuple(args, "|O&", PyArray_OrderConverter, &fortran)) return NULL; return PyArray_Ravel(self, fortran); @@ -1638,7 +1638,7 @@ array_ravel(PyArrayObject *self, PyObject *args) static char doc_round[] = "a.round(decimals=0, out=None)"; static PyObject * -array_round(PyArrayObject *self, PyObject *args, PyObject *kwds) +array_round(PyArrayObject *self, PyObject *args, PyObject *kwds) { int decimals = 0; PyArrayObject *out=NULL; @@ -1648,7 +1648,7 @@ array_round(PyArrayObject *self, PyObject *args, PyObject *kwds) &decimals, PyArray_OutputConverter, &out)) return NULL; - + return _ARET(PyArray_Round(self, decimals, out)); } @@ -1666,7 +1666,7 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds) PyObject *align=Py_None; PyObject *uic=Py_None; int flagback = self->flags; - + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOO", kwlist, &write, &align, &uic)) return NULL; @@ -1675,17 +1675,17 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds) if (PyObject_Not(align)) self->flags &= ~ALIGNED; else if (_IsAligned(self)) self->flags |= ALIGNED; else { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "cannot set aligned flag of mis-"\ "aligned array to True"); return NULL; } } - + if (uic != Py_None) { if (PyObject_IsTrue(uic)) { self->flags = flagback; - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "cannot set UPDATEIFCOPY" \ "flag to True"); return NULL; @@ -1696,15 +1696,15 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds) self->base = NULL; } } - + if (write != Py_None) { - if (PyObject_IsTrue(write)) + if (PyObject_IsTrue(write)) if (_IsWriteable(self)) { self->flags |= WRITEABLE; } else { self->flags = flagback; - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "cannot set WRITEABLE " \ "flag to True of this " \ "array"); \ @@ -1713,7 +1713,7 @@ array_setflags(PyArrayObject *self, PyObject *args, PyObject *kwds) else self->flags &= ~WRITEABLE; } - + Py_INCREF(Py_None); return Py_None; } @@ -1722,11 +1722,11 @@ static char doc_newbyteorder[] = "a.newbyteorder(<byteorder>) is equivalent\n" \ " to a.view(a.dtype.newbytorder(<byteorder>))\n"; static PyObject * -array_newbyteorder(PyArrayObject *self, PyObject *args) +array_newbyteorder(PyArrayObject *self, PyObject *args) { char endian = PyArray_SWAP; PyArray_Descr *new; - + if (!PyArg_ParseTuple(args, "|O&", PyArray_ByteorderConverter, &endian)) return NULL; @@ -1739,30 +1739,30 @@ array_newbyteorder(PyArrayObject *self, PyObject *args) static PyMethodDef array_methods[] = { {"tolist", (PyCFunction)array_tolist, 1, doc_tolist}, {"item", (PyCFunction)array_toscalar, METH_VARARGS, doc_toscalar}, - {"tofile", (PyCFunction)array_tofile, + {"tofile", (PyCFunction)array_tofile, METH_VARARGS | METH_KEYWORDS, doc_tofile}, - {"tostring", (PyCFunction)array_tostring, + {"tostring", (PyCFunction)array_tostring, METH_VARARGS | METH_KEYWORDS, doc_tostring}, {"byteswap", (PyCFunction)array_byteswap, 1, doc_byteswap}, {"astype", (PyCFunction)array_cast, 1, doc_cast}, - {"getfield", (PyCFunction)array_getfield, + {"getfield", (PyCFunction)array_getfield, METH_VARARGS | METH_KEYWORDS, doc_getfield}, - {"setfield", (PyCFunction)array_setfield, + {"setfield", (PyCFunction)array_setfield, METH_VARARGS | METH_KEYWORDS, doc_setfield}, - {"copy", (PyCFunction)array_copy, 1, doc_copy}, - {"resize", (PyCFunction)array_resize, - METH_VARARGS | METH_KEYWORDS, doc_resize}, + {"copy", (PyCFunction)array_copy, 1, doc_copy}, + {"resize", (PyCFunction)array_resize, + METH_VARARGS | METH_KEYWORDS, doc_resize}, /* for subtypes */ {"__array__", (PyCFunction)array_getarray, 1, doc_array_getarray}, {"__array_wrap__", (PyCFunction)array_wraparray, 1, doc_wraparray}, - + /* for the copy module */ - {"__copy__", (PyCFunction)array_copy, 1, doc_copy}, - {"__deepcopy__", (PyCFunction)array_deepcopy, 1, doc_deepcopy}, - + {"__copy__", (PyCFunction)array_copy, 1, doc_copy}, + {"__deepcopy__", (PyCFunction)array_deepcopy, 1, doc_deepcopy}, + /* for Pickling */ - {"__reduce__", (PyCFunction) array_reduce, 1, doc_reduce}, + {"__reduce__", (PyCFunction) array_reduce, 1, doc_reduce}, {"__setstate__", (PyCFunction) array_setstate, 1, doc_setstate}, {"dumps", (PyCFunction) array_dumps, 1, doc_dumps}, {"dump", (PyCFunction) array_dump, 1, doc_dump}, @@ -1770,33 +1770,33 @@ static PyMethodDef array_methods[] = { /* Extended methods added 2005 */ {"fill", (PyCFunction)array_fill, METH_VARARGS, doc_fill}, - {"transpose", (PyCFunction)array_transpose, + {"transpose", (PyCFunction)array_transpose, METH_VARARGS, doc_transpose}, - {"take", (PyCFunction)array_take, + {"take", (PyCFunction)array_take, METH_VARARGS|METH_KEYWORDS, doc_take}, - {"put", (PyCFunction)array_put, + {"put", (PyCFunction)array_put, METH_VARARGS|METH_KEYWORDS, doc_put}, - {"putmask", (PyCFunction)array_putmask, + {"putmask", (PyCFunction)array_putmask, METH_VARARGS|METH_KEYWORDS, doc_putmask}, - {"repeat", (PyCFunction)array_repeat, + {"repeat", (PyCFunction)array_repeat, METH_VARARGS|METH_KEYWORDS, doc_repeat}, - {"choose", (PyCFunction)array_choose, - METH_VARARGS|METH_KEYWORDS, doc_choose}, - {"sort", (PyCFunction)array_sort, + {"choose", (PyCFunction)array_choose, + METH_VARARGS|METH_KEYWORDS, doc_choose}, + {"sort", (PyCFunction)array_sort, METH_VARARGS|METH_KEYWORDS, doc_sort}, - {"argsort", (PyCFunction)array_argsort, + {"argsort", (PyCFunction)array_argsort, METH_VARARGS|METH_KEYWORDS, doc_argsort}, - {"searchsorted", (PyCFunction)array_searchsorted, - METH_VARARGS, doc_searchsorted}, - {"argmax", (PyCFunction)array_argmax, + {"searchsorted", (PyCFunction)array_searchsorted, + METH_VARARGS, doc_searchsorted}, + {"argmax", (PyCFunction)array_argmax, METH_VARARGS|METH_KEYWORDS, doc_argmax}, {"argmin", (PyCFunction)array_argmin, METH_VARARGS|METH_KEYWORDS, doc_argmin}, - {"reshape", (PyCFunction)array_reshape, + {"reshape", (PyCFunction)array_reshape, METH_VARARGS|METH_KEYWORDS, doc_reshape}, {"squeeze", (PyCFunction)array_squeeze, METH_VARARGS, doc_squeeze}, - {"view", (PyCFunction)array_view, + {"view", (PyCFunction)array_view, METH_VARARGS, doc_view}, {"swapaxes", (PyCFunction)array_swapaxes, METH_VARARGS, doc_swapaxes}, @@ -1852,5 +1852,3 @@ static PyMethodDef array_methods[] = { }; #undef _ARET - - diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 51dc4f9b9..e8a6441e2 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -164,7 +164,7 @@ PyArray_Item_INCREF(char *data, PyArray_Descr *descr) PyArray_Descr *new; int offset, pos=0; while (PyDict_Next(descr->fields, &pos, &key, &value)) { - if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, + if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) return; PyArray_Item_INCREF(data + offset, new); } @@ -191,7 +191,7 @@ PyArray_Item_XDECREF(char *data, PyArray_Descr *descr) PyArray_Descr *new; int offset, pos=0; while (PyDict_Next(descr->fields, &pos, &key, &value)) { - if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, + if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) return; PyArray_Item_XDECREF(data + offset, new); } @@ -212,9 +212,9 @@ PyArray_INCREF(PyArrayObject *mp) intp i, n; PyObject **data, **temp; PyArrayIterObject *it; - + if (mp->descr->hasobject == 0) return 0; - + if (mp->descr->type_num != PyArray_OBJECT) { it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp); if (it == NULL) return -1; @@ -265,7 +265,7 @@ PyArray_XDECREF(PyArrayObject *mp) PyArrayIterObject *it; if (mp->descr->hasobject == 0) return 0; - + if (mp->descr->type_num != PyArray_OBJECT) { it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp); if (it == NULL) return -1; @@ -304,7 +304,7 @@ PyArray_XDECREF(PyArrayObject *mp) } static void -_strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides, +_strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides, intp N, int elsize) { intp i, j; @@ -318,7 +318,7 @@ _strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides, tout += outstrides; \ } \ return - + switch(elsize) { case 8: _FAST_MOVE(Float64); @@ -335,7 +335,7 @@ _strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides, tin += instrides; tout += outstrides; } - return; + return; default: for (i=0; i<N; i++) { for (j=0; j<elsize; j++) { @@ -343,15 +343,15 @@ _strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides, } tin = tin + instrides - elsize; tout = tout + outstrides - elsize; - } + } } #undef _FAST_MOVE } - + static void -_unaligned_strided_byte_move(char *dst, intp outstrides, char *src, +_unaligned_strided_byte_move(char *dst, intp outstrides, char *src, intp instrides, intp N, int elsize) { intp i; @@ -366,7 +366,7 @@ _unaligned_strided_byte_move(char *dst, intp outstrides, char *src, tout += outstrides; \ } \ return - + switch(elsize) { case 8: _MOVE_N_SIZE(8); @@ -386,7 +386,7 @@ _unaligned_strided_byte_move(char *dst, intp outstrides, char *src, } static void -_unaligned_strided_byte_copy(char *dst, intp outstrides, char *src, +_unaligned_strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides, intp N, int elsize) { intp i; @@ -424,7 +424,7 @@ _strided_byte_swap(void *p, intp stride, intp n, int size) { char *a, *b, c=0; int j,m; - + switch(size) { case 1: /* no byteswap necessary */ break; @@ -501,7 +501,7 @@ copy_and_swap(void *dst, void *src, int itemsize, intp numitems, static PyArray_Descr **userdescrs=NULL; #define error_converting(x) (((x) == -1) && PyErr_Occurred()) - + /* Computer-generated arraytype and scalartype code */ #include "scalartypes.inc" @@ -690,7 +690,7 @@ index2ptr(PyArrayObject *mp, intp i) if (i<0) i += dim0; if (i==0 && dim0 > 0) return mp->data; - + if (i>0 && i < dim0) { return mp->data+i*mp->strides[0]; } @@ -713,7 +713,7 @@ PyArray_Size(PyObject *op) } static int -_copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap) +_copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap) { char *aligned=NULL; char *sptr; @@ -753,16 +753,16 @@ _copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap) intp dstride; dptr = dest->data; - if (dest->nd == 1) + if (dest->nd == 1) dstride = dest->strides[0]; - else + else dstride = nbytes; PyArray_XDECREF(dest); - NPY_BEGIN_THREADS - + NPY_BEGIN_THREADS + myfunc(dptr, dstride, sptr, 0, numcopies, (int) nbytes); - if (swap) + if (swap) _strided_byte_swap(dptr, dstride, numcopies, (int) nbytes); NPY_END_THREADS @@ -776,30 +776,30 @@ _copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap) PyArray_IterAllButAxis((PyObject *)dest, &axis); if (dit == NULL) goto finish; PyArray_XDECREF(dest); - NPY_BEGIN_THREADS + NPY_BEGIN_THREADS while(dit->index < dit->size) { myfunc(dit->dataptr, PyArray_STRIDE(dest, axis), sptr, 0, PyArray_DIM(dest, axis), nbytes); - if (swap) - _strided_byte_swap(dit->dataptr, + if (swap) + _strided_byte_swap(dit->dataptr, PyArray_STRIDE(dest, axis), PyArray_DIM(dest, axis), nbytes); PyArray_ITER_NEXT(dit); } - NPY_END_THREADS + NPY_END_THREADS PyArray_INCREF(dest); Py_DECREF(dit); } retval = 0; finish: if (aligned != NULL) free(aligned); - return retval; + return retval; } -/* Special-case of PyArray_CopyInto when dst is 1-d - and contiguous (and aligned). - PyArray_CopyInto requires broadcastable arrays while +/* Special-case of PyArray_CopyInto when dst is 1-d + and contiguous (and aligned). + PyArray_CopyInto requires broadcastable arrays while this one is a flattening operation... */ int _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order) { @@ -810,14 +810,14 @@ int _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order) { int elsize; intp nbytes; NPY_BEGIN_THREADS_DEF - + if (PyArray_NDIM(src) == 0) { PyArray_XDECREF((PyArrayObject *)dst); - NPY_BEGIN_THREADS + NPY_BEGIN_THREADS memcpy(PyArray_BYTES(dst), PyArray_BYTES(src), PyArray_ITEMSIZE(src)); - NPY_END_THREADS + NPY_END_THREADS PyArray_INCREF((PyArrayObject *)dst); return 0; } @@ -843,7 +843,7 @@ int _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order) { elsize = PyArray_ITEMSIZE(dst); nbytes = elsize * PyArray_DIM(src, axis); PyArray_XDECREF((PyArrayObject *)dst); - NPY_BEGIN_THREADS + NPY_BEGIN_THREADS while(it->index < it->size) { myfunc(dptr, elsize, it->dataptr, PyArray_STRIDE(src,axis), @@ -851,7 +851,7 @@ int _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order) { dptr += nbytes; PyArray_ITER_NEXT(it); } - NPY_END_THREADS + NPY_END_THREADS PyArray_INCREF((PyArrayObject *)dst); Py_DECREF(it); @@ -860,7 +860,7 @@ int _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order) { static int -_copy_from_same_shape(PyArrayObject *dest, PyArrayObject *src, +_copy_from_same_shape(PyArrayObject *dest, PyArrayObject *src, void (*myfunc)(char *, intp, char *, intp, intp, int), int swap) { @@ -873,9 +873,9 @@ _copy_from_same_shape(PyArrayObject *dest, PyArrayObject *src, PyArray_IterAllButAxis((PyObject *)dest, &maxaxis); sit = (PyArrayIterObject *) \ PyArray_IterAllButAxis((PyObject *)src, &maxaxis); - + maxdim = dest->dimensions[maxaxis]; - + if ((dit == NULL) || (sit == NULL)) { Py_XDECREF(dit); Py_XDECREF(sit); @@ -885,14 +885,14 @@ _copy_from_same_shape(PyArrayObject *dest, PyArrayObject *src, PyArray_XDECREF(dest); - NPY_BEGIN_THREADS + NPY_BEGIN_THREADS while(dit->index < dit->size) { /* strided copy of elsize bytes */ myfunc(dit->dataptr, dest->strides[maxaxis], sit->dataptr, src->strides[maxaxis], maxdim, elsize); if (swap) { - _strided_byte_swap(dit->dataptr, + _strided_byte_swap(dit->dataptr, dest->strides[maxaxis], dest->dimensions[maxaxis], elsize); @@ -900,16 +900,16 @@ _copy_from_same_shape(PyArrayObject *dest, PyArrayObject *src, PyArray_ITER_NEXT(dit); PyArray_ITER_NEXT(sit); } - NPY_END_THREADS + NPY_END_THREADS Py_DECREF(sit); Py_DECREF(dit); - PyArray_INCREF(dest); + PyArray_INCREF(dest); return 0; } static int -_broadcast_copy(PyArrayObject *dest, PyArrayObject *src, +_broadcast_copy(PyArrayObject *dest, PyArrayObject *src, void (*myfunc)(char *, intp, char *, intp, intp, int), int swap) { @@ -942,11 +942,11 @@ _broadcast_copy(PyArrayObject *dest, PyArrayObject *src, PyArray_XDECREF(dest); - NPY_BEGIN_THREADS + NPY_BEGIN_THREADS while(multi->index < multi->size) { - myfunc(multi->iters[0]->dataptr, + myfunc(multi->iters[0]->dataptr, multi->iters[0]->strides[maxaxis], - multi->iters[1]->dataptr, + multi->iters[1]->dataptr, multi->iters[1]->strides[maxaxis], maxdim, elsize); if (swap) { @@ -964,7 +964,7 @@ _broadcast_copy(PyArrayObject *dest, PyArrayObject *src, } /* If destination is not the right type, then src - will be cast to destination -- this requires + will be cast to destination -- this requires src and dest to have the same shape */ @@ -995,9 +995,9 @@ _array_copy_into(PyArrayObject *dest, PyArrayObject *src, int usecopy) } same = PyArray_SAMESHAPE(dest, src); - simple = same && ((PyArray_ISCARRAY_RO(src) && PyArray_ISCARRAY(dest)) || + simple = same && ((PyArray_ISCARRAY_RO(src) && PyArray_ISCARRAY(dest)) || (PyArray_ISFARRAY_RO(src) && PyArray_ISFARRAY(dest))); - + if (simple) { PyArray_XDECREF(dest); NPY_BEGIN_THREADS @@ -1021,12 +1021,12 @@ _array_copy_into(PyArrayObject *dest, PyArrayObject *src, int usecopy) } else if (usecopy) { myfunc = _unaligned_strided_byte_copy; - } + } else { myfunc = _unaligned_strided_byte_move; } - - /* Could combine these because _broadcasted_copy would work as well. + + /* Could combine these because _broadcasted_copy would work as well. But, same-shape copying is so common we want to speed it up. */ if (same) { @@ -1050,28 +1050,28 @@ PyArray_CopyAnyInto(PyArrayObject *dest, PyArrayObject *src) int elsize, simple; PyArrayIterObject *idest, *isrc; void (*myfunc)(char *, intp, char *, intp, intp, int); - NPY_BEGIN_THREADS_DEF + NPY_BEGIN_THREADS_DEF if (!PyArray_EquivArrTypes(dest, src)) { return PyArray_CastAnyTo(dest, src); } - + if (!PyArray_ISWRITEABLE(dest)) { PyErr_SetString(PyExc_RuntimeError, "cannot write to array"); return -1; } - + if ((size=PyArray_SIZE(dest)) != PyArray_SIZE(src)) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "arrays must have the same number of elements" " for copy"); return -1; } - - simple = ((PyArray_ISCARRAY_RO(src) && PyArray_ISCARRAY(dest)) || + + simple = ((PyArray_ISCARRAY_RO(src) && PyArray_ISCARRAY(dest)) || (PyArray_ISFARRAY_RO(src) && PyArray_ISFARRAY(dest))); - + if (simple) { PyArray_XDECREF(dest); NPY_BEGIN_THREADS @@ -1114,7 +1114,7 @@ PyArray_CopyAnyInto(PyArrayObject *dest, PyArrayObject *src) } /*OBJECT_API - Copy an Array into another array -- memory must not overlap. + Copy an Array into another array -- memory must not overlap. */ static int PyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src) @@ -1153,7 +1153,7 @@ PyArray_CopyObject(PyArrayObject *dest, PyObject *src_object) n_old = PyString_Size(src_object); if (n_new > n_old) { new_string = (char *)malloc(n_new); - memmove(new_string, + memmove(new_string, PyString_AS_STRING(src_object), n_old); memset(new_string+n_old, ' ', n_new-n_old); @@ -1162,7 +1162,7 @@ PyArray_CopyObject(PyArrayObject *dest, PyObject *src_object) src_object = tmp; } } - + if (PyArray_Check(src_object)) { dtype = NULL; } @@ -1170,11 +1170,11 @@ PyArray_CopyObject(PyArrayObject *dest, PyObject *src_object) dtype = dest->descr; Py_INCREF(dtype); } - src = (PyArrayObject *)PyArray_FromAny(src_object, dtype, 0, + src = (PyArrayObject *)PyArray_FromAny(src_object, dtype, 0, dest->nd, FORTRAN_IF(dest), NULL); if (src == NULL) return -1; - + ret = PyArray_MoveInto(dest, src); Py_DECREF(src); return ret; @@ -1235,7 +1235,7 @@ PyArray_FromDims(int nd, int *d, int type) */ if (ret && (PyArray_DESCR(ret)->type_num != PyArray_OBJECT)) { memset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret)); - } + } return ret; } @@ -1249,7 +1249,7 @@ static PyObject * PyArray_NewCopy(PyArrayObject *m1, NPY_ORDER fortran) { PyArrayObject *ret; - if (fortran == PyArray_ANYORDER) + if (fortran == PyArray_ANYORDER) fortran = PyArray_ISFORTRAN(m1); Py_INCREF(m1->descr); @@ -1355,7 +1355,7 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base) alloc = 1; memcpy(buffer, data, itemsize); if (!PyArray_ISNOTSWAPPED(base)) { - byte_swap_vector(buffer, + byte_swap_vector(buffer, itemsize >> 2, 4); } } @@ -1364,7 +1364,7 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base) /* Allocated enough for 2-characters per itemsize. Now convert from the data-buffer */ - length = PyUCS2Buffer_FromUCS4(uni->str, + length = PyUCS2Buffer_FromUCS4(uni->str, (PyArray_UCS4 *)buffer, itemsize >> 2); if (alloc) _pya_free(buffer); @@ -1497,7 +1497,7 @@ _default_nonzero(void *ip, void *arr) } /* - Given a string return the type-number for + Given a string return the type-number for the data-type with that string as the type-object name. Returns PyArray_NOTYPE without setting an error if no type can be found. Only works for user-defined data-types. @@ -1516,7 +1516,7 @@ PyArray_TypeNumFromName(char *str) if (strcmp(descr->typeobj->tp_name, str) == 0) return descr->type_num; } - + return PyArray_NOTYPE; } @@ -1535,7 +1535,7 @@ PyArray_RegisterDataType(PyArray_Descr *descr) PyArray_Descr *descr2; int typenum; int i; - PyArray_ArrFuncs *f; + PyArray_ArrFuncs *f; /* See if this type is already registered */ for (i=0; i<NPY_NUMUSERTYPES; i++) { @@ -1554,7 +1554,7 @@ PyArray_RegisterDataType(PyArray_Descr *descr) if (f->nonzero == NULL) { f->nonzero = _default_nonzero; } - if (f->copyswap == NULL || f->getitem == NULL || + if (f->copyswap == NULL || f->getitem == NULL || f->copyswapn == NULL || f->setitem == NULL) { PyErr_SetString(PyExc_ValueError, "a required array function" \ " is missing."); @@ -1575,12 +1575,12 @@ PyArray_RegisterDataType(PyArray_Descr *descr) } /*MULTIARRAY_API - Register Casting Function + Register Casting Function Replaces any function currently stored. */ -static int -PyArray_RegisterCastFunc(PyArray_Descr *descr, int totype, - PyArray_VectorUnaryFunc *castfunc) +static int +PyArray_RegisterCastFunc(PyArray_Descr *descr, int totype, + PyArray_VectorUnaryFunc *castfunc) { PyObject *cobj, *key; int ret; @@ -1625,17 +1625,17 @@ _append_new(int *types, int insert) */ static int PyArray_RegisterCanCast(PyArray_Descr *descr, int totype, - NPY_SCALARKIND scalar) + NPY_SCALARKIND scalar) { if (scalar == PyArray_NOSCALAR) { /* register with cancastto */ - /* These lists won't be freed once created + /* These lists won't be freed once created -- they become part of the data-type */ if (descr->f->cancastto == NULL) { descr->f->cancastto = (int *)malloc(1*sizeof(int)); descr->f->cancastto[0] = PyArray_NOTYPE; } - descr->f->cancastto = _append_new(descr->f->cancastto, + descr->f->cancastto = _append_new(descr->f->cancastto, totype); } else { @@ -1747,7 +1747,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format) if (strobj == NULL) {Py_DECREF(it); return -1;} } NPY_BEGIN_ALLOW_THREADS - n=fwrite(PyString_AS_STRING(strobj), 1, + n=fwrite(PyString_AS_STRING(strobj), 1, n2=PyString_GET_SIZE(strobj), fp); NPY_END_ALLOW_THREADS if (n < n2) { @@ -1760,7 +1760,7 @@ PyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format) return -1; } /* write separator for all but last one */ - if (it->index != it->size-1) + if (it->index != it->size-1) if (fwrite(sep, 1, n3, fp) < n3) { PyErr_Format(PyExc_IOError, "problem writing "\ @@ -1890,7 +1890,7 @@ array_dealloc(PyArrayObject *self) { if (self->flags & UPDATEIFCOPY) { ((PyArrayObject *)self->base)->flags |= WRITEABLE; Py_INCREF(self); /* hold on to self in next call */ - if (PyArray_CopyAnyInto((PyArrayObject *)self->base, + if (PyArray_CopyAnyInto((PyArrayObject *)self->base, self) < 0) { PyErr_Print(); PyErr_Clear(); @@ -2267,14 +2267,14 @@ _swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret) /* arr might not have the right number of dimensions and need to be reshaped first by pre-pending ones */ - arr = *ret; + arr = *ret; if (arr->nd != mit->nd) { for (i=1; i<=arr->nd; i++) { permute.ptr[mit->nd-i] = arr->dimensions[arr->nd-i]; } for (i=0; i<mit->nd-arr->nd; i++) { permute.ptr[i] = 1; - } + } new = PyArray_Newshape(arr, &permute, PyArray_ANYORDER); Py_DECREF(arr); *ret = (PyArrayObject *)new; @@ -2398,7 +2398,7 @@ PyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op) if (arr == NULL) return -1; } } - + if ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) { Py_DECREF(arr); @@ -2589,7 +2589,7 @@ static PyObject *iter_subscript(PyArrayIterObject *, PyObject *); static PyObject * -array_subscript_simple(PyArrayObject *self, PyObject *op) +array_subscript_simple(PyArrayObject *self, PyObject *op) { intp dimensions[MAX_DIMS], strides[MAX_DIMS]; intp offset; @@ -2602,7 +2602,7 @@ array_subscript_simple(PyArrayObject *self, PyObject *op) return array_big_item(self, value); } PyErr_Clear(); - + /* Standard (view-based) Indexing */ if ((nd = parse_index(self, op, dimensions, strides, &offset)) == -1) return NULL; @@ -2616,12 +2616,12 @@ array_subscript_simple(PyArrayObject *self, PyObject *op) self->flags, (PyObject *)self)) == NULL) return NULL; - + other->base = (PyObject *)self; Py_INCREF(self); - + PyArray_UpdateFlags(other, UPDATE_ALL); - + return (PyObject *)other; } @@ -2680,7 +2680,7 @@ array_subscript(PyArrayObject *self, PyObject *op) return NULL; } - if (PyInt_Check(op) || PyArray_IsScalar(op, Integer) || + if (PyInt_Check(op) || PyArray_IsScalar(op, Integer) || PyLong_Check(op)) { intp value; value = PyArray_PyIntAsIntp(op); @@ -2693,7 +2693,7 @@ array_subscript(PyArrayObject *self, PyObject *op) fancy = fancy_indexing_check(op); if (fancy != SOBJ_NOTFANCY) { - oned = ((self->nd == 1) && + oned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1)); /* wrap arguments into a mapiter object */ @@ -2716,7 +2716,7 @@ array_subscript(PyArrayObject *self, PyObject *op) return (PyObject *)other; } - return array_subscript_simple(self, op); + return array_subscript_simple(self, op); } @@ -2743,7 +2743,7 @@ array_ass_sub_simple(PyArrayObject *self, PyObject *index, PyObject *op) return array_ass_big_item(self, value, op); } PyErr_Clear(); - + /* Rest of standard (view-based) indexing */ if (PyArray_CheckExact(self)) { @@ -2755,14 +2755,14 @@ array_ass_sub_simple(PyArrayObject *self, PyObject *index, PyObject *op) tmp0 = PyObject_GetItem((PyObject *)self, index); if (tmp0 == NULL) return -1; if (!PyArray_Check(tmp0)) { - PyErr_SetString(PyExc_RuntimeError, + PyErr_SetString(PyExc_RuntimeError, "Getitem not returning array."); Py_DECREF(tmp0); return -1; } tmp = (PyArrayObject *)tmp0; } - + if (PyArray_ISOBJECT(self) && (tmp->nd == 0)) { ret = tmp->descr->f->setitem(op, tmp->data, tmp); } @@ -2792,7 +2792,7 @@ array_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) return -1; } - if (PyInt_Check(index) || PyArray_IsScalar(index, Integer) || + if (PyInt_Check(index) || PyArray_IsScalar(index, Integer) || PyLong_Check(index)) { intp value; value = PyArray_PyIntAsIntp(index); @@ -2860,7 +2860,7 @@ array_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op) fancy = fancy_indexing_check(index); if (fancy != SOBJ_NOTFANCY) { - oned = ((self->nd == 1) && + oned = ((self->nd == 1) && !(PyTuple_Check(index) && PyTuple_GET_SIZE(index) > 1)); mit = (PyArrayMapIterObject *) \ @@ -2909,7 +2909,7 @@ array_subscript_nice(PyArrayObject *self, PyObject *op) } } /* optimization for a tuple of integers */ - if (self->nd > 1 && PyTuple_Check(op) && + if (self->nd > 1 && PyTuple_Check(op) && (PyTuple_GET_SIZE(op) == self->nd) && PyArray_IntpFromSequence(op, vals, self->nd) == self->nd) { int i; @@ -2932,7 +2932,7 @@ array_subscript_nice(PyArrayObject *self, PyObject *op) mp = (PyArrayObject *)array_subscript(self, op); /* The following is just a copy of PyArray_Return with an - additional logic in the nd == 0 case. + additional logic in the nd == 0 case. */ if (mp == NULL) return NULL; @@ -2941,7 +2941,7 @@ array_subscript_nice(PyArrayObject *self, PyObject *op) Py_XDECREF(mp); return NULL; } - + if (mp->nd == 0) { Bool noellipses = TRUE; if (op == Py_Ellipsis) @@ -2953,7 +2953,7 @@ array_subscript_nice(PyArrayObject *self, PyObject *op) i=0; while (i<n && noellipses) { temp = PySequence_GetItem(op, i); - if (temp == Py_Ellipsis) + if (temp == Py_Ellipsis) noellipses = FALSE; Py_DECREF(temp); i++; @@ -3227,13 +3227,13 @@ _get_keywords(int rtype, PyArrayObject *out) PyArray_Descr *descr; descr = PyArray_DescrFromType(rtype); if (descr) { - PyDict_SetItemString(kwds, "dtype", + PyDict_SetItemString(kwds, "dtype", (PyObject *)descr); Py_DECREF(descr); } } if (out != NULL) { - PyDict_SetItemString(kwds, "out", + PyDict_SetItemString(kwds, "out", (PyObject *)out); } } @@ -3371,10 +3371,10 @@ array_power_is_scalar(PyObject *o2, double* exp) *exp = PyFloat_AsDouble(o2); return 1; } - if ((PyArray_IsZeroDim(o2) && - ((PyArray_ISINTEGER(o2) || - (optimize_fpexps && PyArray_ISFLOAT(o2))))) || - PyArray_IsScalar(o2, Integer) || + if ((PyArray_IsZeroDim(o2) && + ((PyArray_ISINTEGER(o2) || + (optimize_fpexps && PyArray_ISFLOAT(o2))))) || + PyArray_IsScalar(o2, Integer) || (optimize_fpexps && PyArray_IsScalar(o2, Floating))) { temp = o2->ob_type->tp_as_number->nb_float(o2); if (temp != NULL) { @@ -3390,13 +3390,13 @@ array_power_is_scalar(PyObject *o2, double* exp) static PyObject * fast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) { double exp; - if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || + if (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || PyArray_ISCOMPLEX(a1))) { if (array_power_is_scalar(o2, &exp)) { PyObject *fastop = NULL; if (exp == 1.0) { - /* we have to do this one special, as the - "copy" method of array objects isn't set + /* we have to do this one special, as the + "copy" method of array objects isn't set up early enough to be added by PyArray_SetNumericOps. */ @@ -3418,10 +3418,10 @@ fast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) { return NULL; } if (inplace) { - return PyArray_GenericInplaceUnaryFunction(a1, + return PyArray_GenericInplaceUnaryFunction(a1, fastop); } else { - return PyArray_GenericUnaryFunction(a1, + return PyArray_GenericUnaryFunction(a1, fastop); } } @@ -3850,7 +3850,7 @@ static PyNumberMethods array_as_number = { #if PY_VERSION_HEX >= 0x02050000 (unaryfunc)array_index, /* nb_index */ -#endif +#endif }; @@ -3867,7 +3867,7 @@ static PyNumberMethods array_as_number = { static PyObject * -array_slice(PyArrayObject *self, Py_ssize_t ilow, +array_slice(PyArrayObject *self, Py_ssize_t ilow, Py_ssize_t ihigh) { PyArrayObject *r; @@ -3909,7 +3909,7 @@ array_slice(PyArrayObject *self, Py_ssize_t ilow, static int -array_ass_slice(PyArrayObject *self, Py_ssize_t ilow, +array_ass_slice(PyArrayObject *self, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v) { int ret; PyArrayObject *tmp; @@ -3940,8 +3940,8 @@ array_contains(PyArrayObject *self, PyObject *el) PyObject *res; int ret; - - res = PyArray_EnsureAnyArray(PyObject_RichCompare((PyObject *)self, + + res = PyArray_EnsureAnyArray(PyObject_RichCompare((PyObject *)self, el, Py_EQ)); if (res == NULL) return -1; ret = array_any_nonzero((PyArrayObject *)res); @@ -4143,7 +4143,7 @@ PyArray_CompareUCS4(npy_ucs4 *s1, npy_ucs4 *s2, register size_t len) } /* This also handles possibly mis-aligned data */ -/* Compare s1 and s2 which are not necessarily NULL-terminated. +/* Compare s1 and s2 which are not necessarily NULL-terminated. s1 is of length len1 s2 is of length len2 If they are NULL terminated, then stop comparison. @@ -4165,14 +4165,14 @@ _myunincmp(PyArray_UCS4 *s1, PyArray_UCS4 *s2, int len1, int len2) size = len2*sizeof(PyArray_UCS4); s2t = malloc(size); memcpy(s2t, s2, size); - } + } val = PyArray_CompareUCS4(s1t, s2t, MIN(len1,len2)); if ((val != 0) || (len1 == len2)) goto finish; if (len2 > len1) {sptr = s2t+len1; val = -1;} else {sptr = s1t+len2; val = 1;} if (*sptr != 0) goto finish; val = 0; - + finish: if (s1t != s1) free(s1t); if (s2t != s2) free(s2t); @@ -4182,7 +4182,7 @@ _myunincmp(PyArray_UCS4 *s1, PyArray_UCS4 *s2, int len1, int len2) -/* Compare s1 and s2 which are not necessarily NULL-terminated. +/* Compare s1 and s2 which are not necessarily NULL-terminated. s1 is of length len1 s2 is of length len2 If they are NULL terminated, then stop comparison. @@ -4323,7 +4323,7 @@ _uni_release(char *ptr, int nc) else _reg_loop(CMP) static int -_compare_strings(PyObject *result, PyArrayMultiIterObject *multi, +_compare_strings(PyObject *result, PyArrayMultiIterObject *multi, int cmp_op, void *func, int rstrip) { PyArrayIterObject *iself, *iother; @@ -4334,7 +4334,7 @@ _compare_strings(PyObject *result, PyArrayMultiIterObject *multi, int (*cmpfunc)(void *, void *, int, int); void (*relfunc)(char *, int); char* (*stripfunc)(char *, char *, int); - + cmpfunc = func; dptr = (Bool *)PyArray_DATA(result); iself = multi->iters[0]; @@ -4358,7 +4358,7 @@ _compare_strings(PyObject *result, PyArrayMultiIterObject *multi, break; case Py_NE: _loop(!=) - break; + break; case Py_LT: _loop(<) break; @@ -4376,7 +4376,7 @@ _compare_strings(PyObject *result, PyArrayMultiIterObject *multi, "bad comparison operator"); return -1; } - return 0; + return 0; } #undef _loop @@ -4392,14 +4392,14 @@ _strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op, PyArrayMultiIterObject *mit; int val; - /* Cast arrays to a common type */ + /* Cast arrays to a common type */ if (self->descr->type != other->descr->type) { PyObject *new; if (self->descr->type_num == PyArray_STRING && \ other->descr->type_num == PyArray_UNICODE) { Py_INCREF(other); Py_INCREF(other->descr); - new = PyArray_FromAny((PyObject *)self, other->descr, + new = PyArray_FromAny((PyObject *)self, other->descr, 0, 0, 0, NULL); if (new == NULL) return NULL; self = (PyArrayObject *)new; @@ -4408,19 +4408,19 @@ _strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op, other->descr->type_num == PyArray_STRING) { Py_INCREF(self); Py_INCREF(self->descr); - new = PyArray_FromAny((PyObject *)other, self->descr, + new = PyArray_FromAny((PyObject *)other, self->descr, 0, 0, 0, NULL); if (new == NULL) return NULL; other = (PyArrayObject *)new; } else { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "invalid string data-types " "in comparison"); return NULL; } } - else { + else { Py_INCREF(self); Py_INCREF(other); } @@ -4430,27 +4430,27 @@ _strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op, Py_DECREF(self); Py_DECREF(other); if (mit == NULL) return NULL; - + result = PyArray_NewFromDescr(&PyArray_Type, PyArray_DescrFromType(PyArray_BOOL), mit->nd, mit->dimensions, - NULL, NULL, 0, + NULL, NULL, 0, NULL); if (result == NULL) goto finish; if (self->descr->type_num == PyArray_UNICODE) { - val = _compare_strings(result, mit, cmp_op, _myunincmp, + val = _compare_strings(result, mit, cmp_op, _myunincmp, rstrip); } else { - val = _compare_strings(result, mit, cmp_op, _mystrncmp, + val = _compare_strings(result, mit, cmp_op, _mystrncmp, rstrip); } - + if (val < 0) {Py_DECREF(result); result = NULL;} - - finish: + + finish: Py_DECREF(mit); return result; } @@ -4461,7 +4461,7 @@ _strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op, equality testing is performed using logical_ands on all the fields. in-equality testing is performed using logical_ors on all the fields. - VOID-type arrays without fields are compared for equality by comparing their + VOID-type arrays without fields are compared for equality by comparing their memory at each location directly (using string-code). */ @@ -4469,7 +4469,7 @@ static PyObject *array_richcompare(PyArrayObject *, PyObject *, int); static PyObject * -_void_compare(PyArrayObject *self, PyArrayObject *other, int cmp_op) +_void_compare(PyArrayObject *self, PyArrayObject *other, int cmp_op) { if (!(cmp_op == Py_EQ || cmp_op == Py_NE)) { PyErr_SetString(PyExc_ValueError, "Void-arrays can only" \ @@ -4563,11 +4563,11 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) result = PyArray_GenericBinaryFunction(self, array_other, n_ops.equal); - if ((result == Py_NotImplemented) && + if ((result == Py_NotImplemented) && (self->descr->type_num == PyArray_VOID)) { int _res; _res = PyObject_RichCompareBool \ - ((PyObject *)self->descr, + ((PyObject *)self->descr, (PyObject *)\ PyArray_DESCR(array_other), Py_EQ); @@ -4579,7 +4579,7 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) if (_res) { Py_DECREF(result); result = _void_compare\ - (self, + (self, (PyArrayObject *)array_other, cmp_op); Py_DECREF(array_other); @@ -4629,11 +4629,11 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) result = PyArray_GenericBinaryFunction(self, array_other, n_ops.not_equal); - if ((result == Py_NotImplemented) && + if ((result == Py_NotImplemented) && (self->descr->type_num == PyArray_VOID)) { int _res; _res = PyObject_RichCompareBool\ - ((PyObject *)self->descr, + ((PyObject *)self->descr, (PyObject *)\ PyArray_DESCR(array_other), Py_EQ); @@ -4645,8 +4645,8 @@ array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) if (_res) { Py_DECREF(result); result = _void_compare\ - (self, - (PyArrayObject *)array_other, + (self, + (PyArrayObject *)array_other, cmp_op); Py_DECREF(array_other); } @@ -4938,7 +4938,7 @@ PyArray_UpdateFlags(PyArrayObject *ret, int flagmask) if (_IsAligned(ret)) ret->flags |= ALIGNED; else ret->flags &= ~ALIGNED; } - /* This is not checked by default WRITEABLE is not + /* This is not checked by default WRITEABLE is not part of UPDATE_ALL */ if (flagmask & WRITEABLE) { if (_IsWriteable(ret)) ret->flags |= WRITEABLE; @@ -5207,7 +5207,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, return NULL; } } - + self = (PyArrayObject *) subtype->tp_alloc(subtype, 0); if (self == NULL) { Py_DECREF(descr); @@ -5216,7 +5216,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, self->nd = nd; self->dimensions = NULL; self->data = NULL; - if (data == NULL) { + if (data == NULL) { self->flags = DEFAULT; if (flags) { self->flags |= FORTRAN; @@ -5256,7 +5256,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, /* Allocate something even for zero-space arrays e.g. shape=(0,) -- otherwise buffer exposure (a.data) doesn't work as it should. */ - + if (sd==0) sd = descr->elsize; if ((data = PyDataMem_NEW(sd))==NULL) { @@ -5292,7 +5292,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, /* call the __array_finalize__ method if a subtype. - If obj is NULL, then call method with Py_None + If obj is NULL, then call method with Py_None */ if ((subtype != &PyArray_Type)) { PyObject *res, *func, *args; @@ -5303,7 +5303,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, } func = PyObject_GetAttr((PyObject *)self, str); if (func && func != Py_None) { - if (strides != NULL) { /* did not allocate own data + if (strides != NULL) { /* did not allocate own data or funny strides */ /* update flags before finalize function */ PyArray_UpdateFlags(self, UPDATE_ALL); @@ -5328,7 +5328,7 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, } else Py_XDECREF(func); } - + return (PyObject *)self; fail: @@ -5353,7 +5353,7 @@ _putzero(char *optr, PyObject *zero, PyArray_Descr *dtype) PyArray_Descr *new; int offset, pos=0; while (PyDict_Next(dtype->fields, &pos, &key, &value)) { - if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, + if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) return; _putzero(optr + offset, zero, new); } @@ -5389,16 +5389,16 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck, "resize only works on single-segment arrays"); return NULL; } - + if (self->descr->hasobject) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "cannot resize an object-array like this"); return NULL; } if (fortran == PyArray_ANYORDER) fortran = PyArray_CORDER; - + if (self->descr->elsize == 0) { PyErr_SetString(PyExc_ValueError, "Bad data-type size."); return NULL; @@ -5408,7 +5408,7 @@ PyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck, for (k=0; k<new_nd; k++) { if (new_dimensions[k]==0) break; if (new_dimensions[k] < 0) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "negative dimensions not allowed"); return NULL; } @@ -5503,14 +5503,14 @@ static void _fillobject(char *optr, PyObject *obj, PyArray_Descr *dtype) { if (!dtype->hasobject) { - if ((obj == Py_None) || + if ((obj == Py_None) || (PyInt_Check(obj) && PyInt_AsLong(obj)==0)) return; else { PyObject *arr; Py_INCREF(dtype); arr = PyArray_NewFromDescr(&PyArray_Type, dtype, - 0, NULL, NULL, NULL, + 0, NULL, NULL, NULL, 0, NULL); if (arr!=NULL) dtype->f->setitem(obj, optr, arr); @@ -5529,7 +5529,7 @@ _fillobject(char *optr, PyObject *obj, PyArray_Descr *dtype) PyArray_Descr *new; int offset, pos=0; while (PyDict_Next(dtype->fields, &pos, &key, &value)) { - if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, + if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) return; _fillobject(optr + offset, obj, new); } @@ -5633,7 +5633,7 @@ PyArray_FillWithScalar(PyArrayObject *arr, PyObject *obj) static PyObject * array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) { - static char *kwlist[] = {"shape", "dtype", "buffer", + static char *kwlist[] = {"shape", "dtype", "buffer", "offset", "strides", "order", NULL}; PyArray_Descr *descr=NULL; @@ -5679,15 +5679,15 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) itemsize = descr->elsize; if (itemsize == 0) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "data-type with unspecified variable length"); goto fail; } - + if (strides.ptr != NULL) { intp nb, off; if (strides.len != dims.len) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "strides, if given, must be " \ "the same length as shape"); goto fail; @@ -5701,19 +5701,19 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) nb = buffer.len; off = (intp) offset; } - - if (!PyArray_CheckStrides(itemsize, dims.len, + + if (!PyArray_CheckStrides(itemsize, dims.len, nb, off, dims.ptr, strides.ptr)) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "strides is incompatible " \ "with shape of requested " \ "array and size of buffer"); goto fail; } } - + if (buffer.ptr == NULL) { ret = (PyArrayObject *) \ PyArray_NewFromDescr(subtype, descr, @@ -5811,7 +5811,7 @@ array_shape_set(PyArrayObject *self, PyObject *val) if (ret == NULL) return -1; if (PyArray_DATA(ret) != PyArray_DATA(self)) { Py_DECREF(ret); - PyErr_SetString(PyExc_AttributeError, + PyErr_SetString(PyExc_AttributeError, "incompatible shape for a non-contiguous array"); return -1; } @@ -5977,7 +5977,7 @@ static PyObject * array_ctypes_get(PyArrayObject *self) { return PyObject_CallMethod(_numpy_internal, "_ctypes", - "ON", self, + "ON", self, PyLong_FromVoidPtr(self->data)); } @@ -5988,7 +5988,7 @@ array_interface_get(PyArrayObject *self) PyObject *obj; dict = PyDict_New(); if (dict == NULL) return NULL; - + /* dataptr */ obj = array_dataptr_get(self); PyDict_SetItemString(dict, "data", obj); @@ -6005,7 +6005,7 @@ array_interface_get(PyArrayObject *self) obj = arraydescr_protocol_typestr_get(self->descr); PyDict_SetItemString(dict, "typestr", obj); Py_DECREF(obj); - + obj = array_shape_get(self); PyDict_SetItemString(dict, "shape", obj); Py_DECREF(obj); @@ -6149,7 +6149,7 @@ array_descr_set(PyArrayObject *self, PyObject *arg) } if (newtype->elsize == 0) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "data-type must not be 0-sized"); Py_DECREF(newtype); return -1; @@ -6239,7 +6239,7 @@ array_struct_get(PyArrayObject *self) /* reset unused flags */ inter->flags &= ~(UPDATEIFCOPY | OWNDATA); if (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED; - /* Copy shape and strides over since these can be reset + /* Copy shape and strides over since these can be reset when the array is "reshaped". */ if (self->nd > 0) { @@ -6329,7 +6329,7 @@ array_real_set(PyArrayObject *self, PyObject *val) self->strides, self->data, 0, - self->flags, + self->flags, (PyObject *)self); if (ret == NULL) {Py_DECREF(new); return -1;} ret->flags &= ~CONTIGUOUS; @@ -6379,7 +6379,7 @@ array_imag_get(PyArrayObject *self) type, PyArray_ISFORTRAN(self)); ret->flags &= ~WRITEABLE; - if (PyArray_CheckExact(self)) + if (PyArray_CheckExact(self)) return (PyObject *)ret; else { PyObject *newret; @@ -6496,8 +6496,8 @@ array_transpose_get(PyArrayObject *self) return PyArray_Transpose(self, NULL); } -/* If this is None, no function call is made - --- default sub-class behavior +/* If this is None, no function call is made + --- default sub-class behavior */ static PyObject * array_finalize_get(PyArrayObject *self) @@ -6674,7 +6674,7 @@ discover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple) if (PyDict_Check(e)) { PyObject *new; new = PyDict_GetItemString(e, "shape"); - if (new && PyTuple_Check(new)) + if (new && PyTuple_Check(new)) d = PyTuple_GET_SIZE(new); } Py_DECREF(e); @@ -6694,7 +6694,7 @@ discover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple) if (d > -1) return d; } else PyErr_Clear(); - + if (PySequence_Length(s) == 0) return 1; if ((e=PySequence_GetItem(s,0)) == NULL) return -1; @@ -7051,7 +7051,7 @@ Array_FromPyScalar(PyObject *op, PyArray_Descr *typecode) Otherwise: run object_depth_and_dimension on all the elements - and make sure the returned shape and size + and make sure the returned shape and size is the same for each element */ @@ -7066,7 +7066,7 @@ object_depth_and_dimension(PyObject *s, int max, intp *dims) islist = PyList_Check(s); if (!(islist || PyTuple_Check(s)) || - ((size = PySequence_Size(s)) == 0)) + ((size = PySequence_Size(s)) == 0)) return 0; if (max < 2) { if (max < 1) return 0; @@ -7082,13 +7082,13 @@ object_depth_and_dimension(PyObject *s, int max, intp *dims) if (islist) obj = PyList_GET_ITEM(s, i); else obj = PyTuple_GET_ITEM(s, i); test_nd = object_depth_and_dimension(obj, max-1, test_dims); - if ((nd != test_nd) || + if ((nd != test_nd) || (!PyArray_CompareLists(newdims, test_dims, nd))) { nd = 0; break; } } - + for (i=1; i<=nd; i++) dims[i] = newdims[i-1]; dims[0] = size; PyDimMem_FREE(newdims); @@ -7107,12 +7107,12 @@ ObjectArray_FromNestedList(PyObject *s, PyArray_Descr *typecode, int fortran) if (nd < 0) return NULL; if (nd == 0) return Array_FromPyScalar(s, typecode); - + r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode, nd, d, NULL, NULL, fortran, NULL); - + if(!r) return NULL; if(Assign_Array(r,s) == -1) { Py_DECREF(r); @@ -7139,7 +7139,7 @@ Array_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran, int type = typecode->type_num; int itemsize = typecode->elsize; - if (isobject) + if (isobject) return ObjectArray_FromNestedList(s, typecode, fortran); stop_at_string = ((type == PyArray_OBJECT) || \ @@ -7277,9 +7277,9 @@ PyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran) } /*OBJECT_API - Get a cast function to cast from the input descriptor to the + Get a cast function to cast from the input descriptor to the output type_number (must be a registered data-type). - Returns NULL if un-successful. + Returns NULL if un-successful. */ static PyArray_VectorUnaryFunc * PyArray_GetCastFunc(PyArray_Descr *descr, int type_num) @@ -7306,13 +7306,13 @@ PyArray_GetCastFunc(PyArray_Descr *descr, int type_num) PyErr_SetString(PyExc_ValueError, "No cast function available."); - return NULL; + return NULL; } /* Reference counts: copyswapn is used which increases and decreases reference counts for OBJECT arrays. - All that needs to happen is for any reference counts in the buffers to be - decreased when completely finished with the buffers. + All that needs to happen is for any reference counts in the buffers to be + decreased when completely finished with the buffers. buffers[0] is the destination buffers[1] is the source @@ -7343,9 +7343,9 @@ _strided_buffered_cast(char *dptr, intp dstride, int delsize, int dswap, while(N > 0) { int newN; newN = MIN(N, bufsize); - _strided_buffered_cast(dptr+i*dstride, dstride, delsize, + _strided_buffered_cast(dptr+i*dstride, dstride, delsize, dswap, dcopyfunc, - sptr+i*sstride, sstride, selsize, + sptr+i*sstride, sstride, selsize, sswap, scopyfunc, newN, buffers, bufsize, castfunc, dest, src); i += newN; @@ -7354,15 +7354,15 @@ _strided_buffered_cast(char *dptr, intp dstride, int delsize, int dswap, return; } -static int -_broadcast_cast(PyArrayObject *out, PyArrayObject *in, +static int +_broadcast_cast(PyArrayObject *out, PyArrayObject *in, PyArray_VectorUnaryFunc *castfunc, int iswap, int oswap) { int delsize, selsize, maxaxis, i, N; PyArrayMultiIterObject *multi; intp maxdim, ostrides, istrides; char *buffers[2]; - PyArray_CopySwapNFunc *ocopyfunc, *icopyfunc; + PyArray_CopySwapNFunc *ocopyfunc, *icopyfunc; char *obptr; NPY_BEGIN_THREADS_DEF @@ -7379,7 +7379,7 @@ _broadcast_cast(PyArrayObject *out, PyArrayObject *in, Py_DECREF(multi); return -1; } - + icopyfunc = in->descr->f->copyswapn; ocopyfunc = out->descr->f->copyswapn; maxaxis = PyArray_RemoveLargest(multi); @@ -7407,14 +7407,14 @@ _broadcast_cast(PyArrayObject *out, PyArrayObject *in, PyErr_NoMemory(); return -1; } - if (out->descr->hasobject) + if (out->descr->hasobject) memset(buffers[0], 0, N*delsize); - if (in->descr->hasobject) + if (in->descr->hasobject) memset(buffers[1], 0, N*selsize); -#if NPY_ALLOW_THREADS +#if NPY_ALLOW_THREADS if (PyArray_ISNUMBER(in) && PyArray_ISNUMBER(out)) { - NPY_BEGIN_THREADS + NPY_BEGIN_THREADS } #endif @@ -7422,7 +7422,7 @@ _broadcast_cast(PyArrayObject *out, PyArrayObject *in, _strided_buffered_cast(multi->iters[0]->dataptr, ostrides, delsize, oswap, ocopyfunc, - multi->iters[1]->dataptr, + multi->iters[1]->dataptr, istrides, selsize, iswap, icopyfunc, maxdim, buffers, N, @@ -7431,7 +7431,7 @@ _broadcast_cast(PyArrayObject *out, PyArrayObject *in, } #if NPY_ALLOW_THREADS if (PyArray_ISNUMBER(in) && PyArray_ISNUMBER(out)) { - NPY_END_THREADS + NPY_END_THREADS } #endif Py_DECREF(multi); @@ -7442,7 +7442,7 @@ _broadcast_cast(PyArrayObject *out, PyArrayObject *in, } if (out->descr->hasobject) { obptr = buffers[0]; - for (i=0; i<N; i++, obptr+=delsize) + for (i=0; i<N; i++, obptr+=delsize) PyArray_Item_XDECREF(obptr, out->descr); } _pya_free(buffers[0]); @@ -7453,10 +7453,10 @@ _broadcast_cast(PyArrayObject *out, PyArrayObject *in, -/* Must be broadcastable. +/* Must be broadcastable. This code is very similar to PyArray_CopyInto/PyArray_MoveInto - except casting is done --- PyArray_BUFSIZE is used - as the size of the casting buffer. + except casting is done --- PyArray_BUFSIZE is used + as the size of the casting buffer. */ /*OBJECT_API @@ -7471,7 +7471,7 @@ PyArray_CastTo(PyArrayObject *out, PyArrayObject *mp) PyArray_VectorUnaryFunc *castfunc=NULL; int mpsize = PyArray_SIZE(mp); int iswap, oswap; - + NPY_BEGIN_THREADS_DEF if (mpsize == 0) return 0; @@ -7486,7 +7486,7 @@ PyArray_CastTo(PyArrayObject *out, PyArrayObject *mp) same = PyArray_SAMESHAPE(out, mp); - simple = same && ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || + simple = same && ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out))); if (simple) { @@ -7510,13 +7510,13 @@ PyArray_CastTo(PyArrayObject *out, PyArrayObject *mp) iswap = PyArray_ISBYTESWAPPED(mp) && !PyArray_ISFLEXIBLE(mp); oswap = PyArray_ISBYTESWAPPED(out) && !PyArray_ISFLEXIBLE(out); - + return _broadcast_cast(out, mp, castfunc, iswap, oswap); } static int -_bufferedcast(PyArrayObject *out, PyArrayObject *in, +_bufferedcast(PyArrayObject *out, PyArrayObject *in, PyArray_VectorUnaryFunc *castfunc) { char *inbuffer, *bptr, *optr; @@ -7612,7 +7612,7 @@ _bufferedcast(PyArrayObject *out, PyArrayObject *in, /*OBJECT_API Cast to an already created array. Arrays don't have to be "broadcastable" - Only requirement is they have the same number of elements. + Only requirement is they have the same number of elements. */ static int PyArray_CastAnyTo(PyArrayObject *out, PyArrayObject *mp) @@ -7634,14 +7634,14 @@ PyArray_CastAnyTo(PyArrayObject *out, PyArrayObject *mp) " elements for the cast."); return -1; } - + castfunc = PyArray_GetCastFunc(mp->descr, out->descr->type_num); if (castfunc == NULL) return -1; - - - simple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || + + + simple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out))); - + if (simple) { castfunc(mp->data, out->data, mpsize, mp, out); return 0; @@ -7650,7 +7650,7 @@ PyArray_CastAnyTo(PyArrayObject *out, PyArrayObject *mp) if (PyArray_SAMESHAPE(out, mp)) { int iswap, oswap; iswap = PyArray_ISBYTESWAPPED(mp) && !PyArray_ISFLEXIBLE(mp); - oswap = PyArray_ISBYTESWAPPED(out) && !PyArray_ISFLEXIBLE(out); + oswap = PyArray_ISBYTESWAPPED(out) && !PyArray_ISFLEXIBLE(out); return _broadcast_cast(out, mp, castfunc, iswap, oswap); } @@ -7988,7 +7988,7 @@ PyArray_FromInterface(PyObject *input) if (shape == NULL) {Py_DECREF(inter); return Py_NotImplemented;} tstr = PyDict_GetItemString(inter, "typestr"); if (tstr == NULL) {Py_DECREF(inter); return Py_NotImplemented;} - + attr = PyDict_GetItemString(inter, "data"); base = input; if ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) { @@ -8120,7 +8120,7 @@ PyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context) array_meth = PyObject_GetAttrString(op, "__array__"); if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;} if (context == NULL) { - if (typecode == NULL) new = PyObject_CallFunction(array_meth, + if (typecode == NULL) new = PyObject_CallFunction(array_meth, NULL); else new = PyObject_CallFunction(array_meth, "O", typecode); } @@ -8135,12 +8135,12 @@ PyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context) } } else { - new = PyObject_CallFunction(array_meth, "OO", + new = PyObject_CallFunction(array_meth, "OO", typecode, context); if (new == NULL && \ PyErr_ExceptionMatches(PyExc_TypeError)) { PyErr_Clear(); - new = PyObject_CallFunction(array_meth, "O", + new = PyObject_CallFunction(array_meth, "O", typecode); } } @@ -8191,7 +8191,7 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, PyObject *new; if (r == NULL) {Py_XDECREF(newtype); return NULL;} if (newtype != NULL || flags != 0) { - new = PyArray_FromArray((PyArrayObject *)r, newtype, + new = PyArray_FromArray((PyArrayObject *)r, newtype, flags); Py_DECREF(r); r = new; @@ -8215,7 +8215,7 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, min_depth, max_depth, isobject); if (r == NULL && \ ((thiserr = PyErr_Occurred()) && \ - !PyErr_GivenExceptionMatches(thiserr, + !PyErr_GivenExceptionMatches(thiserr, PyExc_MemoryError))) { /* It wasn't really a sequence after all. * Try interpreting it as a scalar */ @@ -8259,7 +8259,7 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth, err: Py_XDECREF(newtype); - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "UPDATEIFCOPY used for non-array input."); return NULL; } @@ -8357,7 +8357,7 @@ PyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth, obj = PyArray_FromAny(op, descr, min_depth, max_depth, requires, context); if (obj == NULL) return NULL; - if ((requires & ELEMENTSTRIDES) && + if ((requires & ELEMENTSTRIDES) && !PyArray_ElementStrides(obj)) { PyObject *new; new = PyArray_NewCopy((PyArrayObject *)obj, PyArray_ANYORDER); @@ -8385,7 +8385,7 @@ PyArray_EnsureArray(PyObject *op) if (op == NULL) return NULL; if (PyArray_CheckExact(op)) return op; - + if (PyArray_Check(op)) { new = PyArray_View((PyArrayObject *)op, NULL, &PyArray_Type); Py_DECREF(op); @@ -8425,7 +8425,7 @@ PyArray_CanCastSafely(int fromtype, int totype) if (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0; from = PyArray_DescrFromType(fromtype); - /* cancastto is a PyArray_NOTYPE terminated C-int-array of types that + /* cancastto is a PyArray_NOTYPE terminated C-int-array of types that the data-type can be cast to safely. */ if (from->f->cancastto) { @@ -8559,9 +8559,9 @@ PyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to) fromtype = _typenum_fromtypeobj((PyObject *)from, 0); totype = _typenum_fromtypeobj((PyObject *)to, 0); - if (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE) + if (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE) return FALSE; - return (Bool) PyArray_CanCastSafely(fromtype, totype); + return (Bool) PyArray_CanCastSafely(fromtype, totype); } @@ -8626,7 +8626,7 @@ PyArray_IterAllButAxis(PyObject *obj, int *inaxis) it = (PyArrayIterObject *)PyArray_IterNew(obj); if (it == NULL) return NULL; - if (PyArray_NDIM(obj)==0) + if (PyArray_NDIM(obj)==0) return (PyObject *)it; if (*inaxis < 0) { int i, maxaxis=0; @@ -8658,9 +8658,9 @@ PyArray_IterAllButAxis(PyObject *obj, int *inaxis) adjusted */ /*OBJECT_API - Adjusts previously broadcasted iterators so that the largest axis - is not iterated over. - Returns dimension which is largest in the range [0,multi->nd). + Adjusts previously broadcasted iterators so that the largest axis + is not iterated over. + Returns dimension which is largest in the range [0,multi->nd). A -1 is returned if multi->nd == 0. */ static int @@ -8672,7 +8672,7 @@ PyArray_RemoveLargest(PyArrayMultiIterObject *multi) intp longest; if (multi->nd == 0) return -1; - + longest = multi->dimensions[0]; /* Find longest dimension */ for (i=1; i<multi->nd; i++) { @@ -8681,14 +8681,14 @@ PyArray_RemoveLargest(PyArrayMultiIterObject *multi) longest = multi->dimensions[i]; } } - + for (i=0; i<multi->numiter; i++) { it = multi->iters[i]; it->contiguous = 0; if (it->size != 0) it->size /= (it->dims_m1[axis]+1); it->dims_m1[axis] = 0; - it->backstrides[axis] = 0; + it->backstrides[axis] = 0; } multi->size = multi->iters[0]->size; @@ -8742,7 +8742,7 @@ iter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind) } index = ind->dimensions[0]; if (index > self->size) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "too many boolean indices"); return NULL; } @@ -9256,7 +9256,7 @@ iter_array(PyArrayIterObject *it, PyObject *op) NULL, NULL, 0, (PyObject *)it->ao); if (r==NULL) return NULL; - if (_flat_copyinto(r, (PyObject *)it->ao, + if (_flat_copyinto(r, (PyObject *)it->ao, PyArray_CORDER) < 0) { Py_DECREF(r); return NULL; @@ -9324,7 +9324,7 @@ iter_coords_get(PyArrayIterObject *self) static PyGetSetDef iter_getsets[] = { {"coords", (getter)iter_coords_get, - NULL, + NULL, NULL}, {NULL, NULL, NULL, NULL}, }; @@ -9706,11 +9706,11 @@ PyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr) /* Here check the indexes (now that we have iteraxes) */ mit->size = PyArray_MultiplyList(mit->dimensions, mit->nd); if (mit->ait->size == 0 && mit->size != 0) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "invalid index into a 0-size array"); goto fail; } - + for (i=0; i<mit->numiter; i++) { intp indval; it = mit->iters[i]; @@ -9934,7 +9934,7 @@ PyArray_MapIterNew(PyObject *indexobj, int oned, int fancy) PyInt_FromLong(0)); } else { /* we need to grow the - new indexing object and fill + new indexing object and fill it with 0s for each of the iterators produced */ int k; @@ -10457,7 +10457,7 @@ arraydescr_typename_get(PyArray_Descr *self) else { if (prefix_len == 0) prefix_len = strlen("numpy."); - + len = strlen(typeobj->tp_name); if (*(typeobj->tp_name + (len-1)) == '_') len-=1; @@ -10529,8 +10529,8 @@ arraydescr_isbuiltin_get(PyArray_Descr *self) return PyInt_FromLong(val); } -static int -_arraydescr_isnative(PyArray_Descr *self) +static int +_arraydescr_isnative(PyArray_Descr *self) { if (self->names == NULL) { return PyArray_ISNBO(self->byteorder); @@ -10550,8 +10550,8 @@ _arraydescr_isnative(PyArray_Descr *self) /* return Py_True if this data-type descriptor has native byteorder if no fields are defined - - or if all sub-fields have native-byteorder if + + or if all sub-fields have native-byteorder if fields are defined */ static PyObject * @@ -10752,7 +10752,7 @@ _descr_find_object(PyArray_Descr *self) PyArray_Descr *new; int offset, pos=0; while (PyDict_Next(self->fields, &pos, &key, &value)) { - if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, + if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) { PyErr_Clear(); return 0; @@ -10778,14 +10778,14 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args) char endian; PyObject *subarray, *fields, *names=NULL; int incref_names = 1; - + if (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;} - + if (!PyArg_ParseTuple(args, "(icOOOii)", &version, &endian, &subarray, &names, &fields, &elsize, &alignment)) { PyErr_Clear(); - if (!PyArg_ParseTuple(args, "(icOOii)", &version, &endian, - &subarray, &fields, &elsize, + if (!PyArg_ParseTuple(args, "(icOOii)", &version, &endian, + &subarray, &fields, &elsize, &alignment)) { PyErr_Clear(); version = 0; @@ -10812,7 +10812,7 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args) } version = 2; } - + /* If we ever need another pickle format, increment the version number. But we should still be able to handle the old versions. */ @@ -10822,14 +10822,14 @@ arraydescr_setstate(PyArray_Descr *self, PyObject *args) version); return NULL; } - + if ((fields == Py_None && names != Py_None) || \ (names == Py_None && fields != Py_None)) { PyErr_Format(PyExc_ValueError, "inconsistent fields and names"); return NULL; } - + if (endian != '|' && PyArray_IsNativeByteOrder(endian)) endian = '='; @@ -11061,25 +11061,25 @@ arraydescr_richcompare(PyArray_Descr *self, PyObject *other, int cmp_op) result = Py_False; break; case Py_EQ: - if (PyArray_EquivTypes(self, new)) + if (PyArray_EquivTypes(self, new)) result = Py_True; else result = Py_False; break; case Py_NE: - if (PyArray_EquivTypes(self, new)) + if (PyArray_EquivTypes(self, new)) result = Py_False; else result = Py_True; break; case Py_GT: - if (!PyArray_EquivTypes(self, new) && PyArray_CanCastTo(new, self)) + if (!PyArray_EquivTypes(self, new) && PyArray_CanCastTo(new, self)) result = Py_True; else result = Py_False; break; case Py_GE: - if (PyArray_CanCastTo(new, self)) + if (PyArray_CanCastTo(new, self)) result = Py_True; else result = Py_False; @@ -11100,10 +11100,10 @@ arraydescr_richcompare(PyArray_Descr *self, PyObject *other, int cmp_op) static Py_ssize_t descr_length(PyObject *self0) { - + PyArray_Descr *self = (PyArray_Descr *)self0; - if (self->names) + if (self->names) return PyDict_Size(self->fields); else return 0; } @@ -11284,13 +11284,13 @@ static PyObject * arrayflags_forc_get(PyArrayFlagsObject *self) { PyObject *item; - + if (((self->flags & FORTRAN) == FORTRAN) || ((self->flags & CONTIGUOUS) == CONTIGUOUS)) item = Py_True; else item = Py_False; - + Py_INCREF(item); return item; } @@ -11299,13 +11299,13 @@ static PyObject * arrayflags_fnc_get(PyArrayFlagsObject *self) { PyObject *item; - + if (((self->flags & FORTRAN) == FORTRAN) && !((self->flags & CONTIGUOUS) == CONTIGUOUS)) item = Py_True; else item = Py_False; - + Py_INCREF(item); return item; } @@ -11314,14 +11314,14 @@ static PyObject * arrayflags_farray_get(PyArrayFlagsObject *self) { PyObject *item; - + if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \ (ALIGNED|WRITEABLE|FORTRAN)) && !((self->flags & CONTIGUOUS) == CONTIGUOUS)) item = Py_True; else item = Py_False; - + Py_INCREF(item); return item; } @@ -11341,7 +11341,7 @@ arrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj) PyErr_SetString(PyExc_ValueError, "Cannot set flags on array scalars."); return -1; } - res = PyObject_CallMethod(self->arr, "setflags", "OOO", Py_None, Py_None, + res = PyObject_CallMethod(self->arr, "setflags", "OOO", Py_None, Py_None, (PyObject_IsTrue(obj) ? Py_True : Py_False)); if (res == NULL) return -1; Py_DECREF(res); @@ -11356,7 +11356,7 @@ arrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj) PyErr_SetString(PyExc_ValueError, "Cannot set flags on array scalars."); return -1; } - res = PyObject_CallMethod(self->arr, "setflags", "OOO", Py_None, + res = PyObject_CallMethod(self->arr, "setflags", "OOO", Py_None, (PyObject_IsTrue(obj) ? Py_True : Py_False), Py_None); if (res == NULL) return -1; @@ -11372,7 +11372,7 @@ arrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj) PyErr_SetString(PyExc_ValueError, "Cannot set flags on array scalars."); return -1; } - res = PyObject_CallMethod(self->arr, "setflags", "OOO", + res = PyObject_CallMethod(self->arr, "setflags", "OOO", (PyObject_IsTrue(obj) ? Py_True : Py_False), Py_None, Py_None); if (res == NULL) return -1; @@ -11492,7 +11492,7 @@ arrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind) if (strncmp(key,"ALIGNED",n)==0) return arrayflags_aligned_get(self); break; - case 9: + case 9: if (strncmp(key,"WRITEABLE",n)==0) return arrayflags_writeable_get(self); break; @@ -11513,7 +11513,7 @@ arrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind) static int arrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item) -{ +{ char *key; int n; if (!PyString_Check(ind)) goto fail; @@ -11522,12 +11522,12 @@ arrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item) if (((n==9) && (strncmp(key, "WRITEABLE", n)==0)) || ((n==1) && (strncmp(key, "W", n)==0))) return arrayflags_writeable_set(self, item); - else if (((n==7) && (strncmp(key, "ALIGNED", n)==0)) || + else if (((n==7) && (strncmp(key, "ALIGNED", n)==0)) || ((n==1) && (strncmp(key, "A", n)==0))) return arrayflags_aligned_set(self, item); else if (((n==12) && (strncmp(key, "UPDATEIFCOPY", n)==0)) || ((n==1) && (strncmp(key, "U", n)==0))) - return arrayflags_updateifcopy_set(self, item); + return arrayflags_updateifcopy_set(self, item); fail: PyErr_SetString(PyExc_KeyError, "Unknown flag"); @@ -11538,14 +11538,14 @@ static char * _torf_(int flags, int val) { if ((flags & val) == val) return "True"; - else return "False"; + else return "False"; } static PyObject * arrayflags_print(PyArrayFlagsObject *self) { int fl = self->flags; - + return PyString_FromFormat(" %s : %s\n %s : %s\n %s : %s\n"\ " %s : %s\n %s : %s\n %s : %s", "CONTIGUOUS", _torf_(fl, CONTIGUOUS), diff --git a/numpy/core/src/arraytypes.inc.src b/numpy/core/src/arraytypes.inc.src index 4d8a853ee..8a2d69d4b 100644 --- a/numpy/core/src/arraytypes.inc.src +++ b/numpy/core/src/arraytypes.inc.src @@ -24,13 +24,13 @@ MyPyLong_As@name@(PyObject *vv) /**end repeat**/ -static double +static double _getNAN(void) { #ifdef NAN return NAN; #else static double nan=0; - + if (nan == 0) { double mul = 1e100; double tmp = 0.0; @@ -51,7 +51,7 @@ static double MyPyFloat_AsDouble(PyObject *obj) { if (obj == Py_None) return _getNAN(); - return PyFloat_AsDouble(obj); + return PyFloat_AsDouble(obj); } @@ -67,7 +67,7 @@ MyPyFloat_AsDouble(PyObject *obj) #kind=Bool, Byte, UByte, Short, UShort, Int, Long, UInt, ULong, LongLong, ULongLong, Float, Double# */ -static PyObject * +static PyObject * @TYP@_getitem(char *ip, PyArrayObject *ap) { @typ@ t1; @@ -82,7 +82,7 @@ static PyObject * } } -static int +static int @TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) { @typ@ temp; /* ensures alignment */ @@ -93,31 +93,31 @@ static int temp = (@typ@)@func2@(op); } if (PyErr_Occurred()) return -1; - if (ap == NULL || PyArray_ISBEHAVED(ap)) + if (ap == NULL || PyArray_ISBEHAVED(ap)) *((@typ@ *)ov)=temp; else { - ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), + ap->descr->f->copyswap(ov, &temp, !PyArray_ISNOTSWAPPED(ap), ap); } - + return 0; } /**end repeat**/ -/**begin repeat +/**begin repeat #TYP=CFLOAT,CDOUBLE# #typ=float, double# */ -static PyObject * +static PyObject * @TYP@_getitem(char *ip, PyArrayObject *ap) { @typ@ t1, t2; - if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { - return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], + if ((ap==NULL) || PyArray_ISBEHAVED_RO(ap)) { + return PyComplex_FromDoubles((double)((@typ@ *)ip)[0], (double)((@typ@ *)ip)[1]); } else { @@ -130,27 +130,27 @@ static PyObject * } /**end repeat**/ -/**begin repeat +/**begin repeat #TYP=CFLOAT, CDOUBLE, CLONGDOUBLE# #typ=float, double, longdouble# #kind=CFloat, CDouble, CLongDouble# */ -static int -@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) +static int +@TYP@_setitem(PyObject *op, char *ov, PyArrayObject *ap) { Py_complex oop; PyObject *op2; c@typ@ temp; int rsize; - + if (!(PyArray_IsScalar(op, @kind@))) { if (PyArray_Check(op) && (PyArray_NDIM(op)==0)) { op2 = ((PyArrayObject *)op)->descr->f->getitem \ - (((PyArrayObject *)op)->data, + (((PyArrayObject *)op)->data, (PyArrayObject *)op); } - else { + else { op2 = op; Py_INCREF(op); } if (op2 == Py_None) { @@ -162,16 +162,16 @@ static int Py_DECREF(op2); if (PyErr_Occurred()) return -1; temp.real = (@typ@) oop.real; - temp.imag = (@typ@) oop.imag; + temp.imag = (@typ@) oop.imag; } else { temp = ((Py@kind@ScalarObject *)op)->obval; } - + memcpy(ov, &temp, ap->descr->elsize); if (!PyArray_ISNOTSWAPPED(ap)) byte_swap_vector(ov, 2, sizeof(@typ@)); - + rsize = sizeof(@typ@); copy_and_swap(ov, &temp, rsize, 2, rsize, !PyArray_ISNOTSWAPPED(ap)); return 0; @@ -204,16 +204,16 @@ LONGDOUBLE_setitem(PyObject *op, char *ov, PyArrayObject *ap) { return 0; } -static PyObject * -CLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) +static PyObject * +CLONGDOUBLE_getitem(char *ip, PyArrayObject *ap) { return PyArray_Scalar(ip, ap->descr, NULL); } /* UNICODE */ -static PyObject * -UNICODE_getitem(char *ip, PyArrayObject *ap) +static PyObject * +UNICODE_getitem(char *ip, PyArrayObject *ap) { PyObject *obj; int mysize; @@ -241,7 +241,7 @@ UNICODE_getitem(char *ip, PyArrayObject *ap) /* create new empty unicode object of length mysize*2 */ obj = MyPyUnicode_New(mysize*2); if (obj == NULL) {if (alloc) _pya_free(buffer); return obj;} - mysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str, + mysize = PyUCS2Buffer_FromUCS4(((PyUnicodeObject *)obj)->str, (PyArray_UCS4 *)buffer, mysize); /* reset length of unicode object to ucs2size */ if (MyPyUnicode_Resize((PyUnicodeObject *)obj, mysize) < 0) { @@ -251,19 +251,19 @@ UNICODE_getitem(char *ip, PyArrayObject *ap) } #endif if (alloc) _pya_free(buffer); - + return obj; } -static int -UNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) +static int +UNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) { PyObject *temp; Py_UNICODE *ptr; int datalen; #ifndef Py_UNICODE_WIDE char *buffer; -#endif +#endif if ((temp=PyObject_Unicode(op)) == NULL) return -1; ptr = PyUnicode_AS_UNICODE(temp); @@ -285,7 +285,7 @@ UNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) } } else buffer = ov; - datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)buffer, + datalen = PyUCS2Buffer_AsUCS4(ptr, (PyArray_UCS4 *)buffer, datalen >> 1, ap->descr->elsize >> 2); datalen <<= 2; @@ -298,16 +298,16 @@ UNICODE_setitem(PyObject *op, char *ov, PyArrayObject *ap) if (ap->descr->elsize > datalen) { memset(ov + datalen, 0, (ap->descr->elsize - datalen)); } - - if (!PyArray_ISNOTSWAPPED(ap)) + + if (!PyArray_ISNOTSWAPPED(ap)) byte_swap_vector(ov, ap->descr->elsize >> 2, 4); Py_DECREF(temp); return 0; } /* STRING -- can handle both NULL-terminated and not NULL-terminated cases */ -static PyObject * -STRING_getitem(char *ip, PyArrayObject *ap) +static PyObject * +STRING_getitem(char *ip, PyArrayObject *ap) { if (ip[ap->descr->elsize-1]) return PyString_FromStringAndSize(ip,ap->descr->elsize); @@ -315,15 +315,15 @@ STRING_getitem(char *ip, PyArrayObject *ap) return PyString_FromString(ip); } -static int -STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) +static int +STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) { char *ptr; int len; PyObject *temp=PyObject_Str(op); - + if (temp == NULL) return -1; - + if (PyString_AsStringAndSize(temp, &ptr, &len) == -1) { Py_DECREF(temp); return -1; @@ -338,8 +338,8 @@ STRING_setitem(PyObject *op, char *ov, PyArrayObject *ap) /* OBJECT */ -static PyObject * -OBJECT_getitem(char *ip, PyArrayObject *ap) +static PyObject * +OBJECT_getitem(char *ip, PyArrayObject *ap) { if (PyArray_ISALIGNED(ap)) { Py_INCREF(*(PyObject **)ip); @@ -354,8 +354,8 @@ OBJECT_getitem(char *ip, PyArrayObject *ap) } -static int -OBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) +static int +OBJECT_setitem(PyObject *op, char *ov, PyArrayObject *ap) { Py_INCREF(op); if (PyArray_ISALIGNED(ap)) { @@ -400,9 +400,9 @@ VOID_getitem(char *ip, PyArrayObject *ap) for (i=0; i<n; i++) { key = PyTuple_GET_ITEM(names, i); tup = PyDict_GetItem(descr->fields, key); - if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset, + if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset, &title)) { - Py_DECREF(ret); + Py_DECREF(ret); ap->descr = descr; return NULL; } @@ -426,10 +426,10 @@ VOID_getitem(char *ip, PyArrayObject *ap) /* return an array of the basic type */ PyArray_Dims shape={NULL,-1}; PyObject *ret; - if (!(PyArray_IntpConverter(descr->subarray->shape, + if (!(PyArray_IntpConverter(descr->subarray->shape, &shape))) { PyDimMem_FREE(shape.ptr); - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "invalid shape in fixed-type tuple."); return NULL; } @@ -448,7 +448,7 @@ VOID_getitem(char *ip, PyArrayObject *ap) finish: if (descr->hasobject) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "tried to get void-array with object" " members as buffer."); return NULL; @@ -463,8 +463,8 @@ VOID_getitem(char *ip, PyArrayObject *ap) /* default is to return buffer object pointing to current item */ /* a view of it */ - return u; - + return u; + fail: return NULL; } @@ -494,7 +494,7 @@ VOID_setitem(PyObject *op, char *ip, PyArrayObject *ap) names = descr->names; n = PyTuple_GET_SIZE(names); if (PyTuple_GET_SIZE(op) != n) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "size of tuple must match "\ "number of fields."); return -1; @@ -503,7 +503,7 @@ VOID_setitem(PyObject *op, char *ip, PyArrayObject *ap) for (i=0; i<n; i++) { key = PyTuple_GET_ITEM(names, i); tup = PyDict_GetItem(descr->fields, key); - if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset, + if (!PyArg_ParseTuple(tup, "Oi|O", &new, &offset, &title)) { ap->descr = descr; return -1; @@ -529,10 +529,10 @@ VOID_setitem(PyObject *op, char *ip, PyArrayObject *ap) /* copy into an array of the same basic type */ PyArray_Dims shape={NULL,-1}; PyObject *ret; - if (!(PyArray_IntpConverter(descr->subarray->shape, + if (!(PyArray_IntpConverter(descr->subarray->shape, &shape))) { PyDimMem_FREE(shape.ptr); - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "invalid shape in fixed-type tuple."); return -1; } @@ -556,7 +556,7 @@ VOID_setitem(PyObject *op, char *ip, PyArrayObject *ap) const void *buffer; Py_ssize_t buflen; if (descr->hasobject) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "tried to set void-array with object" " members using buffer."); return -1; @@ -568,11 +568,11 @@ VOID_setitem(PyObject *op, char *ip, PyArrayObject *ap) return 0; fail: - return -1; + return -1; } -/****************** XXX_to_YYY *******************************/ +/****************** XXX_to_YYY *******************************/ /* Assumes contiguous, and aligned, from and to */ @@ -584,9 +584,9 @@ VOID_setitem(PyObject *op, char *ip, PyArrayObject *ap) #fromtyp=byte*13, ubyte*13, short*13, ushort*13, int*13, uint*13, long*13, ulong*13, longlong*13, ulonglong*13, float*13, double*13, longdouble*13, float*13, double*13, longdouble*13# #incr= ip++*169,ip+=2*39# */ -static void -@from@_to_@to@(register @fromtyp@ *ip, register @totyp@ *op, register intp n, - PyArrayObject *aip, PyArrayObject *aop) +static void +@from@_to_@to@(register @fromtyp@ *ip, register @totyp@ *op, register intp n, + PyArrayObject *aip, PyArrayObject *aop) { while (n--) { *op++ = (@totyp@)*ip; @@ -599,9 +599,9 @@ static void #from=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE# #fromtyp=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble# */ -static void -@from@_to_BOOL(register @fromtyp@ *ip, register Bool *op, register intp n, - PyArrayObject *aip, PyArrayObject *aop) +static void +@from@_to_BOOL(register @fromtyp@ *ip, register Bool *op, register intp n, + PyArrayObject *aip, PyArrayObject *aop) { while (n--) { *op++ = (Bool)(*ip++ != FALSE); @@ -613,9 +613,9 @@ static void #from=CFLOAT, CDOUBLE, CLONGDOUBLE# #fromtyp=cfloat, cdouble, clongdouble# */ -static void -@from@_to_BOOL(register @fromtyp@ *ip, register Bool *op, register intp n, - PyArrayObject *aip, PyArrayObject *aop) +static void +@from@_to_BOOL(register @fromtyp@ *ip, register Bool *op, register intp n, + PyArrayObject *aip, PyArrayObject *aop) { while (n--) { *op = (Bool)(((*ip).real != FALSE) || ((*ip).imag != FALSE)); @@ -628,9 +628,9 @@ static void #to=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE# #totyp=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble# */ -static void -BOOL_to_@to@(register Bool *ip, register @totyp@ *op, register intp n, - PyArrayObject *aip, PyArrayObject *aop) +static void +BOOL_to_@to@(register Bool *ip, register @totyp@ *op, register intp n, + PyArrayObject *aip, PyArrayObject *aop) { while (n--) { *op++ = (@totyp@)(*ip++ != FALSE); @@ -645,10 +645,10 @@ BOOL_to_@to@(register Bool *ip, register @totyp@ *op, register intp n, #fromtyp=Bool*3,byte*3, ubyte*3, short*3, ushort*3, int*3, uint*3, long*3, ulong*3, longlong*3, ulonglong*3, float*3, double*3, longdouble*3# #totyp= (float, double, longdouble)*14# */ -static void -@from@_to_@to@(register @fromtyp@ *ip, register @totyp@ *op, register intp n, - PyArrayObject *aip, PyArrayObject *aop) -{ +static void +@from@_to_@to@(register @fromtyp@ *ip, register @totyp@ *op, register intp n, + PyArrayObject *aip, PyArrayObject *aop) +{ while (n--) { *op++ = (@totyp@)*ip++; *op++ = 0.0; @@ -657,16 +657,16 @@ static void } /**end repeat**/ -/**begin repeat +/**begin repeat #to=(CFLOAT,CDOUBLE,CLONGDOUBLE)*3# #from=CFLOAT*3,CDOUBLE*3,CLONGDOUBLE*3# #totyp=(float, double, longdouble)*3# #fromtyp=float*3, double*3, longdouble*3# */ -static void -@from@_to_@to@(register @fromtyp@ *ip, register @totyp@ *op, register intp n, - PyArrayObject *aip, PyArrayObject *aop) +static void +@from@_to_@to@(register @fromtyp@ *ip, register @totyp@ *op, register intp n, + PyArrayObject *aip, PyArrayObject *aop) { n <<= 1; while (n--) { @@ -676,17 +676,17 @@ static void } /**end repeat**/ -/**begin repeat +/**begin repeat #from=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE, STRING, UNICODE, VOID, OBJECT# #fromtyp=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, char, char, char, PyObject *# #skip= 1*17, aip->descr->elsize*3, 1# */ -static void +static void @from@_to_OBJECT(@fromtyp@ *ip, PyObject **op, intp n, PyArrayObject *aip, PyArrayObject *aop) { - register intp i; + register intp i; int skip=@skip@; for(i=0;i<n;i++,ip+=skip,op++) { Py_XDECREF(*op); @@ -695,17 +695,17 @@ static void } /**end repeat**/ -/**begin repeat +/**begin repeat #to=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE, STRING, UNICODE, VOID# #totyp=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, char, char, char# #skip= 1*17, aip->descr->elsize*3# */ -static void +static void OBJECT_to_@to@(PyObject **ip, @totyp@ *op, intp n, PyArrayObject *aip, PyArrayObject *aop) { - register intp i; + register intp i; int skip=@skip@; for(i=0;i<n;i++,ip++,op+=skip) { @to@_setitem(*ip, (char *)op, aop); @@ -725,7 +725,7 @@ OBJECT_to_@to@(PyObject **ip, @totyp@ *op, intp n, PyArrayObject *aip, #convstr=(Int*9,Long*2,Float*3,Complex*3,Tuple*3)*3# */ static void -@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, +@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, PyArrayObject *aop) { register intp i; @@ -745,7 +745,7 @@ static void temp = new; if (temp==NULL) return; } - + @to@_setitem(temp,(char *)op, aop); Py_DECREF(temp); } @@ -762,7 +762,7 @@ static void */ static void -@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, +@from@_to_@to@(@fromtyp@ *ip, @totyp@ *op, intp n, PyArrayObject *aip, PyArrayObject *aop) { register intp i; @@ -862,7 +862,7 @@ static int { @btype@ result; - result = PyOS_strto@func@(str, endptr, 0); + result = PyOS_strto@func@(str, endptr, 0); *ip = (@type@) result; return 0; } @@ -905,15 +905,15 @@ static int #type=short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble# */ static void -@fname@_copyswapn (void *dst, intp dstride, void *src, intp sstride, +@fname@_copyswapn (void *dst, intp dstride, void *src, intp sstride, intp n, int swap, void *arr) { - if (src != NULL) { + if (src != NULL) { if (sstride == sizeof(@type@) && dstride == sizeof(@type@)) { memcpy(dst, src, n*sizeof(@type@)); } else { - _unaligned_strided_byte_copy(dst, dstride, src, sstride, + _unaligned_strided_byte_copy(dst, dstride, src, sstride, n, sizeof(@type@)); } } @@ -979,7 +979,7 @@ static void c=*a; *a++ = *b; *b-- = c; } } -#endif +#endif } } @@ -992,7 +992,7 @@ static void #type=Bool, byte, ubyte# */ static void -@fname@_copyswapn (void *dst, intp dstride, void *src, intp sstride, intp n, +@fname@_copyswapn (void *dst, intp dstride, void *src, intp sstride, intp n, int swap, void *arr) { if (src != NULL) { @@ -1000,7 +1000,7 @@ static void memcpy(dst, src, n*sizeof(@type@)); } else { - _unaligned_strided_byte_copy(dst, dstride, src, sstride, + _unaligned_strided_byte_copy(dst, dstride, src, sstride, n, sizeof(@type@)); } } @@ -1026,7 +1026,7 @@ static void #fsize=FLOAT,DOUBLE,LONGDOUBLE# */ static void -@fname@_copyswapn (void *dst, intp dstride, void *src, intp sstride, intp n, +@fname@_copyswapn (void *dst, intp dstride, void *src, intp sstride, intp n, int swap, void *arr) { @@ -1035,7 +1035,7 @@ static void memcpy(dst, src, n*sizeof(@type@)); } else { - _unaligned_strided_byte_copy(dst, dstride, src, sstride, + _unaligned_strided_byte_copy(dst, dstride, src, sstride, n, sizeof(@type@)); } } @@ -1139,7 +1139,7 @@ static void c=*a; *a++ = *b; *b-- = c; } } -#endif +#endif } } @@ -1147,7 +1147,7 @@ static void #define __ALIGNED(obj, sz) ((((size_t) obj) % (sz))==0) static void -OBJECT_copyswapn (PyObject **dst, intp dstride, PyObject **src, intp sstride, +OBJECT_copyswapn (PyObject **dst, intp dstride, PyObject **src, intp sstride, register intp n, int swap, void *arr) { register intp i; @@ -1183,7 +1183,7 @@ OBJECT_copyswapn (PyObject **dst, intp dstride, PyObject **src, intp sstride, static void OBJECT_copyswap(PyObject **dst, PyObject **src, int swap, void *arr) { - + if (src != NULL) { if (__ALIGNED(dst,sizeof(PyObject **)) && __ALIGNED(src,sizeof(PyObject **))) { Py_INCREF(*src); @@ -1201,7 +1201,7 @@ OBJECT_copyswap(PyObject **dst, PyObject **src, int swap, void *arr) /* ignore swap */ static void -STRING_copyswapn (char *dst, intp dstride, char *src, intp sstride, +STRING_copyswapn (char *dst, intp dstride, char *src, intp sstride, intp n, int swap, PyArrayObject *arr) { if (src != NULL && arr != NULL) { @@ -1212,13 +1212,13 @@ STRING_copyswapn (char *dst, intp dstride, char *src, intp sstride, else { _unaligned_strided_byte_copy(dst, dstride, src, sstride, n, itemsize); } - } + } return; } /* */ static void -VOID_copyswapn (char *dst, intp dstride, char *src, intp sstride, +VOID_copyswapn (char *dst, intp dstride, char *src, intp sstride, intp n, int swap, PyArrayObject *arr) { int itemsize; @@ -1230,7 +1230,7 @@ VOID_copyswapn (char *dst, intp dstride, char *src, intp sstride, int offset, pos=0; descr = arr->descr; while (PyDict_Next(descr->fields, &pos, &key, &value)) { - if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, + if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) {arr->descr=descr;return;} arr->descr = new; new->f->copyswapn(dst+offset, dstride, src+offset, sstride, n, swap, arr); @@ -1239,7 +1239,7 @@ VOID_copyswapn (char *dst, intp dstride, char *src, intp sstride, return; } if (src != NULL) { - memcpy(dst, src, itemsize * n); + memcpy(dst, src, itemsize * n); } return; } @@ -1254,7 +1254,7 @@ VOID_copyswap (char *dst, char *src, int swap, PyArrayObject *arr) int offset, pos=0; descr = arr->descr; /* Save it */ while (PyDict_Next(descr->fields, &pos, &key, &value)) { - if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, + if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) {arr->descr=descr;return;} arr->descr = new; new->f->copyswap(dst+offset, src+offset, swap, arr); @@ -1270,7 +1270,7 @@ VOID_copyswap (char *dst, char *src, int swap, PyArrayObject *arr) static void -UNICODE_copyswapn (char *dst, intp dstride, char *src, intp sstride, +UNICODE_copyswapn (char *dst, intp dstride, char *src, intp sstride, intp n, int swap, PyArrayObject *arr) { int itemsize; @@ -1280,10 +1280,10 @@ UNICODE_copyswapn (char *dst, intp dstride, char *src, intp sstride, if (dstride == itemsize && sstride == itemsize) memcpy(dst, src, n * itemsize); else - _unaligned_strided_byte_copy(dst, dstride, src, + _unaligned_strided_byte_copy(dst, dstride, src, sstride, n, itemsize); } - + n *= itemsize; if (swap) { register char *a, *b, c; @@ -1303,7 +1303,7 @@ STRING_copyswap (char *dst, char *src, int swap, PyArrayObject *arr) { if (src != NULL && arr != NULL) { memcpy(dst, src, arr->descr->elsize); - } + } } static void @@ -1315,7 +1315,7 @@ UNICODE_copyswap (char *dst, char *src, int swap, PyArrayObject *arr) if (src != NULL) { memcpy(dst, src, itemsize); } - + if (swap) { register char *a, *b, c; itemsize >>= 2; @@ -1335,7 +1335,7 @@ UNICODE_copyswap (char *dst, char *src, int swap, PyArrayObject *arr) #fname=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE# #type=Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble# */ -static Bool +static Bool @fname@_nonzero (@type@ *ip, PyArrayObject *ap) { @type@ t1; @@ -1354,7 +1354,7 @@ static Bool #fname=CFLOAT,CDOUBLE,CLONGDOUBLE# #type=cfloat, cdouble, clongdouble# */ -static Bool +static Bool @fname@_nonzero (@type@ *ip, PyArrayObject *ap) { @type@ t1; @@ -1374,17 +1374,17 @@ static Bool #define WHITELEN 6 static Bool -Py_STRING_ISSPACE(char ch) +Py_STRING_ISSPACE(char ch) { char white[] = WHITESPACE; int j; Bool space=FALSE; - for (j=0; j<WHITELEN; j++) { - if (ch == white[j]) { - space=TRUE; - break; - } - } + for (j=0; j<WHITELEN; j++) { + if (ch == white[j]) { + space=TRUE; + break; + } + } return space; } @@ -1417,7 +1417,7 @@ UNICODE_nonzero (PyArray_UCS4 *ip, PyArrayObject *ap) int len = ap->descr->elsize >> 2; int i; Bool nonz = FALSE; - char *buffer=NULL; + char *buffer=NULL; if ((!PyArray_ISNOTSWAPPED(ap)) || \ (!PyArray_ISALIGNED(ap))) { @@ -1446,7 +1446,7 @@ UNICODE_nonzero (PyArray_UCS4 *ip, PyArrayObject *ap) static Bool OBJECT_nonzero (PyObject **ip, PyArrayObject *ap) { - + if (PyArray_ISALIGNED(ap)) { return (Bool) PyObject_IsTrue(*ip); } @@ -1473,7 +1473,7 @@ VOID_nonzero (char *ip, PyArrayObject *ap) descr = ap->descr; savedflags = ap->flags; while (PyDict_Next(descr->fields, &pos, &key, &value)) { - if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, + if (!PyArg_ParseTuple(value, "Oi|O", &new, &offset, &title)) {PyErr_Clear(); continue;} ap->descr = new; ap->flags = savedflags; @@ -1518,7 +1518,7 @@ BOOL_compare(Bool *ip1, Bool *ip2, PyArrayObject *ap) */ static int -@fname@_compare (@type@ *ip1, @type@ *ip2, PyArrayObject *ap) +@fname@_compare (@type@ *ip1, @type@ *ip2, PyArrayObject *ap) { return *ip1 < *ip2 ? -1 : *ip1 == *ip2 ? 0 : 1; } @@ -1526,13 +1526,13 @@ static int /**end repeat**/ /* compare imaginary part first, then complex if equal imaginary */ -/**begin repeat +/**begin repeat #fname=CFLOAT, CDOUBLE, CLONGDOUBLE# #type= float, double, longdouble# */ static int -@fname@_compare (@type@ *ip1, @type@ *ip2, PyArrayObject *ap) +@fname@_compare (@type@ *ip1, @type@ *ip2, PyArrayObject *ap) { if (*ip1 == *ip2) { return ip1[1]<ip2[1] ? -1 : (ip1[1] == ip2[1] ? 0 : 1); @@ -1543,48 +1543,48 @@ static int } /**end repeat**/ -static int -OBJECT_compare(PyObject **ip1, PyObject **ip2, PyArrayObject *ap) -{ +static int +OBJECT_compare(PyObject **ip1, PyObject **ip2, PyArrayObject *ap) +{ return PyObject_Compare(*ip1, *ip2); } -static int +static int STRING_compare(char *ip1, char *ip2, PyArrayObject *ap) { return strncmp(ip1, ip2, ap->descr->elsize); } /* taken from Python */ -static int -UNICODE_compare(register PyArray_UCS4 *ip1, register PyArray_UCS4 *ip2, +static int +UNICODE_compare(register PyArray_UCS4 *ip1, register PyArray_UCS4 *ip2, PyArrayObject *ap) { register int itemsize=ap->descr->elsize; register PyArray_UCS4 c1, c2; if (itemsize < 0) return 0; - + while(itemsize-- > 0) { c1 = *ip1++; c2 = *ip2++; - - if (c1 != c2) + + if (c1 != c2) return (c1 < c2) ? -1 : 1; } return 0; } /* possibly redefine compare in terms of fields and subarrays if any */ -/* this would have to properly align data (if needed for the type) - before passing on to the _compare function of sub-fields +/* this would have to properly align data (if needed for the type) + before passing on to the _compare function of sub-fields - More importantly, it's unclear what is meant by < and > so we really - can't implement it correctly. + More importantly, it's unclear what is meant by < and > so we really + can't implement it correctly. */ static int -VOID_compare(char *ip1, char *ip2, PyArrayObject *ap) +VOID_compare(char *ip1, char *ip2, PyArrayObject *ap) { return STRING_compare(ip1, ip2, ap); } @@ -1616,18 +1616,18 @@ static int /**end repeat**/ -static int -OBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) +static int +OBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) { - register intp i; + register intp i; PyObject *mp=ip[0]; *max_ind=0; - for(i=1; i<n; i++) { + for(i=1; i<n; i++) { ip++; - if (PyObject_Compare(*ip,mp) > 0) { - mp = *ip; + if (PyObject_Compare(*ip,mp) > 0) { + mp = *ip; *max_ind=i; - } - } + } + } return 0; } @@ -1637,23 +1637,23 @@ OBJECT_argmax(PyObject **ip, intp n, intp *max_ind, PyArrayObject *aip) #type= char, PyArray_UCS4# */ -static int -@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip) +static int +@fname@_argmax(@type@ *ip, intp n, intp *max_ind, PyArrayObject *aip) { - register intp i; + register intp i; int elsize = aip->descr->elsize; @type@ *mp = (@type@ *)_pya_malloc(elsize); - + if (mp==NULL) return 0; memcpy(mp, ip, elsize); *max_ind = 0; - for(i=1; i<n; i++) { + for(i=1; i<n; i++) { ip += elsize; - if (@fname@_compare(ip,mp,aip) > 0) { + if (@fname@_compare(ip,mp,aip) > 0) { memcpy(mp, ip, elsize); *max_ind=i; - } - } + } + } _pya_free(mp); return 0; } @@ -1663,17 +1663,17 @@ static int #define VOID_argmax NULL static void -BOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, +BOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, void *ignore) { register Bool tmp=FALSE; register intp i; - for(i=0;i<n;i++,ip1+=is1,ip2+=is2) { + for(i=0;i<n;i++,ip1+=is1,ip2+=is2) { if ((*((Bool *)ip1) != 0) && (*((Bool *)ip2) != 0)) { tmp = TRUE; break; } - } + } *((Bool *)op) = tmp; } @@ -1683,12 +1683,12 @@ BOOL_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, #out= long, ulong, long, ulong, long, ulong, long, ulong, longlong, ulonglong, float, double, longdouble# */ static void -@name@_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, +@name@_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, void *ignore) { register @out@ tmp=(@out@)0; register intp i; - for(i=0;i<n;i++,ip1+=is1,ip2+=is2) { + for(i=0;i<n;i++,ip1+=is1,ip2+=is2) { tmp += (@out@)(*((@type@ *)ip1)) * \ (@out@)(*((@type@ *)ip2)); } @@ -1702,30 +1702,30 @@ static void #type= float, double, longdouble# */ static void @name@_dot(char *ip1, intp is1, char *ip2, intp is2, - char *op, intp n, void *ignore) -{ - @type@ tmpr=(@type@)0.0, tmpi=(@type@)0.0; - intp i; + char *op, intp n, void *ignore) +{ + @type@ tmpr=(@type@)0.0, tmpi=(@type@)0.0; + intp i; for(i=0;i<n;i++,ip1+=is1,ip2+=is2) { - tmpr += ((@type@ *)ip1)[0] * ((@type@ *)ip2)[0] - - ((@type@ *)ip1)[1] * ((@type@ *)ip2)[1]; - tmpi += ((@type@ *)ip1)[1] * ((@type@ *)ip2)[0] + tmpr += ((@type@ *)ip1)[0] * ((@type@ *)ip2)[0] + - ((@type@ *)ip1)[1] * ((@type@ *)ip2)[1]; + tmpi += ((@type@ *)ip1)[1] * ((@type@ *)ip2)[0] + ((@type@ *)ip1)[0] * ((@type@ *)ip2)[1]; - } + } ((@type@ *)op)[0] = tmpr; ((@type@ *)op)[1] = tmpi; -} +} /**end repeat**/ -static void +static void OBJECT_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, - void *ignore) + void *ignore) { intp i; PyObject *tmp1, *tmp2, *tmp=NULL; PyObject **tmp3; - for(i=0;i<n;i++,ip1+=is1,ip2+=is2) { - tmp1 = PyNumber_Multiply(*((PyObject **)ip1), + for(i=0;i<n;i++,ip1+=is1,ip2+=is2) { + tmp1 = PyNumber_Multiply(*((PyObject **)ip1), *((PyObject **)ip2)); if (!tmp1) { Py_XDECREF(tmp); return;} if (i == 0) { @@ -1737,7 +1737,7 @@ OBJECT_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n, if (!tmp2) return; tmp = tmp2; } - } + } tmp3 = (PyObject**) op; tmp2 = *tmp3; *((PyObject **)op) = tmp; @@ -1758,7 +1758,7 @@ OBJECT_fill(PyObject **buffer, intp length, void *ignored) start = PyNumber_Add(start, delta); if (!start) goto finish; buffer += 2; - + for (i=2; i<length; i++, buffer++) { start = PyNumber_Add(start, delta); if (!start) goto finish; @@ -1768,10 +1768,10 @@ OBJECT_fill(PyObject **buffer, intp length, void *ignored) finish: Py_DECREF(delta); - return; + return; } -/**begin repeat +/**begin repeat #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE# #typ=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble# */ @@ -1826,7 +1826,7 @@ OBJECT_fillwithscalar(PyObject **buffer, intp length, PyObject **value, void *ig buffer[i] = val; } } -/**begin repeat +/**begin repeat #NAME=BOOL,BYTE,UBYTE# #typ=Bool,byte,ubyte# */ @@ -1837,7 +1837,7 @@ static void } /**end repeat**/ -/**begin repeat +/**begin repeat #NAME=SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE,CFLOAT,CDOUBLE,CLONGDOUBLE# #typ=short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble# */ @@ -1856,12 +1856,12 @@ static void #define _ALIGN(type) offsetof(struct {char c; type v;},v) -/* Disable harmless compiler warning "4116: unnamed type definition in - parentheses" which is caused by the _ALIGN macro. */ +/* Disable harmless compiler warning "4116: unnamed type definition in + parentheses" which is caused by the _ALIGN macro. */ -#if defined(_MSC_VER) -#pragma warning(disable:4116) -#endif +#if defined(_MSC_VER) +#pragma warning(disable:4116) +#endif /**begin repeat @@ -1874,35 +1874,35 @@ static void static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = { { - (PyArray_VectorUnaryFunc*)@from@_to_BOOL, - (PyArray_VectorUnaryFunc*)@from@_to_BYTE, - (PyArray_VectorUnaryFunc*)@from@_to_UBYTE, - (PyArray_VectorUnaryFunc*)@from@_to_SHORT, - (PyArray_VectorUnaryFunc*)@from@_to_USHORT, - (PyArray_VectorUnaryFunc*)@from@_to_INT, - (PyArray_VectorUnaryFunc*)@from@_to_UINT, + (PyArray_VectorUnaryFunc*)@from@_to_BOOL, + (PyArray_VectorUnaryFunc*)@from@_to_BYTE, + (PyArray_VectorUnaryFunc*)@from@_to_UBYTE, + (PyArray_VectorUnaryFunc*)@from@_to_SHORT, + (PyArray_VectorUnaryFunc*)@from@_to_USHORT, + (PyArray_VectorUnaryFunc*)@from@_to_INT, + (PyArray_VectorUnaryFunc*)@from@_to_UINT, (PyArray_VectorUnaryFunc*)@from@_to_LONG, - (PyArray_VectorUnaryFunc*)@from@_to_ULONG, - (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, - (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, - (PyArray_VectorUnaryFunc*)@from@_to_FLOAT, - (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, - (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_OBJECT, - (PyArray_VectorUnaryFunc*)@from@_to_STRING, - (PyArray_VectorUnaryFunc*)@from@_to_UNICODE, + (PyArray_VectorUnaryFunc*)@from@_to_ULONG, + (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, + (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, + (PyArray_VectorUnaryFunc*)@from@_to_FLOAT, + (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, + (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_OBJECT, + (PyArray_VectorUnaryFunc*)@from@_to_STRING, + (PyArray_VectorUnaryFunc*)@from@_to_UNICODE, (PyArray_VectorUnaryFunc*)@from@_to_VOID }, - (PyArray_GetItemFunc*)@from@_getitem, + (PyArray_GetItemFunc*)@from@_getitem, (PyArray_SetItemFunc*)@from@_setitem, (PyArray_CopySwapNFunc*)@from@_copyswapn, (PyArray_CopySwapFunc*)@from@_copyswap, - (PyArray_CompareFunc*)@from@_compare, + (PyArray_CompareFunc*)@from@_compare, (PyArray_ArgFunc*)@from@_argmax, - (PyArray_DotFunc*)NULL, + (PyArray_DotFunc*)NULL, (PyArray_ScanFunc*)@from@_scan, (PyArray_FromStrFunc*)@from@_fromstr, (PyArray_NonzeroFunc*)@from@_nonzero, @@ -1921,7 +1921,7 @@ static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = { 0 }; -static PyArray_Descr @from@_Descr = { +static PyArray_Descr @from@_Descr = { PyObject_HEAD_INIT(&PyArrayDescr_Type) &Py@NAME@ArrType_Type, PyArray_@from@LTR, @@ -1951,35 +1951,35 @@ static PyArray_Descr @from@_Descr = { static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = { { - (PyArray_VectorUnaryFunc*)@from@_to_BOOL, + (PyArray_VectorUnaryFunc*)@from@_to_BOOL, (PyArray_VectorUnaryFunc*)@from@_to_BYTE, - (PyArray_VectorUnaryFunc*)@from@_to_UBYTE, - (PyArray_VectorUnaryFunc*)@from@_to_SHORT, - (PyArray_VectorUnaryFunc*)@from@_to_USHORT, - (PyArray_VectorUnaryFunc*)@from@_to_INT, - (PyArray_VectorUnaryFunc*)@from@_to_UINT, + (PyArray_VectorUnaryFunc*)@from@_to_UBYTE, + (PyArray_VectorUnaryFunc*)@from@_to_SHORT, + (PyArray_VectorUnaryFunc*)@from@_to_USHORT, + (PyArray_VectorUnaryFunc*)@from@_to_INT, + (PyArray_VectorUnaryFunc*)@from@_to_UINT, (PyArray_VectorUnaryFunc*)@from@_to_LONG, - (PyArray_VectorUnaryFunc*)@from@_to_ULONG, - (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, - (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, - (PyArray_VectorUnaryFunc*)@from@_to_FLOAT, - (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, - (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, - (PyArray_VectorUnaryFunc*)@from@_to_OBJECT, - (PyArray_VectorUnaryFunc*)@from@_to_STRING, - (PyArray_VectorUnaryFunc*)@from@_to_UNICODE, + (PyArray_VectorUnaryFunc*)@from@_to_ULONG, + (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG, + (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG, + (PyArray_VectorUnaryFunc*)@from@_to_FLOAT, + (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT, + (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE, + (PyArray_VectorUnaryFunc*)@from@_to_OBJECT, + (PyArray_VectorUnaryFunc*)@from@_to_STRING, + (PyArray_VectorUnaryFunc*)@from@_to_UNICODE, (PyArray_VectorUnaryFunc*)@from@_to_VOID }, - (PyArray_GetItemFunc*)@from@_getitem, + (PyArray_GetItemFunc*)@from@_getitem, (PyArray_SetItemFunc*)@from@_setitem, (PyArray_CopySwapNFunc*)@from@_copyswapn, (PyArray_CopySwapFunc*)@from@_copyswap, - (PyArray_CompareFunc*)@from@_compare, + (PyArray_CompareFunc*)@from@_compare, (PyArray_ArgFunc*)@from@_argmax, - (PyArray_DotFunc*)@from@_dot, + (PyArray_DotFunc*)@from@_dot, (PyArray_ScanFunc*)@from@_scan, (PyArray_FromStrFunc*)@from@_fromstr, (PyArray_NonzeroFunc*)@from@_nonzero, @@ -1998,14 +1998,14 @@ static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = { 0 }; -static PyArray_Descr @from@_Descr = { +static PyArray_Descr @from@_Descr = { PyObject_HEAD_INIT(&PyArrayDescr_Type) &Py@NAME@ArrType_Type, PyArray_@kind@LTR, PyArray_@from@LTR, '@endian@', @isobject@, - PyArray_@from@, - @num@*sizeof(@fromtyp@), + PyArray_@from@, + @num@*sizeof(@fromtyp@), _ALIGN(@fromtyp@), NULL, NULL, @@ -2022,22 +2022,22 @@ static PyArray_Descr *_builtin_descrs[] = { &BOOL_Descr, &BYTE_Descr, &UBYTE_Descr, - &SHORT_Descr, - &USHORT_Descr, - &INT_Descr, - &UINT_Descr, - &LONG_Descr, + &SHORT_Descr, + &USHORT_Descr, + &INT_Descr, + &UINT_Descr, + &LONG_Descr, &ULONG_Descr, &LONGLONG_Descr, &ULONGLONG_Descr, - &FLOAT_Descr, + &FLOAT_Descr, &DOUBLE_Descr, &LONGDOUBLE_Descr, - &CFLOAT_Descr, - &CDOUBLE_Descr, + &CFLOAT_Descr, + &CDOUBLE_Descr, &CLONGDOUBLE_Descr, - &OBJECT_Descr, - &STRING_Descr, + &OBJECT_Descr, + &STRING_Descr, &UNICODE_Descr, &VOID_Descr, }; @@ -2056,8 +2056,8 @@ PyArray_DescrFromType(int type) else if (type == PyArray_NOTYPE) { /* This needs to not raise an error so that PyArray_DescrFromType(PyArray_NOTYPE) - works for backwards-compatible C-API - */ + works for backwards-compatible C-API + */ return NULL; } else if ((type == PyArray_CHAR) || \ @@ -2069,10 +2069,10 @@ PyArray_DescrFromType(int type) } else if PyTypeNum_ISUSERDEF(type) { ret = userdescrs[type-PyArray_USERDEF]; - } + } else { int num=PyArray_NTYPES; - if (type < _MAX_LETTER) + if (type < _MAX_LETTER) num = (int) _letter_to_num[type]; if (num >= PyArray_NTYPES) ret = NULL; @@ -2080,8 +2080,8 @@ PyArray_DescrFromType(int type) ret = _builtin_descrs[num]; } if (ret==NULL) { - PyErr_SetString(PyExc_ValueError, - "Invalid data-type for array"); + PyErr_SetString(PyExc_ValueError, + "Invalid data-type for array"); } else Py_INCREF(ret); return ret; @@ -2118,7 +2118,7 @@ set_typeinfo(PyObject *dict) #define BITSOF_INTP CHAR_BIT*SIZEOF_PY_INTPTR_T #define BITSOF_BYTE CHAR_BIT -/**begin repeat +/**begin repeat #name=BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,INTP,UINTP,LONG,ULONG,LONGLONG,ULONGLONG# #uname=BOOL,BYTE*2,SHORT*2,INT*2,INTP*2,LONG*2,LONGLONG*2# @@ -2129,15 +2129,15 @@ set_typeinfo(PyObject *dict) #cx=i*6,N,N,N,l,N,N,N# #cn=i*7,N,i,l,i,N,i# */ - PyDict_SetItemString(infodict, "@name@", - s=Py_BuildValue("ciii@cx@@cn@O", - PyArray_@name@LTR, + PyDict_SetItemString(infodict, "@name@", + s=Py_BuildValue("ciii@cx@@cn@O", + PyArray_@name@LTR, PyArray_@name@, BITSOF_@uname@, _ALIGN(@type@), @max@, @min@, (PyObject *)&Py@Name@ArrType_Type)); - Py_DECREF(s); + Py_DECREF(s); /**end repeat**/ #define BITSOF_CFLOAT 2*BITSOF_FLOAT @@ -2150,43 +2150,43 @@ set_typeinfo(PyObject *dict) #name=FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE# #Name=Float,Double,LongDouble,CFloat,CDouble,CLongDouble# */ - PyDict_SetItemString(infodict, "@name@", - s=Py_BuildValue("ciiiO", PyArray_@name@LTR, + PyDict_SetItemString(infodict, "@name@", + s=Py_BuildValue("ciiiO", PyArray_@name@LTR, PyArray_@name@, BITSOF_@name@, _ALIGN(@type@), (PyObject *)\ &Py@Name@ArrType_Type)); Py_DECREF(s); /**end repeat**/ - - PyDict_SetItemString(infodict, "OBJECT", - s=Py_BuildValue("ciiiO", PyArray_OBJECTLTR, - PyArray_OBJECT, + + PyDict_SetItemString(infodict, "OBJECT", + s=Py_BuildValue("ciiiO", PyArray_OBJECTLTR, + PyArray_OBJECT, sizeof(PyObject *)*CHAR_BIT, _ALIGN(PyObject *), (PyObject *)\ &PyObjectArrType_Type)); Py_DECREF(s); - PyDict_SetItemString(infodict, "STRING", - s=Py_BuildValue("ciiiO", PyArray_STRINGLTR, + PyDict_SetItemString(infodict, "STRING", + s=Py_BuildValue("ciiiO", PyArray_STRINGLTR, PyArray_STRING, 0, _ALIGN(char), (PyObject *)\ &PyStringArrType_Type)); Py_DECREF(s); - PyDict_SetItemString(infodict, "UNICODE", - s=Py_BuildValue("ciiiO", PyArray_UNICODELTR, + PyDict_SetItemString(infodict, "UNICODE", + s=Py_BuildValue("ciiiO", PyArray_UNICODELTR, PyArray_UNICODE, 0, _ALIGN(PyArray_UCS4), (PyObject *)\ - &PyUnicodeArrType_Type)); + &PyUnicodeArrType_Type)); Py_DECREF(s); - PyDict_SetItemString(infodict, "VOID", - s=Py_BuildValue("ciiiO", PyArray_VOIDLTR, + PyDict_SetItemString(infodict, "VOID", + s=Py_BuildValue("ciiiO", PyArray_VOIDLTR, PyArray_VOID, 0, _ALIGN(char), (PyObject *)\ - &PyVoidArrType_Type)); + &PyVoidArrType_Type)); Py_DECREF(s); #define SETTYPE(name) \ @@ -2205,7 +2205,7 @@ set_typeinfo(PyObject *dict) SETTYPE(Flexible) SETTYPE(Character) -#undef SETTYPE +#undef SETTYPE PyDict_SetItemString(dict, "typeinfo", infodict); Py_DECREF(infodict); @@ -2213,4 +2213,3 @@ set_typeinfo(PyObject *dict) } #undef _MAX_LETTER - diff --git a/numpy/core/src/multiarraymodule.c b/numpy/core/src/multiarraymodule.c index 9cad7af92..bbe2bd893 100644 --- a/numpy/core/src/multiarraymodule.c +++ b/numpy/core/src/multiarraymodule.c @@ -2,13 +2,13 @@ Python Multiarray Module -- A useful collection of functions for creating and using ndarrays - Original file + Original file Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu - Modified extensively for numpy in 2005 + Modified extensively for numpy in 2005 Travis E. Oliphant - oliphant@ee.byu.edu + oliphant@ee.byu.edu */ /* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */ @@ -36,7 +36,7 @@ _arraydescr_fromobj(PyObject *obj) PyObject *dtypedescr; PyArray_Descr *new; int ret; - + dtypedescr = PyObject_GetAttrString(obj, "dtype"); PyErr_Clear(); if (dtypedescr) { @@ -51,14 +51,14 @@ _arraydescr_fromobj(PyObject *obj) /* Including this file is the only way I know how to declare functions static in each file, and store the pointers from functions in both - arrayobject.c and multiarraymodule.c for the C-API + arrayobject.c and multiarraymodule.c for the C-API Declarying an external pointer-containing variable in arrayobject.c and trying to copy it to PyArray_API, did not work. Think about two modules with a common api that import each other... - This file would just be the module calls. + This file would just be the module calls. */ #include "arrayobject.c" @@ -71,7 +71,7 @@ static PyObject *MultiArrayError; Multiply a List of ints */ static int -PyArray_MultiplyIntList(register int *l1, register int n) +PyArray_MultiplyIntList(register int *l1, register int n) { register int s=1; while (n--) s *= (*l1++); @@ -81,8 +81,8 @@ PyArray_MultiplyIntList(register int *l1, register int n) /*MULTIARRAY_API Multiply a List */ -static intp -PyArray_MultiplyList(register intp *l1, register int n) +static intp +PyArray_MultiplyList(register intp *l1, register int n) { register intp s=1; while (n--) s *= (*l1++); @@ -98,7 +98,7 @@ PyArray_GetPtr(PyArrayObject *obj, register intp* ind) register int n = obj->nd; register intp *strides = obj->strides; register char *dptr = obj->data; - + while (n--) dptr += (*strides++) * (*ind++); return (void *)dptr; } @@ -106,7 +106,7 @@ PyArray_GetPtr(PyArrayObject *obj, register intp* ind) /*MULTIARRAY_API Get axis from an object (possibly None) -- a converter function, */ -static int +static int PyArray_AxisConverter(PyObject *obj, int *axis) { if (obj == Py_None) { @@ -124,13 +124,13 @@ PyArray_AxisConverter(PyObject *obj, int *axis) /*MULTIARRAY_API Compare Lists */ -static int -PyArray_CompareLists(intp *l1, intp *l2, int n) +static int +PyArray_CompareLists(intp *l1, intp *l2, int n) { int i; for(i=0;i<n;i++) { if (l1[i] != l2[i]) return 0; - } + } return 1; } @@ -146,7 +146,7 @@ PyArray_View(PyArrayObject *self, PyArray_Descr *type, PyTypeObject *pytype) if (pytype) subtype = pytype; else subtype = self->ob_type; - + Py_INCREF(self->descr); new = PyArray_NewFromDescr(subtype, self->descr, @@ -154,11 +154,11 @@ PyArray_View(PyArrayObject *self, PyArray_Descr *type, PyTypeObject *pytype) self->strides, self->data, self->flags, (PyObject *)self); - + if (new==NULL) return NULL; Py_INCREF(self); PyArray_BASE(new) = (PyObject *)self; - + if (type != NULL) { if (PyObject_SetAttrString(new, "dtype", (PyObject *)type) < 0) { @@ -168,7 +168,7 @@ PyArray_View(PyArrayObject *self, PyArray_Descr *type, PyTypeObject *pytype) } Py_DECREF(type); } - return new; + return new; } /*MULTIARRAY_API @@ -180,18 +180,18 @@ PyArray_Ravel(PyArrayObject *a, NPY_ORDER fortran) PyArray_Dims newdim = {NULL,1}; intp val[1] = {-1}; - if (fortran == PyArray_ANYORDER) - fortran = PyArray_ISFORTRAN(a); - - newdim.ptr = val; - if (!fortran && PyArray_ISCONTIGUOUS(a)) { - return PyArray_Newshape(a, &newdim, PyArray_CORDER); - } - else if (fortran && PyArray_ISFORTRAN(a)) { - return PyArray_Newshape(a, &newdim, PyArray_FORTRANORDER); - } - else - return PyArray_Flatten(a, fortran); + if (fortran == PyArray_ANYORDER) + fortran = PyArray_ISFORTRAN(a); + + newdim.ptr = val; + if (!fortran && PyArray_ISCONTIGUOUS(a)) { + return PyArray_Newshape(a, &newdim, PyArray_CORDER); + } + else if (fortran && PyArray_ISFORTRAN(a)) { + return PyArray_Newshape(a, &newdim, PyArray_FORTRANORDER); + } + else + return PyArray_Flatten(a, fortran); } static double @@ -217,7 +217,7 @@ PyArray_Round(PyArrayObject *a, int decimals, PyArrayObject *out) { PyObject *f, *ret=NULL, *tmp, *op1, *op2; if (out && (PyArray_SIZE(out) != PyArray_SIZE(a))) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "invalid output shape"); return NULL; } @@ -239,7 +239,7 @@ PyArray_Round(PyArrayObject *a, int decimals, PyArrayObject *out) part = PyObject_GetAttrString(new, "real"); if (part == NULL) {Py_DECREF(new); return NULL;} part = PyArray_EnsureAnyArray(part); - round_part = PyArray_Round((PyArrayObject *)part, + round_part = PyArray_Round((PyArrayObject *)part, decimals, NULL); Py_DECREF(part); if (round_part == NULL) {Py_DECREF(new); return NULL;} @@ -250,8 +250,8 @@ PyArray_Round(PyArrayObject *a, int decimals, PyArrayObject *out) /* new.imag = a.imag.round(decimals) */ part = PyObject_GetAttrString(new, "imag"); if (part == NULL) {Py_DECREF(new); return NULL;} - part = PyArray_EnsureAnyArray(part); - round_part = PyArray_Round((PyArrayObject *)part, + part = PyArray_EnsureAnyArray(part); + round_part = PyArray_Round((PyArrayObject *)part, decimals, NULL); Py_DECREF(part); if (round_part == NULL) {Py_DECREF(new); return NULL;} @@ -275,7 +275,7 @@ PyArray_Round(PyArrayObject *a, int decimals, PyArrayObject *out) } if (decimals == 0) { if (out) { - return PyObject_CallFunction(n_ops.rint, "OO", + return PyObject_CallFunction(n_ops.rint, "OO", a, out); } return PyObject_CallFunction(n_ops.rint, "O", a); @@ -290,8 +290,8 @@ PyArray_Round(PyArrayObject *a, int decimals, PyArrayObject *out) } if (!out) { Py_INCREF(a->descr); - out = (PyArrayObject *)PyArray_Empty(a->nd, a->dimensions, - a->descr, + out = (PyArrayObject *)PyArray_Empty(a->nd, a->dimensions, + a->descr, PyArray_ISFORTRAN(a)); if (out == NULL) return NULL; } @@ -311,7 +311,7 @@ PyArray_Round(PyArrayObject *a, int decimals, PyArrayObject *out) Py_DECREF(f); Py_DECREF(out); return ret; - + } @@ -324,7 +324,7 @@ PyArray_Flatten(PyArrayObject *a, NPY_ORDER order) PyObject *ret; intp size; - if (order == PyArray_ANYORDER) + if (order == PyArray_ANYORDER) order = PyArray_ISFORTRAN(a); size = PyArray_SIZE(a); @@ -335,7 +335,7 @@ PyArray_Flatten(PyArrayObject *a, NPY_ORDER order) NULL, NULL, 0, (PyObject *)a); - + if (ret== NULL) return NULL; if (_flat_copyinto(ret, (PyObject *)a, order) < 0) { Py_DECREF(ret); @@ -353,7 +353,7 @@ PyArray_Flatten(PyArrayObject *a, NPY_ORDER order) Reshape an array */ static PyObject * -PyArray_Reshape(PyArrayObject *self, PyObject *shape) +PyArray_Reshape(PyArrayObject *self, PyObject *shape) { PyObject *ret; PyArray_Dims newdims; @@ -400,19 +400,19 @@ _fix_unknown_dimension(PyArray_Dims *newshape, intp s_original) intp *dimensions; intp i_unknown, s_known; int i, n; - static char msg[] = "total size of new array must be unchanged"; - + static char msg[] = "total size of new array must be unchanged"; + dimensions = newshape->ptr; - n = newshape->len; + n = newshape->len; s_known = 1; i_unknown = -1; - + for(i=0; i<n; i++) { if (dimensions[i] < 0) { if (i_unknown == -1) { i_unknown = i; } else { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "can only specify one" \ " unknown dimension"); return -1; @@ -421,7 +421,7 @@ _fix_unknown_dimension(PyArray_Dims *newshape, intp s_original) s_known *= dimensions[i]; } } - + if (i_unknown >= 0) { if ((s_known == 0) || (s_original % s_known != 0)) { PyErr_SetString(PyExc_ValueError, msg); @@ -437,19 +437,19 @@ _fix_unknown_dimension(PyArray_Dims *newshape, intp s_original) return 0; } -/* Returns a new array +/* Returns a new array with the new shape from the data in the old array --- order-perspective depends on fortran argument. copy-if-necessary (currently if not contiguous or fortran-contiguous) - perhaps a more general-purpose strategy for determining this can + perhaps a more general-purpose strategy for determining this can be worked out */ /*MULTIARRAY_API New shape for an array */ -static PyObject * -PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, +static PyObject * +PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, NPY_ORDER fortran) { intp i; @@ -462,31 +462,31 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, if (fortran == PyArray_ANYORDER) fortran = PyArray_ISFORTRAN(self); - + /* Quick check to make sure anything actually needs to be done */ if (n == self->nd) { same = TRUE; i=0; while(same && i<n) { - if (PyArray_DIM(self,i) != dimensions[i]) + if (PyArray_DIM(self,i) != dimensions[i]) same=FALSE; i++; } if (same) return PyArray_View(self, NULL, NULL); } - + /* Returns a pointer to an appropriate strides array if all we are doing is inserting ones into the shape, - or removing ones from the shape + or removing ones from the shape or doing a combination of the two*/ i=_check_ones(self, n, dimensions, newstrides); if (i==0) strides=newstrides; - - if (strides==NULL) { + + if (strides==NULL) { if ((n == 0) || (PyArray_ISCONTIGUOUS(self) && (fortran != PyArray_FORTRANORDER)) || (PyArray_ISFORTRAN(self) && (fortran != PyArray_CORDER))) { - incref = TRUE; + incref = TRUE; } else { PyObject *tmp; @@ -495,7 +495,7 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, self = (PyArrayObject *)tmp; incref = FALSE; } - + if (_fix_unknown_dimension(newdims, PyArray_SIZE(self)) < 0) goto fail; } @@ -504,7 +504,7 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, appropriate value to preserve contiguousness */ if (fortran == PyArray_FORTRANORDER) { - if (strides[0] == 0) + if (strides[0] == 0) strides[0] = self->descr->elsize; for (i=1; i<n; i++) { if (strides[i] == 0) @@ -522,7 +522,7 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, } } } - + Py_INCREF(self->descr); ret = (PyAO *)PyArray_NewFromDescr(self->ob_type, self->descr, @@ -530,15 +530,15 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, strides, self->data, self->flags, (PyObject *)self); - + if (ret== NULL) goto fail; - + if (incref) Py_INCREF(self); ret->base = (PyObject *)self; PyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN); - + return (PyObject *)ret; - + fail: if (!incref) {Py_DECREF(self);} return NULL; @@ -546,7 +546,7 @@ PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, -/* return a new view of the array object with all of its unit-length +/* return a new view of the array object with all of its unit-length dimensions squeezed out if needed, otherwise return the same array. */ @@ -575,12 +575,12 @@ PyArray_Squeeze(PyArrayObject *self) strides[j++] = self->strides[i]; } } - + Py_INCREF(self->descr); - ret = PyArray_NewFromDescr(self->ob_type, + ret = PyArray_NewFromDescr(self->ob_type, self->descr, - newnd, dimensions, - strides, self->data, + newnd, dimensions, + strides, self->data, self->flags, (PyObject *)self); if (ret == NULL) return NULL; @@ -627,7 +627,7 @@ PyArray_Mean(PyArrayObject *self, int axis, int rtype, PyArrayObject *out) Std */ static PyObject * -PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, +PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, int variance) { PyObject *obj1=NULL, *obj2=NULL, *new=NULL; @@ -639,7 +639,7 @@ PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, /* Compute and reshape mean */ obj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype, NULL)); - if (obj1 == NULL) {Py_DECREF(new); return NULL;} + if (obj1 == NULL) {Py_DECREF(new); return NULL;} n = PyArray_NDIM(new); newshape = PyTuple_New(n); if (newshape == NULL) {Py_DECREF(obj1); Py_DECREF(new); return NULL;} @@ -652,12 +652,12 @@ PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, Py_DECREF(obj1); Py_DECREF(newshape); if (obj2 == NULL) {Py_DECREF(new); return NULL;} - + /* Compute x = x - mx */ obj1 = PyArray_EnsureArray(PyNumber_Subtract((PyObject *)new, obj2)); Py_DECREF(obj2); if (obj1 == NULL) {Py_DECREF(new); return NULL;} - + /* Compute x * x */ obj2 = PyArray_EnsureArray \ (PyArray_GenericBinaryFunction((PyAO *)obj1, obj1, n_ops.multiply)); @@ -681,7 +681,7 @@ PyArray_Std(PyArrayObject *self, int axis, int rtype, PyArrayObject *out, if (!variance) { obj1 = PyArray_EnsureArray(ret); - + /* sqrt() */ ret = PyArray_GenericUnaryFunction((PyAO *)obj1, n_ops.sqrt); Py_DECREF(obj1); @@ -715,7 +715,7 @@ PyArray_Sum(PyArrayObject *self, int axis, int rtype, PyArrayObject *out) if ((new = _check_axis(self, &axis, 0))==NULL) return NULL; - ret = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis, + ret = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis, rtype, out); Py_DECREF(new); return ret; @@ -763,7 +763,7 @@ PyArray_CumProd(PyArrayObject *self, int axis, int rtype, PyArrayObject *out) if ((new = _check_axis(self, &axis, 0))==NULL) return NULL; - ret = PyArray_GenericAccumulateFunction((PyAO *)new, + ret = PyArray_GenericAccumulateFunction((PyAO *)new, n_ops.multiply, axis, rtype, out); Py_DECREF(new); @@ -780,8 +780,8 @@ PyArray_Any(PyArrayObject *self, int axis, PyArrayObject *out) if ((new = _check_axis(self, &axis, 0))==NULL) return NULL; - ret = PyArray_GenericReduceFunction((PyAO *)new, - n_ops.logical_or, axis, + ret = PyArray_GenericReduceFunction((PyAO *)new, + n_ops.logical_or, axis, PyArray_BOOL, out); Py_DECREF(new); return ret; @@ -797,8 +797,8 @@ PyArray_All(PyArrayObject *self, int axis, PyArrayObject *out) if ((new = _check_axis(self, &axis, 0))==NULL) return NULL; - ret = PyArray_GenericReduceFunction((PyAO *)new, - n_ops.logical_and, axis, + ret = PyArray_GenericReduceFunction((PyAO *)new, + n_ops.logical_and, axis, PyArray_BOOL, out); Py_DECREF(new); return ret; @@ -809,7 +809,7 @@ PyArray_All(PyArrayObject *self, int axis, PyArrayObject *out) Compress */ static PyObject * -PyArray_Compress(PyArrayObject *self, PyObject *condition, int axis, +PyArray_Compress(PyArrayObject *self, PyObject *condition, int axis, PyArrayObject *out) { PyArrayObject *cond; @@ -817,10 +817,10 @@ PyArray_Compress(PyArrayObject *self, PyObject *condition, int axis, cond = (PyAO *)PyArray_FROM_O(condition); if (cond == NULL) return NULL; - + if (cond->nd != 1) { Py_DECREF(cond); - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "condition must be 1-d array"); return NULL; } @@ -828,7 +828,7 @@ PyArray_Compress(PyArrayObject *self, PyObject *condition, int axis, res = PyArray_Nonzero(cond); Py_DECREF(cond); if (res == NULL) return res; - ret = PyArray_TakeFrom(self, PyTuple_GET_ITEM(res, 0), axis, + ret = PyArray_TakeFrom(self, PyTuple_GET_ITEM(res, 0), axis, out, NPY_RAISE); Py_DECREF(res); return ret; @@ -857,9 +857,9 @@ PyArray_Nonzero(PyArrayObject *self) PyArray_ITER_RESET(it); ret = PyTuple_New(n); - if (ret == NULL) goto fail; + if (ret == NULL) goto fail; for (j=0; j<n; j++) { - item = PyArray_New(self->ob_type, 1, &count, + item = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, NULL, NULL, 0, 0, (PyObject *)self); if (item == NULL) goto fail; @@ -868,17 +868,17 @@ PyArray_Nonzero(PyArrayObject *self) } if (n==1) { for (i=0; i<size; i++) { - if (self->descr->f->nonzero(it->dataptr, self)) + if (self->descr->f->nonzero(it->dataptr, self)) *(dptr[0])++ = i; PyArray_ITER_NEXT(it); - } + } } else { /* reset contiguous so that coordinates gets updated */ it->contiguous = 0; for (i=0; i<size; i++) { - if (self->descr->f->nonzero(it->dataptr, self)) - for (j=0; j<n; j++) + if (self->descr->f->nonzero(it->dataptr, self)) + for (j=0; j<n; j++) *(dptr[j])++ = it->coordinates[j]; PyArray_ITER_NEXT(it); } @@ -891,7 +891,7 @@ PyArray_Nonzero(PyArrayObject *self) Py_XDECREF(ret); Py_XDECREF(it); return NULL; - + } /*MULTIARRAY_API @@ -914,8 +914,8 @@ PyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max, PyArrayObject *o return NULL; } res3 = PyNumber_Multiply(two, res1); - Py_DECREF(two); - Py_DECREF(res1); + Py_DECREF(two); + Py_DECREF(res1); if (res3 == NULL) return NULL; selector = PyArray_EnsureAnyArray(PyNumber_Add(res2, res3)); @@ -963,10 +963,10 @@ PyArray_Conjugate(PyArrayObject *self, PyArrayObject *out) for (i=0; i<size; i++) { dptr->imag = -dptr->imag; dptr++; - } - } + } + } if (out) { - if (PyArray_CopyAnyInto(out, (PyArrayObject *)new)<0) + if (PyArray_CopyAnyInto(out, (PyArrayObject *)new)<0) return NULL; Py_INCREF(out); Py_DECREF(new); @@ -991,7 +991,7 @@ PyArray_Conjugate(PyArrayObject *self, PyArrayObject *out) Trace */ static PyObject * -PyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, +PyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, int rtype, PyArrayObject *out) { PyObject *diag=NULL, *ret=NULL; @@ -1013,11 +1013,11 @@ PyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2) PyObject *new; PyArray_Dims newaxes; intp dims[MAX_DIMS]; - int i, pos; + int i, pos; newaxes.ptr = dims; if (n < 2) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "array.ndim must be >= 2"); return NULL; } @@ -1030,7 +1030,7 @@ PyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2) axis1, axis2, n); return NULL; } - + newaxes.len = n; /* insert at the end */ newaxes.ptr[n-2] = axis1; @@ -1043,7 +1043,7 @@ PyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2) new = PyArray_Transpose(self, &newaxes); if (new == NULL) return NULL; self = (PyAO *)new; - + if (n == 2) { PyObject *a=NULL, *indices=NULL, *ret=NULL; intp n1, n2, start, stop, step, count; @@ -1059,11 +1059,11 @@ PyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2) start = offset; stop = MIN(n1, n2-offset)*(n2+1) + offset; } - + /* count = ceil((stop-start)/step) */ count = ((stop-start) / step) + (((stop-start) % step) != 0); - - indices = PyArray_New(&PyArray_Type, 1, &count, + + indices = PyArray_New(&PyArray_Type, 1, &count, PyArray_INTP, NULL, NULL, 0, 0, NULL); if (indices == NULL) { Py_DECREF(self); return NULL; @@ -1077,15 +1077,15 @@ PyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2) Py_DECREF(a); Py_DECREF(indices); return ret; - } + } else { - /* + /* my_diagonal = [] for i in range (s [0]) : my_diagonal.append (diagonal (a [i], offset)) - return array (my_diagonal) - */ + return array (my_diagonal) + */ PyObject *mydiagonal=NULL, *new=NULL, *ret=NULL, *sel=NULL; intp i, n1; int res; @@ -1128,13 +1128,13 @@ PyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2) } } -/* 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 +/* 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. + 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. */ /* steals a reference to typedescr -- can be NULL*/ @@ -1142,7 +1142,7 @@ PyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2) Simulat a C-array */ static int -PyArray_AsCArray(PyObject **op, void *ptr, intp *dims, int nd, +PyArray_AsCArray(PyObject **op, void *ptr, intp *dims, int nd, PyArray_Descr* typedescr) { PyArrayObject *ap; @@ -1171,7 +1171,7 @@ PyArray_AsCArray(PyObject **op, void *ptr, intp *dims, int nd, ptr2[i] = ap->data + i*ap->strides[0]; } *((char ***)ptr) = ptr2; - break; + break; case 3: n = ap->dimensions[0]; m = ap->dimensions[1]; @@ -1200,15 +1200,15 @@ PyArray_AsCArray(PyObject **op, void *ptr, intp *dims, int nd, /*MULTIARRAY_API Convert to a 1D C-array */ -static int -PyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) +static int +PyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) { intp newd1; PyArray_Descr *descr; - descr = PyArray_DescrFromType(typecode); + descr = PyArray_DescrFromType(typecode); if (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, descr) == -1) - return -1; + return -1; *d1 = (int) newd1; return 0; } @@ -1216,13 +1216,13 @@ PyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) /*MULTIARRAY_API Convert to a 2D C-array */ -static int -PyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) +static int +PyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) { intp newdims[2]; PyArray_Descr *descr; - descr = PyArray_DescrFromType(typecode); + descr = PyArray_DescrFromType(typecode); if (PyArray_AsCArray(op, (void *)ptr, newdims, 2, descr) == -1) return -1; @@ -1236,12 +1236,12 @@ PyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) /*MULTIARRAY_API Free pointers created if As2D is called */ -static int -PyArray_Free(PyObject *op, void *ptr) +static int +PyArray_Free(PyObject *op, void *ptr) { PyArrayObject *ap = (PyArrayObject *)op; - - if ((ap->nd < 1) || (ap->nd > 3)) + + if ((ap->nd < 1) || (ap->nd > 3)) return -1; if (ap->nd >= 2) { _pya_free(ptr); @@ -1276,28 +1276,28 @@ _swap_and_concat(PyObject *op, int axis, int n) arr = PyArray_SwapAxes((PyArrayObject *)otmp, axis, 0); Py_DECREF(otmp); return arr; - + fail: Py_DECREF(newtup); return NULL; } /*op is a python object supporting the sequence interface. - Its elements will be concatenated together to form a single + Its elements will be concatenated together to form a single multidimensional array.*/ -/* If axis is MAX_DIMS or bigger, then each sequence object will - be flattened before concatenation +/* If axis is MAX_DIMS or bigger, then each sequence object will + be flattened before concatenation */ /*MULTIARRAY_API Concatenate an arbitrary Python sequence into an array. */ static PyObject * -PyArray_Concatenate(PyObject *op, int axis) +PyArray_Concatenate(PyObject *op, int axis) { PyArrayObject *ret, **mps; PyObject *otmp; int i, n, tmp, nd=0, new_dim; - char *data; + char *data; PyTypeObject *subtype; double prior1, prior2; intp numbytes; @@ -1307,7 +1307,7 @@ PyArray_Concatenate(PyObject *op, int axis) return NULL; } if (n == 0) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "concatenation of zero-length sequences is "\ "impossible"); return NULL; @@ -1315,13 +1315,13 @@ PyArray_Concatenate(PyObject *op, int axis) if ((axis < 0) || ((0 < axis) && (axis < MAX_DIMS))) return _swap_and_concat(op, axis, n); - + mps = PyArray_ConvertToCommonType(op, &n); if (mps == NULL) return NULL; /* Make sure these arrays are legal to concatenate. */ /* Must have same dimensions except d0 */ - + prior1 = PyArray_PRIORITY; subtype = &PyArray_Type; ret = NULL; @@ -1339,59 +1339,59 @@ PyArray_Concatenate(PyObject *op, int axis) } } } - + new_dim = 0; for(i=0; i<n; i++) { if (mps[i] == NULL) goto fail; if (i == 0) nd = mps[i]->nd; else { if (nd != mps[i]->nd) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "arrays must have same "\ "number of dimensions"); goto fail; } - if (!PyArray_CompareLists(mps[0]->dimensions+1, - mps[i]->dimensions+1, + if (!PyArray_CompareLists(mps[0]->dimensions+1, + mps[i]->dimensions+1, nd-1)) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "array dimensions must "\ "agree except for d_0"); goto fail; } } if (nd == 0) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "0-d arrays can't be concatenated"); goto fail; } new_dim += mps[i]->dimensions[0]; } - + tmp = mps[0]->dimensions[0]; mps[0]->dimensions[0] = new_dim; Py_INCREF(mps[0]->descr); - ret = (PyArrayObject *)PyArray_NewFromDescr(subtype, + ret = (PyArrayObject *)PyArray_NewFromDescr(subtype, mps[0]->descr, nd, - mps[0]->dimensions, + mps[0]->dimensions, NULL, NULL, 0, (PyObject *)ret); mps[0]->dimensions[0] = tmp; - + if (ret == NULL) goto fail; - + data = ret->data; for(i=0; i<n; i++) { numbytes = PyArray_NBYTES(mps[i]); memcpy(data, mps[i]->data, numbytes); data += numbytes; } - + PyArray_INCREF(ret); for(i=0; i<n; i++) Py_XDECREF(mps[i]); PyDataMem_FREE(mps); return (PyObject *)ret; - + fail: Py_XDECREF(ret); for(i=0; i<n; i++) Py_XDECREF(mps[i]); @@ -1409,12 +1409,12 @@ PyArray_SwapAxes(PyArrayObject *ap, int a1, int a2) intp dims[MAX_DIMS]; int n, i, val; PyObject *ret; - + if (a1 == a2) { Py_INCREF(ap); return (PyObject *)ap; } - + n = ap->nd; if (n <= 1) { Py_INCREF(ap); @@ -1424,12 +1424,12 @@ PyArray_SwapAxes(PyArrayObject *ap, int a1, int a2) if (a1 < 0) a1 += n; if (a2 < 0) a2 += n; if ((a1 < 0) || (a1 >= n)) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "bad axis1 argument to swapaxes"); return NULL; } if ((a2 < 0) || (a2 >= n)) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "bad axis2 argument to swapaxes"); return NULL; } @@ -1466,7 +1466,7 @@ PyArray_Transpose(PyArrayObject *ap, PyArray_Dims *permute) n = permute->len; axes = permute->ptr; if (n != ap->nd) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "axes don't match array"); return NULL; } @@ -1477,7 +1477,7 @@ PyArray_Transpose(PyArrayObject *ap, PyArray_Dims *permute) axis = axes[i]; if (axis < 0) axis = ap->nd+axis; if (axis < 0 || axis >= ap->nd) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "invalid axis for this array"); return NULL; } @@ -1492,29 +1492,29 @@ PyArray_Transpose(PyArrayObject *ap, PyArray_Dims *permute) for (i=0; i<n; i++) { } } - + /* this allocates memory for dimensions and strides (but fills them incorrectly), sets up descr, and points data at ap->data. */ Py_INCREF(ap->descr); ret = (PyArrayObject *)\ - PyArray_NewFromDescr(ap->ob_type, - ap->descr, - n, permutation, + PyArray_NewFromDescr(ap->ob_type, + ap->descr, + n, permutation, NULL, ap->data, ap->flags, (PyObject *)ap); if (ret == NULL) return NULL; - + /* point at true owner of memory: */ ret->base = (PyObject *)ap; Py_INCREF(ap); - + for(i=0; i<n; i++) { ret->dimensions[i] = ap->dimensions[permutation[i]]; ret->strides[i] = ap->strides[permutation[i]]; } - PyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN); + PyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN); - return (PyObject *)ret; + return (PyObject *)ret; } /*MULTIARRAY_API @@ -1550,16 +1550,16 @@ PyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis) n = aop->dimensions[axis]; if (aop->dimensions[axis] != n) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "a.shape[axis] != len(repeats)"); goto fail; } - - if (nd == 0) + + if (nd == 0) total = counts[0]*n; else { - + total = 0; for(j=0; j<n; j++) { if (counts[j] < 0) { @@ -1574,24 +1574,24 @@ PyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis) /* Construct new array */ aop->dimensions[axis] = total; Py_INCREF(aop->descr); - ret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, + ret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, aop->descr, aop->nd, aop->dimensions, NULL, NULL, 0, (PyObject *)aop); aop->dimensions[axis] = n; - + if (ret == NULL) goto fail; - + new_data = ret->data; old_data = aop->data; - + chunk = aop->descr->elsize; for(i=axis+1; i<aop->nd; i++) { chunk *= aop->dimensions[i]; } - + n_outer = 1; for(i=0; i<axis; i++) n_outer *= aop->dimensions[i]; @@ -1610,7 +1610,7 @@ PyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis) PyArray_INCREF(ret); Py_XDECREF(aop); return (PyObject *)ret; - + fail: Py_DECREF(repeats); Py_XDECREF(aop); @@ -1635,14 +1635,14 @@ _signbit_set(PyArrayObject *arr) (byteorder == PyArray_NATIVE && PyArray_ISNBO(PyArray_LITTLE)))) ptr += elsize-1; - - return ((*ptr & bitmask) != 0); + + return ((*ptr & bitmask) != 0); } /*OBJECT_API*/ static NPY_SCALARKIND -PyArray_ScalarKind(int typenum, PyArrayObject **arr) +PyArray_ScalarKind(int typenum, PyArrayObject **arr) { if (PyTypeNum_ISSIGNED(typenum)) { if (arr && _signbit_set(*arr)) return PyArray_INTNEG_SCALAR; @@ -1657,9 +1657,9 @@ PyArray_ScalarKind(int typenum, PyArrayObject **arr) NPY_SCALARKIND retval; PyArray_Descr* descr; descr = PyArray_DescrFromType(typenum); - if (descr->f->scalarkind) + if (descr->f->scalarkind) retval = descr->f->scalarkind((arr ? *arr : NULL)); - else + else retval = PyArray_NOSCALAR; Py_DECREF(descr); return retval; @@ -1668,10 +1668,10 @@ PyArray_ScalarKind(int typenum, PyArrayObject **arr) } /*OBJECT_API*/ -static int -PyArray_CanCoerceScalar(int thistype, int neededtype, - NPY_SCALARKIND scalar) -{ +static int +PyArray_CanCoerceScalar(int thistype, int neededtype, + NPY_SCALARKIND scalar) +{ PyArray_Descr* from; int *castlist; @@ -1679,9 +1679,9 @@ PyArray_CanCoerceScalar(int thistype, int neededtype, return PyArray_CanCastSafely(thistype, neededtype); } from = PyArray_DescrFromType(thistype); - if (from->f->cancastscalarkindto && + if (from->f->cancastscalarkindto && (castlist = from->f->cancastscalarkindto[scalar])) { - while (*castlist != PyArray_NOTYPE) + while (*castlist != PyArray_NOTYPE) if (*castlist++ == neededtype) return 1; } switch(scalar) { @@ -1712,25 +1712,25 @@ PyArray_CanCoerceScalar(int thistype, int neededtype, static PyArrayObject ** PyArray_ConvertToCommonType(PyObject *op, int *retn) { - int i, n, allscalars=0; + int i, n, allscalars=0; PyArrayObject **mps=NULL; PyObject *otmp; PyArray_Descr *intype=NULL, *stype=NULL; PyArray_Descr *newtype=NULL; NPY_SCALARKIND scalarkind; - + *retn = n = PySequence_Length(op); if (PyErr_Occurred()) {*retn = 0; return NULL;} - + mps = (PyArrayObject **)PyDataMem_NEW(n*sizeof(PyArrayObject *)); if (mps == NULL) { *retn = 0; return (void*)PyErr_NoMemory(); } - + for(i=0; i<n; i++) { otmp = PySequence_GetItem(op, i); - if (!PyArray_CheckAnyScalar(otmp)) { + if (!PyArray_CheckAnyScalar(otmp)) { newtype = PyArray_DescrFromObject(otmp, intype); Py_XDECREF(intype); intype = newtype; @@ -1740,11 +1740,11 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) newtype = PyArray_DescrFromObject(otmp, stype); Py_XDECREF(stype); stype = newtype; - scalarkind = PyArray_ScalarKind(newtype->type_num, + scalarkind = PyArray_ScalarKind(newtype->type_num, NULL); if (intype && \ !PyArray_CanCoerceScalar(newtype->type_num, - intype->type_num, + intype->type_num, scalarkind)) { Py_XDECREF(intype); intype = stype; @@ -1766,7 +1766,7 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) /* Make sure all arrays are actual array objects. */ for(i=0; i<n; i++) { int flags = CARRAY; - if ((otmp = PySequence_GetItem(op, i)) == NULL) + if ((otmp = PySequence_GetItem(op, i)) == NULL) goto fail; if (!allscalars && ((PyObject *)(mps[i]) == Py_None)) { /* forcecast scalars */ @@ -1784,7 +1784,7 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) return mps; fail: - Py_XDECREF(intype); + Py_XDECREF(intype); Py_XDECREF(stype); *retn = 0; for (i=0; i<n; i++) Py_XDECREF(mps[i]); @@ -1796,7 +1796,7 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn) /*MULTIARRAY_API */ static PyObject * -PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *ret, +PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *ret, NPY_CLIPMODE clipmode) { intp *sizes, offset; @@ -1807,42 +1807,42 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *ret, intp *self_data, mi; int copyret=0; ap = NULL; - + /* Convert all inputs to arrays of a common type */ mps = PyArray_ConvertToCommonType(op, &n); if (mps == NULL) return NULL; sizes = (intp *)_pya_malloc(n*sizeof(intp)); if (sizes == NULL) goto fail; - - ap = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ip, - PyArray_INTP, + + ap = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ip, + PyArray_INTP, 0, 0); if (ap == NULL) goto fail; - + /* Check the dimensions of the arrays */ for(i=0; i<n; i++) { if (mps[i] == NULL) goto fail; if (ap->nd < mps[i]->nd) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "too many dimensions"); goto fail; } if (!PyArray_CompareLists(ap->dimensions+(ap->nd-mps[i]->nd), mps[i]->dimensions, mps[i]->nd)) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "array dimensions must agree"); goto fail; } sizes[i] = PyArray_NBYTES(mps[i]); } - + Py_INCREF(mps[0]->descr); if (!ret) { - ret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, + ret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, mps[0]->descr, ap->nd, - ap->dimensions, + ap->dimensions, NULL, NULL, 0, (PyObject *)ap); if (ret == NULL) goto fail; @@ -1852,7 +1852,7 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *ret, int flags = NPY_CARRAY | NPY_UPDATEIFCOPY; if (PyArray_SIZE(ret) != PyArray_SIZE(ap)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "invalid shape for output array."); ret = NULL; Py_DECREF(mps[0]->descr); @@ -1861,27 +1861,27 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *ret, if (clipmode == NPY_RAISE) { /* we need to make sure and get a copy so the input array is not changed - before the error is called + before the error is called */ flags |= NPY_ENSURECOPY; } - obj = (PyArrayObject *)PyArray_FromArray(ret, mps[0]->descr, + obj = (PyArrayObject *)PyArray_FromArray(ret, mps[0]->descr, flags); if (obj != ret) copyret = 1; ret = obj; } - + elsize = ret->descr->elsize; m = PyArray_SIZE(ret); self_data = (intp *)ap->data; - ret_data = ret->data; + ret_data = ret->data; for (i=0; i<m; i++) { mi = *self_data; if (mi < 0 || mi >= n) { switch(clipmode) { case NPY_RAISE: - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "invalid entry in choice "\ "array"); goto fail; @@ -1904,7 +1904,7 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *ret, memmove(ret_data, mps[mi]->data+offset, elsize); ret_data += elsize; self_data++; } - + PyArray_INCREF(ret); for(i=0; i<n; i++) Py_XDECREF(mps[i]); Py_DECREF(ap); @@ -1914,11 +1914,11 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *ret, PyObject *obj; obj = ret->base; Py_INCREF(obj); - Py_DECREF(ret); + Py_DECREF(ret); ret = (PyArrayObject *)obj; } return (PyObject *)ret; - + fail: for(i=0; i<n; i++) Py_XDECREF(mps[i]); Py_XDECREF(ap); @@ -1928,19 +1928,19 @@ PyArray_Choose(PyArrayObject *ip, PyObject *op, PyArrayObject *ret, return NULL; } -/* These algorithms use special sorting. They are not called unless the - underlying sort function for the type is available. +/* These algorithms use special sorting. They are not called unless the + underlying sort function for the type is available. Note that axis is already valid. The sort functions require 1-d contiguous and well-behaved data. - Therefore, a copy will be made of the data if needed before handing + Therefore, a copy will be made of the data if needed before handing it to the sorting routine. - An iterator is constructed and adjusted to walk over all but + An iterator is constructed and adjusted to walk over all but the desired sorting - axis. + axis. */ static int -_new_sort(PyArrayObject *op, int axis, NPY_SORTKIND which) +_new_sort(PyArrayObject *op, int axis, NPY_SORTKIND which) { PyArrayIterObject *it; int needcopy=0, swap; @@ -1948,7 +1948,7 @@ _new_sort(PyArrayObject *op, int axis, NPY_SORTKIND which) int elsize; intp astride; PyArray_SortFunc *sort; - BEGIN_THREADS_DEF + BEGIN_THREADS_DEF it = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, &axis); swap = !PyArray_ISNOTSWAPPED(op); @@ -1968,15 +1968,15 @@ _new_sort(PyArrayObject *op, int axis, NPY_SORTKIND which) char *buffer; buffer = PyDataMem_NEW(N*elsize); while (size--) { - _unaligned_strided_byte_copy(buffer, (intp) elsize, it->dataptr, + _unaligned_strided_byte_copy(buffer, (intp) elsize, it->dataptr, astride, N, elsize); if (swap) _strided_byte_swap(buffer, (intp) elsize, N, elsize); if (sort(buffer, N, op) < 0) { PyDataMem_FREE(buffer); goto fail; } if (swap) _strided_byte_swap(buffer, (intp) elsize, N, elsize); - - _unaligned_strided_byte_copy(it->dataptr, astride, buffer, + + _unaligned_strided_byte_copy(it->dataptr, astride, buffer, (intp) elsize, N, elsize); PyArray_ITER_NEXT(it); } @@ -1987,10 +1987,10 @@ _new_sort(PyArrayObject *op, int axis, NPY_SORTKIND which) if (sort(it->dataptr, N, op) < 0) goto fail; PyArray_ITER_NEXT(it); } - } - + } + END_THREADS - + Py_DECREF(it); return 0; @@ -2002,7 +2002,7 @@ _new_sort(PyArrayObject *op, int axis, NPY_SORTKIND which) } static PyObject* -_new_argsort(PyArrayObject *op, int axis, NPY_SORTKIND which) +_new_argsort(PyArrayObject *op, int axis, NPY_SORTKIND which) { PyArrayIterObject *it=NULL; @@ -2013,7 +2013,7 @@ _new_argsort(PyArrayObject *op, int axis, NPY_SORTKIND which) int elsize, swap; intp astride, rstride, *iptr; PyArray_ArgSortFunc *argsort; - BEGIN_THREADS_DEF + BEGIN_THREADS_DEF ret = PyArray_New(op->ob_type, op->nd, op->dimensions, PyArray_INTP, @@ -2037,7 +2037,7 @@ _new_argsort(PyArrayObject *op, int axis, NPY_SORTKIND which) needcopy = swap || !(op->flags & ALIGNED) || (astride != (intp) elsize) || \ (rstride != sizeof(intp)); - + if (needcopy) { char *valbuffer, *indbuffer; valbuffer = PyDataMem_NEW(N*elsize); @@ -2049,11 +2049,11 @@ _new_argsort(PyArrayObject *op, int axis, NPY_SORTKIND which) iptr = (intp *)indbuffer; for (i=0; i<N; i++) *iptr++ = i; if (argsort(valbuffer, (intp *)indbuffer, N, op) < 0) { - PyDataMem_FREE(valbuffer); + PyDataMem_FREE(valbuffer); PyDataMem_FREE(indbuffer); goto fail; } - _unaligned_strided_byte_copy(rit->dataptr, rstride, indbuffer, + _unaligned_strided_byte_copy(rit->dataptr, rstride, indbuffer, sizeof(intp), N, sizeof(intp)); PyArray_ITER_NEXT(it); PyArray_ITER_NEXT(rit); @@ -2065,13 +2065,13 @@ _new_argsort(PyArrayObject *op, int axis, NPY_SORTKIND which) while (size--) { iptr = (intp *)rit->dataptr; for (i=0; i<N; i++) *iptr++ = i; - if (argsort(it->dataptr, (intp *)rit->dataptr, + if (argsort(it->dataptr, (intp *)rit->dataptr, N, op) < 0) goto fail; PyArray_ITER_NEXT(it); PyArray_ITER_NEXT(rit); } } - + END_THREADS Py_DECREF(it); @@ -2093,8 +2093,8 @@ _new_argsort(PyArrayObject *op, int axis, NPY_SORTKIND which) static PyArrayObject *global_obj; -static int -qsortCompare (const void *a, const void *b) +static int +qsortCompare (const void *a, const void *b) { return global_obj->descr->f->compare(a,b,global_obj); } @@ -2102,7 +2102,7 @@ qsortCompare (const void *a, const void *b) /* Consumes reference to ap (op gets it) op contains a version of the array with axes swapped if local variable axis is not the last dimension. - orign must be defined locally. + orign must be defined locally. */ #define SWAPAXES(op, ap) { \ @@ -2116,9 +2116,9 @@ qsortCompare (const void *a, const void *b) } /* Consumes reference to ap (op gets it) - origin must be previously defined locally. - SWAPAXES must have been called previously. - op contains the swapped version of the array. + origin must be previously defined locally. + SWAPAXES must have been called previously. + op contains the swapped version of the array. */ #define SWAPBACK(op, ap) { \ if (axis != orign) { \ @@ -2152,7 +2152,7 @@ qsortCompare (const void *a, const void *b) Sort an array in-place */ static int -PyArray_Sort(PyArrayObject *op, int axis, NPY_SORTKIND which) +PyArray_Sort(PyArrayObject *op, int axis, NPY_SORTKIND which) { PyArrayObject *ap=NULL, *store_arr=NULL; char *ip; @@ -2163,12 +2163,12 @@ PyArray_Sort(PyArrayObject *op, int axis, NPY_SORTKIND which) if (axis < 0) axis += n; if ((axis < 0) || (axis >= n)) { - PyErr_Format(PyExc_ValueError, + PyErr_Format(PyExc_ValueError, "axis(=%d) out of bounds", axis); return -1; } if (!PyArray_ISWRITEABLE(op)) { - PyErr_SetString(PyExc_RuntimeError, + PyErr_SetString(PyExc_RuntimeError, "attempted sort on unwriteable array."); return -1; } @@ -2180,18 +2180,18 @@ PyArray_Sort(PyArrayObject *op, int axis, NPY_SORTKIND which) if ((which != PyArray_QUICKSORT) || \ op->descr->f->compare == NULL) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "desired sort not supported for this type"); return -1; } SWAPAXES2(op); - ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, - NULL, 1, 0, - DEFAULT | UPDATEIFCOPY, NULL); + ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, + NULL, 1, 0, + DEFAULT | UPDATEIFCOPY, NULL); if (ap == NULL) goto fail; - + elsize = ap->descr->elsize; m = ap->dimensions[ap->nd-1]; if (m == 0) goto finish; @@ -2199,15 +2199,15 @@ PyArray_Sort(PyArrayObject *op, int axis, NPY_SORTKIND which) n = PyArray_SIZE(ap)/m; /* Store global -- allows re-entry -- restore before leaving*/ - store_arr = global_obj; + store_arr = global_obj; global_obj = ap; - + for (ip=ap->data, i=0; i<n; i++, ip+=elsize*m) { qsort(ip, m, elsize, qsortCompare); } - + global_obj = store_arr; - + if (PyErr_Occurred()) goto fail; finish: @@ -2223,14 +2223,14 @@ PyArray_Sort(PyArrayObject *op, int axis, NPY_SORTKIND which) static char *global_data; -static int -argsort_static_compare(const void *ip1, const void *ip2) +static int +argsort_static_compare(const void *ip1, const void *ip2) { int isize = global_obj->descr->elsize; const intp *ipa = ip1; - const intp *ipb = ip2; + const intp *ipb = ip2; return global_obj->descr->f->compare(global_data + (isize * *ipa), - global_data + (isize * *ipb), + global_data + (isize * *ipb), global_obj); } @@ -2238,7 +2238,7 @@ argsort_static_compare(const void *ip1, const void *ip2) ArgSort an array */ static PyObject * -PyArray_ArgSort(PyArrayObject *op, int axis, NPY_SORTKIND which) +PyArray_ArgSort(PyArrayObject *op, int axis, NPY_SORTKIND which) { PyArrayObject *ap=NULL, *ret=NULL, *store; intp *ip; @@ -2249,9 +2249,9 @@ PyArray_ArgSort(PyArrayObject *op, int axis, NPY_SORTKIND which) n = op->nd; if ((n==0) || (PyArray_SIZE(op)==1)) { ret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd, - op->dimensions, + op->dimensions, PyArray_INTP, - NULL, NULL, 0, 0, + NULL, NULL, 0, 0, (PyObject *)op); if (ret == NULL) return NULL; *((intp *)ret->data) = 0; @@ -2259,7 +2259,7 @@ PyArray_ArgSort(PyArrayObject *op, int axis, NPY_SORTKIND which) } if (axis < 0) axis += n; if ((axis < 0) || (axis >= n)) { - PyErr_Format(PyExc_ValueError, + PyErr_Format(PyExc_ValueError, "axis(=%d) out of bounds", axis); return NULL; } @@ -2270,25 +2270,25 @@ PyArray_ArgSort(PyArrayObject *op, int axis, NPY_SORTKIND which) } if ((which != PyArray_QUICKSORT) || op->descr->f->compare == NULL) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "requested sort not available for type"); goto fail; } SWAPAXES(ap, op); - op = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, + op = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, PyArray_NOTYPE, 1, 0); if (op == NULL) return NULL; - + ret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd, op->dimensions, PyArray_INTP, NULL, NULL, 0, 0, (PyObject *)op); if (ret == NULL) goto fail; - - + + ip = (intp *)ret->data; argsort_elsize = op->descr->elsize; m = op->dimensions[op->nd-1]; @@ -2318,7 +2318,7 @@ PyArray_ArgSort(PyArrayObject *op, int axis, NPY_SORTKIND which) Py_XDECREF(ret); return NULL; -} +} /*MULTIARRAY_API @@ -2326,11 +2326,11 @@ PyArray_ArgSort(PyArrayObject *op, int axis, NPY_SORTKIND which) lexicographically. The first key is sorted on first, followed by the second key -- requires that arg"merge"sort is available for each sort_key - Returns an index array that shows the indexes for the lexicographic sort along - the given axis. + Returns an index array that shows the indexes for the lexicographic sort along + the given axis. */ static PyObject * -PyArray_LexSort(PyObject *sort_keys, int axis) +PyArray_LexSort(PyObject *sort_keys, int axis) { PyArrayObject **mps; PyArrayIterObject **its; @@ -2349,7 +2349,7 @@ PyArray_LexSort(PyObject *sort_keys, int axis) if (!PySequence_Check(sort_keys) || \ ((n=PySequence_Size(sort_keys)) <= 0)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "need sequence of keys with len > 0 in lexsort"); return NULL; } @@ -2375,7 +2375,7 @@ PyArray_LexSort(PyObject *sort_keys, int axis) } } if (!mps[i]->descr->f->argsort[PyArray_MERGESORT]) { - PyErr_Format(PyExc_TypeError, + PyErr_Format(PyExc_TypeError, "merge sort not available for item %d", i); goto fail; } @@ -2388,7 +2388,7 @@ PyArray_LexSort(PyObject *sort_keys, int axis) nd = mps[0]->nd; if ((nd==0) || (PyArray_SIZE(mps[0])==1)) { ret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd, - mps[0]->dimensions, + mps[0]->dimensions, PyArray_INTP, NULL, NULL, 0, 0, NULL); if (ret == NULL) return NULL; @@ -2397,7 +2397,7 @@ PyArray_LexSort(PyObject *sort_keys, int axis) } if (axis < 0) axis += nd; if ((axis < 0) || (axis >= nd)) { - PyErr_Format(PyExc_ValueError, + PyErr_Format(PyExc_ValueError, "axis(=%d) out of bounds", axis); goto fail; } @@ -2425,7 +2425,7 @@ PyArray_LexSort(PyObject *sort_keys, int axis) needcopy = PyArray_ISBYTESWAPPED(mps[j]) || \ !(mps[j]->flags & ALIGNED) || \ (mps[j]->strides[axis] != (intp)mps[j]->descr->elsize); - if (mps[j]->descr->elsize > maxelsize) + if (mps[j]->descr->elsize > maxelsize) maxelsize = mps[j]->descr->elsize; } @@ -2441,14 +2441,14 @@ PyArray_LexSort(PyObject *sort_keys, int axis) for (i=0; i<N; i++) *iptr++ = i; for (j=0; j<n; j++) { elsize = mps[j]->descr->elsize; - astride = mps[j]->strides[axis]; + astride = mps[j]->strides[axis]; argsort = mps[j]->descr->f->argsort[PyArray_MERGESORT]; - _unaligned_strided_byte_copy(valbuffer, (intp) elsize, + _unaligned_strided_byte_copy(valbuffer, (intp) elsize, its[j]->dataptr, astride, N, elsize); - if (swaps[j]) + if (swaps[j]) _strided_byte_swap(valbuffer, (intp) elsize, N, elsize); if (argsort(valbuffer, (intp *)indbuffer, N, mps[j]) < 0) { - PyDataMem_FREE(valbuffer); + PyDataMem_FREE(valbuffer); PyDataMem_FREE(indbuffer); free(swaps); goto fail; @@ -2479,7 +2479,7 @@ PyArray_LexSort(PyObject *sort_keys, int axis) NPY_END_THREADS - for (i=0; i<n; i++) {Py_XDECREF(mps[i]); Py_XDECREF(its[i]);} + for (i=0; i<n; i++) {Py_XDECREF(mps[i]); Py_XDECREF(its[i]);} Py_DECREF(rit); _pya_free(mps); _pya_free(its); @@ -2498,9 +2498,9 @@ PyArray_LexSort(PyObject *sort_keys, int axis) } -static void +static void local_where(PyArrayObject *ap1, PyArrayObject *ap2, PyArrayObject *ret) -{ +{ PyArray_CompareFunc *compare = ap2->descr->f->compare; intp min_i, max_i, i, j; int location, elsize = ap1->descr->elsize; @@ -2540,43 +2540,43 @@ local_where(PyArrayObject *ap1, PyArrayObject *ap2, PyArrayObject *ret) Numeric.searchsorted(a,v) */ static PyObject * -PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) +PyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) { PyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL; int typenum = 0; NPY_BEGIN_THREADS_DEF - + typenum = PyArray_ObjectType((PyObject *)op1, 0); typenum = PyArray_ObjectType(op2, typenum); ret = NULL; - ap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, - typenum, + ap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, + typenum, 1, 1); if (ap1 == NULL) return NULL; - ap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, + ap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, 0, 0); if (ap2 == NULL) goto fail; - - ret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, + + ret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, ap2->dimensions, PyArray_INTP, NULL, NULL, 0, 0, (PyObject *)ap2); if (ret == NULL) goto fail; if (ap2->descr->f->compare == NULL) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "compare not supported for type"); goto fail; } NPY_BEGIN_THREADS_DESCR(ap2->descr) - local_where(ap1, ap2, ret); + local_where(ap1, ap2, ret); NPY_END_THREADS_DESCR(ap2->descr) - + Py_DECREF(ap1); Py_DECREF(ap2); return (PyObject *)ret; - + fail: Py_XDECREF(ap1); Py_XDECREF(ap2); @@ -2595,7 +2595,7 @@ new_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2, PyArrayObject *ret; PyTypeObject *subtype; double prior1, prior2; - /* Need to choose an output array that can hold a sum + /* Need to choose an output array that can hold a sum -- use priority to determine which subtype. */ if (ap2->ob_type != ap1->ob_type) { @@ -2608,21 +2608,21 @@ new_array_for_sum(PyArrayObject *ap1, PyArrayObject *ap2, subtype = ap1->ob_type; } - ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, - typenum, NULL, NULL, 0, 0, + ret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, + typenum, NULL, NULL, 0, 0, (PyObject *) (prior2 > prior1 ? ap2 : ap1)); return ret; } -/* Could perhaps be redone to not make contiguous arrays +/* Could perhaps be redone to not make contiguous arrays */ /*MULTIARRAY_API Numeric.innerproduct(a,v) */ static PyObject * -PyArray_InnerProduct(PyObject *op1, PyObject *op2) +PyArray_InnerProduct(PyObject *op1, PyObject *op2) { PyArrayObject *ap1, *ap2, *ret=NULL; PyArrayIterObject *it1, *it2; @@ -2636,18 +2636,18 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2) NPY_BEGIN_THREADS_DEF - typenum = PyArray_ObjectType(op1, 0); + typenum = PyArray_ObjectType(op1, 0); typenum = PyArray_ObjectType(op2, typenum); typec = PyArray_DescrFromType(typenum); Py_INCREF(typec); - ap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, + ap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, BEHAVED, NULL); if (ap1 == NULL) {Py_DECREF(typec); return NULL;} ap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0, BEHAVED, NULL); if (ap2 == NULL) goto fail; - + if (ap1->nd == 0 || ap2->nd == 0) { ret = (ap1->nd == 0 ? ap1 : ap2); ret = (PyArrayObject *)ret->ob_type->tp_as_number->\ @@ -2656,14 +2656,14 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2) Py_DECREF(ap2); return (PyObject *)ret; } - + l = ap1->dimensions[ap1->nd-1]; - + if (ap2->dimensions[ap2->nd-1] != l) { PyErr_SetString(PyExc_ValueError, "matrices are not aligned"); goto fail; } - + nd = ap1->nd+ap2->nd-2; j = 0; for(i=0; i<ap1->nd-1; i++) { @@ -2674,21 +2674,21 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2) } - /* Need to choose an output array that can hold a sum + /* Need to choose an output array that can hold a sum -- use priority to determine which subtype. */ ret = new_array_for_sum(ap1, ap2, nd, dimensions, typenum); if (ret == NULL) goto fail; dot = (ret->descr->f->dotfunc); - + if (dot == NULL) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "dot not available for this type"); goto fail; } - - is1 = ap1->strides[ap1->nd-1]; + + is1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[ap2->nd-1]; op = ret->data; os = ret->descr->elsize; @@ -2699,7 +2699,7 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2) it2 = (PyArrayIterObject *)\ PyArray_IterAllButAxis((PyObject *)ap2, &axis); - NPY_BEGIN_THREADS_DESCR(ap2->descr) + NPY_BEGIN_THREADS_DESCR(ap2->descr) while(1) { while(it2->index < it2->size) { dot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret); @@ -2715,12 +2715,12 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2) Py_DECREF(it2); if (PyErr_Occurred()) goto fail; - - + + Py_DECREF(ap1); Py_DECREF(ap2); return (PyObject *)ret; - + fail: Py_XDECREF(ap1); Py_XDECREF(ap2); @@ -2734,7 +2734,7 @@ PyArray_InnerProduct(PyObject *op1, PyObject *op2) Numeric.matrixproduct(a,v) */ static PyObject * -PyArray_MatrixProduct(PyObject *op1, PyObject *op2) +PyArray_MatrixProduct(PyObject *op1, PyObject *op2) { PyArrayObject *ap1, *ap2, *ret=NULL; PyArrayIterObject *it1, *it2; @@ -2748,18 +2748,18 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2) NPY_BEGIN_THREADS_DEF - typenum = PyArray_ObjectType(op1, 0); - typenum = PyArray_ObjectType(op2, typenum); - + typenum = PyArray_ObjectType(op1, 0); + typenum = PyArray_ObjectType(op2, typenum); + typec = PyArray_DescrFromType(typenum); Py_INCREF(typec); - ap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, + ap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 0, 0, BEHAVED, NULL); if (ap1 == NULL) {Py_DECREF(typec); return NULL;} ap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 0, 0, BEHAVED, NULL); if (ap2 == NULL) goto fail; - + if (ap1->nd == 0 || ap2->nd == 0) { ret = (ap1->nd == 0 ? ap1 : ap2); ret = (PyArrayObject *)ret->ob_type->tp_as_number->\ @@ -2768,7 +2768,7 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2) Py_DECREF(ap2); return (PyObject *)ret; } - + l = ap1->dimensions[ap1->nd-1]; if (ap2->nd > 1) { matchDim = ap2->nd - 2; @@ -2781,7 +2781,7 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2) PyErr_SetString(PyExc_ValueError, "objects are not aligned"); goto fail; } - + nd = ap1->nd+ap2->nd-2; j = 0; for(i=0; i<ap1->nd-1; i++) { @@ -2795,9 +2795,9 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2) } /* fprintf(stderr, "nd=%d dimensions=", nd); - for(i=0; i<j; i++) + for(i=0; i<j; i++) fprintf(stderr, "%d ", dimensions[i]); - fprintf(stderr, "\n"); + fprintf(stderr, "\n"); */ is1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim]; @@ -2817,11 +2817,11 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2) dot = ret->descr->f->dotfunc; if (dot == NULL) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "dot not available for this type"); goto fail; } - + op = ret->data; os = ret->descr->elsize; axis = ap1->nd-1; @@ -2830,7 +2830,7 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2) it2 = (PyArrayIterObject *)\ PyArray_IterAllButAxis((PyObject *)ap2, &matchDim); - NPY_BEGIN_THREADS_DESCR(ap2->descr) + NPY_BEGIN_THREADS_DESCR(ap2->descr) while(1) { while(it2->index < it2->size) { dot(it1->dataptr, is1, it2->dataptr, is2, op, l, ret); @@ -2849,7 +2849,7 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2) Py_DECREF(ap1); Py_DECREF(ap2); return (PyObject *)ret; - + fail: Py_XDECREF(ap1); Py_XDECREF(ap2); @@ -2861,7 +2861,7 @@ PyArray_MatrixProduct(PyObject *op1, PyObject *op2) Fast Copy and Transpose */ static PyObject * -PyArray_CopyAndTranspose(PyObject *op) +PyArray_CopyAndTranspose(PyObject *op) { PyObject *ret, *arr; int nd; @@ -2877,11 +2877,11 @@ PyArray_CopyAndTranspose(PyObject *op) if (nd == 1) { /* we will give in to old behavior */ ret = PyArray_Copy((PyArrayObject *)arr); Py_DECREF(arr); - return ret; + return ret; } else if (nd != 2) { Py_DECREF(arr); - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "only 2-d arrays are allowed"); return NULL; } @@ -2890,11 +2890,11 @@ PyArray_CopyAndTranspose(PyObject *op) dims[0] = PyArray_DIM(arr,1); dims[1] = PyArray_DIM(arr,0); elsize = PyArray_ITEMSIZE(arr); - + Py_INCREF(PyArray_DESCR(arr)); - ret = PyArray_NewFromDescr(arr->ob_type, + ret = PyArray_NewFromDescr(arr->ob_type, PyArray_DESCR(arr), - 2, dims, + 2, dims, NULL, NULL, 0, arr); if (ret == NULL) { @@ -2918,12 +2918,12 @@ PyArray_CopyAndTranspose(PyObject *op) Py_DECREF(arr); return ret; } - + /*MULTIARRAY_API Numeric.correlate(a1,a2,mode) */ static PyObject * -PyArray_Correlate(PyObject *op1, PyObject *op2, int mode) +PyArray_Correlate(PyObject *op1, PyObject *op2, int mode) { PyArrayObject *ap1, *ap2, *ret=NULL; intp length; @@ -2935,10 +2935,10 @@ PyArray_Correlate(PyObject *op1, PyObject *op2, int mode) PyArray_Descr *typec; NPY_BEGIN_THREADS_DEF - - typenum = PyArray_ObjectType(op1, 0); + + typenum = PyArray_ObjectType(op1, 0); typenum = PyArray_ObjectType(op2, typenum); - + typec = PyArray_DescrFromType(typenum); Py_INCREF(typec); ap1 = (PyArrayObject *)PyArray_FromAny(op1, typec, 1, 1, @@ -2947,18 +2947,18 @@ PyArray_Correlate(PyObject *op1, PyObject *op2, int mode) ap2 = (PyArrayObject *)PyArray_FromAny(op2, typec, 1, 1, DEFAULT, NULL); if (ap2 == NULL) goto fail; - + n1 = ap1->dimensions[0]; n2 = ap2->dimensions[0]; - if (n1 < n2) { - ret = ap1; ap1 = ap2; ap2 = ret; + if (n1 < n2) { + ret = ap1; ap1 = ap2; ap2 = ret; ret = NULL; i = n1;n1=n2;n2=i; } length = n1; n = n2; switch(mode) { - case 0: + case 0: length = length-n+1; n_left = n_right = 0; break; @@ -2972,20 +2972,20 @@ PyArray_Correlate(PyObject *op1, PyObject *op2, int mode) length = length+n-1; break; default: - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "mode must be 0, 1, or 2"); goto fail; } - /* Need to choose an output array that can hold a sum + /* Need to choose an output array that can hold a sum -- use priority to determine which subtype. */ ret = new_array_for_sum(ap1, ap2, 1, &length, typenum); if (ret == NULL) goto fail; - + dot = ret->descr->f->dotfunc; if (dot == NULL) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "function not available for this data type"); goto fail; } @@ -2994,7 +2994,7 @@ PyArray_Correlate(PyObject *op1, PyObject *op2, int mode) is1 = ap1->strides[0]; is2 = ap2->strides[0]; op = ret->data; os = ret->descr->elsize; - + ip1 = ap1->data; ip2 = ap2->data+n_left*is2; n = n-n_left; for(i=0; i<n_left; i++) { @@ -3020,7 +3020,7 @@ PyArray_Correlate(PyObject *op1, PyObject *op2, int mode) Py_DECREF(ap1); Py_DECREF(ap2); return (PyObject *)ret; - + fail: Py_XDECREF(ap1); Py_XDECREF(ap2); @@ -3033,24 +3033,24 @@ PyArray_Correlate(PyObject *op1, PyObject *op2, int mode) ArgMin */ static PyObject * -PyArray_ArgMin(PyArrayObject *ap, int axis, PyArrayObject *out) +PyArray_ArgMin(PyArrayObject *ap, int axis, PyArrayObject *out) { PyObject *obj, *new, *ret; if (PyArray_ISFLEXIBLE(ap)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "argmax is unsupported for this type"); return NULL; } - else if (PyArray_ISUNSIGNED(ap)) + else if (PyArray_ISUNSIGNED(ap)) obj = PyInt_FromLong((long) -1); - - else if (PyArray_TYPE(ap)==PyArray_BOOL) + + else if (PyArray_TYPE(ap)==PyArray_BOOL) obj = PyInt_FromLong((long) 1); - - else + + else obj = PyInt_FromLong((long) 0); - + new = PyArray_EnsureAnyArray(PyNumber_Subtract(obj, (PyObject *)ap)); Py_DECREF(obj); if (new == NULL) return NULL; @@ -3070,10 +3070,10 @@ PyArray_Max(PyArrayObject *ap, int axis, PyArrayObject *out) if ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL) return NULL; - ret = PyArray_GenericReduceFunction(arr, n_ops.maximum, axis, + ret = PyArray_GenericReduceFunction(arr, n_ops.maximum, axis, arr->descr->type_num, out); Py_DECREF(arr); - return ret; + return ret; } /*MULTIARRAY_API @@ -3090,7 +3090,7 @@ PyArray_Min(PyArrayObject *ap, int axis, PyArrayObject *out) ret = PyArray_GenericReduceFunction(arr, n_ops.minimum, axis, arr->descr->type_num, out); Py_DECREF(arr); - return ret; + return ret; } /*MULTIARRAY_API @@ -3132,7 +3132,7 @@ PyArray_Ptp(PyArrayObject *ap, int axis, PyArrayObject *out) ArgMax */ static PyObject * -PyArray_ArgMax(PyArrayObject *op, int axis, PyArrayObject *out) +PyArray_ArgMax(PyArrayObject *op, int axis, PyArrayObject *out) { PyArrayObject *ap=NULL, *rp=NULL; PyArray_ArgFunc* arg_func; @@ -3143,7 +3143,7 @@ PyArray_ArgMax(PyArrayObject *op, int axis, PyArrayObject *out) int copyret=0; NPY_BEGIN_THREADS_DEF - + if ((ap=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL; /* We need to permute the array so that axis is placed at the end. @@ -3167,12 +3167,12 @@ PyArray_ArgMax(PyArrayObject *op, int axis, PyArrayObject *out) } ap = (PyArrayObject *)\ - PyArray_ContiguousFromAny((PyObject *)op, + PyArray_ContiguousFromAny((PyObject *)op, PyArray_NOTYPE, 1, 0); Py_DECREF(op); if (ap == NULL) return NULL; - + arg_func = ap->descr->f->argmax; if (arg_func == NULL) { PyErr_SetString(PyExc_TypeError, "data type not ordered"); @@ -3182,7 +3182,7 @@ PyArray_ArgMax(PyArrayObject *op, int axis, PyArrayObject *out) elsize = ap->descr->elsize; m = ap->dimensions[ap->nd-1]; if (m == 0) { - PyErr_SetString(MultiArrayError, + PyErr_SetString(MultiArrayError, "attempt to get argmax/argmin "\ "of an empty sequence??"); goto fail; @@ -3191,18 +3191,18 @@ PyArray_ArgMax(PyArrayObject *op, int axis, PyArrayObject *out) if (!out) { rp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1, ap->dimensions, PyArray_INTP, - NULL, NULL, 0, 0, + NULL, NULL, 0, 0, (PyObject *)ap); if (rp == NULL) goto fail; } else { if (PyArray_SIZE(out) != \ PyArray_MultiplyList(ap->dimensions, ap->nd-1)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "invalid shape for output array."); } rp = (PyArrayObject *)\ - PyArray_FromArray(out, + PyArray_FromArray(out, PyArray_DescrFromType(PyArray_INTP), NPY_CARRAY | NPY_UPDATEIFCOPY); if (rp == NULL) goto fail; @@ -3227,19 +3227,19 @@ PyArray_ArgMax(PyArrayObject *op, int axis, PyArrayObject *out) rp = obj; } return (PyObject *)rp; - + fail: Py_DECREF(ap); Py_XDECREF(rp); return NULL; -} +} /*MULTIARRAY_API Take */ static PyObject * -PyArray_TakeFrom(PyArrayObject *self0, PyObject *indices0, int axis, +PyArray_TakeFrom(PyArrayObject *self0, PyObject *indices0, int axis, PyArrayObject *ret, NPY_CLIPMODE clipmode) { PyArrayObject *self, *indices; @@ -3247,16 +3247,16 @@ PyArray_TakeFrom(PyArrayObject *self0, PyObject *indices0, int axis, intp shape[MAX_DIMS]; char *src, *dest; int copyret=0; - + indices = ret = NULL; self = (PyAO *)_check_axis(self0, &axis, CARRAY); if (self == NULL) return NULL; - - indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, - PyArray_INTP, + + indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, + PyArray_INTP, 1, 0); if (indices == NULL) goto fail; - + n = m = chunk = 1; nd = self->nd + indices->nd - 1; for (i=0; i< nd; i++) { @@ -3275,21 +3275,21 @@ PyArray_TakeFrom(PyArrayObject *self0, PyObject *indices0, int axis, } Py_INCREF(self->descr); if (!ret) { - ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, + ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, self->descr, - nd, shape, - NULL, NULL, 0, + nd, shape, + NULL, NULL, 0, (PyObject *)self); - + if (ret == NULL) goto fail; } else { PyArrayObject *obj; int flags = NPY_CARRAY | NPY_UPDATEIFCOPY; - if ((ret->nd != nd) || + if ((ret->nd != nd) || !PyArray_CompareLists(ret->dimensions, shape, nd)) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "bad shape in output array"); ret = NULL; Py_DECREF(self->descr); @@ -3299,16 +3299,16 @@ PyArray_TakeFrom(PyArrayObject *self0, PyObject *indices0, int axis, if (clipmode == NPY_RAISE) { /* we need to make sure and get a copy so the input array is not changed - before the error is called + before the error is called */ flags |= NPY_ENSURECOPY; } obj = (PyArrayObject *)PyArray_FromArray(ret, self->descr, flags); if (obj != ret) copyret = 1; - ret = obj; + ret = obj; } - + max_item = self->dimensions[axis]; chunk = chunk * ret->descr->elsize; src = self->data; @@ -3321,7 +3321,7 @@ PyArray_TakeFrom(PyArrayObject *self0, PyObject *indices0, int axis, tmp = ((intp *)(indices->data))[j]; if (tmp < 0) tmp = tmp+max_item; if ((tmp < 0) || (tmp >= max_item)) { - PyErr_SetString(PyExc_IndexError, + PyErr_SetString(PyExc_IndexError, "index out of range "\ "for array"); goto fail; @@ -3338,7 +3338,7 @@ PyArray_TakeFrom(PyArrayObject *self0, PyObject *indices0, int axis, tmp = ((intp *)(indices->data))[j]; if (tmp < 0) while (tmp < 0) tmp += max_item; else if (tmp >= max_item) - while (tmp >= max_item) + while (tmp >= max_item) tmp -= max_item; memmove(dest, src+tmp*chunk, chunk); dest += chunk; @@ -3350,9 +3350,9 @@ PyArray_TakeFrom(PyArrayObject *self0, PyObject *indices0, int axis, for(i=0; i<n; i++) { for(j=0; j<m; j++) { tmp = ((intp *)(indices->data))[j]; - if (tmp < 0) + if (tmp < 0) tmp = 0; - else if (tmp >= max_item) + else if (tmp >= max_item) tmp = max_item-1; memmove(dest, src+tmp*chunk, chunk); dest += chunk; @@ -3370,13 +3370,13 @@ PyArray_TakeFrom(PyArrayObject *self0, PyObject *indices0, int axis, PyObject *obj; obj = ret->base; Py_INCREF(obj); - Py_DECREF(ret); + Py_DECREF(ret); ret = (PyArrayObject *)obj; } return (PyObject *)ret; - - + + fail: PyArray_XDECREF_ERR(ret); Py_XDECREF(indices); @@ -3392,7 +3392,7 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0, NPY_CLIPMODE clipmode) { PyArrayObject *indices, *values; - int i, chunk, ni, max_item, nv, tmp, thistype; + int i, chunk, ni, max_item, nv, tmp, thistype; char *src, *dest; int copied = 0; @@ -3400,7 +3400,7 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0, values = NULL; if (!PyArray_Check(self)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "put: first argument must be an array"); return NULL; } @@ -3411,7 +3411,7 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0, flags |= NPY_ENSURECOPY; } Py_INCREF(self->descr); - obj = (PyArrayObject *)PyArray_FromArray(self, + obj = (PyArrayObject *)PyArray_FromArray(self, self->descr, flags); if (obj != self) copied = 1; self = obj; @@ -3420,19 +3420,19 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0, dest = self->data; chunk = self->descr->elsize; - indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, + indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0); if (indices == NULL) goto fail; ni = PyArray_SIZE(indices); thistype = self->descr->type_num; - Py_INCREF(self->descr); - values = (PyArrayObject *)PyArray_FromAny(values0, self->descr, 0, 0, - DEFAULT | FORCECAST, NULL); + Py_INCREF(self->descr); + values = (PyArrayObject *)PyArray_FromAny(values0, self->descr, 0, 0, + DEFAULT | FORCECAST, NULL); if (values == NULL) goto fail; nv = PyArray_SIZE(values); if (nv <= 0) goto finish; - if (self->descr->hasobject) { + if (self->descr->hasobject) { switch(clipmode) { case NPY_RAISE: for(i=0; i<ni; i++) { @@ -3440,7 +3440,7 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0, tmp = ((intp *)(indices->data))[i]; if (tmp < 0) tmp = tmp+max_item; if ((tmp < 0) || (tmp >= max_item)) { - PyErr_SetString(PyExc_IndexError, + PyErr_SetString(PyExc_IndexError, "index out of " \ "range for array"); goto fail; @@ -3455,7 +3455,7 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0, src = values->data + chunk * (i % nv); tmp = ((intp *)(indices->data))[i]; if (tmp < 0) while(tmp < 0) tmp+=max_item; - else if (tmp >= max_item) + else if (tmp >= max_item) while(tmp >= max_item) tmp -= max_item; PyArray_Item_INCREF(src, self->descr); @@ -3485,7 +3485,7 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0, tmp = ((intp *)(indices->data))[i]; if (tmp < 0) tmp = tmp+max_item; if ((tmp < 0) || (tmp >= max_item)) { - PyErr_SetString(PyExc_IndexError, + PyErr_SetString(PyExc_IndexError, "index out of " \ "range for array"); goto fail; @@ -3498,7 +3498,7 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0, src = values->data + chunk * (i % nv); tmp = ((intp *)(indices->data))[i]; if (tmp < 0) while(tmp < 0) tmp+=max_item; - else if (tmp >= max_item) + else if (tmp >= max_item) while(tmp >= max_item) tmp -= max_item; memmove(dest + tmp * chunk, src, chunk); @@ -3517,7 +3517,7 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0, } } - finish: + finish: Py_XDECREF(values); Py_XDECREF(indices); if (copied) { @@ -3525,7 +3525,7 @@ PyArray_PutTo(PyArrayObject *self, PyObject* values0, PyObject *indices0, } Py_INCREF(Py_None); return Py_None; - + fail: Py_XDECREF(indices); Py_XDECREF(values); @@ -3550,7 +3550,7 @@ PyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) values = NULL; if (!PyArray_Check(self)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "putmask: first argument must "\ "be an array"); return NULL; @@ -3559,7 +3559,7 @@ PyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) PyArrayObject *obj; int flags = NPY_CARRAY | NPY_UPDATEIFCOPY; Py_INCREF(self->descr); - obj = (PyArrayObject *)PyArray_FromArray(self, + obj = (PyArrayObject *)PyArray_FromArray(self, self->descr, flags); if (obj != self) copied = 1; self = obj; @@ -3574,7 +3574,7 @@ PyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) if (mask == NULL) goto fail; ni = PyArray_SIZE(mask); if (ni != max_item) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "putmask: mask and data must be "\ "the same size"); goto fail; @@ -3619,7 +3619,7 @@ PyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) } Py_INCREF(Py_None); return Py_None; - + fail: Py_XDECREF(mask); Py_XDECREF(values); @@ -3632,18 +3632,18 @@ PyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) /* This conversion function can be used with the "O&" argument for PyArg_ParseTuple. It will immediately return an object of array type - or will convert to a CARRAY any other object. + or will convert to a CARRAY any other object. If you use PyArray_Converter, you must DECREF the array when finished as you get a new reference to it. */ - + /*MULTIARRAY_API Useful to pass as converter function for O& processing in PyArgs_ParseTuple. */ -static int -PyArray_Converter(PyObject *object, PyObject **address) +static int +PyArray_Converter(PyObject *object, PyObject **address) { if (PyArray_Check(object)) { *address = object; @@ -3661,8 +3661,8 @@ PyArray_Converter(PyObject *object, PyObject **address) Useful to pass as converter function for O& processing in PyArgs_ParseTuple for output arrays */ -static int -PyArray_OutputConverter(PyObject *object, PyArrayObject **address) +static int +PyArray_OutputConverter(PyObject *object, PyArrayObject **address) { if (object == NULL || object == Py_None) { *address = NULL; @@ -3673,7 +3673,7 @@ PyArray_OutputConverter(PyObject *object, PyArrayObject **address) return PY_SUCCEED; } else { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "output must be an array"); *address = NULL; return PY_FAIL; @@ -3686,7 +3686,7 @@ PyArray_OutputConverter(PyObject *object, PyArrayObject **address) */ static int PyArray_BoolConverter(PyObject *object, Bool *val) -{ +{ if (PyObject_IsTrue(object)) *val=TRUE; else *val=FALSE; @@ -3717,7 +3717,7 @@ PyArray_OrderConverter(PyObject *object, NPY_ORDER *val) else { str = PyString_AS_STRING(object); if (str[0] == 'C' || str[0] == 'c') { - *val = PyArray_CORDER; + *val = PyArray_CORDER; } else if (str[0] == 'F' || str[0] == 'f') { *val = PyArray_FORTRANORDER; @@ -3726,7 +3726,7 @@ PyArray_OrderConverter(PyObject *object, NPY_ORDER *val) *val = PyArray_ANYORDER; } else { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "order not understood"); return PY_FAIL; } @@ -3747,7 +3747,7 @@ PyArray_ClipmodeConverter(PyObject *object, NPY_CLIPMODE *val) char *str; str = PyString_AS_STRING(object); if (str[0] == 'C' || str[0] == 'c') { - *val = NPY_CLIP; + *val = NPY_CLIP; } else if (str[0] == 'W' || str[0] == 'w') { *val = NPY_WRAP; @@ -3769,7 +3769,7 @@ PyArray_ClipmodeConverter(PyObject *object, NPY_CLIPMODE *val) number >= (int) NPY_CLIP) *val = (NPY_CLIPMODE) number; else goto fail; - } + } return PY_SUCCEED; fail: @@ -3787,11 +3787,11 @@ static int PyArray_TypestrConvert(int itemsize, int gentype) { register int newtype = gentype; - + if (gentype == PyArray_GENBOOLLTR) { if (itemsize == 1) newtype = PyArray_BOOL; - else + else newtype = PyArray_NOTYPE; } else if (gentype == PyArray_SIGNEDLTR) { @@ -3859,7 +3859,7 @@ PyArray_TypestrConvert(int itemsize, int gentype) case 12: newtype = PyArray_FLOAT96; break; -#endif +#endif #ifdef PyArray_FLOAT128 case 16: newtype = PyArray_FLOAT128; @@ -3867,9 +3867,9 @@ PyArray_TypestrConvert(int itemsize, int gentype) #endif default: newtype = PyArray_NOTYPE; - } + } } - + else if (gentype == PyArray_COMPLEXLTR) { switch(itemsize) { case 8: @@ -3885,9 +3885,9 @@ PyArray_TypestrConvert(int itemsize, int gentype) #endif #ifdef PyArray_FLOAT96 case 24: - newtype = PyArray_COMPLEX192; + newtype = PyArray_COMPLEX192; break; -#endif +#endif #ifdef PyArray_FLOAT128 case 32: newtype = PyArray_COMPLEX256; @@ -3895,7 +3895,7 @@ PyArray_TypestrConvert(int itemsize, int gentype) #endif default: newtype = PyArray_NOTYPE; - } + } } return newtype; @@ -3904,7 +3904,7 @@ PyArray_TypestrConvert(int itemsize, int gentype) /* this function takes a Python object which exposes the (single-segment) buffer interface and returns a pointer to the data segment - + You should increment the reference count by one of buf->base if you will hang on to a reference @@ -3931,17 +3931,17 @@ PyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf) if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) { PyErr_Clear(); buf->flags &= ~WRITEABLE; - if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), + if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), &buflen) < 0) return PY_FAIL; } buf->len = (intp) buflen; - + /* Point to the base of the buffer object if present */ if (PyBuffer_Check(obj)) buf->base = ((PyArray_Chunk *)obj)->base; if (buf->base == NULL) buf->base = obj; - - return PY_SUCCEED; + + return PY_SUCCEED; } @@ -3969,7 +3969,7 @@ PyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq) if (PyNumber_Check(obj)) len = 1; } if (len < 0) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "expected sequence object with len >= 0"); return PY_FAIL; } @@ -3996,26 +3996,26 @@ PyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq) } -/* A tuple type would be either (generic typeobject, typesize) - or (fixed-length data-type, shape) +/* A tuple type would be either (generic typeobject, typesize) + or (fixed-length data-type, shape) or (inheriting data-type, new-data-type) The new data-type must have the same itemsize as the inheriting data-type - unless the latter is 0 - + unless the latter is 0 + Thus (int32, {'real':(int16,0),'imag',(int16,2)}) - is one way to specify a descriptor that will give + is one way to specify a descriptor that will give a['real'] and a['imag'] to an int32 array. */ /* leave type reference alone */ static PyArray_Descr * -_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) +_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) { PyArray_Descr *new; PyArray_Descr *conv; - + *errflag = 0; if (!PyArray_DescrConverter(newobj, &conv)) { return NULL; @@ -4025,7 +4025,7 @@ _use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) if (new == NULL) goto fail; if (new->elsize && new->elsize != conv->elsize) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "mismatch in size of old "\ "and new data-descriptor"); goto fail; @@ -4050,15 +4050,15 @@ _use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) } static PyArray_Descr * -_convert_from_tuple(PyObject *obj) +_convert_from_tuple(PyObject *obj) { PyArray_Descr *type, *res; PyObject *val; int errflag; - + if (PyTuple_GET_SIZE(obj) != 2) return NULL; - if (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) + if (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) return NULL; val = PyTuple_GET_ITEM(obj,1); /* try to interpret next item as a type */ @@ -4077,28 +4077,28 @@ _convert_from_tuple(PyObject *obj) int itemsize; itemsize = PyArray_PyIntAsInt(PyTuple_GET_ITEM(obj,1)); if (error_converting(itemsize)) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "invalid itemsize in generic type "\ "tuple"); goto fail; } PyArray_DESCR_REPLACE(type); if (type->type_num == PyArray_UNICODE) - type->elsize = itemsize << 2; + type->elsize = itemsize << 2; else type->elsize = itemsize; } else { /* interpret next item as shape (if it's a tuple) - and reset the type to PyArray_VOID with - a new fields attribute. + and reset the type to PyArray_VOID with + a new fields attribute. */ PyArray_Dims shape={NULL,-1}; PyArray_Descr *newdescr; - if (!(PyArray_IntpConverter(val, &shape)) || + if (!(PyArray_IntpConverter(val, &shape)) || (shape.len > MAX_DIMS)) { PyDimMem_FREE(shape.ptr); - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "invalid shape in fixed-type tuple."); goto fail; } @@ -4111,7 +4111,7 @@ _convert_from_tuple(PyObject *obj) newdescr = PyArray_DescrNewFromType(PyArray_VOID); if (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;} newdescr->elsize = type->elsize; - newdescr->elsize *= PyArray_MultiplyList(shape.ptr, + newdescr->elsize *= PyArray_MultiplyList(shape.ptr, shape.len); PyDimMem_FREE(shape.ptr); newdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr)); @@ -4134,7 +4134,7 @@ _convert_from_tuple(PyObject *obj) /* obj is a list. Each item is a tuple with -(field-name, data-type (either a list or a string), and an optional +(field-name, data-type (either a list or a string), and an optional shape parameter). */ static PyArray_Descr * @@ -4148,8 +4148,8 @@ _convert_from_array_descr(PyObject *obj) PyArray_Descr *new; PyArray_Descr *conv; int hasobject=0; - - n = PyList_GET_SIZE(obj); + + n = PyList_GET_SIZE(obj); nameslist = PyTuple_New(n); if (!nameslist) return NULL; totalsize = 0; @@ -4171,7 +4171,7 @@ _convert_from_array_descr(PyObject *obj) } else goto fail; if (PyString_GET_SIZE(name)==0) { - if (title==NULL) + if (title==NULL) name = PyString_FromFormat("f%d", i); else { name = title; @@ -4183,9 +4183,9 @@ _convert_from_array_descr(PyObject *obj) } PyTuple_SET_ITEM(nameslist, i, name); if (PyTuple_GET_SIZE(item) == 2) { - ret = PyArray_DescrConverter(PyTuple_GET_ITEM(item, 1), + ret = PyArray_DescrConverter(PyTuple_GET_ITEM(item, 1), &conv); - if (ret == PY_FAIL) + if (ret == PY_FAIL) PyObject_Print(PyTuple_GET_ITEM(item,1), stderr, 0); } @@ -4197,8 +4197,8 @@ _convert_from_array_descr(PyObject *obj) else goto fail; if (ret == PY_FAIL) goto fail; if ((PyDict_GetItem(fields, name) != NULL) || - (title && - (PyString_Check(title) || PyUnicode_Check(title)) && + (title && + (PyString_Check(title) || PyUnicode_Check(title)) && (PyDict_GetItem(fields, title) != NULL))) { PyErr_SetString(PyExc_ValueError, "two fields with the same name"); @@ -4213,10 +4213,10 @@ _convert_from_array_descr(PyObject *obj) /* Title can be "meta-data". Only insert it into the fields dictionary if it is a string */ - if (title != NULL) { + if (title != NULL) { Py_INCREF(title); PyTuple_SET_ITEM(tup, 2, title); - if (PyString_Check(title) || PyUnicode_Check(title)) + if (PyString_Check(title) || PyUnicode_Check(title)) PyDict_SetItem(fields, title, tup); } PyDict_SetItem(fields, name, tup); @@ -4229,7 +4229,7 @@ _convert_from_array_descr(PyObject *obj) new->elsize = totalsize; new->hasobject=hasobject; return new; - + fail: Py_DECREF(fields); Py_DECREF(nameslist); @@ -4242,7 +4242,7 @@ _convert_from_array_descr(PyObject *obj) will default to f0, f1, f2, and so forth. or it can be an array_descr format string -- in which case - align must be 0. + align must be 0. */ static PyArray_Descr * @@ -4258,13 +4258,13 @@ _convert_from_list(PyObject *obj, int align) int ret; int maxalign=0; int hasobject=0; - + n = PyList_GET_SIZE(obj); /* Ignore any empty string at end which _internal._commastring can produce */ key = PyList_GET_ITEM(obj, n-1); if (PyString_Check(key) && PyString_GET_SIZE(key) == 0) n = n-1; - /* End ignore code.*/ + /* End ignore code.*/ totalsize = 0; if (n==0) return NULL; nameslist = PyTuple_New(n); @@ -4280,7 +4280,7 @@ _convert_from_list(PyObject *obj, int align) goto fail; } if (!hasobject && conv->hasobject) - hasobject=1; + hasobject=1; PyTuple_SET_ITEM(tup, 0, (PyObject *)conv); if (align) { int _align; @@ -4316,9 +4316,9 @@ _convert_from_list(PyObject *obj, int align) /* comma-separated string */ /* this is the format developed by the numarray records module */ /* and implemented by the format parser in that module */ -/* this is an alternative implementation found in the _internal.py - file patterned after that one -- the approach is to try to convert - to a list (with tuples if any repeat information is present) +/* this is an alternative implementation found in the _internal.py + file patterned after that one -- the approach is to try to convert + to a list (with tuples if any repeat information is present) and then call the _convert_from_list) */ @@ -4360,42 +4360,42 @@ _convert_from_commastring(PyObject *obj, int align) must have at least two and up to four keys These must all be sequences of the same length. - "names" --- field names + "names" --- field names "formats" --- the data-type descriptors for the field. - + Optional: - "offsets" --- integers indicating the offset into the + "offsets" --- integers indicating the offset into the record of the start of the field. - if not given, then "consecutive offsets" + if not given, then "consecutive offsets" will be assumed and placed in the dictionary. - + "titles" --- Allows the use of an additional key - for the fields dictionary.(if these are strings - or unicode objects) or + for the fields dictionary.(if these are strings + or unicode objects) or this can also be meta-data to - be passed around with the field description. - -Attribute-lookup-based field names merely has to query the fields + be passed around with the field description. + +Attribute-lookup-based field names merely has to query the fields dictionary of the data-descriptor. Any result present can be used to return the correct field. So, the notion of what is a name and what is a title is really quite -arbitrary. +arbitrary. -What does distinguish a title, however, is that if it is not None, -it will be placed at the end of the tuple inserted into the -fields dictionary.and can therefore be used to carry meta-data around. +What does distinguish a title, however, is that if it is not None, +it will be placed at the end of the tuple inserted into the +fields dictionary.and can therefore be used to carry meta-data around. If the dictionary does not have "names" and "formats" entries, -then it will be checked for conformity and used directly. +then it will be checked for conformity and used directly. */ static PyArray_Descr * _use_fields_dict(PyObject *obj, int align) { - return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal, - "_usefields", + return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal, + "_usefields", "Oi", obj, align); } @@ -4409,10 +4409,10 @@ _convert_from_dict(PyObject *obj, int align) int totalsize; int maxalign=0; int hasobject=0; - + fields = PyDict_New(); if (fields == NULL) return (PyArray_Descr *)PyErr_NoMemory(); - + names = PyDict_GetItemString(obj, "names"); descrs = PyDict_GetItemString(obj, "formats"); @@ -4484,7 +4484,7 @@ _convert_from_dict(PyObject *obj, int align) name = PyObject_GetItem(names, index); Py_DECREF(index); if (!(PyString_Check(name) || PyUnicode_Check(name))) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "field names must be strings"); ret = PY_FAIL; } @@ -4500,7 +4500,7 @@ _convert_from_dict(PyObject *obj, int align) if (len == 3) { if ((PyString_Check(item) || PyUnicode_Check(item)) && \ PyDict_GetItem(fields, item) != NULL) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "title already used as a "\ "name or title."); ret=PY_FAIL; @@ -4543,25 +4543,25 @@ _check_for_commastring(char *type, int len) { int i; - if ((type[0] >= '0' && type[0] <= '9') || + if ((type[0] >= '0' && type[0] <= '9') || ((len > 1) && (type[0] == '>' || type[0] == '<' || \ type[0] == '|' || type[0] == '=') && \ (type[1] >= '0' && type[1] <= '9'))) return 1; for (i=1;i<len;i++) if (type[i] == ',') return 1; - + return 0; } -/* - any object with - the .fields attribute and/or .itemsize attribute +/* + any object with + the .fields attribute and/or .itemsize attribute (if the .fields attribute does not give the total size -- i.e. a partial record naming). If itemsize is given it must be >= size computed from fields - - The .fields attribute must return a convertible dictionary if + + The .fields attribute must return a convertible dictionary if present. Result inherits from PyArray_VOID. */ @@ -4579,13 +4579,13 @@ PyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at) else return PyArray_DescrConverter(obj, at); } -/* This function takes a Python object representing a type and converts it +/* This function takes a Python object representing a type and converts it to a the correct PyArray_Descr * structure to describe the type. - + Many objects can be used to represent a data-type which in NumPy is - quite a flexible concept. + quite a flexible concept. - This is the central code that converts Python objects to + This is the central code that converts Python objects to Type-descriptor objects that are used throughout numpy. */ @@ -4604,21 +4604,21 @@ PyArray_DescrConverter(PyObject *obj, PyArray_Descr **at) char endian = '='; *at=NULL; - + /* default */ if (obj == Py_None) { *at = PyArray_DescrFromType(PyArray_DEFAULT); return PY_SUCCEED; } - + if (PyArray_DescrCheck(obj)) { *at = (PyArray_Descr *)obj; Py_INCREF(*at); return PY_SUCCEED; } - + if (PyType_Check(obj)) { - if (PyType_IsSubtype((PyTypeObject *)obj, + if (PyType_IsSubtype((PyTypeObject *)obj, &PyGenericArrType_Type)) { *at = PyArray_DescrFromTypeObject(obj); if (*at) return PY_SUCCEED; @@ -4629,9 +4629,9 @@ PyArray_DescrConverter(PyObject *obj, PyArray_Descr **at) check_num = PyArray_LONG; else if (obj == (PyObject *)(&PyLong_Type)) check_num = PyArray_LONGLONG; - else if (obj == (PyObject *)(&PyFloat_Type)) + else if (obj == (PyObject *)(&PyFloat_Type)) check_num = PyArray_DOUBLE; - else if (obj == (PyObject *)(&PyComplex_Type)) + else if (obj == (PyObject *)(&PyComplex_Type)) check_num = PyArray_CDOUBLE; else if (obj == (PyObject *)(&PyBool_Type)) check_num = PyArray_BOOL; @@ -4656,7 +4656,7 @@ PyArray_DescrConverter(PyObject *obj, PyArray_Descr **at) len = PyString_GET_SIZE(obj); if (len <= 0) goto fail; - /* check for commas present + /* check for commas present or first (or second) element a digit */ if (_check_for_commastring(type, len)) { *at = _convert_from_commastring(obj, 0); @@ -4678,7 +4678,7 @@ PyArray_DescrConverter(PyObject *obj, PyArray_Descr **at) check_num = PyArray_NOTYPE+10; } /* When specifying length of UNICODE - the number of characters is given to match + the number of characters is given to match the STRING interface. Each character can be more than one byte and itemsize must be the number of bytes. @@ -4686,7 +4686,7 @@ PyArray_DescrConverter(PyObject *obj, PyArray_Descr **at) else if (check_num == PyArray_UNICODELTR) { elsize <<= 2; } - /* Support for generic processing + /* Support for generic processing c4, i4, f8, etc... */ else if ((check_num != PyArray_STRINGLTR) && \ @@ -4752,27 +4752,27 @@ PyArray_DescrConverter(PyObject *obj, PyArray_Descr **at) } goto fail; } - + if (((*at)->elsize == 0) && (elsize != 0)) { PyArray_DESCR_REPLACE(*at); (*at)->elsize = elsize; } - if (endian != '=' && PyArray_ISNBO(endian)) endian = '='; - + if (endian != '=' && PyArray_ISNBO(endian)) endian = '='; + if (endian != '=' && (*at)->byteorder != '|' && \ (*at)->byteorder != endian) { PyArray_DESCR_REPLACE(*at); (*at)->byteorder = endian; } - + return PY_SUCCEED; fail: - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "data type not understood"); *at=NULL; return PY_FAIL; -} +} /*MULTIARRAY_API Convert object to endian @@ -4785,7 +4785,7 @@ PyArray_ByteorderConverter(PyObject *obj, char *endian) str = PyString_AsString(obj); if (!str) return PY_FAIL; if (strlen(str) < 1) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "Byteorder string must be at least length 1"); return PY_FAIL; } @@ -4803,7 +4803,7 @@ PyArray_ByteorderConverter(PyObject *obj, char *endian) else if (str[0] == 's' || str[0] == 'S') *endian = PyArray_SWAP; else { - PyErr_Format(PyExc_ValueError, + PyErr_Format(PyExc_ValueError, "%s is an unrecognized byteorder", str); return PY_FAIL; @@ -4813,7 +4813,7 @@ PyArray_ByteorderConverter(PyObject *obj, char *endian) } /*MULTIARRAY_API - Convert object to sort kind + Convert object to sort kind */ static int PyArray_SortkindConverter(PyObject *obj, NPY_SORTKIND *sortkind) @@ -4823,7 +4823,7 @@ PyArray_SortkindConverter(PyObject *obj, NPY_SORTKIND *sortkind) str = PyString_AsString(obj); if (!str) return PY_FAIL; if (strlen(str) < 1) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "Sort kind string must be at least length 1"); return PY_FAIL; } @@ -4834,7 +4834,7 @@ PyArray_SortkindConverter(PyObject *obj, NPY_SORTKIND *sortkind) else if (str[0] == 'm' || str[0] == 'M') *sortkind = PyArray_MERGESORT; else { - PyErr_Format(PyExc_ValueError, + PyErr_Format(PyExc_ValueError, "%s is an unrecognized kind of sort", str); return PY_FAIL; @@ -4844,14 +4844,14 @@ PyArray_SortkindConverter(PyObject *obj, NPY_SORTKIND *sortkind) /* compare the field dictionary for two types - return 1 if the same or 0 if not + return 1 if the same or 0 if not */ static int _equivalent_fields(PyObject *field1, PyObject *field2) { int same, val; - + if (field1 == field2) return 1; if (field1 == NULL || field2 == NULL) return 0; val = PyObject_Compare(field1, field2); @@ -4861,7 +4861,7 @@ _equivalent_fields(PyObject *field1, PyObject *field2) { return same; } -/* This function returns true if the two typecodes are +/* This function returns true if the two typecodes are equivalent (same basic kind and same itemsize). */ @@ -4881,7 +4881,7 @@ PyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2) if (typenum1 == PyArray_VOID || \ typenum2 == PyArray_VOID) { - return ((typenum1 == typenum2) && + return ((typenum1 == typenum2) && (typ1->typeobj == typ2->typeobj) && _equivalent_fields(typ1->fields, typ2->fields)); } @@ -4945,7 +4945,7 @@ static PyObject * _array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws) { PyObject *op, *ret=NULL; - static char *kwd[]= {"object", "dtype", "copy", "order", "subok", + static char *kwd[]= {"object", "dtype", "copy", "order", "subok", "ndmin", NULL}; Bool subok=FALSE; Bool copy=TRUE; @@ -4956,22 +4956,22 @@ _array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws) int flags=0; if (PyTuple_GET_SIZE(args) > 2) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "only 2 non-keyword arguments accepted"); return NULL; } - if(!PyArg_ParseTupleAndKeywords(args, kws, "O|O&O&O&O&i", kwd, &op, + if(!PyArg_ParseTupleAndKeywords(args, kws, "O|O&O&O&O&i", kwd, &op, PyArray_DescrConverter2, - &type, - PyArray_BoolConverter, ©, + &type, + PyArray_BoolConverter, ©, PyArray_OrderConverter, &order, - PyArray_BoolConverter, &subok, - &ndmin)) + PyArray_BoolConverter, &subok, + &ndmin)) return NULL; /* fast exit if simple call */ - if ((subok && PyArray_Check(op)) || + if ((subok && PyArray_Check(op)) || (!subok && PyArray_CheckExact(op))) { if (type==NULL) { if (!copy && STRIDING_OK(op, order)) { @@ -4980,7 +4980,7 @@ _array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws) goto finish; } else { - ret = PyArray_NewCopy((PyArrayObject*)op, + ret = PyArray_NewCopy((PyArrayObject*)op, order); goto finish; } @@ -5011,7 +5011,7 @@ _array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws) if (order == PyArray_CORDER) { flags |= CONTIGUOUS; } - else if ((order == PyArray_FORTRANORDER) || + else if ((order == PyArray_FORTRANORDER) || /* order == PyArray_ANYORDER && */ (PyArray_Check(op) && PyArray_ISFORTRAN(op))) { flags |= FORTRAN; @@ -5038,14 +5038,14 @@ static PyObject * PyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran) { PyArrayObject *ret; - + if (!type) type = PyArray_DescrFromType(PyArray_DEFAULT); - ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, - type, nd, dims, + ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, + type, nd, dims, NULL, NULL, fortran, NULL); if (ret == NULL) return NULL; - + if (type->hasobject) { PyArray_FillObjectArray(ret, Py_None); if (PyErr_Occurred()) {Py_DECREF(ret); return NULL;} @@ -5054,28 +5054,28 @@ PyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran) } static PyObject * -array_empty(PyObject *ignored, PyObject *args, PyObject *kwds) +array_empty(PyObject *ignored, PyObject *args, PyObject *kwds) { - + static char *kwlist[] = {"shape","dtype","order",NULL}; PyArray_Descr *typecode=NULL; PyArray_Dims shape = {NULL, 0}; - NPY_ORDER order = PyArray_CORDER; + NPY_ORDER order = PyArray_CORDER; Bool fortran; PyObject *ret=NULL; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&O&", kwlist, PyArray_IntpConverter, - &shape, + &shape, PyArray_DescrConverter, - &typecode, - PyArray_OrderConverter, &order)) + &typecode, + PyArray_OrderConverter, &order)) goto fail; if (order == PyArray_FORTRANORDER) fortran = TRUE; else fortran = FALSE; - ret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); + ret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); PyDimMem_FREE(shape.ptr); return ret; @@ -5085,9 +5085,9 @@ array_empty(PyObject *ignored, PyObject *args, PyObject *kwds) } static PyObject * -array_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) +array_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) { - + static char *kwlist[] = {"dtype","obj", NULL}; PyArray_Descr *typecode; PyObject *obj=NULL; @@ -5095,13 +5095,13 @@ array_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) void *dptr; PyObject *ret; - + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|O", - kwlist, &PyArrayDescr_Type, + kwlist, &PyArrayDescr_Type, &typecode, - &obj)) + &obj)) return NULL; - + if (typecode->elsize == 0) { PyErr_SetString(PyExc_ValueError, \ "itemsize cannot be zero"); @@ -5123,7 +5123,7 @@ array_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) } else { if (!PyString_Check(obj)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "initializing object must "\ "be a string"); return NULL; @@ -5139,7 +5139,7 @@ array_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) } ret = PyArray_Scalar(dptr, typecode, NULL); - + /* free dptr which contains zeros */ if (alloc) _pya_free(dptr); return ret; @@ -5158,13 +5158,13 @@ PyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran) intp n; if (!type) type = PyArray_DescrFromType(PyArray_DEFAULT); - ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, + ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, type, - nd, dims, - NULL, NULL, + nd, dims, + NULL, NULL, fortran, NULL); if (ret == NULL) return NULL; - + if (type->hasobject) { PyObject *zero = PyInt_FromLong(0); PyArray_FillObjectArray(ret, zero); @@ -5180,22 +5180,22 @@ PyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran) } static PyObject * -array_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) +array_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"shape","dtype","order",NULL}; /* XXX ? */ PyArray_Descr *typecode=NULL; PyArray_Dims shape = {NULL, 0}; NPY_ORDER order = PyArray_CORDER; - Bool fortran = FALSE; + Bool fortran = FALSE; PyObject *ret=NULL; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|O&O&", kwlist, PyArray_IntpConverter, - &shape, + &shape, PyArray_DescrConverter, - &typecode, + &typecode, PyArray_OrderConverter, - &order)) + &order)) goto fail; if (order == PyArray_FORTRANORDER) fortran = TRUE; @@ -5238,7 +5238,7 @@ _skip_sep(char **ptr, char *sep) /* steals a reference to dtype -- accepts NULL */ /*OBJECT_API*/ static PyObject * -PyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, +PyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, intp n, char *sep) { int itemsize; @@ -5250,13 +5250,13 @@ PyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, dtype=PyArray_DescrFromType(PyArray_DEFAULT); if (dtype->hasobject) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "Cannot create an object array from" \ " a string"); Py_DECREF(dtype); return NULL; - } - + } + itemsize = dtype->elsize; if (itemsize == 0) { PyErr_SetString(PyExc_ValueError, "zero-valued itemsize"); @@ -5264,12 +5264,12 @@ PyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, return NULL; } - binary = ((sep == NULL) || (strlen(sep) == 0)); + binary = ((sep == NULL) || (strlen(sep) == 0)); if (binary) { if (n < 0 ) { if (slen % itemsize != 0) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "string size must be a "\ "multiple of element size"); Py_DECREF(dtype); @@ -5278,24 +5278,24 @@ PyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, n = slen/itemsize; } else { if (slen < n*itemsize) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "string is smaller than " \ "requested size"); Py_DECREF(dtype); return NULL; } } - + if ((ret = (PyArrayObject *)\ PyArray_NewFromDescr(&PyArray_Type, dtype, 1, &n, NULL, NULL, 0, NULL)) == NULL) - return NULL; + return NULL; memcpy(ret->data, data, n*dtype->elsize); return (PyObject *)ret; } else { /* read from character-based string */ - char *ptr; + char *ptr; PyArray_FromStrFunc *fromstr; char *dptr; intp nread=0; @@ -5303,7 +5303,7 @@ PyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, fromstr = dtype->f->fromstr; if (fromstr == NULL) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "don't know how to read " \ "character strings for given " \ "array type"); @@ -5325,19 +5325,19 @@ PyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, break; nread += 1; dptr += dtype->elsize; - if (_skip_sep(&ptr, sep) < 0) + if (_skip_sep(&ptr, sep) < 0) break; } if (nread < n) { fprintf(stderr, "%ld items requested but "\ - "only %ld read\n", + "only %ld read\n", (long) n, (long) nread); ret->data = \ - PyDataMem_RENEW(ret->data, + PyDataMem_RENEW(ret->data, nread * \ ret->descr->elsize); PyArray_DIM(ret,0) = nread; - + } NPY_END_ALLOW_THREADS } @@ -5351,10 +5351,10 @@ PyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, int val; ret = (PyArrayObject *)\ - PyArray_NewFromDescr(&PyArray_Type, + PyArray_NewFromDescr(&PyArray_Type, dtype, - 1, &size, - NULL, NULL, + 1, &size, + NULL, NULL, 0, NULL); if (ret==NULL) return NULL; NPY_BEGIN_ALLOW_THREADS @@ -5372,14 +5372,14 @@ PyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, dptr += dtype->elsize; if (thisbuf == size) { totalbytes += bytes; - ret->data = PyDataMem_RENEW(ret->data, + ret->data = PyDataMem_RENEW(ret->data, totalbytes); dptr = ret->data + \ (totalbytes - bytes); thisbuf = 0; } } - ret->data = PyDataMem_RENEW(ret->data, + ret->data = PyDataMem_RENEW(ret->data, nread*ret->descr->elsize); PyArray_DIM(ret,0) = nread; #undef _FILEBUFNUM @@ -5399,9 +5399,9 @@ array_fromString(PyObject *ignored, PyObject *args, PyObject *keywds) static char *kwlist[] = {"string", "dtype", "count", "sep", NULL}; PyArray_Descr *descr=NULL; - if (!PyArg_ParseTupleAndKeywords(args, keywds, "s#|O&" - NPY_SSIZE_T_PYFMT "s", kwlist, - &data, &s, + if (!PyArg_ParseTupleAndKeywords(args, keywds, "s#|O&" + NPY_SSIZE_T_PYFMT "s", kwlist, + &data, &s, PyArray_DescrConverter, &descr, &nin, &sep)) { return NULL; @@ -5426,9 +5426,9 @@ PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, intp count) elcount = (count < 0) ? 0 : count; elsize = dtype->elsize; - + /* We would need to alter the memory RENEW code to decrement any - reference counts before just throwing away the memory. + reference counts before just throwing away the memory. */ if (dtype->hasobject) { PyErr_SetString(PyExc_ValueError, "cannot create "\ @@ -5441,11 +5441,11 @@ PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, intp count) dtype = NULL; if (ret == NULL) goto done; - for (i = 0; (i < count || count == -1) && + for (i = 0; (i < count || count == -1) && (value = PyIter_Next(iter)); i++) { - + if (i >= elcount) { - /* + /* Grow ret->data: this is similar for the strategy for PyListObject, but we use 50% overallocation => 0, 4, 8, 14, 23, 36, 56, 86 ... @@ -5456,7 +5456,7 @@ PyArray_FromIter(PyObject *obj, PyArray_Descr *dtype, intp count) else new_data = NULL; if (new_data == NULL) { - PyErr_SetString(PyExc_MemoryError, + PyErr_SetString(PyExc_MemoryError, "cannot allocate array memory"); Py_DECREF(value); goto done; @@ -5508,9 +5508,9 @@ array_fromIter(PyObject *ignored, PyObject *args, PyObject *keywds) static char *kwlist[] = {"iter", "dtype", "count", NULL}; PyArray_Descr *descr=NULL; - if (!PyArg_ParseTupleAndKeywords(args, keywds, - "OO&|" NPY_SSIZE_T_PYFMT, - kwlist, + if (!PyArg_ParseTupleAndKeywords(args, keywds, + "OO&|" NPY_SSIZE_T_PYFMT, + kwlist, &iter, PyArray_DescrConverter, &descr, &nin)) { @@ -5523,10 +5523,10 @@ array_fromIter(PyObject *ignored, PyObject *args, PyObject *keywds) -/* This needs an open file object and reads it in directly. +/* This needs an open file object and reads it in directly. memory-mapped files handled differently through buffer interface. -file pointer number in resulting 1d array +file pointer number in resulting 1d array (can easily reshape later, -1 for to end of file) type of array sep is a separator string for character-based data (or NULL for binary) @@ -5566,19 +5566,19 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep) numbytes -= start; if (fseek(fp, start, SEEK_SET) < 0) fail=1; if (fail) { - PyErr_SetString(PyExc_IOError, + PyErr_SetString(PyExc_IOError, "could not seek in file"); Py_DECREF(typecode); return NULL; } num = numbytes / typecode->elsize; } - + if (binary) { /* binary data */ - r = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, + r = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode, - 1, &num, - NULL, NULL, + 1, &num, + NULL, NULL, 0, NULL); if (r==NULL) return NULL; NPY_BEGIN_ALLOW_THREADS @@ -5592,7 +5592,7 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep) scan = typecode->f->scanfunc; if (scan == NULL) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "don't know how to read " \ "character files with that " \ "array type"); @@ -5602,13 +5602,13 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep) if (num != -1) { /* number to read is known */ r = (PyArrayObject *)\ - PyArray_NewFromDescr(&PyArray_Type, - typecode, - 1, &num, - NULL, NULL, + PyArray_NewFromDescr(&PyArray_Type, + typecode, + 1, &num, + NULL, NULL, 0, NULL); if (r==NULL) return NULL; - NPY_BEGIN_ALLOW_THREADS + NPY_BEGIN_ALLOW_THREADS dptr = r->data; for (i=0; i < num; i++) { if (done) break; @@ -5617,13 +5617,13 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep) nread += 1; dptr += r->descr->elsize; } - NPY_END_ALLOW_THREADS + NPY_END_ALLOW_THREADS if (PyErr_Occurred()) { Py_DECREF(r); return NULL; } } - else { /* we have to watch for the end of the file and + else { /* we have to watch for the end of the file and reallocate at the end */ #define _FILEBUFNUM 4096 intp thisbuf=0; @@ -5632,19 +5632,19 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep) intp totalbytes; r = (PyArrayObject *)\ - PyArray_NewFromDescr(&PyArray_Type, + PyArray_NewFromDescr(&PyArray_Type, typecode, - 1, &size, - NULL, NULL, + 1, &size, + NULL, NULL, 0, NULL); if (r==NULL) return NULL; - NPY_BEGIN_ALLOW_THREADS + NPY_BEGIN_ALLOW_THREADS totalbytes = bytes = size * typecode->elsize; dptr = r->data; while (!done) { done = scan(fp, dptr, sep, NULL); - /* end of file reached trying to + /* end of file reached trying to scan value. done is 1 or 2 if end of file reached trying to scan separator. Still good value. @@ -5655,7 +5655,7 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep) dptr += r->descr->elsize; if (!done && thisbuf == size) { totalbytes += bytes; - r->data = PyDataMem_RENEW(r->data, + r->data = PyDataMem_RENEW(r->data, totalbytes); dptr = r->data + (totalbytes - bytes); thisbuf = 0; @@ -5674,7 +5674,7 @@ PyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep) } if (((intp) nread) < num) { - fprintf(stderr, "%ld items requested but only %ld read\n", + fprintf(stderr, "%ld items requested but only %ld read\n", (long) num, (long) nread); r->data = PyDataMem_RENEW(r->data, nread * r->descr->elsize); PyArray_DIM(r,0) = nread; @@ -5691,10 +5691,10 @@ array_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds) Py_ssize_t nin=-1; static char *kwlist[] = {"file", "dtype", "count", "sep", NULL}; PyArray_Descr *type=NULL; - - if (!PyArg_ParseTupleAndKeywords(args, keywds, - "O|O&" NPY_SSIZE_T_PYFMT "s", - kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, keywds, + "O|O&" NPY_SSIZE_T_PYFMT "s", + kwlist, &file, PyArray_DescrConverter, &type, &nin, &sep)) { @@ -5713,7 +5713,7 @@ array_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds) } fp = PyFile_AsFile(file); if (fp == NULL) { - PyErr_SetString(PyExc_IOError, + PyErr_SetString(PyExc_IOError, "first argument must be an open file"); Py_DECREF(file); return NULL; @@ -5725,8 +5725,8 @@ array_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds) /*OBJECT_API*/ static PyObject * -PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, - intp count, intp offset) +PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, + intp count, intp offset) { PyArrayObject *ret; char *data; @@ -5737,17 +5737,17 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, if (type->hasobject) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "cannot create an OBJECT array from memory"\ " buffer"); Py_DECREF(type); return NULL; } if (type->elsize == 0) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "itemsize cannot be zero in type"); Py_DECREF(type); - return NULL; + return NULL; } if (buf->ob_type->tp_as_buffer == NULL || \ @@ -5769,7 +5769,7 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, return NULL; } } - + if ((offset < 0) || (offset >= ts)) { PyErr_Format(PyExc_ValueError, "offset must be positive and smaller than %" @@ -5780,10 +5780,10 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, s = (intp)ts - offset; n = (intp)count; itemsize = type->elsize; - + if (n < 0 ) { if (s % itemsize != 0) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "buffer size must be a multiple"\ " of element size"); Py_DECREF(buf); @@ -5793,7 +5793,7 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, n = s/itemsize; } else { if (s < n*itemsize) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "buffer is smaller than requested"\ " size"); Py_DECREF(buf); @@ -5801,17 +5801,17 @@ PyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, return NULL; } } - - if ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, - type, - 1, &n, - NULL, data, + + if ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, + type, + 1, &n, + NULL, data, DEFAULT, NULL)) == NULL) { Py_DECREF(buf); return NULL; } - + if (!write) ret->flags &= ~WRITEABLE; /* Store a reference for decref on deallocation */ @@ -5829,8 +5829,8 @@ array_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds) PyArray_Descr *type=NULL; if (!PyArg_ParseTupleAndKeywords(args, keywds, "O|O&" - NPY_SSIZE_T_PYFMT - NPY_SSIZE_T_PYFMT, kwlist, + NPY_SSIZE_T_PYFMT + NPY_SSIZE_T_PYFMT, kwlist, &obj, PyArray_DescrConverter, &type, &nin, &offset)) { @@ -5838,17 +5838,17 @@ array_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds) } if (type==NULL) type = PyArray_DescrFromType(PyArray_DEFAULT); - + return PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset); } static PyObject * -array_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) +array_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) { PyObject *a0; int axis=0; static char *kwlist[] = {"seq", "axis", NULL}; - + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|O&", kwlist, &a0, PyArray_AxisConverter, &axis)) @@ -5858,25 +5858,25 @@ array_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) static PyObject *array_innerproduct(PyObject *dummy, PyObject *args) { PyObject *b0, *a0; - + if (!PyArg_ParseTuple(args, "OO", &a0, &b0)) return NULL; - + return _ARET(PyArray_InnerProduct(a0, b0)); } static PyObject *array_matrixproduct(PyObject *dummy, PyObject *args) { PyObject *v, *a; - + if (!PyArg_ParseTuple(args, "OO", &a, &v)) return NULL; - + return _ARET(PyArray_MatrixProduct(a, v)); } static PyObject *array_fastCopyAndTranspose(PyObject *dummy, PyObject *args) { PyObject *a0; - + if (!PyArg_ParseTuple(args, "O", &a0)) return NULL; - + return _ARET(PyArray_CopyAndTranspose(a0)); } @@ -5884,16 +5884,16 @@ static PyObject *array_correlate(PyObject *dummy, PyObject *args, PyObject *kwds PyObject *shape, *a0; int mode=0; static char *kwlist[] = {"a", "v", "mode", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|i", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|i", kwlist, &a0, &shape, &mode)) return NULL; - + return PyArray_Correlate(a0, shape, mode); } /*MULTIARRAY_API - Arange, + Arange, */ static PyObject * PyArray_Arange(double start, double stop, double step, int type_num) @@ -5905,18 +5905,18 @@ PyArray_Arange(double start, double stop, double step, int type_num) int ret; length = (intp ) ceil((stop - start)/step); - + if (length <= 0) { length = 0; return PyArray_New(&PyArray_Type, 1, &length, type_num, NULL, NULL, 0, 0, NULL); } - range = PyArray_New(&PyArray_Type, 1, &length, type_num, + range = PyArray_New(&PyArray_Type, 1, &length, type_num, NULL, NULL, 0, 0, NULL); if (range == NULL) return NULL; - funcs = PyArray_DESCR(range)->f; + funcs = PyArray_DESCR(range)->f; /* place start in the buffer and the next value in the second position */ /* if length > 2, then call the inner loop, otherwise stop */ @@ -5928,7 +5928,7 @@ PyArray_Arange(double start, double stop, double step, int type_num) if (length == 1) return range; obj = PyFloat_FromDouble(start + step); - ret = funcs->setitem(obj, PyArray_BYTES(range)+PyArray_ITEMSIZE(range), + ret = funcs->setitem(obj, PyArray_BYTES(range)+PyArray_ITEMSIZE(range), (PyArrayObject *)range); Py_DECREF(obj); if (ret < 0) goto fail; @@ -5941,7 +5941,7 @@ PyArray_Arange(double start, double stop, double step, int type_num) } funcs->fill(PyArray_DATA(range), length, (PyArrayObject *)range); if (PyErr_Occurred()) goto fail; - + return range; fail: @@ -5949,7 +5949,7 @@ PyArray_Arange(double start, double stop, double step, int type_num) return NULL; } -/* the formula is +/* the formula is len = (intp) ceil((start - stop) / step); */ static intp @@ -5958,7 +5958,7 @@ _calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, i intp len; PyObject *val; double value; - + *next = PyNumber_Subtract(stop, start); if (!(*next)) return -1; val = PyNumber_TrueDivide(*next, step); @@ -5979,7 +5979,7 @@ _calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, i if (error_converting(value)) return -1; len = (intp) ceil(value); } - + if (len > 0) { *next = PyNumber_Add(start, step); if (!next) return -1; @@ -5992,7 +5992,7 @@ _calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, i ArangeObj, */ static PyObject * -PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) +PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) { PyObject *range; PyArray_ArrFuncs *funcs; @@ -6035,7 +6035,7 @@ PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr else Py_INCREF(start); /* calculate the length and next = start + step*/ - length = _calc_length(start, stop, step, &next, + length = _calc_length(start, stop, step, &next, PyTypeNum_ISCOMPLEX(dtype->type_num)); if (PyErr_Occurred()) {Py_DECREF(dtype); goto fail;} @@ -6068,7 +6068,7 @@ PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr if (funcs->setitem(start, PyArray_DATA(range), (PyArrayObject *)range) < 0) goto fail; if (length == 1) goto finish; - if (funcs->setitem(next, PyArray_BYTES(range)+PyArray_ITEMSIZE(range), + if (funcs->setitem(next, PyArray_BYTES(range)+PyArray_ITEMSIZE(range), (PyArrayObject *)range) < 0) goto fail; if (length == 2) goto finish; @@ -6093,7 +6093,7 @@ PyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr Py_DECREF(step); Py_DECREF(next); return range; - + fail: Py_DECREF(start); Py_DECREF(step); @@ -6106,18 +6106,18 @@ array_arange(PyObject *ignored, PyObject *args, PyObject *kws) { PyObject *o_start=NULL, *o_stop=NULL, *o_step=NULL; static char *kwd[]= {"start", "stop", "step", "dtype", NULL}; PyArray_Descr *typecode=NULL; - + if(!PyArg_ParseTupleAndKeywords(args, kws, "O|OOO&", kwd, &o_start, - &o_stop, &o_step, + &o_stop, &o_step, PyArray_DescrConverter2, - &typecode)) + &typecode)) return NULL; return PyArray_ArangeObj(o_start, o_stop, o_step, typecode); } /* -Included at the very first so not auto-grabbed and thus not +Included at the very first so not auto-grabbed and thus not labeled. */ static unsigned int @@ -6127,35 +6127,35 @@ PyArray_GetNDArrayCVersion(void) } static PyObject * -array__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) +array__get_ndarray_c_version(PyObject *dummy, PyObject *args, PyObject *kwds) { static char *kwlist[] = {NULL}; if(!PyArg_ParseTupleAndKeywords(args, kwds, "", kwlist )) return NULL; - + return PyInt_FromLong( (long) PyArray_GetNDArrayCVersion() ); } static PyObject * -array__reconstruct(PyObject *dummy, PyObject *args) +array__reconstruct(PyObject *dummy, PyObject *args) { PyObject *ret; PyTypeObject *subtype; PyArray_Dims shape = {NULL, 0}; PyArray_Descr *dtype=NULL; - if (!PyArg_ParseTuple(args, "O!O&O&", &PyType_Type, &subtype, + if (!PyArg_ParseTuple(args, "O!O&O&", &PyType_Type, &subtype, PyArray_IntpConverter, &shape, - PyArray_DescrConverter, &dtype)) + PyArray_DescrConverter, &dtype)) goto fail; if (!PyType_IsSubtype(subtype, &PyArray_Type)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "_reconstruct: First argument must be " \ "a sub-type of ndarray"); goto fail; } - - ret = PyArray_NewFromDescr(subtype, dtype, + + ret = PyArray_NewFromDescr(subtype, dtype, (int)shape.len, shape.ptr, NULL, NULL, 0, NULL); if (shape.ptr) PyDimMem_FREE(shape.ptr); @@ -6168,16 +6168,16 @@ array__reconstruct(PyObject *dummy, PyObject *args) } static PyObject * -array_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) +array_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) { PyObject *op; int repr=1; static char *kwlist[] = {"f", "repr", NULL}; - if(!PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, - &op, &repr)) return NULL; + if(!PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, + &op, &repr)) return NULL; if (!PyCallable_Check(op)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "Argument must be callable."); return NULL; } @@ -6187,19 +6187,19 @@ array_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) } static PyObject * -array_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) +array_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) { PyObject *oldops=NULL; - + if ((oldops = PyArray_GetNumericOps())==NULL) return NULL; /* 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 + later when use is attempted */ if (kwds && PyArray_SetNumericOps(kwds) == -1) { Py_DECREF(oldops); - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "one or more objects not callable"); return NULL; } @@ -6237,7 +6237,7 @@ PyArray_Where(PyObject *condition, PyObject *x, PyObject *y) zero = PyInt_FromLong((long) 0); - obj = PyArray_EnsureAnyArray(PyArray_GenericBinaryFunction(arr, zero, + obj = PyArray_EnsureAnyArray(PyArray_GenericBinaryFunction(arr, zero, n_ops.not_equal)); Py_DECREF(zero); Py_DECREF(arr); @@ -6257,7 +6257,7 @@ static PyObject * array_where(PyObject *ignored, PyObject *args) { PyObject *obj=NULL, *x=NULL, *y=NULL; - + if (!PyArg_ParseTuple(args, "O|OO", &obj, &x, &y)) return NULL; return PyArray_Where(obj, x, y); @@ -6269,10 +6269,10 @@ array_lexsort(PyObject *ignored, PyObject *args, PyObject *kwds) int axis=-1; PyObject *obj; static char *kwlist[] = {"keys", "axis", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &obj, &axis)) return NULL; - + return _ARET(PyArray_LexSort(obj, axis)); } @@ -6287,17 +6287,17 @@ array_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds) PyObject *retobj; static char *kwlist[] = {"from", "to", NULL}; - if(!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&", kwlist, + if(!PyArg_ParseTupleAndKeywords(args, kwds, "O&O&", kwlist, PyArray_DescrConverter, &d1, PyArray_DescrConverter, &d2)) return NULL; if (d1 == NULL || d2 == NULL) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "did not understand one of the types; " \ "'None' not accepted"); return NULL; } - + ret = PyArray_CanCastTo(d1, d2); retobj = (ret ? Py_True : Py_False); Py_INCREF(retobj); @@ -6311,7 +6311,7 @@ new_buffer(PyObject *dummy, PyObject *args) if(!PyArg_ParseTuple(args, "i", &size)) return NULL; - + return PyBuffer_New(size); } @@ -6322,16 +6322,16 @@ buffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds) Py_ssize_t offset=0, size=Py_END_OF_BUFFER, n; void *unused; static char *kwlist[] = {"object", "offset", "size", NULL}; - + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|" NPY_SSIZE_T_PYFMT \ - NPY_SSIZE_T_PYFMT, kwlist, + NPY_SSIZE_T_PYFMT, kwlist, &obj, &offset, &size)) return NULL; if (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) { PyErr_Clear(); - return PyBuffer_FromObject(obj, offset, size); + return PyBuffer_FromObject(obj, offset, size); } else return PyBuffer_FromReadWriteObject(obj, offset, size); @@ -6379,7 +6379,7 @@ compare_chararrays(PyObject *dummy, PyObject *args, PyObject *kwds) static char *kwlist[] = {"a1", "a2", "cmp", "rstrip", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOs#O&", kwlist, - &array, &other, + &array, &other, &cmp_str, &strlen, PyArray_BoolConverter, &rstrip)) return NULL; @@ -6398,20 +6398,20 @@ compare_chararrays(PyObject *dummy, PyObject *args, PyObject *kwds) else if (cmp_str[0] == '>') cmp_op = Py_GT; else goto err; } - + newarr = (PyArrayObject *)PyArray_FROM_O(array); if (newarr == NULL) return NULL; newoth = (PyArrayObject *)PyArray_FROM_O(other); if (newoth == NULL) { Py_DECREF(newarr); return NULL; - } - + } + if (PyArray_ISSTRING(newarr) && PyArray_ISSTRING(newoth)) { res = _strings_richcompare(newarr, newoth, cmp_op, rstrip != 0); } else { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "comparison of non-string arrays"); } @@ -6428,24 +6428,24 @@ compare_chararrays(PyObject *dummy, PyObject *args, PyObject *kwds) static struct PyMethodDef array_module_methods[] = { - {"_get_ndarray_c_version", (PyCFunction)array__get_ndarray_c_version, + {"_get_ndarray_c_version", (PyCFunction)array__get_ndarray_c_version, METH_VARARGS|METH_KEYWORDS, NULL}, {"_reconstruct", (PyCFunction)array__reconstruct, METH_VARARGS, NULL}, - {"set_string_function", (PyCFunction)array_set_string_function, + {"set_string_function", (PyCFunction)array_set_string_function, METH_VARARGS|METH_KEYWORDS, NULL}, {"set_numeric_ops", (PyCFunction)array_set_ops_function, METH_VARARGS|METH_KEYWORDS, NULL}, {"set_typeDict", (PyCFunction)array_set_typeDict, METH_VARARGS, NULL}, - {"array", (PyCFunction)_array_fromobject, + {"array", (PyCFunction)_array_fromobject, METH_VARARGS|METH_KEYWORDS, NULL}, - {"arange", (PyCFunction)array_arange, + {"arange", (PyCFunction)array_arange, METH_VARARGS|METH_KEYWORDS, NULL}, - {"zeros", (PyCFunction)array_zeros, + {"zeros", (PyCFunction)array_zeros, METH_VARARGS|METH_KEYWORDS, NULL}, - {"empty", (PyCFunction)array_empty, + {"empty", (PyCFunction)array_empty, METH_VARARGS|METH_KEYWORDS, NULL}, {"scalar", (PyCFunction)array_scalar, METH_VARARGS|METH_KEYWORDS, NULL}, @@ -6457,15 +6457,15 @@ static struct PyMethodDef array_module_methods[] = { METH_VARARGS|METH_KEYWORDS, NULL}, {"fromiter",(PyCFunction)array_fromIter, METH_VARARGS|METH_KEYWORDS, NULL}, - {"concatenate", (PyCFunction)array_concatenate, + {"concatenate", (PyCFunction)array_concatenate, METH_VARARGS|METH_KEYWORDS, NULL}, - {"inner", (PyCFunction)array_innerproduct, + {"inner", (PyCFunction)array_innerproduct, METH_VARARGS, NULL}, - {"dot", (PyCFunction)array_matrixproduct, + {"dot", (PyCFunction)array_matrixproduct, METH_VARARGS, NULL}, - {"_fastCopyAndTranspose", (PyCFunction)array_fastCopyAndTranspose, + {"_fastCopyAndTranspose", (PyCFunction)array_fastCopyAndTranspose, METH_VARARGS, NULL}, - {"correlate", (PyCFunction)array_correlate, + {"correlate", (PyCFunction)array_correlate, METH_VARARGS | METH_KEYWORDS, NULL}, {"frombuffer", (PyCFunction)array_frombuffer, METH_VARARGS | METH_KEYWORDS, NULL}, @@ -6490,11 +6490,11 @@ static struct PyMethodDef array_module_methods[] = { /* 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 + 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. -*/ +*/ static int setup_scalartypes(PyObject *dict) { @@ -6517,7 +6517,7 @@ setup_scalartypes(PyObject *dict) #child); \ return -1; \ } - + if (PyType_Ready(&PyGenericArrType_Type) < 0) return -1; @@ -6530,7 +6530,7 @@ setup_scalartypes(PyObject *dict) SINGLE_INHERIT(ComplexFloating, Inexact); SINGLE_INHERIT(Flexible, Generic); SINGLE_INHERIT(Character, Flexible); - + #define DUAL_INHERIT(child, parent1, parent2) \ Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type; \ Py##child##ArrType_Type.tp_bases = \ @@ -6596,9 +6596,9 @@ setup_scalartypes(PyObject *dict) DUAL_INHERIT2(String, String, Character); DUAL_INHERIT2(Unicode, Unicode, Character); - + SINGLE_INHERIT(Void, Flexible); - + SINGLE_INHERIT(Object, Generic); return 0; @@ -6618,7 +6618,7 @@ set_flaginfo(PyObject *d) { PyObject *s; PyObject *newd; - + newd = PyDict_New(); PyDict_SetItemString(newd, "OWNDATA", s=PyInt_FromLong(OWNDATA)); @@ -6634,7 +6634,7 @@ set_flaginfo(PyObject *d) Py_DECREF(s); PyDict_SetItemString(newd, "WRITEABLE", s=PyInt_FromLong(WRITEABLE)); Py_DECREF(s); - + PyDict_SetItemString(d, "_flagdict", newd); Py_DECREF(newd); return; @@ -6655,7 +6655,7 @@ PyMODINIT_FUNC initmultiarray(void) { /* Add some symbolic constants to the module */ d = PyModule_GetDict(m); - if (!d) goto err; + if (!d) goto err; if (PyType_Ready(&PyArray_Type) < 0) return; @@ -6665,10 +6665,10 @@ PyMODINIT_FUNC initmultiarray(void) { PyArrayIter_Type.tp_iter = PyObject_SelfIter; PyArrayMultiIter_Type.tp_iter = PyObject_SelfIter; if (PyType_Ready(&PyArrayIter_Type) < 0) - return; - + return; + if (PyType_Ready(&PyArrayMapIter_Type) < 0) - return; + return; if (PyType_Ready(&PyArrayMultiIter_Type) < 0) return; @@ -6687,7 +6687,7 @@ PyMODINIT_FUNC initmultiarray(void) { MultiArrayError = PyString_FromString ("multiarray.error"); PyDict_SetItemString (d, "error", MultiArrayError); - + s = PyString_FromString("3.0"); PyDict_SetItemString(d, "__version__", s); Py_DECREF(s); @@ -6720,7 +6720,7 @@ PyMODINIT_FUNC initmultiarray(void) { Py_INCREF(&PyArrayIter_Type); PyDict_SetItemString(d, "flatiter", (PyObject *)&PyArrayIter_Type); Py_INCREF(&PyArrayMultiIter_Type); - PyDict_SetItemString(d, "broadcast", + PyDict_SetItemString(d, "broadcast", (PyObject *)&PyArrayMultiIter_Type); Py_INCREF(&PyArrayDescr_Type); PyDict_SetItemString(d, "dtype", (PyObject *)&PyArrayDescr_Type); @@ -6736,11 +6736,10 @@ PyMODINIT_FUNC initmultiarray(void) { PyImport_ImportModule("numpy.core._internal"); if (_numpy_internal != NULL) return; - err: + err: if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_RuntimeError, + PyErr_SetString(PyExc_RuntimeError, "cannot load multiarray module."); } return; } - diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src index be35878ca..1f2591d01 100644 --- a/numpy/core/src/scalarmathmodule.c.src +++ b/numpy/core/src/scalarmathmodule.c.src @@ -1,9 +1,9 @@ /* -*- c -*- */ /* The purpose of this module is to add faster math for array scalars - that does not go through the ufunc machinery + that does not go through the ufunc machinery - but still supports error-modes. + but still supports error-modes. */ #include "Python.h" @@ -105,7 +105,7 @@ static int slonglong_overflow(longlong a0, longlong b0) BINARY: -add, subtract, multiply, divide, remainder, divmod, power, +add, subtract, multiply, divide, remainder, divmod, power, floor_divide, true_divide lshift, rshift, and, or, xor (integers only) @@ -173,7 +173,7 @@ static void #if @neg@ if (temp > MAX_@NAME@ || temp < MIN_@NAME@) #else - if (temp > MAX_@NAME@) + if (temp > MAX_@NAME@) #endif generate_overflow_error(); return; @@ -336,14 +336,14 @@ static @name@ (*_basic_@name@_fmod)(@name@, @name@); /**begin repeat #name=float,double,longdouble# **/ -static void -@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { +static void +@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { @name@ mod; mod = _basic_@name@_fmod(a, b); if (mod && (((b < 0) != (mod < 0)))) mod += b; *out = mod; -} -/**end repeat**/ +} +/**end repeat**/ @@ -402,8 +402,8 @@ static void } /**end repeat**/ -/* Get the nc_powf, nc_pow, and nc_powl functions from - the data area of the power ufunc in umathmodule. +/* Get the nc_powf, nc_pow, and nc_powl functions from + the data area of the power ufunc in umathmodule. */ /**begin repeat @@ -465,7 +465,7 @@ static void 1) Convert the types to the common type if both are scalars (0 return) 2) If both are not scalars use ufunc machinery (-2 return) -3) If both are scalars but cannot be cast to the right type +3) If both are scalars but cannot be cast to the right type return NotImplmented (-1 return) 4) Perform the function on the C-type. @@ -474,18 +474,18 @@ what the current error-handling is and handle the error. 6) Construct and return the output scalar. */ - + /**begin repeat #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble# #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble# #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE# -**/ +**/ static int _@name@_convert_to_ctype(PyObject *a, @name@ *arg1) { - PyObject *temp; + PyObject *temp; if (PyArray_IsScalar(a, @Name@)) { *arg1 = PyArrayScalar_VAL(a, @Name@); @@ -511,10 +511,10 @@ _@name@_convert_to_ctype(PyObject *a, @name@ *arg1) return retval; } return -2; -} +} static int -_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, +_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, PyObject *b, @name@ *arg2) { int ret; @@ -550,7 +550,7 @@ static PyObject * #if @fperr@ int retstatus; -#endif +#endif switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) { case 0: @@ -581,8 +581,8 @@ static PyObject * if (retstatus) { int bufsize, errmask; PyObject *errobj; - if (PyUFunc_GetPyValues("@name@_scalars", &bufsize, &errmask, - &errobj) < 0) + if (PyUFunc_GetPyValues("@name@_scalars", &bufsize, &errmask, + &errobj) < 0) return NULL; if (PyUFunc_handlefperr(errmask, errobj, retstatus)) return NULL; @@ -634,11 +634,11 @@ static PyObject * @name@ out = 0; @otyp@ out1=0; #endif - + switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) { case 0: break; - case -1: /* can't cast both safely + case -1: /* can't cast both safely mixed-types? */ return PyArray_Type.tp_as_number->nb_power(a,b,NULL); case -2: /* use default handling */ @@ -658,7 +658,7 @@ static PyObject * #else if (arg2 == 0) { out1 = out = 1; - } + } #endif #if @isint@ else if (arg2 < 0) { @@ -675,8 +675,8 @@ static PyObject * if (retstatus) { int bufsize, errmask; PyObject *errobj; - if (PyUFunc_GetPyValues("@name@_scalars", &bufsize, &errmask, - &errobj) < 0) + if (PyUFunc_GetPyValues("@name@_scalars", &bufsize, &errmask, + &errobj) < 0) return NULL; if (PyUFunc_handlefperr(errmask, errobj, retstatus)) return NULL; @@ -698,7 +698,7 @@ static PyObject * if (ret==NULL) return NULL; PyArrayScalar_ASSIGN(ret, @Name@, out); #endif - + return ret; } /**end repeat**/ @@ -731,7 +731,7 @@ static PyObject * @name@ arg1; @otyp@ out; PyObject *ret; - + switch(_@name@_convert_to_ctype(a, &arg1)) { case 0: break; @@ -770,21 +770,21 @@ static int { int ret; @name@ arg1; - + if (_@name@_convert_to_ctype(a, &arg1) < 0) { if (PyErr_Occurred()) return -1; return PyGenericArrType_Type.tp_as_number->nb_nonzero(a); } - + /* here we do the actual calculation with arg1 and arg2 */ /* make it a function call. */ #if @simp@ ret = (arg1 != 0); -#else +#else ret = ((arg1.real != 0) || (arg1.imag != 0)); #endif - + return ret; } /**end repeat**/ @@ -838,7 +838,7 @@ static PyObject* { @name@ arg1, arg2; int out=0; - + switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) { case 0: break; @@ -869,7 +869,7 @@ static PyObject* out = @simp@_cmp_gt(arg1, arg2); break; } - + if (out) { PyArrayScalar_RETURN_TRUE; } @@ -963,17 +963,17 @@ get_functions(void) char *signatures; int i, j; int ret = -1; - + /* Get the nc_pow functions */ /* Get the pow functions */ mm = PyImport_ImportModule("numpy.core.umath"); if (mm == NULL) return -1; - + obj = PyObject_GetAttrString(mm, "power"); if (obj == NULL) goto fail; funcdata = ((PyUFuncObject *)obj)->data; signatures = ((PyUFuncObject *)obj)->types; - + i = 0; j = 0; while(signatures[i] != PyArray_FLOAT) {i+=3; j++;} @@ -1058,9 +1058,9 @@ alter_pyscalars(PyObject *dummy, PyObject *args) PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare; PyComplex_Type.tp_richcompare = \ PyCDoubleArrType_Type.tp_richcompare; - } + } else { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "arguments must be int, float, or complex"); return NULL; } @@ -1092,9 +1092,9 @@ restore_pyscalars(PyObject *dummy, PyObject *args) PyComplex_Type.tp_as_number = saved_tables[6]; PyComplex_Type.tp_compare = saved_tables[7]; PyComplex_Type.tp_richcompare = saved_tables[8]; - } + } else { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "arguments must be int, float, or complex"); return NULL; } @@ -1126,9 +1126,9 @@ use_pythonmath(PyObject *dummy, PyObject *args) PyCDoubleArrType_Type.tp_as_number = saved_tables[6]; PyCDoubleArrType_Type.tp_compare = saved_tables[7]; PyCDoubleArrType_Type.tp_richcompare = saved_tables[8]; - } + } else { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "arguments must be int, float, or complex"); return NULL; } @@ -1160,9 +1160,9 @@ use_scalarmath(PyObject *dummy, PyObject *args) PyCDoubleArrType_Type.tp_as_number = saved_tables_arrtype[6]; PyCDoubleArrType_Type.tp_compare = saved_tables_arrtype[7]; PyCDoubleArrType_Type.tp_richcompare = saved_tables_arrtype[8]; - } + } else { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "arguments must be int, float, or complex"); return NULL; } @@ -1187,9 +1187,9 @@ PyMODINIT_FUNC initscalarmath(void) { PyObject *m; m = Py_InitModule("scalarmath", methods); - - import_array(); - import_umath(); + + import_array(); + import_umath(); if (get_functions() < 0) return; diff --git a/numpy/core/src/scalartypes.inc.src b/numpy/core/src/scalartypes.inc.src index e839c65bb..67b6338be 100644 --- a/numpy/core/src/scalartypes.inc.src +++ b/numpy/core/src/scalartypes.inc.src @@ -868,7 +868,7 @@ gentype_real_get(PyObject *self) if (PyArray_IsScalar(self, ComplexFloating)) { typecode = _realdescr_fromcomplexscalar(self, &typenum); - ret = PyArray_Scalar(scalar_value(self, NULL), + ret = PyArray_Scalar(scalar_value(self, NULL), typecode, NULL); Py_DECREF(typecode); return ret; @@ -1782,7 +1782,7 @@ bool_arrtype_nonzero(PyObject *a) /**begin repeat #name=byte, short, int, long, ubyte, ushort, longlong, uint, ulong, ulonglong# #Name=Byte, Short, Int, Long, UByte, UShort, LongLong, UInt, ULong, ULongLong# -#type=PyInt_FromLong*6, PyLong_FromLongLong*1, PyLong_FromUnsignedLong*2, PyLong_FromUnsignedLongLong# +#type=PyInt_FromLong*6, PyLong_FromLongLong*1, PyLong_FromUnsignedLong*2, PyLong_FromUnsignedLongLong# */ static PyNumberMethods @name@_arrtype_as_number; static PyObject * diff --git a/numpy/core/src/ucsnarrow.c b/numpy/core/src/ucsnarrow.c index 990d678c6..6eceadd0e 100644 --- a/numpy/core/src/ucsnarrow.c +++ b/numpy/core/src/ucsnarrow.c @@ -1,16 +1,16 @@ -/* Functions only needed on narrow builds of Python - for converting back and forth between the NumPy Unicode data-type +/* Functions only needed on narrow builds of Python + for converting back and forth between the NumPy Unicode data-type (always 4-byte) - and the Python Unicode scalar (2-bytes on a narrow build). + and the Python Unicode scalar (2-bytes on a narrow build). */ /* the ucs2 buffer must be large enough to hold 2*ucs4length characters - due to the use of surrogate pairs. + due to the use of surrogate pairs. The return value is the number of ucs2 bytes used-up which - is ucs4length + number of surrogate pairs found. + is ucs4length + number of surrogate pairs found. - values above 0xffff are converted to surrogate pairs. + values above 0xffff are converted to surrogate pairs. */ static int PyUCS2Buffer_FromUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs4length) @@ -41,7 +41,7 @@ PyUCS2Buffer_FromUCS4(Py_UNICODE *ucs2, PyArray_UCS4 *ucs4, int ucs4length) It returns the number of characters converted which can be less than ucslen if there are surrogate pairs in ucs2. - The return value is the actual size of the used part of the ucs4 buffer. + The return value is the actual size of the used part of the ucs4 buffer. */ static int @@ -92,9 +92,9 @@ MyPyUnicode_New(int length) static int MyPyUnicode_Resize(PyUnicodeObject *uni, int length) -{ +{ void *oldstr; - + oldstr = uni->str; PyMem_RESIZE(uni->str, Py_UNICODE, length+1); if (!uni->str) { diff --git a/numpy/core/src/ufuncobject.c b/numpy/core/src/ufuncobject.c index 8cdba7718..917a4c739 100644 --- a/numpy/core/src/ufuncobject.c +++ b/numpy/core/src/ufuncobject.c @@ -1,17 +1,17 @@ /* - Python Universal Functions Object -- Math for all types, plus fast + Python Universal Functions Object -- Math for all types, plus fast arrays math - + Full description - + This supports mathematical (and Boolean) functions on arrays and other python objects. Math on large arrays of basic C types is rather efficient. Travis E. Oliphant (2005-2006), oliphant@ee.byu.edu (oliphant.travis@ieee.org) - based on the + based on the - Original Implementation: + Original Implementation: Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu with inspiration and code from @@ -20,7 +20,7 @@ J. Todd Miller Perry Greenfield Rick White - + */ @@ -43,7 +43,7 @@ PyUFunc_ff_f_As_dd_d(char **args, intp *dimensions, intp *steps, void *func) register intp i, n=dimensions[0]; register intp is1=steps[0],is2=steps[1],os=steps[2]; char *ip1=args[0], *ip2=args[1], *op=args[2]; - + for(i=0; i<n; i++, ip1+=is1, ip2+=is2, op+=os) { *(float *)op = (float)((DoubleBinaryFunc *)func) \ ((double)*(float *)ip1, (double)*(float *)ip2); @@ -51,29 +51,29 @@ PyUFunc_ff_f_As_dd_d(char **args, intp *dimensions, intp *steps, void *func) } /*UFUNC_API*/ -static void -PyUFunc_ff_f(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_ff_f(char **args, intp *dimensions, intp *steps, void *func) { register intp i, n=dimensions[0]; register intp is1=steps[0],is2=steps[1],os=steps[2]; char *ip1=args[0], *ip2=args[1], *op=args[2]; - - + + for(i=0; i<n; i++, ip1+=is1, ip2+=is2, op+=os) { - *(float *)op = ((FloatBinaryFunc *)func)(*(float *)ip1, + *(float *)op = ((FloatBinaryFunc *)func)(*(float *)ip1, *(float *)ip2); } -} +} /*UFUNC_API*/ -static void -PyUFunc_dd_d(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_dd_d(char **args, intp *dimensions, intp *steps, void *func) { register intp i, n=dimensions[0]; register intp is1=steps[0],is2=steps[1],os=steps[2]; char *ip1=args[0], *ip2=args[1], *op=args[2]; - + for(i=0; i<n; i++, ip1+=is1, ip2+=is2, op+=os) { *(double *)op = ((DoubleBinaryFunc *)func)\ (*(double *)ip1, *(double *)ip2); @@ -81,29 +81,29 @@ PyUFunc_dd_d(char **args, intp *dimensions, intp *steps, void *func) } /*UFUNC_API*/ -static void -PyUFunc_gg_g(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_gg_g(char **args, intp *dimensions, intp *steps, void *func) { register intp i, n=dimensions[0]; register intp is1=steps[0],is2=steps[1],os=steps[2]; char *ip1=args[0], *ip2=args[1], *op=args[2]; - + for(i=0; i<n; i++, ip1+=is1, ip2+=is2, op+=os) { *(longdouble *)op = \ - ((LongdoubleBinaryFunc *)func)(*(longdouble *)ip1, + ((LongdoubleBinaryFunc *)func)(*(longdouble *)ip1, *(longdouble *)ip2); } } /*UFUNC_API*/ -static void -PyUFunc_FF_F_As_DD_D(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_FF_F_As_DD_D(char **args, intp *dimensions, intp *steps, void *func) { register intp i,n=dimensions[0],is1=steps[0],is2=steps[1],os=steps[2]; char *ip1=args[0], *ip2=args[1], *op=args[2]; cdouble x, y, r; - + for(i=0; i<n; i++, ip1+=is1, ip2+=is2, op+=os) { x.real = ((float *)ip1)[0]; x.imag = ((float *)ip1)[1]; y.real = ((float *)ip2)[0]; y.imag = ((float *)ip2)[1]; @@ -114,13 +114,13 @@ PyUFunc_FF_F_As_DD_D(char **args, intp *dimensions, intp *steps, void *func) } /*UFUNC_API*/ -static void +static void PyUFunc_DD_D(char **args, intp *dimensions, intp *steps, void *func) { register intp i, is1=steps[0],is2=steps[1],os=steps[2],n=dimensions[0]; char *ip1=args[0], *ip2=args[1], *op=args[2]; cdouble x,y,r; - + for(i=0; i<n; i++, ip1+=is1, ip2+=is2, op+=os) { x.real = ((double *)ip1)[0]; x.imag = ((double *)ip1)[1]; y.real = ((double *)ip2)[0]; y.imag = ((double *)ip2)[1]; @@ -131,13 +131,13 @@ PyUFunc_DD_D(char **args, intp *dimensions, intp *steps, void *func) } /*UFUNC_API*/ -static void -PyUFunc_FF_F(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_FF_F(char **args, intp *dimensions, intp *steps, void *func) { register intp i, is1=steps[0],is2=steps[1],os=steps[2],n=dimensions[0]; char *ip1=args[0], *ip2=args[1], *op=args[2]; cfloat x,y,r; - + for(i=0; i<n; i++, ip1+=is1, ip2+=is2, op+=os) { x.real = ((float *)ip1)[0]; x.imag = ((float *)ip1)[1]; y.real = ((float *)ip2)[0]; y.imag = ((float *)ip2)[1]; @@ -148,17 +148,17 @@ PyUFunc_FF_F(char **args, intp *dimensions, intp *steps, void *func) } /*UFUNC_API*/ -static void -PyUFunc_GG_G(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_GG_G(char **args, intp *dimensions, intp *steps, void *func) { register intp i, is1=steps[0],is2=steps[1],os=steps[2],n=dimensions[0]; char *ip1=args[0], *ip2=args[1], *op=args[2]; clongdouble x,y,r; - + for(i=0; i<n; i++, ip1+=is1, ip2+=is2, op+=os) { - x.real = ((longdouble *)ip1)[0]; + x.real = ((longdouble *)ip1)[0]; x.imag = ((longdouble *)ip1)[1]; - y.real = ((longdouble *)ip2)[0]; + y.real = ((longdouble *)ip2)[0]; y.imag = ((longdouble *)ip2)[1]; ((ClongdoubleBinaryFunc *)func)(&x, &y, &r); ((longdouble *)op)[0] = r.real; @@ -167,15 +167,15 @@ PyUFunc_GG_G(char **args, intp *dimensions, intp *steps, void *func) } /*UFUNC_API*/ -static void -PyUFunc_OO_O(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_OO_O(char **args, intp *dimensions, intp *steps, void *func) { register intp i, is1=steps[0],is2=steps[1],os=steps[2], \ n=dimensions[0]; char *ip1=args[0], *ip2=args[1], *op=args[2]; PyObject *tmp; PyObject *x1, *x2; - + for(i=0; i<n; i++, ip1+=is1, ip2+=is2, op+=os) { x1 = *((PyObject **)ip1); x2 = *((PyObject **)ip2); @@ -234,8 +234,8 @@ typedef void CfloatUnaryFunc(cfloat *x, cfloat *res); typedef void ClongdoubleUnaryFunc(clongdouble *x, clongdouble *res); /*UFUNC_API*/ -static void -PyUFunc_f_f_As_d_d(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_f_f_As_d_d(char **args, intp *dimensions, intp *steps, void *func) { register intp i, n=dimensions[0]; char *ip1=args[0], *op=args[1]; @@ -245,8 +245,8 @@ PyUFunc_f_f_As_d_d(char **args, intp *dimensions, intp *steps, void *func) } /*UFUNC_API*/ -static void -PyUFunc_d_d(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_d_d(char **args, intp *dimensions, intp *steps, void *func) { intp i; char *ip1=args[0], *op=args[1]; @@ -256,8 +256,8 @@ PyUFunc_d_d(char **args, intp *dimensions, intp *steps, void *func) } /*UFUNC_API*/ -static void -PyUFunc_f_f(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_f_f(char **args, intp *dimensions, intp *steps, void *func) { register intp i; intp n=dimensions[0]; @@ -268,8 +268,8 @@ PyUFunc_f_f(char **args, intp *dimensions, intp *steps, void *func) } /*UFUNC_API*/ -static void -PyUFunc_g_g(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_g_g(char **args, intp *dimensions, intp *steps, void *func) { register intp i; intp n=dimensions[0]; @@ -282,8 +282,8 @@ PyUFunc_g_g(char **args, intp *dimensions, intp *steps, void *func) /*UFUNC_API*/ -static void -PyUFunc_F_F_As_D_D(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_F_F_As_D_D(char **args, intp *dimensions, intp *steps, void *func) { register intp i; cdouble x, res; intp n=dimensions[0]; @@ -297,13 +297,13 @@ PyUFunc_F_F_As_D_D(char **args, intp *dimensions, intp *steps, void *func) } /*UFUNC_API*/ -static void -PyUFunc_F_F(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_F_F(char **args, intp *dimensions, intp *steps, void *func) { intp i; cfloat x, res; char *ip1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, ip1+=steps[0], op+=steps[1]) { - x.real = ((float *)ip1)[0]; + x.real = ((float *)ip1)[0]; x.imag = ((float *)ip1)[1]; ((CfloatUnaryFunc *)func)(&x, &res); ((float *)op)[0] = res.real; @@ -313,13 +313,13 @@ PyUFunc_F_F(char **args, intp *dimensions, intp *steps, void *func) /*UFUNC_API*/ -static void -PyUFunc_D_D(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_D_D(char **args, intp *dimensions, intp *steps, void *func) { intp i; cdouble x, res; char *ip1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, ip1+=steps[0], op+=steps[1]) { - x.real = ((double *)ip1)[0]; + x.real = ((double *)ip1)[0]; x.imag = ((double *)ip1)[1]; ((CdoubleUnaryFunc *)func)(&x, &res); ((double *)op)[0] = res.real; @@ -329,13 +329,13 @@ PyUFunc_D_D(char **args, intp *dimensions, intp *steps, void *func) /*UFUNC_API*/ -static void -PyUFunc_G_G(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_G_G(char **args, intp *dimensions, intp *steps, void *func) { intp i; clongdouble x, res; char *ip1=args[0], *op=args[1]; for(i=0; i<*dimensions; i++, ip1+=steps[0], op+=steps[1]) { - x.real = ((longdouble *)ip1)[0]; + x.real = ((longdouble *)ip1)[0]; x.imag = ((longdouble *)ip1)[1]; ((ClongdoubleUnaryFunc *)func)(&x, &res); ((double *)op)[0] = res.real; @@ -344,8 +344,8 @@ PyUFunc_G_G(char **args, intp *dimensions, intp *steps, void *func) } /*UFUNC_API*/ -static void -PyUFunc_O_O(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_O_O(char **args, intp *dimensions, intp *steps, void *func) { intp i; PyObject *tmp, *x1; char *ip1=args[0], *op=args[1]; @@ -363,8 +363,8 @@ PyUFunc_O_O(char **args, intp *dimensions, intp *steps, void *func) } /*UFUNC_API*/ -static void -PyUFunc_O_O_method(char **args, intp *dimensions, intp *steps, void *func) +static void +PyUFunc_O_O_method(char **args, intp *dimensions, intp *steps, void *func) { intp i; PyObject *tmp, *meth, *arglist, *x1; char *ip1=args[0], *op=args[1]; @@ -407,7 +407,7 @@ PyUFunc_On_Om(char **args, intp *dimensions, intp *steps, void *func) PyUFunc_PyFuncData *data = (PyUFunc_PyFuncData *)func; int nin = data->nin, nout=data->nout; int ntot; - PyObject *tocall = data->callable; + PyObject *tocall = data->callable; char *ptrs[NPY_MAXARGS]; PyObject *arglist, *result; PyObject *in, **op; @@ -423,7 +423,7 @@ PyUFunc_On_Om(char **args, intp *dimensions, intp *steps, void *func) if (in == NULL) {Py_DECREF(arglist); return;} PyTuple_SET_ITEM(arglist, j, in); Py_INCREF(in); - } + } result = PyEval_CallObject(tocall, arglist); Py_DECREF(arglist); if (result == NULL) return; @@ -456,20 +456,20 @@ PyUFunc_On_Om(char **args, intp *dimensions, intp *steps, void *func) /* ---------------------------------------------------------------- */ -/* fpstatus is the ufunc_formatted hardware status +/* fpstatus is the ufunc_formatted hardware status errmask is the handling mask specified by the user. errobj is a Python object with (string, callable object or None) or NULL */ /* - 2. for each of the flags + 2. for each of the flags determine whether to ignore, warn, raise error, or call Python function. If ignore, do nothing If warn, print a warning and continue If raise return an error If call, call a user-defined function with string -*/ +*/ static int _error_handler(int method, PyObject *errobj, char *errtype, int retstatus) @@ -488,7 +488,7 @@ _error_handler(int method, PyObject *errobj, char *errtype, int retstatus) if (PyErr_Warn(PyExc_RuntimeWarning, msg) < 0) goto fail; break; case UFUNC_ERR_RAISE: - PyErr_Format(PyExc_FloatingPointError, + PyErr_Format(PyExc_FloatingPointError, "%s encountered in %s", errtype, name); goto fail; @@ -496,13 +496,13 @@ _error_handler(int method, PyObject *errobj, char *errtype, int retstatus) pyfunc = PyTuple_GET_ITEM(errobj, 1); if (pyfunc == Py_None) { - PyErr_Format(PyExc_NameError, + PyErr_Format(PyExc_NameError, "python callback specified for %s (in " \ - " %s) but no function found.", + " %s) but no function found.", errtype, name); goto fail; } - args = Py_BuildValue("NN", PyString_FromString(errtype), + args = Py_BuildValue("NN", PyString_FromString(errtype), PyInt_FromLong((long) retstatus)); if (args == NULL) goto fail; ret = PyObject_CallObject(pyfunc, args); @@ -515,9 +515,9 @@ _error_handler(int method, PyObject *errobj, char *errtype, int retstatus) DISABLE_C_API return 0; - fail: + fail: DISABLE_C_API - return -1; + return -1; } @@ -548,7 +548,7 @@ PyUFunc_handlefperr(int errmask, PyObject *errobj, int retstatus) HANDLEIT(OVERFLOW, "overflow"); HANDLEIT(UNDERFLOW, "underflow"); HANDLEIT(INVALID, "invalid"); - } + } return 0; } @@ -618,8 +618,8 @@ _lowest_type(char intype) /* Called to determine coercion */ -static int -select_types(PyUFuncObject *self, int *arg_types, +static int +select_types(PyUFuncObject *self, int *arg_types, PyUFuncGenericFunction *function, void **data, PyArray_SCALARKIND *scalars) { @@ -635,18 +635,18 @@ select_types(PyUFuncObject *self, int *arg_types, } } } - + if (userdef > 0) { PyObject *key, *obj; int *this_types=NULL; - + obj = NULL; key = PyInt_FromLong((long) userdef); if (key == NULL) return -1; obj = PyDict_GetItem(self->userloops, key); Py_DECREF(key); if (obj == NULL) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "user-defined type used in ufunc" \ " with no registered loops"); return -1; @@ -669,7 +669,7 @@ select_types(PyUFuncObject *self, int *arg_types, PyCObject_AsVoidPtr(obj); *data = NULL; } - + if (this_types == NULL) { for (i=1; i<self->nargs; i++) { arg_types[i] = userdef; @@ -685,7 +685,7 @@ select_types(PyUFuncObject *self, int *arg_types, } start_type = arg_types[0]; - /* If the first argument is a scalar we need to place + /* If the first argument is a scalar we need to place the start type as the lowest type in the class */ if (scalars[0] != PyArray_NOSCALAR) { @@ -693,12 +693,12 @@ select_types(PyUFuncObject *self, int *arg_types, } i = 0; - while (i<self->ntypes && start_type > self->types[i*self->nargs]) + while (i<self->ntypes && start_type > self->types[i*self->nargs]) i++; for(;i<self->ntypes; i++) { for(j=0; j<self->nin; j++) { - if (!PyArray_CanCoerceScalar(arg_types[j], + if (!PyArray_CanCoerceScalar(arg_types[j], self->types[i*self->nargs+j], scalars[j])) break; @@ -706,17 +706,17 @@ select_types(PyUFuncObject *self, int *arg_types, if (j == self->nin) break; } if(i>=self->ntypes) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "function not supported for these types, "\ "and can't coerce safely to supported types"); return -1; } - for(j=0; j<self->nargs; j++) + for(j=0; j<self->nargs; j++) arg_types[j] = self->types[i*self->nargs+j]; if (self->data) *data = self->data[i]; - else + else *data = NULL; *function = self->functions[i]; @@ -788,19 +788,19 @@ PyUFunc_GetPyValues(char *name, int *bufsize, int *errmask, PyObject **errobj) *errmask); return -1; } - + retval = PyList_GET_ITEM(ref, 2); if (retval != Py_None && !PyCallable_Check(retval)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "callback function must be callable"); return -1; } - *errobj = Py_BuildValue("NO", + *errobj = Py_BuildValue("NO", PyString_FromString(name), retval); if (*errobj == NULL) return -1; - + return 0; } @@ -816,7 +816,7 @@ _create_copies(PyUFuncLoopObject *loop, int *arg_types, PyArrayObject **mps) int i; intp size; PyObject *new; - PyArray_Descr *ntype; + PyArray_Descr *ntype; PyArray_Descr *atype; for (i=0; i<nin; i++) { @@ -837,7 +837,7 @@ _create_copies(PyUFuncLoopObject *loop, int *arg_types, PyArrayObject **mps) if (!(PyArray_ISBEHAVED_RO(mps[i])) || \ PyArray_TYPE(mps[i]) != arg_types[i]) { ntype = PyArray_DescrFromType(arg_types[i]); - new = PyArray_FromAny((PyObject *)mps[i], + new = PyArray_FromAny((PyObject *)mps[i], ntype, 0, 0, FORCECAST | ALIGNED, NULL); if (new == NULL) return -1; @@ -846,7 +846,7 @@ _create_copies(PyUFuncLoopObject *loop, int *arg_types, PyArrayObject **mps) } } } - + return 0; } @@ -891,7 +891,7 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) /* Check number of arguments */ nargs = PyTuple_Size(args); if ((nargs < self->nin) || (nargs > self->nargs)) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "invalid number of arguments"); return -1; } @@ -914,7 +914,7 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) object = 1; } /* - fprintf(stderr, "array %d has reference %d\n", i, + fprintf(stderr, "array %d has reference %d\n", i, (mps[i])->ob_refcnt); */ @@ -940,15 +940,15 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) scalars[i] = PyArray_NOSCALAR; } } - + /* Select an appropriate function for these argument types. */ - if (select_types(loop->ufunc, arg_types, &(loop->function), + if (select_types(loop->ufunc, arg_types, &(loop->function), &(loop->funcdata), scalars) == -1) return -1; - /* FAIL with NotImplemented if the other object has - the __r<op>__ method and has __array_priority__ as - an attribute (signalling it can handle ndarray's) + /* FAIL with NotImplemented if the other object has + the __r<op>__ method and has __array_priority__ as + an attribute (signalling it can handle ndarray's) and is not already an ndarray or bigndarray */ if ((arg_types[1] == PyArray_OBJECT) && \ @@ -961,22 +961,22 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) return nargs; } } - + /* Create copies for some of the arrays if appropriate */ if (_create_copies(loop, arg_types, mps) < 0) return -1; - + /* Create Iterators for the Inputs */ for (i=0; i<self->nin; i++) { loop->iters[i] = (PyArrayIterObject *) \ PyArray_IterNew((PyObject *)mps[i]); if (loop->iters[i] == NULL) return -1; } - + /* Broadcast the result */ loop->numiter = self->nin; if (PyArray_Broadcast((PyArrayMultiIterObject *)loop) < 0) return -1; - + /* Get any return arguments */ for (i=self->nin; i<nargs; i++) { mps[i] = (PyArrayObject *)PyTuple_GET_ITEM(args, i); @@ -994,7 +994,7 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) mps[i] = (PyArrayObject *)new; } else { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "return arrays must be "\ "of ArrayType"); Py_DECREF(mps[i]); @@ -1003,16 +1003,16 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) } } if (mps[i]->nd != loop->nd || - !PyArray_CompareLists(mps[i]->dimensions, + !PyArray_CompareLists(mps[i]->dimensions, loop->dimensions, loop->nd)) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "invalid return array shape"); Py_DECREF(mps[i]); mps[i] = NULL; return -1; } if (!PyArray_ISWRITEABLE(mps[i])) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "return array is not writeable"); Py_DECREF(mps[i]); mps[i] = NULL; @@ -1021,21 +1021,21 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) } /* construct any missing return arrays and make output iterators */ - + for (i=self->nin; i<self->nargs; i++) { PyArray_Descr *ntype; if (mps[i] == NULL) { mps[i] = (PyArrayObject *)PyArray_New(subtype, - loop->nd, + loop->nd, loop->dimensions, - arg_types[i], + arg_types[i], NULL, NULL, 0, 0, NULL); if (mps[i] == NULL) return -1; } - /* reset types for outputs that are equivalent + /* reset types for outputs that are equivalent -- no sense casting uselessly */ else { @@ -1048,13 +1048,13 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) } Py_DECREF(atype); } - + /* still not the same -- or will we have to use buffers?*/ if (mps[i]->descr->type_num != arg_types[i] || !PyArray_ISBEHAVED_RO(mps[i])) { if (loop->size < loop->bufsize) { PyObject *new; - /* Copy the array to a temporary copy + /* Copy the array to a temporary copy and set the UPDATEIFCOPY flag */ ntype = PyArray_DescrFromType(arg_types[i]); @@ -1068,7 +1068,7 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) } } } - + loop->iters[i] = (PyArrayIterObject *) \ PyArray_IterNew((PyObject *)mps[i]); if (loop->iters[i] == NULL) return -1; @@ -1090,7 +1090,7 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) maxsize = 0; for (i=0; i<self->nargs; i++) { loop->needbuffer[i] = 0; - if (arg_types[i] != mps[i]->descr->type_num || + if (arg_types[i] != mps[i]->descr->type_num || !PyArray_ISBEHAVED_RO(mps[i])) { loop->meth = BUFFER_UFUNCLOOP; loop->needbuffer[i] = 1; @@ -1099,9 +1099,9 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) loop->obj = 1; } } - + if (loop->meth == NO_UFUNCLOOP) { - + loop->meth = ONE_UFUNCLOOP; /* All correct type and BEHAVED */ @@ -1136,7 +1136,7 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) /* Fix iterators */ /* Find the **largest** dimension */ - + maxdim = -1; for (i=loop->nd - 1; i>=0; i--) { if (loop->dimensions[i] > maxdim) { @@ -1149,9 +1149,9 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) loop->bufcnt = maxdim; loop->lastdim = ldim; - /* Fix the iterators so the inner loop occurs over the - largest dimensions -- This can be done by - setting the size to 1 in that dimension + /* Fix the iterators so the inner loop occurs over the + largest dimensions -- This can be done by + setting the size to 1 in that dimension (just in the iterators) */ @@ -1163,16 +1163,16 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) it->backstrides[ldim] = 0; /* (won't fix factors because we - don't use PyArray_ITER_GOTO1D + don't use PyArray_ITER_GOTO1D so don't change them) */ /* Set the steps to the strides in that dimension */ loop->steps[i] = it->strides[ldim]; } - /* fix up steps where we will be copying data to + /* fix up steps where we will be copying data to buffers and calculate the ninnerloops and leftover - values -- if step size is already zero that is not changed... + values -- if step size is already zero that is not changed... */ if (loop->meth == BUFFER_UFUNCLOOP) { loop->leftover = maxdim % loop->bufsize; @@ -1193,10 +1193,10 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) loop->steps[i] = mps[i]->strides[mps[i]->nd-1]; } } - + /* Finally, create memory for buffers if we need them */ - + /* buffers for scalars are specially made small -- scalars are not copied multiple times */ if (loop->meth == BUFFER_UFUNCLOOP) { @@ -1275,7 +1275,7 @@ construct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps) loop->bufptr[i] = loop->buffer[i]; } if (!loop->objfunc && loop->obj) { - if (arg_types[i] == PyArray_OBJECT) { + if (arg_types[i] == PyArray_OBJECT) { loop->objfunc = 1; } } @@ -1303,7 +1303,7 @@ static void ufuncloop_dealloc(PyUFuncLoopObject *self) { int i; - + if (self->ufunc != NULL) { for (i=0; i<self->ufunc->nargs; i++) Py_XDECREF(self->iters[i]); @@ -1319,7 +1319,7 @@ construct_loop(PyUFuncObject *self, PyObject *args, PyArrayObject **mps) { PyUFuncLoopObject *loop; int i; - + if (self == NULL) { PyErr_SetString(PyExc_ValueError, "function not supported"); return NULL; @@ -1327,7 +1327,7 @@ construct_loop(PyUFuncObject *self, PyObject *args, PyArrayObject **mps) if ((loop = _pya_malloc(sizeof(PyUFuncLoopObject)))==NULL) { PyErr_NoMemory(); return loop; } - + loop->index = 0; loop->ufunc = self; Py_INCREF(self); @@ -1340,9 +1340,9 @@ construct_loop(PyUFuncObject *self, PyObject *args, PyArrayObject **mps) loop->notimplemented = 0; if (PyUFunc_GetPyValues((self->name ? self->name : ""), - &(loop->bufsize), &(loop->errormask), + &(loop->bufsize), &(loop->errormask), &(loop->errobj)) < 0) goto fail; - + /* Setup the matrices */ if (construct_matrices(loop, args, mps) < 0) goto fail; @@ -1356,51 +1356,51 @@ construct_loop(PyUFuncObject *self, PyObject *args, PyArrayObject **mps) } -/* +/* static void -_printbytebuf(PyUFuncLoopObject *loop, int bufnum) -{ +_printbytebuf(PyUFuncLoopObject *loop, int bufnum) +{ int i; - + fprintf(stderr, "Printing byte buffer %d\n", bufnum); for (i=0; i<loop->bufcnt; i++) { fprintf(stderr, " %d\n", *(((byte *)(loop->buffer[bufnum]))+i)); - } + } } static void -_printlongbuf(PyUFuncLoopObject *loop, int bufnum) -{ +_printlongbuf(PyUFuncLoopObject *loop, int bufnum) +{ int i; - + fprintf(stderr, "Printing long buffer %d\n", bufnum); for (i=0; i<loop->bufcnt; i++) { fprintf(stderr, " %ld\n", *(((long *)(loop->buffer[bufnum]))+i)); - } + } } static void -_printlongbufptr(PyUFuncLoopObject *loop, int bufnum) -{ +_printlongbufptr(PyUFuncLoopObject *loop, int bufnum) +{ int i; - + fprintf(stderr, "Printing long buffer %d\n", bufnum); for (i=0; i<loop->bufcnt; i++) { fprintf(stderr, " %ld\n", *(((long *)(loop->bufptr[bufnum]))+i)); - } + } } - + static void -_printcastbuf(PyUFuncLoopObject *loop, int bufnum) -{ +_printcastbuf(PyUFuncLoopObject *loop, int bufnum) +{ int i; - + fprintf(stderr, "Printing long buffer %d\n", bufnum); for (i=0; i<loop->bufcnt; i++) { fprintf(stderr, " %ld\n", *(((long *)(loop->castbuf[bufnum]))+i)); - } + } } */ @@ -1410,7 +1410,7 @@ _printcastbuf(PyUFuncLoopObject *loop, int bufnum) /* currently generic ufuncs cannot be built for use on flexible arrays. - The cast functions in the generic loop would need to be fixed to pass + The cast functions in the generic loop would need to be fixed to pass in something besides NULL, NULL. Also the underlying ufunc loops would not know the element-size unless @@ -1419,14 +1419,14 @@ _printcastbuf(PyUFuncLoopObject *loop, int bufnum) */ /* This generic function is called with the ufunc object, the arguments to it, - and an array of (pointers to) PyArrayObjects which are NULL. The + and an array of (pointers to) PyArrayObjects which are NULL. The arguments are parsed and placed in mps in construct_loop (construct_matrices) */ /*UFUNC_API*/ -static int -PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, - PyArrayObject **mps) +static int +PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, + PyArrayObject **mps) { PyUFuncLoopObject *loop; int i; @@ -1442,20 +1442,20 @@ PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, /* Everything is contiguous, notswapped, aligned, and of the right type. -- Fastest. Or if not contiguous, then a single-stride - increment moves through the entire array. + increment moves through the entire array. */ /*fprintf(stderr, "ONE...%d\n", loop->size);*/ - loop->function((char **)loop->bufptr, &(loop->size), + loop->function((char **)loop->bufptr, &(loop->size), loop->steps, loop->funcdata); UFUNC_CHECK_ERROR(loop); break; case NOBUFFER_UFUNCLOOP: - /* Everything is notswapped, aligned and of the + /* Everything is notswapped, aligned and of the right type but not contiguous. -- Almost as fast. */ /*fprintf(stderr, "NOBUFFER...%d\n", loop->size);*/ while (loop->index < loop->size) { - for (i=0; i<self->nargs; i++) + for (i=0; i<self->nargs; i++) loop->bufptr[i] = loop->iters[i]->dataptr; loop->function((char **)loop->bufptr, &(loop->bufcnt), @@ -1492,7 +1492,7 @@ PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, int i, j, k, stopcondition; char *myptr1, *myptr2; - + for (i=0; i<self->nargs; i++) { copyswapn[i] = mps[i]->descr->f->copyswapn; mpselsize[i] = mps[i]->descr->elsize; @@ -1503,25 +1503,25 @@ PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, else fastmemcpy[i] = 1; } /* Do generic buffered looping here (works for any kind of - arrays -- some need buffers, some don't. + arrays -- some need buffers, some don't. */ - + /* New algorithm: N is the largest dimension. B is the buffer-size. quotient is loop->ninnerloops-1 remainder is loop->leftover - Compute N = quotient * B + remainder. - quotient = N / B # integer math + Compute N = quotient * B + remainder. + quotient = N / B # integer math (store quotient + 1) as the number of innerloops remainder = N % B # integer remainder - - On the inner-dimension we will have (quotient + 1) loops where + + On the inner-dimension we will have (quotient + 1) loops where the size of the inner function is B for all but the last when the niter size is - remainder. - - So, the code looks very similar to NOBUFFER_LOOP except the inner-most loop is + remainder. + + So, the code looks very similar to NOBUFFER_LOOP except the inner-most loop is replaced with... - + for(i=0; i<quotient+1; i++) { if (i==quotient+1) make itersize remainder size copy only needed items to buffer. @@ -1530,18 +1530,18 @@ PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, call loop_function() cast outputs in buffers if needed swap outputs in buffers if needed - copy only needed items back to output arrays. + copy only needed items back to output arrays. update all data-pointers by strides*niter - } + } */ - /* fprintf(stderr, "BUFFER...%d,%d,%d\n", loop->size, + /* fprintf(stderr, "BUFFER...%d,%d,%d\n", loop->size, loop->ninnerloops, loop->leftover); */ /* for (i=0; i<self->nargs; i++) { - fprintf(stderr, "iters[%d]->dataptr = %p, %p of size %d\n", i, + fprintf(stderr, "iters[%d]->dataptr = %p, %p of size %d\n", i, iters[i], iters[i]->ao->data, PyArray_NBYTES(iters[i]->ao)); } */ @@ -1572,10 +1572,10 @@ PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, copysizes[i] = datasize[i] * mpselsize[i]; } } - + for (i=0; i<self->nin; i++) { if (!needbuffer[i]) continue; - if (fastmemcpy[i]) + if (fastmemcpy[i]) memcpy(buffer[i], tptr[i], copysizes[i]); else { @@ -1587,7 +1587,7 @@ PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, myptr2 += laststrides[i]; } } - + /* swap the buffer if necessary */ if (swap[i]) { /* fprintf(stderr, "swapping...\n");*/ @@ -1603,10 +1603,10 @@ PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, NULL, NULL); } } - + bufcnt = (intp) bufsize; loop->function((char **)dptr, &bufcnt, steps, loop->funcdata); - + for (i=self->nin; i<self->nargs; i++) { if (!needbuffer[i]) continue; if (loop->cast[i]) { @@ -1617,7 +1617,7 @@ PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, } if (swap[i]) { copyswapn[i](buffer[i], mpselsize[i], NULL, -1, - (intp) datasize[i], 1, + (intp) datasize[i], 1, mps[i]); } /* copy back to output arrays */ @@ -1629,13 +1629,13 @@ PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, myptr1 += laststrides[i]; } } - if (fastmemcpy[i]) + if (fastmemcpy[i]) memcpy(tptr[i], buffer[i], copysizes[i]); else { myptr2 = buffer[i]; myptr1 = tptr[i]; for (j=0; j<bufsize; j++) { - memcpy(myptr1, myptr2, + memcpy(myptr1, myptr2, mpselsize[i]); myptr1 += laststrides[i]; myptr2 += mpselsize[i]; @@ -1664,7 +1664,7 @@ PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, was only one loop */ if (ninnerloops == 1) \ size = loop->leftover; - + for (j=0; j<size; j++) { Py_XDECREF(*objptr); objptr += 1; @@ -1672,11 +1672,11 @@ PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, } } } - + } - + UFUNC_CHECK_ERROR(loop); - + for (i=0; i<self->nargs; i++) { PyArray_ITER_NEXT(loop->iters[i]); } @@ -1684,9 +1684,9 @@ PyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, } } } - + NPY_LOOP_END_THREADS - + ufuncloop_dealloc(loop); return 0; @@ -1702,9 +1702,9 @@ _getidentity(PyUFuncObject *self, int otype, char *str) { PyObject *obj, *arr; PyArray_Descr *typecode; - + if (self->identity == PyUFunc_None) { - PyErr_Format(PyExc_ValueError, + PyErr_Format(PyExc_ValueError, "zero-size array to ufunc.%s " \ "without identity", str); return NULL; @@ -1715,7 +1715,7 @@ _getidentity(PyUFuncObject *self, int otype, char *str) obj = PyInt_FromLong((long) 0); } - typecode = PyArray_DescrFromType(otype); + typecode = PyArray_DescrFromType(otype); arr = PyArray_FromAny(obj, typecode, 0, 0, CARRAY, NULL); Py_DECREF(obj); return (PyArrayObject *)arr; @@ -1727,14 +1727,14 @@ _create_reduce_copy(PyUFuncReduceObject *loop, PyArrayObject **arr, int rtype) intp maxsize; PyObject *new; PyArray_Descr *ntype; - + maxsize = PyArray_SIZE(*arr); - + if (maxsize < loop->bufsize) { if (!(PyArray_ISBEHAVED_RO(*arr)) || \ PyArray_TYPE(*arr) != rtype) { ntype = PyArray_DescrFromType(rtype); - new = PyArray_FromAny((PyObject *)(*arr), + new = PyArray_FromAny((PyObject *)(*arr), ntype, 0, 0, FORCECAST | ALIGNED, NULL); if (new == NULL) return -1; @@ -1745,17 +1745,17 @@ _create_reduce_copy(PyUFuncReduceObject *loop, PyArrayObject **arr, int rtype) /* Don't decref *arr before re-assigning because it was not going to be DECREF'd anyway. - + If a copy is made, then the copy will be removed - on deallocation of the loop structure by setting + on deallocation of the loop structure by setting loop->decref. */ - + return 0; } static PyUFuncReduceObject * -construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, +construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, int axis, int otype, int operation, intp ind_size, char *str) { PyUFuncReduceObject *loop; @@ -1763,14 +1763,14 @@ construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, PyArrayObject *aar; intp loop_i[MAX_DIMS], outsize=0; int arg_types[3] = {otype, otype, otype}; - PyArray_SCALARKIND scalars[3] = {PyArray_NOSCALAR, PyArray_NOSCALAR, + PyArray_SCALARKIND scalars[3] = {PyArray_NOSCALAR, PyArray_NOSCALAR, PyArray_NOSCALAR}; int i, j; int nd = (*arr)->nd; int flags; - /* Reduce type is the type requested of the input + /* Reduce type is the type requested of the input during reduction */ - + if ((loop = _pya_malloc(sizeof(PyUFuncReduceObject)))==NULL) { PyErr_NoMemory(); return loop; } @@ -1786,34 +1786,34 @@ construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, loop->it = NULL; loop->rit = NULL; loop->errobj = NULL; - loop->decref=NULL; + loop->decref=NULL; loop->N = (*arr)->dimensions[axis]; loop->instrides = (*arr)->strides[axis]; - if (select_types(loop->ufunc, arg_types, &(loop->function), - &(loop->funcdata), scalars) == -1) goto fail; - - /* output type may change -- if it does - reduction is forced into that type + if (select_types(loop->ufunc, arg_types, &(loop->function), + &(loop->funcdata), scalars) == -1) goto fail; + + /* output type may change -- if it does + reduction is forced into that type and we need to select the reduction function again */ if (otype != arg_types[2]) { otype = arg_types[2]; arg_types[0] = otype; arg_types[1] = otype; - if (select_types(loop->ufunc, arg_types, &(loop->function), - &(loop->funcdata), scalars) == -1) - goto fail; + if (select_types(loop->ufunc, arg_types, &(loop->function), + &(loop->funcdata), scalars) == -1) + goto fail; } - + /* get looping parameters from Python */ - if (PyUFunc_GetPyValues(str, &(loop->bufsize), &(loop->errormask), + if (PyUFunc_GetPyValues(str, &(loop->bufsize), &(loop->errormask), &(loop->errobj)) < 0) goto fail; - + /* Make copy if misbehaved or not otype for small arrays */ - if (_create_reduce_copy(loop, arr, otype) < 0) goto fail; + if (_create_reduce_copy(loop, arr, otype) < 0) goto fail; aar = *arr; - + if (loop->N == 0) { loop->meth = ZERODIM_REDUCELOOP; } @@ -1843,7 +1843,7 @@ construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, idarr = _getidentity(self, otype, str); if (idarr == NULL) goto fail; if (idarr->descr->elsize > UFUNC_MAXIDENTITY) { - PyErr_Format(PyExc_RuntimeError, + PyErr_Format(PyExc_RuntimeError, "UFUNC_MAXIDENTITY (%d)" \ " is too small (needs to be at least %d)", UFUNC_MAXIDENTITY, idarr->descr->elsize); @@ -1853,20 +1853,20 @@ construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, memcpy(loop->idptr, idarr->data, idarr->descr->elsize); Py_DECREF(idarr); } - + /* Construct return array */ flags = NPY_CARRAY | NPY_UPDATEIFCOPY | NPY_FORCECAST; switch(operation) { case UFUNC_REDUCE: for (j=0, i=0; i<nd; i++) { - if (i != axis) + if (i != axis) loop_i[j++] = (aar)->dimensions[i]; - + } if (out == NULL) { loop->ret = (PyArrayObject *) \ - PyArray_New(aar->ob_type, aar->nd-1, loop_i, - otype, NULL, NULL, 0, 0, + PyArray_New(aar->ob_type, aar->nd-1, loop_i, + otype, NULL, NULL, 0, 0, (PyObject *)aar); } else { @@ -1876,7 +1876,7 @@ construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, case UFUNC_ACCUMULATE: if (out == NULL) { loop->ret = (PyArrayObject *) \ - PyArray_New(aar->ob_type, aar->nd, aar->dimensions, + PyArray_New(aar->ob_type, aar->nd, aar->dimensions, otype, NULL, NULL, 0, 0, (PyObject *)aar); } else { @@ -1886,7 +1886,7 @@ construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, case UFUNC_REDUCEAT: memcpy(loop_i, aar->dimensions, nd*sizeof(intp)); /* Index is 1-d array */ - loop_i[axis] = ind_size; + loop_i[axis] = ind_size; if (out == NULL) { loop->ret = (PyArrayObject *) \ PyArray_New(aar->ob_type, aar->nd, loop_i, otype, @@ -1905,12 +1905,12 @@ construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, } if (out) { if (PyArray_SIZE(out) != outsize) { - PyErr_SetString(PyExc_ValueError, + PyErr_SetString(PyExc_ValueError, "wrong shape for output"); goto fail; } loop->ret = (PyArrayObject *) \ - PyArray_FromArray(out, PyArray_DescrFromType(otype), + PyArray_FromArray(out, PyArray_DescrFromType(otype), flags); if (loop->ret && loop->ret != out) { loop->retbase = 1; @@ -1930,13 +1930,13 @@ construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, if (loop->it == NULL) return NULL; if (loop->meth == ONEDIM_REDUCELOOP) { - loop->size = loop->it->size; + loop->size = loop->it->size; return loop; } /* Fix iterator to loop over correct dimension */ /* Set size in axis dimension to 1 */ - + loop->it->contiguous = 0; loop->it->size /= (loop->it->dims_m1[axis]+1); loop->it->dims_m1[axis] = 0; @@ -1951,11 +1951,11 @@ construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, else { loop->rit = (PyArrayIterObject *) \ PyArray_IterNew((PyObject *)(loop->ret)); - if (loop->rit == NULL) return NULL; + if (loop->rit == NULL) return NULL; /* Fix iterator to loop over correct dimension */ /* Set size in axis dimension to 1 */ - + loop->rit->contiguous = 0; loop->rit->size /= (loop->rit->dims_m1[axis]+1); loop->rit->dims_m1[axis] = 0; @@ -1963,13 +1963,13 @@ construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, if (operation == UFUNC_ACCUMULATE) loop->steps[1] = loop->ret->strides[axis]; - else + else loop->steps[1] = 0; } loop->steps[2] = loop->steps[1]; loop->bufptr[2] = loop->bufptr[1] + loop->steps[2]; - + if (loop->meth == BUFFER_UFUNCLOOP) { int _size; loop->steps[0] = loop->outsize; @@ -2000,7 +2000,7 @@ construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, fail: ufuncreduce_dealloc(loop); - return NULL; + return NULL; } @@ -2013,7 +2013,7 @@ construct_reduce(PyUFuncObject *self, PyArrayObject **arr, PyArrayObject *out, */ static PyObject * -PyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, +PyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, int axis, int otype) { PyArrayObject *ret=NULL; @@ -2021,7 +2021,7 @@ PyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, intp i, n; char *dptr; NPY_BEGIN_THREADS_DEF - + /* Construct loop object */ loop = construct_reduce(self, &arr, out, axis, otype, UFUNC_REDUCE, 0, "reduce"); @@ -2040,26 +2040,26 @@ PyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, case ONEDIM_REDUCELOOP: /*fprintf(stderr, "ONEDIM..%d\n", loop->size); */ while(loop->index < loop->size) { - if (loop->obj) + if (loop->obj) Py_INCREF(*((PyObject **)loop->it->dataptr)); - memmove(loop->bufptr[1], loop->it->dataptr, + memmove(loop->bufptr[1], loop->it->dataptr, loop->outsize); PyArray_ITER_NEXT(loop->it); loop->bufptr[1] += loop->outsize; loop->index++; - } + } break; case NOBUFFER_UFUNCLOOP: /*fprintf(stderr, "NOBUFFER..%d\n", loop->size); */ while(loop->index < loop->size) { /* Copy first element to output */ - if (loop->obj) + if (loop->obj) Py_INCREF(*((PyObject **)loop->it->dataptr)); - memmove(loop->bufptr[1], loop->it->dataptr, + memmove(loop->bufptr[1], loop->it->dataptr, loop->outsize); /* Adjust input pointer */ loop->bufptr[0] = loop->it->dataptr+loop->steps[0]; - loop->function((char **)loop->bufptr, + loop->function((char **)loop->bufptr, &(loop->N), loop->steps, loop->funcdata); UFUNC_CHECK_ERROR(loop); @@ -2067,24 +2067,24 @@ PyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, PyArray_ITER_NEXT(loop->it) loop->bufptr[1] += loop->outsize; loop->bufptr[2] = loop->bufptr[1]; - loop->index++; + loop->index++; } break; - case BUFFER_UFUNCLOOP: + case BUFFER_UFUNCLOOP: /* use buffer for arr */ - /* + /* For each row to reduce 1. copy first item over to output (casting if necessary) - 2. Fill inner buffer + 2. Fill inner buffer 3. When buffer is filled or end of row a. Cast input buffers if needed b. Call inner function. 4. Repeat 2 until row is done. */ - /* fprintf(stderr, "BUFFERED..%d %d\n", loop->size, + /* fprintf(stderr, "BUFFERED..%d %d\n", loop->size, loop->swap); */ while(loop->index < loop->size) { - loop->inptr = loop->it->dataptr; + loop->inptr = loop->it->dataptr; /* Copy (cast) First term over to output */ if (loop->cast) { /* A little tricky because we need to @@ -2095,20 +2095,20 @@ PyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, NULL); loop->cast(loop->buffer, loop->castbuf, 1, NULL, NULL); - if (loop->obj) + if (loop->obj) Py_INCREF(*((PyObject **)loop->castbuf)); memcpy(loop->bufptr[1], loop->castbuf, loop->outsize); } else { /* Simple copy */ - arr->descr->f->copyswap(loop->bufptr[1], + arr->descr->f->copyswap(loop->bufptr[1], loop->inptr, loop->swap, NULL); } loop->inptr += loop->instrides; n = 1; while(n < loop->N) { - /* Copy up to loop->bufsize elements to + /* Copy up to loop->bufsize elements to buffer */ dptr = loop->buffer; for (i=0; i<loop->bufsize; i++, n++) { @@ -2125,15 +2125,15 @@ PyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, loop->castbuf, i, NULL, NULL); loop->function((char **)loop->bufptr, - &i, + &i, loop->steps, loop->funcdata); loop->bufptr[1] += loop->steps[1]*i; loop->bufptr[2] += loop->steps[2]*i; UFUNC_CHECK_ERROR(loop); - } + } PyArray_ITER_NEXT(loop->it); loop->bufptr[1] += loop->outsize; - loop->bufptr[2] = loop->bufptr[1]; + loop->bufptr[2] = loop->bufptr[1]; loop->index++; } } @@ -2156,7 +2156,7 @@ PyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, static PyObject * -PyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, +PyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, int axis, int otype) { PyArrayObject *ret=NULL; @@ -2164,7 +2164,7 @@ PyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, intp i, n; char *dptr; NPY_BEGIN_THREADS_DEF - + /* Construct loop object */ loop = construct_reduce(self, &arr, out, axis, otype, UFUNC_ACCUMULATE, 0, "accumulate"); @@ -2175,35 +2175,35 @@ PyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, case ZERODIM_REDUCELOOP: /* Accumulate */ /* fprintf(stderr, "ZERO..%d\n", loop->size); */ for(i=0; i<loop->size; i++) { - if (loop->obj) + if (loop->obj) Py_INCREF(*((PyObject **)loop->idptr)); memcpy(loop->bufptr[1], loop->idptr, loop->outsize); loop->bufptr[1] += loop->outsize; - } + } break; case ONEDIM_REDUCELOOP: /* Accumulate */ /* fprintf(stderr, "ONEDIM..%d\n", loop->size); */ while(loop->index < loop->size) { - if (loop->obj) + if (loop->obj) Py_INCREF(*((PyObject **)loop->it->dataptr)); - memcpy(loop->bufptr[1], loop->it->dataptr, + memcpy(loop->bufptr[1], loop->it->dataptr, loop->outsize); PyArray_ITER_NEXT(loop->it); loop->bufptr[1] += loop->outsize; loop->index++; - } + } break; case NOBUFFER_UFUNCLOOP: /* Accumulate */ /* fprintf(stderr, "NOBUFFER..%d\n", loop->size); */ while(loop->index < loop->size) { /* Copy first element to output */ - if (loop->obj) + if (loop->obj) Py_INCREF(*((PyObject **)loop->it->dataptr)); - memcpy(loop->bufptr[1], loop->it->dataptr, + memcpy(loop->bufptr[1], loop->it->dataptr, loop->outsize); /* Adjust input pointer */ loop->bufptr[0] = loop->it->dataptr+loop->steps[0]; - loop->function((char **)loop->bufptr, + loop->function((char **)loop->bufptr, &(loop->N), loop->steps, loop->funcdata); UFUNC_CHECK_ERROR(loop); @@ -2217,19 +2217,19 @@ PyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, break; case BUFFER_UFUNCLOOP: /* Accumulate */ /* use buffer for arr */ - /* + /* For each row to reduce 1. copy identity over to output (casting if necessary) - 2. Fill inner buffer + 2. Fill inner buffer 3. When buffer is filled or end of row a. Cast input buffers if needed b. Call inner function. 4. Repeat 2 until row is done. */ - /* fprintf(stderr, "BUFFERED..%d %p\n", loop->size, + /* fprintf(stderr, "BUFFERED..%d %p\n", loop->size, loop->cast); */ while(loop->index < loop->size) { - loop->inptr = loop->it->dataptr; + loop->inptr = loop->it->dataptr; /* Copy (cast) First term over to output */ if (loop->cast) { /* A little tricky because we need to @@ -2240,13 +2240,13 @@ PyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, NULL); loop->cast(loop->buffer, loop->castbuf, 1, NULL, NULL); - if (loop->obj) + if (loop->obj) Py_INCREF(*((PyObject **)loop->castbuf)); memcpy(loop->bufptr[1], loop->castbuf, loop->outsize); } else { /* Simple copy */ - arr->descr->f->copyswap(loop->bufptr[1], + arr->descr->f->copyswap(loop->bufptr[1], loop->inptr, loop->swap, NULL); @@ -2254,7 +2254,7 @@ PyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, loop->inptr += loop->instrides; n = 1; while(n < loop->N) { - /* Copy up to loop->bufsize elements to + /* Copy up to loop->bufsize elements to buffer */ dptr = loop->buffer; for (i=0; i<loop->bufsize; i++, n++) { @@ -2271,12 +2271,12 @@ PyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, loop->castbuf, i, NULL, NULL); loop->function((char **)loop->bufptr, - &i, + &i, loop->steps, loop->funcdata); loop->bufptr[1] += loop->steps[1]*i; loop->bufptr[2] += loop->steps[2]*i; UFUNC_CHECK_ERROR(loop); - } + } PyArray_ITER_NEXT(loop->it); PyArray_ITER_NEXT(loop->rit); loop->bufptr[1] = loop->rit->dataptr; @@ -2304,11 +2304,11 @@ PyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *out, /* Reduceat performs a reduce over an axis using the indices as a guide op.reduceat(array,indices) computes -op.reduce(array[indices[i]:indices[i+1]] +op.reduce(array[indices[i]:indices[i+1]] for i=0..end with an implicit indices[i+1]=len(array) assumed when i=end-1 -if indices[i+1] <= indices[i]+1 +if indices[i+1] <= indices[i]+1 then the result is array[indices[i]] for that value op.accumulate(array) is the same as @@ -2321,28 +2321,28 @@ output shape is based on the size of indices */ static PyObject * -PyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, +PyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, PyArrayObject *out, int axis, int otype) -{ +{ PyArrayObject *ret; PyUFuncReduceObject *loop; intp *ptr=(intp *)ind->data; - intp nn=ind->dimensions[0]; + intp nn=ind->dimensions[0]; intp mm=arr->dimensions[axis]-1; intp n, i, j; char *dptr; NPY_BEGIN_THREADS_DEF - /* Check for out-of-bounds values in indices array */ + /* Check for out-of-bounds values in indices array */ for (i=0; i<nn; i++) { if ((*ptr < 0) || (*ptr > mm)) { - PyErr_Format(PyExc_IndexError, + PyErr_Format(PyExc_IndexError, "index out-of-bounds (0, %d)", (int) mm); return NULL; } ptr++; } - + ptr = (intp *)ind->data; /* Construct loop object */ loop = construct_reduce(self, &arr, out, axis, otype, UFUNC_REDUCEAT, nn, @@ -2363,7 +2363,7 @@ PyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, for (i=0; i<nn; i++) { loop->bufptr[0] = loop->it->dataptr + \ (*ptr)*loop->instrides; - if (loop->obj) + if (loop->obj) Py_INCREF(*((PyObject **)loop->bufptr[0])); memcpy(loop->bufptr[1], loop->bufptr[0], loop->outsize); @@ -2376,7 +2376,7 @@ PyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, &mm, loop->steps, loop->funcdata); UFUNC_CHECK_ERROR(loop); - } + } loop->bufptr[1] += loop->ret->strides[axis]; ptr++; } @@ -2387,15 +2387,15 @@ PyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, } break; - /* BUFFER -- misbehaved array or different types */ + /* BUFFER -- misbehaved array or different types */ case BUFFER_UFUNCLOOP: /* Reduceat */ /* fprintf(stderr, "BUFFERED..%d\n", loop->size); */ while(loop->index < loop->size) { ptr = (intp *)ind->data; for (i=0; i<nn; i++) { - if (loop->obj) + if (loop->obj) Py_INCREF(*((PyObject **)loop->idptr)); - memcpy(loop->bufptr[1], loop->idptr, + memcpy(loop->bufptr[1], loop->idptr, loop->outsize); n = 0; mm = (i==nn-1 ? arr->dimensions[axis] - *ptr :\ @@ -2426,7 +2426,7 @@ PyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, loop->funcdata); UFUNC_CHECK_ERROR(loop); loop->bufptr[1] += j*loop->steps[1]; - } + } loop->bufptr[1] += loop->ret->strides[axis]; ptr++; } @@ -2440,13 +2440,13 @@ PyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, NPY_LOOP_END_THREADS - /* Hang on to this reference -- will be decref'd with loop */ + /* Hang on to this reference -- will be decref'd with loop */ if (loop->retbase) ret = (PyArrayObject *)loop->ret->base; else ret = loop->ret; Py_INCREF(ret); ufuncreduce_dealloc(loop); return (PyObject *)ret; - + fail: NPY_LOOP_END_THREADS @@ -2455,33 +2455,33 @@ PyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, } -/* This code handles reduce, reduceat, and accumulate - (accumulate and reduce are special cases of the more general reduceat - but they are handled separately for speed) +/* This code handles reduce, reduceat, and accumulate + (accumulate and reduce are special cases of the more general reduceat + but they are handled separately for speed) */ -static PyObject * -PyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, - PyObject *kwds, int operation) +static PyObject * +PyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, + PyObject *kwds, int operation) { int axis=0; PyArrayObject *mp, *ret = NULL; PyObject *op, *res=NULL; - PyObject *obj_ind, *context; + PyObject *obj_ind, *context; PyArrayObject *indices = NULL; PyArray_Descr *otype=NULL; PyArrayObject *out=NULL; static char *kwlist1[] = {"array", "axis", "dtype", "out", NULL}; - static char *kwlist2[] = {"array", "indices", "axis", "dtype", "out", NULL}; + static char *kwlist2[] = {"array", "indices", "axis", "dtype", "out", NULL}; static char *_reduce_type[] = {"reduce", "accumulate", \ "reduceat", NULL}; if (self == NULL) { PyErr_SetString(PyExc_ValueError, "function not supported"); return NULL; - } + } if (self->nin != 2) { - PyErr_Format(PyExc_ValueError, + PyErr_Format(PyExc_ValueError, "%s only supported for binary functions", _reduce_type[operation]); return NULL; @@ -2497,26 +2497,26 @@ PyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, if (operation == UFUNC_REDUCEAT) { PyArray_Descr *indtype; indtype = PyArray_DescrFromType(PyArray_INTP); - if(!PyArg_ParseTupleAndKeywords(args, kwds, "OO|iO&O&", kwlist2, - &op, &obj_ind, &axis, - PyArray_DescrConverter2, + if(!PyArg_ParseTupleAndKeywords(args, kwds, "OO|iO&O&", kwlist2, + &op, &obj_ind, &axis, + PyArray_DescrConverter2, &otype, PyArray_OutputConverter, &out)) return NULL; - indices = (PyArrayObject *)PyArray_FromAny(obj_ind, indtype, + indices = (PyArrayObject *)PyArray_FromAny(obj_ind, indtype, 1, 1, CARRAY, NULL); if (indices == NULL) return NULL; } else { if(!PyArg_ParseTupleAndKeywords(args, kwds, "O|iO&O&", kwlist1, - &op, &axis, - PyArray_DescrConverter2, + &op, &axis, + PyArray_DescrConverter2, &otype, PyArray_OutputConverter, &out)) return NULL; } - - /* Ensure input is an array */ + + /* Ensure input is an array */ if (!PyArray_Check(op) && !PyArray_IsScalar(op, Generic)) { context = Py_BuildValue("O(O)i", self, op, 0); } @@ -2532,13 +2532,13 @@ PyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, PyErr_Format(PyExc_TypeError, "cannot %s on a scalar", _reduce_type[operation]); Py_DECREF(mp); - return NULL; + return NULL; } /* Check to see that type (and otype) is not FLEXIBLE */ - if (PyArray_ISFLEXIBLE(mp) || + if (PyArray_ISFLEXIBLE(mp) || (otype && PyTypeNum_ISFLEXIBLE(otype->type_num))) { - PyErr_Format(PyExc_TypeError, + PyErr_Format(PyExc_TypeError, "cannot perform %s with flexible type", _reduce_type[operation]); Py_DECREF(mp); @@ -2561,7 +2561,7 @@ PyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, } if (otype == NULL) { - /* For integer types --- makes sure at + /* For integer types --- makes sure at least a long is used */ int typenum = PyArray_TYPE(mp); if (PyTypeNum_ISINTEGER(typenum) && \ @@ -2581,15 +2581,15 @@ PyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, switch(operation) { case UFUNC_REDUCE: - ret = (PyArrayObject *)PyUFunc_Reduce(self, mp, out, axis, + ret = (PyArrayObject *)PyUFunc_Reduce(self, mp, out, axis, otype->type_num); break; case UFUNC_ACCUMULATE: - ret = (PyArrayObject *)PyUFunc_Accumulate(self, mp, out, axis, + ret = (PyArrayObject *)PyUFunc_Accumulate(self, mp, out, axis, otype->type_num); break; case UFUNC_REDUCEAT: - ret = (PyArrayObject *)PyUFunc_Reduceat(self, mp, indices, out, + ret = (PyArrayObject *)PyUFunc_Reduceat(self, mp, indices, out, axis, otype->type_num); Py_DECREF(indices); break; @@ -2604,30 +2604,30 @@ PyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, else { Py_DECREF(ret); return res; - } + } } return PyArray_Return(ret); - + } /* This function analyzes the input arguments and determines an appropriate __array_wrap__ function to call - for the outputs. + for the outputs. - If an output argument is provided, then it is wrapped + If an output argument is provided, then it is wrapped with its own __array_wrap__ not with the one determined by - the input arguments. + the input arguments. if the provided output argument is already an array, the wrapping function is None (which means no wrapping will - be done --- not even PyArray_Return). + be done --- not even PyArray_Return). A NULL is placed in output_wrap for outputs that should just have PyArray_Return called. */ static void -_find_array_wrap(PyObject *args, PyObject **output_wrap, int nin, int nout) +_find_array_wrap(PyObject *args, PyObject **output_wrap, int nin, int nout) { int nargs, i; int np = 0; @@ -2659,11 +2659,11 @@ _find_array_wrap(PyObject *args, PyObject **output_wrap, int nin, int nout) } if (np >= 2) { wrap = wraps[0]; - maxpriority = PyArray_GetPriority(with_wrap[0], + maxpriority = PyArray_GetPriority(with_wrap[0], PyArray_SUBTYPE_PRIORITY); for (i = 1; i < np; ++i) { priority = \ - PyArray_GetPriority(with_wrap[i], + PyArray_GetPriority(with_wrap[i], PyArray_SUBTYPE_PRIORITY); if (priority > maxpriority) { maxpriority = priority; @@ -2676,18 +2676,18 @@ _find_array_wrap(PyObject *args, PyObject **output_wrap, int nin, int nout) } /* Here wrap is the wrapping function determined from the - input arrays (could be NULL). + input arrays (could be NULL). For all the output arrays decide what to do. - + 1) Use the wrap function determined from the input arrays This is the default if the output array is not passed in. 2) Use the __array_wrap__ method of the output object passed in. -- this is special cased for - exact ndarray so that no PyArray_Return is - done in that case. + exact ndarray so that no PyArray_Return is + done in that case. */ for (i=0; i<nout; i++) { @@ -2725,7 +2725,7 @@ _find_array_wrap(PyObject *args, PyObject **output_wrap, int nin, int nout) } static PyObject * -ufunc_generic_call(PyUFuncObject *self, PyObject *args) +ufunc_generic_call(PyUFuncObject *self, PyObject *args) { int i; PyTupleObject *ret; @@ -2734,11 +2734,11 @@ ufunc_generic_call(PyUFuncObject *self, PyObject *args) PyObject *wraparr[NPY_MAXARGS]; PyObject *res; int errval; - - /* Initialize all array objects to NULL to make cleanup easier + + /* Initialize all array objects to NULL to make cleanup easier if something goes wrong. */ for(i=0; i<self->nargs; i++) mps[i] = NULL; - + errval = PyUFunc_GenericFunction(self, args, mps); if (errval < 0) { for(i=0; i<self->nargs; i++) { @@ -2751,40 +2751,40 @@ ufunc_generic_call(PyUFuncObject *self, PyObject *args) return Py_NotImplemented; } } - + for(i=0; i<self->nin; i++) Py_DECREF(mps[i]); - /* Use __array_wrap__ on all outputs + /* Use __array_wrap__ on all outputs if present on one of the input arguments. If present for multiple inputs: - use __array_wrap__ of input object with largest + use __array_wrap__ of input object with largest __array_priority__ (default = 0.0) */ - /* Exception: we should not wrap outputs for items already + /* Exception: we should not wrap outputs for items already passed in as output-arguments. These items should either be left unwrapped or wrapped by calling their own __array_wrap__ routine. - For each output argument, wrap will be either + For each output argument, wrap will be either NULL --- call PyArray_Return() -- default if no output arguments given None --- array-object passed in don't call PyArray_Return - method --- the __array_wrap__ method to call. + method --- the __array_wrap__ method to call. */ _find_array_wrap(args, wraparr, self->nin, self->nout); - + /* wrap outputs */ for (i=0; i<self->nout; i++) { int j=self->nin+i; PyObject *wrap; - /* check to see if any UPDATEIFCOPY flags are set - which meant that a temporary output was generated + /* check to see if any UPDATEIFCOPY flags are set + which meant that a temporary output was generated */ if (mps[j]->flags & UPDATEIFCOPY) { PyObject *old = mps[j]->base; Py_INCREF(old); /* we want to hang on to this */ - Py_DECREF(mps[j]); /* should trigger the copy + Py_DECREF(mps[j]); /* should trigger the copy back into old */ mps[j] = (PyArrayObject *)old; } @@ -2800,8 +2800,8 @@ ufunc_generic_call(PyUFuncObject *self, PyObject *args) if (res == NULL && \ PyErr_ExceptionMatches(PyExc_TypeError)) { PyErr_Clear(); - res = PyObject_CallFunctionObjArgs(wrap, - mps[j], + res = PyObject_CallFunctionObjArgs(wrap, + mps[j], NULL); } Py_DECREF(wrap); @@ -2816,10 +2816,10 @@ ufunc_generic_call(PyUFuncObject *self, PyObject *args) /* default behavior */ retobj[i] = PyArray_Return(mps[j]); } - - if (self->nout == 1) { + + if (self->nout == 1) { return retobj[0]; - } else { + } else { ret = (PyTupleObject *)PyTuple_New(self->nout); for(i=0; i<self->nout; i++) { PyTuple_SET_ITEM(ret, i, retobj[i]); @@ -2836,9 +2836,9 @@ ufunc_geterr(PyObject *dummy, PyObject *args) { PyObject *thedict; PyObject *res; - + if (!PyArg_ParseTuple(args, "")) return NULL; - + if (PyUFunc_PYVALS_NAME == NULL) { PyUFunc_PYVALS_NAME = PyString_InternFromString(UFUNC_PYVALS_NAME); } @@ -2861,26 +2861,26 @@ ufunc_geterr(PyObject *dummy, PyObject *args) } #if USE_USE_DEFAULTS==1 -/* +/* This is a strategy to buy a little speed up and avoid the dictionary look-up in the default case. It should work in the presence of threads. If it is deemed too complicated or it doesn't actually work it could be taken out. */ -static int +static int ufunc_update_use_defaults(void) { PyObject *errobj; int errmask, bufsize; int res; - + PyUFunc_NUM_NODEFAULTS += 1; - res = PyUFunc_GetPyValues("test", &bufsize, &errmask, + res = PyUFunc_GetPyValues("test", &bufsize, &errmask, &errobj); PyUFunc_NUM_NODEFAULTS -= 1; - + if (res < 0) return -1; - + if ((errmask != UFUNC_ERR_DEFAULT) || \ (bufsize != PyArray_BUFSIZE) || \ (PyTuple_GET_ITEM(errobj, 1) != Py_None)) { @@ -2900,9 +2900,9 @@ ufunc_seterr(PyObject *dummy, PyObject *args) int res; PyObject *val; static char *msg = "Error object must be a list of length 3"; - + if (!PyArg_ParseTuple(args, "O", &val)) return NULL; - + if (!PyList_CheckExact(val) || PyList_GET_SIZE(val) != 3) { PyErr_SetString(PyExc_ValueError, msg); return NULL; @@ -2927,13 +2927,13 @@ ufunc_seterr(PyObject *dummy, PyObject *args) static PyUFuncGenericFunction pyfunc_functions[] = {PyUFunc_On_Om}; -static char +static char doc_frompyfunc[] = "frompyfunc(func, nin, nout) take an arbitrary python function that takes nin objects as input and returns nout objects and return a universal function (ufunc). This ufunc always returns PyObject arrays"; static PyObject * ufunc_frompyfunc(PyObject *dummy, PyObject *args, PyObject *kwds) { /* Keywords are ignored for now */ - + PyObject *function, *pyname=NULL; int nin, nout, i; PyUFunc_PyFuncData *fdata; @@ -2948,7 +2948,7 @@ ufunc_frompyfunc(PyObject *dummy, PyObject *args, PyObject *kwds) { PyErr_SetString(PyExc_TypeError, "function must be callable"); return NULL; } - + self = _pya_malloc(sizeof(PyUFuncObject)); if (self == NULL) return NULL; PyObject_Init((PyObject *)self, &PyUFunc_Type); @@ -2957,7 +2957,7 @@ ufunc_frompyfunc(PyObject *dummy, PyObject *args, PyObject *kwds) { self->nin = nin; self->nout = nout; self->nargs = nin+nout; - self->identity = PyUFunc_None; + self->identity = PyUFunc_None; self->functions = pyfunc_functions; self->ntypes = 1; @@ -2966,12 +2966,12 @@ ufunc_frompyfunc(PyObject *dummy, PyObject *args, PyObject *kwds) { pyname = PyObject_GetAttrString(function, "__name__"); if (pyname) (void) PyString_AsStringAndSize(pyname, &fname, &fname_len); - + if (PyErr_Occurred()) { fname = "?"; fname_len = 1; PyErr_Clear(); - } + } Py_XDECREF(pyname); @@ -3002,45 +3002,45 @@ ufunc_frompyfunc(PyObject *dummy, PyObject *args, PyObject *kwds) { fdata->nin = nin; fdata->nout = nout; fdata->callable = function; - + self->data = (void **)(((char *)self->ptr) + offset[0]); self->data[0] = (void *)fdata; - + self->types = (char *)self->data + sizeof(void *); for (i=0; i<self->nargs; i++) self->types[i] = PyArray_OBJECT; str = self->types + offset[1]; memcpy(str, fname, fname_len); memcpy(str+fname_len, " (vectorized)", 14); - + self->name = str; /* Do a better job someday */ self->doc = "dynamic ufunc based on a python function"; - - + + return (PyObject *)self; } /*UFUNC_API*/ static PyObject * -PyUFunc_FromFuncAndData(PyUFuncGenericFunction *func, void **data, +PyUFunc_FromFuncAndData(PyUFuncGenericFunction *func, void **data, char *types, int ntypes, - int nin, int nout, int identity, - char *name, char *doc, int check_return) + int nin, int nout, int identity, + char *name, char *doc, int check_return) { PyUFuncObject *self; self = _pya_malloc(sizeof(PyUFuncObject)); if (self == NULL) return NULL; PyObject_Init((PyObject *)self, &PyUFunc_Type); - + self->nin = nin; self->nout = nout; self->nargs = nin+nout; self->identity = identity; - + self->functions = func; self->data = data; self->types = types; @@ -3049,19 +3049,19 @@ PyUFunc_FromFuncAndData(PyUFuncGenericFunction *func, void **data, self->ptr = NULL; self->obj = NULL; self->userloops=NULL; - + if (name == NULL) self->name = "?"; else self->name = name; - + if (doc == NULL) self->doc = "NULL"; else self->doc = doc; - + return (PyObject *)self; } /*UFUNC_API*/ static int -PyUFunc_RegisterLoopForType(PyUFuncObject *ufunc, +PyUFunc_RegisterLoopForType(PyUFuncObject *ufunc, int usertype, PyUFuncGenericFunction function, int *arg_types, @@ -3069,16 +3069,16 @@ PyUFunc_RegisterLoopForType(PyUFuncObject *ufunc, { PyArray_Descr *descr; PyObject *key, *cobj; - int ret; - + int ret; + descr=PyArray_DescrFromType(usertype); if ((usertype < PyArray_USERDEF) || (descr==NULL)) { - PyErr_SetString(PyExc_TypeError, + PyErr_SetString(PyExc_TypeError, "unknown user-defined type"); return -1; } Py_DECREF(descr); - + if (ufunc->userloops == NULL) { ufunc->userloops = PyDict_New(); } @@ -3114,7 +3114,7 @@ PyUFunc_RegisterLoopForType(PyUFuncObject *ufunc, cobj3 = PyCObject_FromVoidPtr(data, NULL); if (cobj3 == NULL) { Py_DECREF(cobj2); - Py_DECREF(cobj); + Py_DECREF(cobj); Py_DECREF(key); return -1; } @@ -3140,9 +3140,9 @@ static PyObject * ufunc_repr(PyUFuncObject *self) { char buf[100]; - + sprintf(buf, "<ufunc '%.50s'>", self->name); - + return PyString_FromString(buf); } @@ -3156,7 +3156,7 @@ ufunc_repr(PyUFuncObject *self) */ static PyObject * -ufunc_outer(PyUFuncObject *self, PyObject *args) +ufunc_outer(PyUFuncObject *self, PyObject *args) { int i; PyObject *ret; @@ -3170,20 +3170,20 @@ ufunc_outer(PyUFuncObject *self, PyObject *args) "for binary functions"); return NULL; } - + if (PySequence_Length(args) != 2) { PyErr_SetString(PyExc_TypeError, "exactly two arguments expected"); return NULL; } - + tmp = PySequence_GetItem(args, 0); if (tmp == NULL) return NULL; ap1 = (PyArrayObject *) \ PyArray_FromObject(tmp, PyArray_NOTYPE, 0, 0); Py_DECREF(tmp); if (ap1 == NULL) return NULL; - + tmp = PySequence_GetItem(args, 1); if (tmp == NULL) return NULL; ap2 = (PyArrayObject *)PyArray_FromObject(tmp, PyArray_NOTYPE, 0, 0); @@ -3193,28 +3193,28 @@ ufunc_outer(PyUFuncObject *self, PyObject *args) /* Construct new shape tuple */ shape1 = PyTuple_New(ap1->nd); if (shape1 == NULL) goto fail; - for (i=0; i<ap1->nd; i++) - PyTuple_SET_ITEM(shape1, i, + for (i=0; i<ap1->nd; i++) + PyTuple_SET_ITEM(shape1, i, PyLong_FromLongLong((longlong)ap1-> \ dimensions[i])); - + shape2 = PyTuple_New(ap2->nd); - for (i=0; i<ap2->nd; i++) + for (i=0; i<ap2->nd; i++) PyTuple_SET_ITEM(shape2, i, PyInt_FromLong((long) 1)); if (shape2 == NULL) {Py_DECREF(shape1); goto fail;} newshape = PyNumber_Add(shape1, shape2); Py_DECREF(shape1); Py_DECREF(shape2); if (newshape == NULL) goto fail; - + ap_new = (PyArrayObject *)PyArray_Reshape(ap1, newshape); Py_DECREF(newshape); if (ap_new == NULL) goto fail; - + new_args = Py_BuildValue("(OO)", ap_new, ap2); Py_DECREF(ap1); Py_DECREF(ap2); - Py_DECREF(ap_new); + Py_DECREF(ap_new); ret = ufunc_generic_call(self, new_args); Py_DECREF(new_args); return ret; @@ -3229,32 +3229,32 @@ ufunc_outer(PyUFuncObject *self, PyObject *args) static PyObject * -ufunc_reduce(PyUFuncObject *self, PyObject *args, PyObject *kwds) +ufunc_reduce(PyUFuncObject *self, PyObject *args, PyObject *kwds) { - + return PyUFunc_GenericReduction(self, args, kwds, UFUNC_REDUCE); } static PyObject * -ufunc_accumulate(PyUFuncObject *self, PyObject *args, PyObject *kwds) +ufunc_accumulate(PyUFuncObject *self, PyObject *args, PyObject *kwds) { - + return PyUFunc_GenericReduction(self, args, kwds, UFUNC_ACCUMULATE); } static PyObject * -ufunc_reduceat(PyUFuncObject *self, PyObject *args, PyObject *kwds) -{ +ufunc_reduceat(PyUFuncObject *self, PyObject *args, PyObject *kwds) +{ return PyUFunc_GenericReduction(self, args, kwds, UFUNC_REDUCEAT); } static struct PyMethodDef ufunc_methods[] = { {"reduce", (PyCFunction)ufunc_reduce, METH_VARARGS | METH_KEYWORDS}, - {"accumulate", (PyCFunction)ufunc_accumulate, + {"accumulate", (PyCFunction)ufunc_accumulate, + METH_VARARGS | METH_KEYWORDS}, + {"reduceat", (PyCFunction)ufunc_reduceat, METH_VARARGS | METH_KEYWORDS}, - {"reduceat", (PyCFunction)ufunc_reduceat, - METH_VARARGS | METH_KEYWORDS}, {"outer", (PyCFunction)ufunc_outer, METH_VARARGS}, {NULL, NULL} /* sentinel */ }; @@ -3265,7 +3265,7 @@ static struct PyMethodDef ufunc_methods[] = { y1,y2,...,yn */ static PyObject * -_makeargs(int num, char *ltr) +_makeargs(int num, char *ltr) { PyObject *str; int i; @@ -3286,12 +3286,12 @@ static char _typecharfromnum(int num) { PyArray_Descr *descr; char ret; - + descr = PyArray_DescrFromType(num); ret = descr->type; Py_DECREF(descr); return ret; -} +} static PyObject * ufunc_get_doc(PyUFuncObject *self) @@ -3300,15 +3300,15 @@ ufunc_get_doc(PyUFuncObject *self) /* could so some introspection on name and nin + nout */ /* to automate the first part of it */ /* the doc string shouldn't need the calling convention */ - /* construct + /* construct y1,y2,,... = name(x1,x2,...) __doc__ */ PyObject *outargs, *inargs, *doc; outargs = _makeargs(self->nout, "y"); inargs = _makeargs(self->nin, "x"); - doc = PyString_FromFormat("%s = %s(%s) %s", + doc = PyString_FromFormat("%s = %s(%s) %s", PyString_AS_STRING(outargs), - self->name, + self->name, PyString_AS_STRING(inargs), self->doc); Py_DECREF(outargs); @@ -3372,7 +3372,7 @@ ufunc_get_types(PyUFuncObject *self) } _pya_free(t); return list; - + } static PyObject * @@ -3396,7 +3396,7 @@ ufunc_get_identity(PyUFuncObject *self) #undef _typecharfromnum -static char Ufunctype__doc__[] = +static char Ufunctype__doc__[] = "Optimized functions make it possible to implement arithmetic "\ "with arrays efficiently"; diff --git a/numpy/core/src/umathmodule.c.src b/numpy/core/src/umathmodule.c.src index a8a751a21..79488b5db 100644 --- a/numpy/core/src/umathmodule.c.src +++ b/numpy/core/src/umathmodule.c.src @@ -244,21 +244,21 @@ static double hypot(double x, double y) #ifndef HAVE_RINT -static double +static double rint (double x) { double y, r; - + y = floor(x); r = x - y; - + if (r > 0.5) goto rndup; /* Round to nearest even */ if (r==0.5) { r = y - 2.0*floor(0.5*y); if (r==1.0) { - rndup: + rndup: y+=1.0; } } @@ -1191,7 +1191,7 @@ static void char *i1 = args[0], *op = args[1]; c@typ@ *x, *y; @typ@ xr, xi, xmag2; - + for (i = 0; i < n; i++, i1 += is1, op += os) { x = (c@typ@ *)i1; y = (c@typ@ *)op; |