shaunc | 12 Jun 2012 21:19
Gravatar

ndarray conversion to memoryview -- bug when using inline?

I've got an inline function:

cdef inline np.ndarray[ long, ndim = 1 ] buildlist_create_array(

        buildlist_t *blist ):

    cdef np.ndarray[ long, ndim = 1 ] out = np.empty( blist.size, dtype = 'i8' )

    buildlist_fill( blist, out )

    return out

It compiles to a chunk of c code including the following line:

  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(((PyObject *)__pyx_v_out));

This line triggers the following error:

/Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/factfiber/stat/util/tests/_test_sparseview.c:2703: warning: implicit declaration of function ‘__Pyx_PyObject_to_MemoryviewSlice_ds_long’

/Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/factfiber/stat/util/tests/_test_sparseview.c:2703: error: incompatible types in assignment

--------------

I presume that the compiler has forgotten to generate proper declaration for "__Pyx_PyObject_to_MemoryviewSlice_ds_long" ? I stand ready to be corrected if there is something I'm overlooking. Thanks!

mark florisson | 13 Jun 2012 17:52
Picon
Gravatar

Re: ndarray conversion to memoryview -- bug when using inline?

On 12 June 2012 20:19, shaunc <shaun <at> cuttshome.net> wrote:
> I've got an inline function:
>
> cdef inline np.ndarray[ long, ndim = 1 ] buildlist_create_array(
>
>         buildlist_t *blist ):
>
>     cdef np.ndarray[ long, ndim = 1 ] out = np.empty( blist.size, dtype =
> 'i8' )
>
>     buildlist_fill( blist, out )
>
>     return out
>
> It compiles to a chunk of c code including the following line:
>
>   __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(((PyObject
> *)__pyx_v_out));
>
> This line triggers the following error:
>
> /Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/factfiber/stat/util/tests/_test_sparseview.c:2703:
> warning: implicit declaration of function
> ‘__Pyx_PyObject_to_MemoryviewSlice_ds_long’
>
> /Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/factfiber/stat/util/tests/_test_sparseview.c:2703:
> error: incompatible types in assignment
>
> --------------
>
> I presume that the compiler has forgotten to generate proper declaration for
> "__Pyx_PyObject_to_MemoryviewSlice_ds_long" ? I stand ready to be corrected
> if there is something I'm overlooking. Thanks!

I don't see any memoryview usage in that example. Could you post a
minimal working example (not dependent on any external types or
functions) that produces this behaviour?

shaunc | 14 Jun 2012 15:22
Gravatar

Re: ndarray conversion to memoryview -- bug when using inline?



I don't see any memoryview usage in that example. Could you post a
minimal working example (not dependent on any external types or
functions) that produces this behaviour?

In foo.pyx:
----------------------------------------------------
from foo cimport *

cdef int baz( long[:] a ):
    return 0
----------------------------------------------------

In foo.pxd:
----------------------------------------------------

cimport numpy as np

cdef int baz( long[:] a )

cdef inline np.ndarray[ long, ndim = 1 ] foo():
    cdef np.ndarray[ long, ndim = 1 ] out = np.empty( ( 8, ), dtype = 'i8' )
    baz( out )
    return out
----------------------------------------------------
in bar.pyx: 
----------------------------------------------------
cimport numpy as np
from foo cimport foo

cdef int bar():
  cdef np.ndarray[ long, ndim = 1 ] q = foo()

----------------------------------------------------
Now, in python, import of bar fails:

----------------------------------------------------
In [1]: import pyximport; pyximport.install(); import bar
/Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/bar.c: In function ‘__pyx_f_3foo_foo’:
/Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/bar.c:1761: warning: implicit declaration of function ‘__Pyx_PyObject_to_MemoryviewSlice_ds_long’
/Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/bar.c:1761: error: incompatible types in assignment
/Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/bar.c: In function ‘__pyx_f_3foo_foo’:
/Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/bar.c:1761: warning: implicit declaration of function ‘__Pyx_PyObject_to_MemoryviewSlice_ds_long’
/Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/bar.c:1761: error: incompatible types in assignment
/Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/bar.c: In function ‘__pyx_array_MemoryView_5array___cinit__’:
/Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/bar.c:3931: warning: implicit conversion shortens 64-bit value into a 32-bit value
/Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/bar.c: In function ‘__pyx_memoryview_get_item_pointer’:
/Users/shauncutts/.pyxbld/temp.macosx-10.7-intel-2.7/pyrex/bar.c:5896: warning: implicit conversion shortens 64-bit value into a 32-bit value
lipo: can't open input file: /var/folders/pq/ww1fn4v55h77lg9xpxvt6htm0000gn/T//ccYJkRAx.out (No such file or directory)

----------------------------------------------------
Note if bar.pyx is changed to itself have an assignment of a memoryview from a vector everything is ok, as the compiler includes proper prototype for __Pyx_PyObject_to_MemoryviewSlice_ds_long.

The point is, when bar.pyx doesn't have any such copies, but the prototype is required because of inline code included from foo.pxd, we have a problem.


Gmane