[SciPy-dev] PyArray_CanCastSafely(exact,inexact) on 64-bit
Pearu Peterson
pearu at scipy.org
Sun Oct 30 21:57:01 CST 2005
On Sun, 30 Oct 2005, Travis Oliphant wrote:
> Pearu Peterson wrote:
>
>> By the definition of can_cast, no bitwise information is lost, but
>> it is not meaningful to pass (double*)(<pointer to long array>) to a
>> numeric function, for example.
>>
>>
> But, that's never been what CanCastSafely has been used to represent.
> Perhaps we need a different function that distinguishes between
> different kinds. Again, what are you trying to do, specifically?
>
>> Or may be I should use some different function than PyArray_CanCastSafely
>> in this situation?
>>
> I suspect so...
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>) */
But I now realize that this is a incorrect usage of PyArray_CanCastSafely.
The above codelet should probably then read as
if ((! (intent & F2PY_INTENT_COPY))
&& PyArray_ITEMSIZE(arr)==descr->elsize
&& ( (PyArray_ISINTEGER(arr) && PyTypeNum_ISINTEGER(type_num))
|| (PyArray_ISFLOAT(arr) && PyTypeNum_ISFLOAT(type_num))
|| (PyArray_ISCOMPLEX(arr) && PyTypeNum_ISCOMPLEX(type_num))
|| (PyArray_ISSTRING(arr) && PyTypeNum_ISSTRING(type_num))
)
) {
...
though I am not sure about the STRING case, e.g. what happens when passing
unicode arr->data to fortran character*(*) argument, for instance.
Thanks,
Pearu
More information about the Scipy-dev
mailing list