Kurt Smith | 30 Jun 01:18 2014
Picon

Regression with cimport of cython.operator.dereference, Cython 0.20.2

Hi all,

Is this a regression with cython.operator.dereference?

$ cython --version
Cython version 0.20.2
$ cat e_dereference.pyx
from cython.operator cimport dereference

def foo():
    cdef int *i
    cdef int j, k
    j = 10
    i = &j
    k = dereference(i)
$ cython e_dereference.pyx

Error compiling Cython file:
------------------------------------------------------------
...
def foo():
    cdef int *i
    cdef int j, k
    j = 10
    i = &j
    k = dereference(i)
                  ^
------------------------------------------------------------

e_dereference.pyx:10:19: undeclared name not builtin: dereference

Error compiling Cython file:
------------------------------------------------------------
...
def foo():
    cdef int *i
    cdef int j, k
    j = 10
    i = &j
    k = dereference(i)
                    ^
------------------------------------------------------------

e_dereference.pyx:10:21: Cannot convert 'int *' to Python object

If I change the cimport to

    from cython.operator cimport dereference as deref

or even

    from cython.operator cimport dereference as dereference

things work, and the correct code is generated.

I can of course use the k = i[0] syntax; just wanted to point out the above issue.

--

---
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.
steve stevo | 28 Jun 13:56 2014
Picon

"Exported" functions in .pyd module

Hello,
I'm using cython to build pyd module from my python script.
My python script looks like:
             class WorkingThread(QtCore.QThread):
                       ...
             class Ui_Dialog(object):
                       ...
             def Function1():
                       ...
             def Function2():
                       ...
             def main():
                      ...

How can I make all classes and functions accessible only inside compiled .pyd module?
So basically I want compiled module to "export" only main() function, nothing more.

--

---
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 | 27 Jun 10:49 2014
Picon

Pure Python Mode and public

Hi,

I want to use pure python mode in my module so I can use it directly without compiling it.
But it seems that some features in this mode are missing, like the key "public". 
Is this true? Is there a plan to extend the pure python mode?

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

Gregor Thalhammer | 26 Jun 13:21 2014
Picon

best practice for cython singleton extension class

Hi all,

I experience some problems with my wrapper for AMDs open source GPU FFT library (clFFT),
https://github.com/geggo/gpyfft  It seems that the clFFT library does not like to be initialized and
released repeatedly. Therefor I would like to change my cython extension class (GpyFFT), which wraps
access to the C library, to a singleton class. Some nice recipes I found for Python singletons that
redefine __new__, seem not to work with cython, it refuses to compile ('use __cinit__ instead'). Can
somebody recommend a best practice approach to realize a singleton class with cython?

Another question: For easy installation of the wrapper on Windows, I would like to add the external library
(clFFT.dll) to the package directory. Any advice on a best practice? I found some hints to use
install_clib from numpy.distutils, but it seems cython and numpy.distutils don't play well together,
and some patching is required (https://github.com/matthew-brett/du-cy-numpy)

thanks
Gregor

--

-- 

--- 
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 Augier | 23 Jun 12:36 2014
Picon

Python crash with minimal Cython module (Python3, Anaconda3, Windows7)

Hello,

I try to use Cython with Python3 (Anaconda3) under Windows 7. After having solved a problem in distutils by editing the file cygwinccompiler.py (cf. Building minimal cython file with python 3.3 (Anaconda) under windows 7), modules can be built without any problems:

C:\path\testcython> python setup.py build running build running build_ext cythoning testcython.pyx to testcython.c building 'testcython' extension C:\Prog\Anaconda3\Scripts\gcc.bat -mdll -O -Wall -IC:\Prog\Anaconda3\include -IC :\Prog\Anaconda3\include -c testcython.c -o build\temp.win-amd64-3.4\Release\tes tcython.o writing build\temp.win-amd64-3.4\Release\testcython.def C:\Prog\Anaconda3\Scripts\gcc.bat -shared -s build\temp.win-amd64-3.4\Release\te stcython.o build\temp.win-amd64-3.4\Release\testcython.def -LC:\Prog\Anaconda3\l ibs -LC:\Prog\Anaconda3\PCbuild\amd64 -lpython34 -lmsvcr100 -o build\lib.win-amd 64-3.4\testcython.pyd

However, as soon as there is an import or a print statement in the .pyx file, the produced .pyd file makes Python crash. For example, if testcython.pyx contains

def say_hello(): print('Hello')

it gives

In [1]: import testcython # no crash here In [2]: testcython.say_hello() Hello

Here the "Python.exe has stopped working" window pops up and it's finished.

In that kind of situation (crash without error log, segmentation fault I suppose), what can I do to understand the problem?

Does anyone understand what happens here with Cython, Python 3 (Anaconda3) under Windows?

I am quite stuck and really need some help on this...

PS: This problem is specific to Python 3 (Anaconda) under Windows. No problem with Python 2.7 (Anaconda) under Windows and no problem with Python 3 (Anaconda) under Linux.

--

---
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.
Tim Jones | 22 Jun 12:11 2014
Picon

Major issues with SDL2 on Mavericks!

Hi all,

Not posted here before, so hi!

I'm having some trouble getting my SDL2 app working with Cython in OS X.  The versions are:

 - OS X Mavericks (10.9)
 - Python 3.4 (installed into /Library/Frameworks)
 - Cython 0.20.2
 - SDL2 2.0.3 (installed into /Library/Frameworks)

The cython code snippet is as follows:

cdef class Display:

    def __init__(self):

        if SDL_Init(SDL_INIT_VIDEO) != 0:
            raise SDLError

        n = SDL_GetNumRenderDrivers()
        print(n)
        cdef SDL_RendererInfo renderer_info
        for ri in range(n):
            SDL_GetRenderDriverInfo(ri, &renderer_info)
            print(renderer_info.name)


        window = SDL_CreateWindow("Hello Lena!", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 512, 512,
                                  SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL)

        if window == NULL:
            raise SDLError

        renderer = SDL_CreateRenderer(window, 1, SDL_RENDERER_ACCELERATED)
        if renderer == NULL:
            raise SDLError

        surface = SDL_LoadBMP('/Users/Tim/Downloads/lena.bmp')
        if surface == NULL:
            raise SDLError

        texture = SDL_CreateTextureFromSurface(renderer, surface)
        if surface == NULL:
            raise SDLError

        SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255)
        SDL_RenderClear(renderer)
        SDL_RenderCopy(renderer, texture, NULL, NULL)
        SDL_RenderPresent(renderer)
        with nogil:
            SDL_Delay(120000)
        SDL_DestroyTexture(texture)
        SDL_DestroyRenderer(renderer)
        SDL_DestroyWindow(window)
        SDL_Quit()

