diff options
author | Pearu Peterson <pearu.peterson@gmail.com> | 2009-10-25 09:37:31 +0000 |
---|---|---|
committer | Pearu Peterson <pearu.peterson@gmail.com> | 2009-10-25 09:37:31 +0000 |
commit | 11de890bdf5d91179cd9f75062e27a89a5f9fffb (patch) | |
tree | ce5ddbf1b213b5ea1ea8d75ca0ad40c11299f6aa /numpy/f2py | |
parent | 944524fa0ba6a9a174e1e3af99be61f35c8b4503 (diff) | |
download | numpy-11de890bdf5d91179cd9f75062e27a89a5f9fffb.tar.gz |
Introduced intent(align4|align8|align16) attributes. Fixes scipy ticket 794 after using intent(align8) in the corresponding scipy pyf files.
Diffstat (limited to 'numpy/f2py')
-rw-r--r-- | numpy/f2py/auxfuncs.py | 12 | ||||
-rwxr-xr-x | numpy/f2py/crackfortran.py | 2 | ||||
-rw-r--r-- | numpy/f2py/src/fortranobject.c | 11 | ||||
-rw-r--r-- | numpy/f2py/src/fortranobject.h | 14 |
4 files changed, 36 insertions, 3 deletions
diff --git a/numpy/f2py/auxfuncs.py b/numpy/f2py/auxfuncs.py index facbd0534..18eea6520 100644 --- a/numpy/f2py/auxfuncs.py +++ b/numpy/f2py/auxfuncs.py @@ -345,11 +345,21 @@ def isintent_inplace(var): def isintent_aux(var): return 'aux' in var.get('intent',[]) +def isintent_aligned4(var): + return 'aligned4' in var.get('intent',[]) +def isintent_aligned8(var): + return 'aligned8' in var.get('intent',[]) +def isintent_aligned16(var): + return 'aligned16' in var.get('intent',[]) + isintent_dict = {isintent_in:'INTENT_IN',isintent_inout:'INTENT_INOUT', isintent_out:'INTENT_OUT',isintent_hide:'INTENT_HIDE', isintent_cache:'INTENT_CACHE', isintent_c:'INTENT_C',isoptional:'OPTIONAL', - isintent_inplace:'INTENT_INPLACE' + isintent_inplace:'INTENT_INPLACE', + isintent_aligned4:'INTENT_ALIGNED4', + isintent_aligned8:'INTENT_ALIGNED8', + isintent_aligned16:'INTENT_ALIGNED16', } def isprivate(var): diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py index 9901eb11d..9f6f7c710 100755 --- a/numpy/f2py/crackfortran.py +++ b/numpy/f2py/crackfortran.py @@ -84,7 +84,7 @@ f2py_version = __version__.version D['typespec'] = 'byte' | 'character' | 'complex' | 'double complex' | 'double precision' | 'integer' | 'logical' | 'real' | 'type' D['attrspec'] --- list of attributes (e.g. 'dimension(<arrayspec>)', - 'external','intent(in|out|inout|hide|c|callback|cache)', + 'external','intent(in|out|inout|hide|c|callback|cache|aligned4|aligned8|aligned16)', 'optional','required', etc) K = D['kindselector'] = {['*','kind']} (only if D['typespec'] = 'complex' | 'integer' | 'logical' | 'real' ) diff --git a/numpy/f2py/src/fortranobject.c b/numpy/f2py/src/fortranobject.c index 624b58a00..66e02ff89 100644 --- a/numpy/f2py/src/fortranobject.c +++ b/numpy/f2py/src/fortranobject.c @@ -614,10 +614,17 @@ PyArrayObject* array_from_pyobj(const int type_num, if (check_and_fix_dimensions(arr,rank,dims)) { return NULL; /*XXX: set exception */ } - + /* + printf("intent alignement=%d\n", F2PY_GET_ALIGNMENT(intent)); + printf("alignement check=%d\n", F2PY_CHECK_ALIGNMENT(arr, intent)); + int i; + for (i=1;i<=16;i++) + printf("i=%d isaligned=%d\n", i, ARRAY_ISALIGNED(arr, i)); + */ if ((! (intent & F2PY_INTENT_COPY)) && PyArray_ITEMSIZE(arr)==elsize && ARRAY_ISCOMPATIBLE(arr,type_num) + && F2PY_CHECK_ALIGNMENT(arr, intent) ) { if ((intent & F2PY_INTENT_C)?PyArray_ISCARRAY(arr):PyArray_ISFARRAY(arr)) { if ((intent & F2PY_INTENT_OUT)) { @@ -642,6 +649,8 @@ PyArrayObject* array_from_pyobj(const int type_num, if (!(ARRAY_ISCOMPATIBLE(arr,type_num))) sprintf(mess+strlen(mess)," -- input '%c' not compatible to '%c'", arr->descr->type,typechar); + if (!(F2PY_CHECK_ALIGNMENT(arr, intent))) + sprintf(mess+strlen(mess)," -- input not %d-aligned", F2PY_GET_ALIGNMENT(intent)); PyErr_SetString(PyExc_ValueError,mess); return NULL; } diff --git a/numpy/f2py/src/fortranobject.h b/numpy/f2py/src/fortranobject.h index b28848b79..d08c65808 100644 --- a/numpy/f2py/src/fortranobject.h +++ b/numpy/f2py/src/fortranobject.h @@ -106,6 +106,20 @@ typedef struct { #define F2PY_INTENT_C 64 #define F2PY_OPTIONAL 128 #define F2PY_INTENT_INPLACE 256 +#define F2PY_INTENT_ALIGNED4 512 +#define F2PY_INTENT_ALIGNED8 1024 +#define F2PY_INTENT_ALIGNED16 2048 + +#define ARRAY_ISALIGNED(ARR, SIZE) ((size_t)(PyArray_DATA(ARR)) % (SIZE) == 0) +#define F2PY_ALIGN4(intent) (intent & F2PY_INTENT_ALIGNED4) +#define F2PY_ALIGN8(intent) (intent & F2PY_INTENT_ALIGNED8) +#define F2PY_ALIGN16(intent) (intent & F2PY_INTENT_ALIGNED16) + +#define F2PY_GET_ALIGNMENT(intent) \ + (F2PY_ALIGN4(intent) ? 4 : \ + (F2PY_ALIGN8(intent) ? 8 : \ + (F2PY_ALIGN16(intent) ? 16 : 1) )) +#define F2PY_CHECK_ALIGNMENT(arr, intent) ARRAY_ISALIGNED(arr, F2PY_GET_ALIGNMENT(intent)) extern PyArrayObject* array_from_pyobj(const int type_num, npy_intp *dims, |