Stefan Behnel | 8 Sep 22:23 2014
Picon

Cython 0.21 release candidate

Hi all,

I uploaded a release candidate for 0.21. There were a couple of more
changes and cleanups since the last beta, so please give it another quick
round of testing.

http://www.cython.org/release/Cython-0.21rc1.tar.gz

http://www.cython.org/release/Cython-0.21rc1.tar.gz.asc

Complete changelog:

https://github.com/cython/cython/blob/8337b8aec2ecbb4480d551e12b1faf9b21ba2cb1/CHANGES.rst

Stefan

--

-- 

--- 
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 Landau | 8 Sep 13:54 2014

Suggested addition to the docs on memory allocation

I have this Stack Overflow post:

http://stackoverflow.com/a/21054369/1763356

People seem to find it useful and I recently got a comment saying that
this should be in the docs. Thus, I'm raising the idea here. It might
make sense to just have a link, but you could also properly integrate
it if you have an appropriate place. One advantage of a link is that I
can keep it up to date (you can, too, being on Stack Overflow).

--

-- 

--- 
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.

Nathan Goldbaum | 4 Sep 22:05 2014
Picon

cython.parallel.prange num_threads keyword argument must be a constant

I have the following test code:

    from cython import parallel

    def test_function(num_threads=4):
        cdef int i

        with nogil:
            for i in parallel.prange(10, num_threads=num_threads):
                pass

When I cythonize and compile this, I get the following error from gcc 4.4.6:

    [goldbaum <at> eudora cython_test]$ python setup.py install
    running install
    running build
    running build_ext
    cythoning test.pyx to test.c
    building 'test' extension
    gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/pfs/goldbaum/anaconda/include/python2.7 -c test.c -o build/temp.linux-x86_64-2.7/test.o -fopenmp
    test.c: In function ‘__pyx_pf_4test_test_function’:
    test.c:765: error: expected integer expression before end of line
    error: command 'gcc' failed with exit status 1