When I compile and run my Cython on Windows the above works fine, the window pops up and everything works as expected.  However, when I compile and run on OS X all I get is a 'Not Responding' bouncing python icon for 120000 seconds! Its very frustrating as a raw C equivalent program works as expected in OS X...

I've tried absolutely loads of things, with no success! Any clues extremely welcome...

Thanks in advance
Tim

--

---
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.
Alex Meakins | 21 Jun 17:45 2014
Picon

request for a <at> cython.nochecks(True) compilation option - tuple access etc has a None check I can't get rid of!

Hello, I'm having a small problem with the code generated when I'm unpacking a tuple in a reasonably time critical bit of code. I've optimised the unpacking as far as I believe I can, but I can't get rid of a None check that is added when the tuple is accessed. In my code I can absolutely guarantee the tuple access is valid so there is no need for the check. This is the code in question - note I have <at> cython.boundscheck(False) set for the enclosing function:

intersection = self.world_box.full_intersection(ray)
hit = intersection[0]
min_range = intersection[1]
max_range = intersection[2]

the full_intersection method is as follows:

cpdef tuple full_intersection(self, Ray ray):

    cdef double front_intersection, back_intersection
    cdef bint hit
   
    :
    :

    return (hit, front_intersection, back_intersection)

Cython 0.20 generates the following code:

intersection = self.world_box.full_intersection(ray)

  __pyx_t_1 = ((struct __pyx_vtabstruct_7raysect_4core_12acceleration_11boundingbox_BoundingBox *)__pyx_v_self->world_box->__pyx_vtab)->full_intersection(__pyx_v_self->world_box, __pyx_v_ray, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_intersection = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

 hit = intersection[0]

  if (unlikely(__pyx_v_intersection == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_4 = __Pyx_PyObject_IsTrue(PyTuple_GET_ITEM(__pyx_v_intersection, 0)); if (unlikely(__pyx_t_4 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_hit = __pyx_t_4;

min_range = intersection[1]

  if (unlikely(__pyx_v_intersection == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_5 = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_v_intersection, 1)); if (unlikely((__pyx_t_5 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_min_range = __pyx_t_5;

 max_range = intersection[2]

  if (unlikely(__pyx_v_intersection == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_5 = __pyx_PyFloat_AsDouble(PyTuple_GET_ITEM(__pyx_v_intersection, 2)); if (unlikely((__pyx_t_5 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_max_range = __pyx_t_5;


The if .... == PyNone calls are entirely unnecessary, however I can't find a way to remove them.

Would it be possible for you to provide a general cython.nochecks(True) compilation options that entirely removes all checks (bounds, wraparound, type)? This would be a great help to me as I can keep the code neat and fast. Such an option would also be very useful for getting rid of the numerous boundscheck and wraparound disabling options I have endlessly scattered in my core code.

I'll probably make this particular part of the code faster by replacing the tuple, however this is a general problem I'm having with accessing python types in known safe code.

--

---
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.
CJ Carey | 19 Jun 22:44 2014
Picon

Sharing memoryviews with prange

I'm trying to parallelize some code, and I've gotten to a point of confusion: http://stackoverflow.com/questions/24315302/parallelizing-with-cython-memoryviews

I suspect there's something simple that I'm missing, but I can't find it.

--

---
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.
Robert Bradshaw | 17 Jun 06:39 2014
Picon

Cython bugfix release

I just pushed another bugfix release for the 0.20.x line, available on
github, cython.org, or and pypi.

== Features added ==

* Some optimisations for set/frozenset instantiation.
* Support for C++ unordered_set and unordered_map.

== Bugs fixed ==

* Access to attributes of optimised builtin methods (e.g.
[].append.__name__) could fail to compile.
* Memory leak when extension subtypes add a memory view as attribute
to those of the parent type without having Python object attributes or
a user provided dealloc method.
* Compiler crash on readonly properties in "binding" mode.
* Auto-encoding with c_string_encoding=ascii failed in Py3.3.
* Crash when subtyping freelist enabled Cython extension types with
Python classes that use __slots__.
* Freelist usage is restricted to CPython to avoid problems with other
Python implementations.
* Memory leak in memory views when copying overlapping, contiguous slices.
* Format checking when requesting non-contiguous buffers from
cython.array objects was disabled in Py3.
* C++ destructor calls in extension types could fail to compile in clang.
* Buffer format validation failed for sequences of strings in structs.
* Docstrings on extension type attributes in .pxd files were rejected.

== Contributors ==

Andreas van Cranenburgh
Ian Bell
Lars Buitinck
Martin Quarda
Mikhail Korobov
Robert Bradshaw
Stefan Behnel

--

-- 

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

Wenxiang He | 17 Jun 05:49 2014
Picon

issue only cython3

I try to make the example of logging module of [Learning Cython Programming] using cython3,

I got these errors.

cython3 logger.pyx
gcc -g -O2 -fpic -c logger.c -o logger.o `python3.3-config --includes`
gcc -g -O2 -fpic -c main.c -o main.o `python3.3-config --includes`
In file included from main.h:31:0,
                 from main.c:1:
logger.h: In function ‘DL_IMPORT’:
logger.h:15:32: error: expected declaration specifiers before ‘initLogging’
 __PYX_EXTERN_C DL_IMPORT(void) initLogging(char *);
                                ^
logger.h:16:32: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pyinfo’
 __PYX_EXTERN_C DL_IMPORT(void) pyinfo(char *);
                                ^
logger.h:17:32: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pydebug’
 __PYX_EXTERN_C DL_IMPORT(void) pydebug(char *);
                                ^
logger.h:18:32: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘pyerror’
 __PYX_EXTERN_C DL_IMPORT(void) pyerror(char *);
                                ^
main.c:6:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
 {
 ^
main.c:34:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
 {
 ^
In file included from main.h:31:0,
                 from main.c:1:
logger.h:15:16: error: old-style parameter declarations in prototyped function definition
 __PYX_EXTERN_C DL_IMPORT(void) initLogging(char *);
                ^
main.c:60:1: error: expected ‘{’ at end of input
 }
 ^
make: *** [all] 错误 1

here is Makefile

all:
    cython3 logger.pyx
    gcc -g -O2 -fpic -c logger.c -o logger.o `python3.3-config --includes`
    gcc -g -O2 -fpic -c main.c -o main.o `python3.3-config --includes`
    gcc -g -O2 -o example main.o logger.o `python3.3-config --libs`

clean:
    rm -f example logger.c *.o

Why it could make successfully in python2, not in python3. 

--

---
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.
Stefan Behnel | 16 Jun 15:59 2014
Picon

JyNI - C-API emulation for Jython

Hi,

it looks like there is a C-API emulation for Jython on the way:

http://jyni.org/

https://github.com/Stewori/JyNI

I haven't tried it yet, and I'm sure Cython modules won't work with its
current state, but the effort I put into making them run in PyPy's cpyext
should pay off here, so we might at some point have a third backend to target.

This also reminded me of IronClad, the C-API layer for IronPython. I looked
it up, but it seems to have died some years ago, with no current effort to
improve it or even just make it work with the latest IronPython releases.

https://groups.google.com/d/msg/c-extensions-for-ironpython/SrIesUIh1Gw/cBQG1FMt0AUJ

https://code.google.com/p/ironclad/

Not sure if it's still worth trying to make that run in Cython.

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.


Gmane