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.

Björn Dahlgren | 16 Jun 14:21 2014
Picon

Non-type template arguments

Hi I am trying to wrap some C++ functions which take a mix of typename and non-type template arguments.

Here is minimal (non-)working example:

https://gist.github.com/bjodah/3cc42d9c5f70a321af29

I've tried [T, int n] and [T, int] in the pxd but I find no info in the docs on whether this is supported (is it?).

Thanks!
/Björn

--

---
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.
Yuxiang Wang | 13 Jun 18:45 2014
Picon

Cython in Win64 with TDM-GCC reports "'utf-8' codec can't decode byte 0x83 in position 1: invalid start byte"

Hi all,

I am using Cython 0.20.1 with Python 3.3 in 64 bit Windows 7, with latest TDM-GCC installed.

Here is the test_cy.pyx file:

import numpy as np

cpdef func():
    cdef double [:] a = np.arange(10)
    return a

And then, I used this setup_test.py:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import numpy as np

extensions = [
    Extension('test_cy', ['test_cy.pyx'], include_dirs = [np.get_include()]),
    ]

setup(
    ext_modules = cythonize(extensions)
    )

In the command console, I used:

python setup_test.py build_ext --inplace --compiler=mingw32

And it compiled fine. However, when I tried to import the module in python using import test_cy, it says:

---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-2-533d835504db> in <module>()
----> 1 import test_cy

X:\WorkFolder\DataAnalysis\lw9pg\mol\stringsource in init test_cy (test_cy.c:13209)()

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 1: invalid start byte


Could anyone help me with this?

Thank you!

Shawn

--

---
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.
Zahra Sheikh | 12 Jun 17:05 2014
Picon

Inconsistency of cython_gsl function with a class instance


Hi everybody, I am trying to use cython_GSL in a code I have written, but  I faced a problem. I just gave here an example of my problem. Suppose I have a class with bunch of instance and in one of them I  want to use gsl_integration module to speed up the performance of my code. But the problem comes from this fact that the integrand I am using for GSL is inside the class and it got confused when it tries to declare the integrand for GSL. My code is as following: 

import cython cimport cython import numpy as np cimport numpy as np from cython_gsl cimport * ctypedef double * double_ptr ctypedef void * void_ptr from math import * cdef class Foo(object): def __init__(self, double a=1.2, double b=0.6): self.a = a self.b = b def _integrand(self,double x) nogil: cdef double self.a = (<double_ptr> params)[0] cdef double self.b = (<double_ptr> params)[1] return self.a*log(x)+self.b/x**3 def whole(self, double upper_limit=10,double lower_limit=0): cdef gsl_integration_workspace * w cdef double result, error, expected, alpha w = gsl_integration_workspace_alloc (1000) expected = -4.0 params[0] = self.a params[1] = self.b cdef gsl_function F F.function = &self._integrand F.params = params gsl_integration_qags (&F, lower_limit,upper_limit , 0, 1e-7, 1000, w, &result, &error) return result,error

the error message when I wanted to build it was as following :

Cannot assign type double (Foo, double, void *) nogil' to 'double (*)(double, void *) nogil

Could something like  <at> staticmethod  or sending the class pointer in the void parameter help to solve the problem? 

Regards,
Zahra 

--

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