The autogenerated c near line 765 looks like this:

 761            __pyx_t_2 = (10 - 0) / 1;
 762            if (__pyx_t_2 > 0)
 763            {
 764                #ifdef _OPENMP
 765                #pragma omp parallel num_threads(__pyx_v_num_threads)
 766                #endif /* _OPENMP */
 767                {
 768                    #ifdef _OPENMP
 769                    #pragma omp for firstprivate(__pyx_v_i) lastprivate(__pyx_v_i)


If I change the argument of the num_threads keyword argument to a constant, it builds and runs correctly.

I'm not sure whether this is a bug, a misunderstanding on my part, or simply an undocumented caveat of the way prange is transpiled to openmp pragmas. Optimally I'd like to be able to control the number of threads used in the prange from python.

Best,

Nathan Goldbaum

--

---
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.
Lars Bittrich | 4 Sep 20:38 2014
Picon

Segmentation Fault due to reference counting problem with typed memory views and ternary operators

Hi all,

I believe that I stumbled upon a bug with typed memory views in conjunction with ternary operators. A small reduced example follows:

# example.pyx
cdef localviewtest(double[:] cview1, double[:] cview2, int i):
   cdef int j
   cdef double[:] cviewlocal
   # no crash with
   #if i==0:
   #    cviewlocal = cview1
   #else:
   #    cviewlocal = cview2
   # crash on exit of localviewtest in __PYX_XDEC_MEMVIEW
   cviewlocal = cview1 if i==0 else cview2
   for j in range(cviewlocal.shape[0]):
       print cviewlocal[j]

def test(int i):
   cdef double c[2]
   cdef double b[2]
   c[0] = 1.0
   c[1] = 2.0
   b[0] = 3.0
   b[1] = 4.0
   localviewtest(c, b, i)

In Ipython the example crashes:
In [1]: import pyximport; pyximport.install()
In [2]: import example
In [3]: example.test(0)
1.0
2.0
Fatal Python error: Acquisition count is 0 (line 1614)

I tested this on Windows with cython 0.20.2 and on Ubuntu cython 0.20.1post0. The use of the ternary operator seems to cause the problem. If this is hard fix maybe a hint in the documentation would be nice, as this problem is really hard to track down.

Thanks,
Lars

--

---
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.
Ivan Smirnov | 1 Sep 14:37 2014
Picon

cdef extern packed struct?

Wonder what's the correct course of action if I have a packed structure defined in C++ world and it needs to be used in Cython:

#pragma pack(push, 1)
typedef struct Foo {
    int32_t a
;
   
char s[10];
    uint16_t b
;
} Foo;
#pragma pack(pop)

Since "packed" qualifier is not permitted inside extern blocks, would Cython be able to figure out that the structure is packed?

cdef extern from "foo.h":
    ctypedef
struct Foo:
        int32_t a
       
char[10] s
        uint16_t b

It seems to work on simplest examples, is there any catch?

--

---
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.
Pierre Carbonnelle | 31 Aug 11:58 2014
Picon

how to have hashable extension types in pure python mode ? (__eq__ error)

Hi,

I'm in the process of converting a pure python library to Cython to obtain speed gains, and it looks promising.  Because it is distributed on pypi, it needs to work in as many environments as possible (currently 2.7, 3+ and pypy).  To allow for Windows users without C compilers, I plan to use Cython in pure python mode, with all Cython declarations in a augmenting .pxd file.

I need to convert one class to a cdef extension type, but it is hashable (__hash__), and thus needs a __eq__ method in CPython 3.  Unfortunately, Cython raises an error :

Special method __eq__ must be implemented via __richcmp_


I did implement an extra __richcmp__ method, but it still raises this error.  Using __cmp__ instead would work on Python 2.7, but not 3+.

I found a recent discussion on this forum, leading to bug 130, but it's 6 years old, and demoted to 'wishlist'.  

Is there a solution in pure python mode with pxd file ?  (or Via cython decorators, but  I'm afraid I would lose readability).

Wouldn't it be possible for Cython to ignore this error when a richcmp method is defined ?

Thanks in advance.
Pierre C.

--

---
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 | 30 Aug 17:55 2014
Picon

Syntax error in simple statement list when trying to annotate file

What is wrong here:

cpdef unsigned int get_typesize(unicode dtype):
    return { u"BYTE" : 1, u"UBYTE" : 1, u"SBYTE" : 1, u"PBYTE" : 1, u"WORD" : 2, u"UWORD" : 2, u"SWORD" : 2, u"PWORD" : 2,
             u"LONG" : 4, u"ULONG" : 4, u"SLONG" : 4, u"PLONG" : 4,
             u"FLOAT32_IEEE" : 4, u"FLOAT64_IEEE" : 8, u"A_INT64" : 8, u"A_UINT64" : 8 }[dtype]

Fails when I call cython with option "-a". Without the option "-a" the file compiles without errors.


--

---
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.
Matthew Johnson | 29 Aug 15:02 2014
Picon

redefinition error creating C++ vectors of typed memoryviews

I'm getting a compilation error that I think might be a bug.

I'm trying to make C++ vectors of typed memoryviews like

    cdef vector[double[:]] v = some_list

It seems to work fine when I only have one such line, but when there are two lines (i.e. two such vectors being created) I get a redefinition error:
    
    error: redefinition of 'std::vector<__Pyx_memviewslice> __pyx_convert_vector_from_py___Pyx_memviewslice(PyObject*)'

Here is a minimal example: https://gist.github.com/mattjj/15f28177d68238659386

The error does not happen if we instead try to create two vector[int] types or one vector[double[:]] and one vector[int].

This might be the same error as with https://groups.google.com/forum/#!topic/cython-users/NMfMmNkBp9w but my minimal example is much smaller!

Should I submit this as a bug?

--

---
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.
Ivan Smirnov | 29 Aug 14:27 2014
Picon

Converting packed structs with char[N] fields to numpy record arrays (views)

Hi all,

I was wondering, is it possible to convert Cython packed structs with fixed-length string fields (char[N]) to numpy arrays (views)?

In the example below, the returned value is:

array([{'s': 'qwe'}, {'s': 'ewq'}], dtype=object)

and I can't seem to make it to return [('s', '|S10')] dtype no matter what. Would anyone have an idea if it's possible with the latest Cython? Thanks.

The test example:

# cython: language=c++ from libcpp.vector cimport vector from libc.string cimport strcpy cimport numpy as np import numpy as np np.import_array() cdef packed struct Foo: char[10] s cpdef test_foo(): cdef: Foo foo1, foo2 vector[Foo] v Foo[:] view Foo *pointer strcpy(foo1.s, 'qwe') strcpy(foo2.s, 'ewq') v.push_back(foo1) v.push_back(foo2) pointer = &v.front() view = <Foo[:2]> pointer return np.asarray(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.
Marc-Alexandre Côté | 27 Aug 20:00 2014
Picon

Memory leak with vector of memoryviews

Hi,

I'm using Cython 0.21b1 on LinuxMint 17 and I think a found a memory leak when passing a list of Numpy array to a Cython function expecting vector of memoryviews.

I made a minimalist gist exposing that memory leak: https://gist.github.com/MarcCote/11cf991d94a5076ccbc4

For now, I fixed that leak by calling __PYX_XDEC_MEMVIEW explicitly on every memoryviews contained in the vector before returning (see gist).

--
Marc

--

---
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.
JF Gallant | 26 Aug 16:15 2014
Picon

Microsoft SDK 7.1 and OpenMP

Hi all,

I try to recompile a addon I made for Blender 2.71. Because Blender 2.71 upgrade to python 3.4.0 , I need to compile it for this version ( previous working very well because it's python 3.3 ).
So I install python 3.4.0 , cython 0.20.2 , SDK 7.1  ( following the process that I already follow for python 3.3 here : https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows ).

When I try to compile my addon ( python module ) with this new setup , I get this error:

cmolcore.c(352) : fatal error C1083: Cannot open include file: 'omp.h': No such file or directory

I read that apparently openmp is not included in SDK7.1.

Somebody find a solution or workaround to this issue ?

thanks a lot !

--

---
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