[SciPy-dev] PyArray_CanCastSafely(exact,inexact) on 64-bit

Travis Oliphant oliphant at ee.byu.edu
Mon Oct 31 00:40:10 CST 2005


>PyArray_CanCastSafely has been used in array_from_pyobj function (see 
>fortranobject.c) to decide whether the data pointer of an input array can 
>be directly passed on to the Fortran or C function:
>
>     if ((! (intent & F2PY_INTENT_COPY))
> 	&& PyArray_ITEMSIZE(arr)==descr->elsize
> 	&& PyArray_CanCastSafely(arr->descr->type_num,type_num)
> 	) {
>       if ((intent&F2PY_INTENT_C)?PyArray_ISCARRAY(arr):PyArray_ISFARRAY(arr)) {
> 	if ((intent & F2PY_INTENT_OUT)) {
> 	  Py_INCREF(arr);
> 	}
> 	/* Returning input array */
> 	return arr;
>       }
>     }
>     /* else apply arr.astype(<type_num>) */
>
>
>  
>
There are new functions in the C-API called PyArray_EquivalentTypes and 
PyArray_EquivArrType that can be used to check what you want to check.

These functions are used internally to decide whether or not two types 
are compatible and can be substituted one for another.

-Travis






More information about the Scipy-dev mailing list