Yury V. Zaytsev | 19 Jan 16:39 2016

Temporaries cause broken code for std::make_unique<>(), any hints?

Hi,

I've implemented a wrapper for std::make_unique<>() as follows:

     from libcpp.memory cimport unique_ptr

     cdef extern from "<memory>" namespace "std" nogil:
         unique_ptr[T] make_unique[T]() except +
         unique_ptr[T] make_unique[T](T&) except +

Very unfortunately, this forces Cython to generate a temporary for 
handling the exceptions, which, obviously breaks the whole thing:

     try {
       __pyx_t_10 = std::make_unique<XXX>(__pyx_v_uv);
     } catch(...) {
       __Pyx_CppExn2PyErr(); /* ... */
     }
     __pyx_v_pyuv->thisptr = __pyx_t_10;

When I remove "except +", then the generated code is correct, but, of 
course, possible exceptions (std::bad_alloc or any exception thrown by the 
constructor of T) are not handled.

Is it somehow possible to force Cython to generate a move, as in

     __pyx_v_pyuv->thisptr = std::move(__pyx_t_10);

Maybe it actually makes sense to always generate a move if the compiler 
supports it? I can't see any obvious disadvantages to not doing so, at 
(Continue reading)

Yury V. Zaytsev | 19 Jan 14:01 2016

Possible memory leak in support for memoryviews

Hi,

I'm trying to check my Cython modules with LeakSanitizer, and I'm getting 
the following report for every module that uses memoryviews:

Direct leak of 3072 byte(s) in 1 object(s) allocated from:
     #0 0x7fd58f0a75b1 in __interceptor_calloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x945b1)
     #1 0x458543 in dictresize Objects/dictobject.c:643
     #2 0x7fd58ac83e8d in initleaktest2 /home/zaytsev/src/cython/leak/leaktest2.cpp:14131
     #3 0x4ced57 in _PyImport_LoadDynamicModule Python/importdl.c:53

The correspondent line from leaktest2.cpp:14131 looks as follows:

     if (__Pyx_SetVtable(__pyx_type___pyx_memoryview.tp_dict, __pyx_vtabptr_memoryview) < 0) { /* ...
*/ }

I attach the reproducer:

     make

     python -c "import leaktest1; leaktest1.main()"
     # no leak report that looks like the above

     python -c "import leaktest2; leaktest2.main()"
     # leak report that looks like the above

Unfortunately, your Python should be linked with -fsanitize=address, or 
else you can try LD_PRELOAD'ing ASan, but I've faced so many issues along 
this path that I don't recommend it.

(Continue reading)

remi.cambuzat | 19 Jan 04:52 2016
Picon

Import .pxd object into anoter .pxd file

Good afternoon.

I'm facing an include problem that drive me mad.

As you will see here in my file Arm.pxd, I'm trying to use two object ArmParameters and MusclesParameters, that are also cython classes from the package ArmModel.

However even if the compilation of the package ArmModel is going without error (compiler script here : Cythonize_ArmModel.py).
I got some strange error when I'm running my test script runTest.py.
Here is the log :

python runTest.py 
 
--------------Muscles---------------
init MusclesParameters
--------------ArmParam---------------
init ArmParameters
--------------Arm---------------
(array([0, 1, 2, 3, 4, 5]), array([ 0, 11, 22, 33]))
     ---------Arm cython---------
Traceback (most recent call last):
  File "runTest.py", line 28, in <module>
    from ArmModel import Arm as Arm
  File "MotorControlModel/ArmModel/MusclesParameters.pxd", line 4, in init MotorControlModel.ArmModel.Arm (MotorControlModel/ArmModel/Arm.c:8141)
ImportError: No module named MotorControlModel.ArmModel.MusclesParameters

The strange thing is that I have my all of the files I need in my package ArmModel. My files MusclesParameters.pxd,ArmParameters.pxd and Arm.pxd are also inside it with their respective .c and.so files.
So I really don't understand why I have this problem.

I read a lot of documentation on Sharing Extension Types and implemented their solution and took into account this post.
Unfortunately I still get the error.

Could you help me on this before It mate me blow a fuse ^^.

If the answer is on the web could you link me to it, as I wasn't able to find something relevant with google.

Many Thanks <3 :D








--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Soren Christensen | 14 Jan 21:47 2016
Picon

library resolution when running cython module

Hi,
 I have a cython module that link to an application in a dynamic library (on linux).
This dynamic library uses a number of other dynamic libraries (it is a Qt application)
I get a lot of errors on execution and they seem to be caused by incorrect resolution of dynamic libraries. 
My .so file is linked with -path so ldd mylib.so shows the absolute path of all libraries. 
Why is this not respected when called from python? 
Apparently the rpath is ignored and the library names are then in several cases resolved to something different.
Has anyone had similar issues and know of a good way to deal with it?

I did solve one of my issues using ctypes, but it can be difficult from the error messages to work out which library is not resolved correctly.
Eg: ctypes.CDLL(util.find_library('GL'), ctypes.RTLD_GLOBAL) solved finding the correct GL.


Thanks!

Soren



 

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Joshua | 14 Jan 21:16 2016
Picon

Error in calling generated __Pyx_carray_to_py_ function

I've started testing cython 0.23.4 having been running 0.22.1 in production for a long while. When I attempted to re-compile my code, I get a bunch of errors of the form:

f1000.c:25937:76: error: too few arguments to function call, expected 3, have 1
    __pyx_v_3res_5fcode_2bb_6factor_tr = __Pyx_carray_from_py_xarr__type(o); if (PyErr_Occu...

This call is in the function definition of

static int __pyx_import_star_set(PyObject *o, PyObject* py_name, char *name) {

Looking through the generated c code, I see the function definition of `__Pyx_carray_from_py_xarr__type` is:

static int __Pyx_carray_from_py_xarr__type(PyObject *, struct __pyx_t_3res_5fcode_2bb_11fast_tables_xarr_type *, Py_ssize_t); /*proto*/

Is this an outright codegen bug given that the call and function signatures are different? Any suggestions would be greatly appreciated?

Best wishes,
Josh





--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Antony Lee | 14 Jan 07:06 2016
Picon

Incorrect inference of return type of conditional

Consider

cdef main(bint flag, size_t up):
    cdef size_t i
    for i in range(up if flag else up // 2):
        pass

pyximporting this compiles, but with the following warning (apparently LANG=C isn't propagated to gcc here but the error message is about comparing signed and unsigned expressions):

/home/antony/.pyxbld/temp.linux-x86_64-3.5/pyrex/cymod.c: Dans la fonction ‘__pyx_f_5cymod_main’:
/home/antony/.pyxbld/temp.linux-x86_64-3.5/pyrex/cymod.c:600:33: attention : comparaison entre des expressions entières signée et non signée [-Wsign-compare]
   for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {

Indeed __pyx_t_1 (holding the result of the ternary) is declared as a "long".

I'd guess "(flag ? up : up / 2)" should be understood as being of the same numeric type as "up" (...right?) and likewise Cython should compile the ternary into a "size_t".

Antony

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Martin Bammer | 13 Jan 07:04 2016
Picon

cython.declare is ignored

Simple example:

test.py:

class A(object):
    cython.declare(Z = cython.int)
    def __init__(self, z):
        self.Z = z

Cython should create a "cython.declare(Z = cython.int)" should act like a "cdef int Z", but Z is still created as a Python attribute.
In the cpp-file in __init__ I get:

__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_ZZ, __pyx_v_zz)


Regards, Martin

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Julien Delafontaine | 12 Jan 11:50 2016
Picon
Gravatar

Should I drop numpy for plain lists?

Hello,

I spent a certain amount of time converting every of my outputs to numpy arrays, thinking that having typed arrays (of unsigned integers) would increase Cython's performance. But looking at the profile that "cython -a" produces, I see that once the code is devectorized, my inner-most, time consuming operations, such as <uint8> & <uint8>, call Python to cast both operands to ints.
Would I gain something by refactoring all my code to pass lists of  standard ints instead of typed arrays ? Or should I use a more convertible dtype (np.int_) ?
I have a 2D array, but it could be a list of lists as well (I thought an array would make indexing faster).
I've attached one of my .html profiles as example.

Also, "cython -a", even with "-X" options added, seems to ignore compiler directives (#cython: profile=True, cdivision=True, ... on top of my file). Am I right ?

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Arthur Zalevsky | 10 Jan 15:11 2016
Picon
Gravatar

Corruption of array accessed by raw C pointer

I'm trying to write small wrapper which will feed data to some C library. Code for wrapper is here: 
http://pastebin.com/Lvm00JM1 
I'm using array access through raw C pointer as stated in docs: "To avoid any overhead and to be able to pass a C pointer to other functions" 

The issue i have is a corruption of array data in one of struct fields:

./test_array.exe
Before
Atom N: 5
Labels: [6, 4, 6, 1, 1]
After
Atom N: 5
Labels: [147954576, 4, 6, 1, 1]

Am i doing something wrong or is it a bug?  

Thanks in advance,
Arthur

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
pal pandi | 10 Jan 07:13 2016
Picon

pyd file for python package

Hi All,

I have a package structure 

A (uses files from B and C)
B (init.py, a.py, b.py)
C (init.py, c.py, d.py)

How to create a pyd file for the above structure?
Is it possible to create a single .pyd file?
Do I need cython to run .pyd file?


Thanks.

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ian Bell | 10 Jan 03:09 2016
Picon

Issues with use of numpy coercion

According to the docs (http://docs.cython.org/src/userguide/memoryviews.html#coercion-to-numpy), it should be possible to coerce arrays to numpy arrays without making a copy.  I'm trying to do this to have a matrix managed by an extension class, and visible to python just like a numpy array.

This following example below doesn't work, and consistently gives me the error:

numpy_array = np.asarray(<np.int32_t[:3, :3]> cyarr_view)
                                                         ^
------------------------------------------------------------

main.pyx:17:58: Can only create cython.array from pointer or array

even when I try narr, narr_view, carr, carr_view, cyarr and cyarr_view.  Am I doing something wrong?  If not, perhaps the docs could be expanded a bit, as it seems it should be possible to do what I would like to according to the docs.  Isn't cyarr_view a valid candidate for this?

Here is the sample:

from cython.view cimport array as cvarray
import numpy as np
cimport numpy as np

# Memoryview on a NumPy array
narr = np.arange(27, dtype=np.dtype("i")).reshape((3, 3, 3))
cdef int [:, :, :] narr_view = narr

# Memoryview on a C array
cdef int carr[3][3][3]
cdef int [:, :, :] carr_view = carr

# Memoryview on a Cython array
cyarr = cvarray(shape=(3, 3, 3), itemsize=sizeof(int), format="i")
cdef int [:, :, :] cyarr_view = cyarr

numpy_array = np.asarray(<np.int32_t[:3, :3]> cyarr_view)

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gmane