Adam Callison | 25 May 22:57 2015

include statement

Hi all,

In the documentation for the cython 'include' statement (http://docs.cython.org/src/userguide/language_basics.html#the-include-statement), it is claimed that "the included file can contain any complete statements or declarations that are valid in the context where the include statement appears, including other include statements. The contents of the included file should begin at an indentation level of zero, and will be treated as though they were indented to the level of the include statement that is including the file.".

However, when I attempt to use it:

cdef int init_psi(double * psi, s_params params):
    include
"initpsi.pxi"
   
return 0

I am told "include statement not allowed here".

The file "initpsi.pxi" begins at 0 indentation, as instructed. What am I doing wrong?

Adam



--

---
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.
MinRK | 25 May 22:11 2015
Picon

Python 3.5 support

I’ve been testing with the Python 3.5 beta, and there appears to be something preventing Cython modules from being importable.

Compilation runs fine, but when I try to import the compiled module:

python -c 'import Cython.Runtime.refnanny'

I get:

ImportError: dynamic module does not define module export function (PyInit_.refnanny)

which suggests it is related to PEP-489.

When I do a simpler test with tst.pyx (after installing Cython with --no-cython-compile):

# tst.pyx from libc.stdio cimport printf def p(int i): printf("%d\n", i)

And compile manually, it seems to work:

cython tst.pyx clang -fpic `python3.5-config --cflags` -c tst.c -o tst.o^C clang -shared -o tst.so tst.o `python3.5-config --ldflags` python -c 'import tst; tst.p(5)'

But all Cython Extensions get the same export error above.

This is on OS X 10.10 with the Python 3.5 beta bdist from Python.org.

Is this a known issue? Is anyone successfully using Cython with Python 3.5?

-MinRK

--

---
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.
pebo.groups | 25 May 14:51 2015
Picon

Cross-compile cython in buildroot

Hi,

I had some troubles to cross-compile Cython in buildroot, but in the end was able to do it. I wanted to ask here if it makes sense to integrate the solution in Cython somehow (although I am not really sure how...)...

The basic problem was the "build_ext" step in "setup.py", which loads the Cython libraries from the "build" direcory. This directory contains binaries for the target architecture, so they cannot be loaded when I compile on the host (I get an error about the wrong architecture). As I have to seperately compile and install cython for the host anyway, it is save to just fall back to the host Cython. In my case I just had to comment line 186 in the setup.py, which adds the "build" path to sys.path:

https://github.com/cython/cython/blob/master/setup.py#L186

The question is how to detect if cython is cross-compiled; then one could just add one "if" statement before the "sys.path.append". Compiling the cython for the host was straight-forward, btw, I just followed the buildroot documentation for Python packages.

Peter

--

---
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.
Giuseppe Attardi | 24 May 15:53 2015
Picon

compiler crash (again)

On May 21st I submitted a report on the compiler crashing.
I added a complete example of code for reproducing the error.
So far I got no answer.
Can somebody at least confirm with an acknowledgement that the bug exists and is reproducible?

Thank you

--

--

---
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.
Andrea Bedini | 22 May 10:58 2015
Picon

npy_bool

Hi people,

I am having some issues with numpy arrays of bools.

Say I have the following in tmp.pyx

import cython
import numpy

cimport numpy
cimport numpy as cnp

from numpy cimport npy_bool, npy_int

cnp.import_array()

ctypedef fused array_type:
    npy_bool[:]
    npy_int[:]

def fuffy(array_type array):
    pass


If I call it with

tmp.fuffy(numpy.array([True, False], dtype=numpy.bool))

It says 'No matching signature found' but it I call it with

tmp.fuffy(numpy.array([True, False], dtype=numpy.uint8))


it works. Note that npy_bool is actually identical to npy_uint8 (same typedef).

The signatures tmp.fuffy.__signatures__ correctly say

{'npy_bool[:]': <cyfunction fuffy at 0x112ede938>,
 
'npy_int[:]': <cyfunction fuffy at 0x112edeee8>}


Any help on solving this?

 
Thanks,
Andrea

--

---
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 | 22 May 08:52 2015
Picon

Current master fails to compile

Current master fails with following error:

C:\temp\cython-master\Cython\Compiler\Scanning.c(1946) : error C2099: initializer is not a constant
C:\temp\cython-master\Cython\Compiler\Scanning.c(1946) : warning C4047: 'initializing' : 'PyObject *' differs in levels of indirection from 'PyObject **'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\Bin\\cl.exe' failed with exit status 2

Source line is:
static __Pyx_CachedCFunction __pyx_umethod_PyList_Type_pop = {(PyObject*)&PyList_Type, &__pyx_n_s_pop, 0, 0, 0};

This problem seems to be introduced with commit "cache underlying PyCFunction of calls to unbound methods of builtins …".

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.
Tzu-ping Chung | 21 May 12:17 2015
Picon

Error running tox

Hi,

Just tried running tox on master, but all my invocations ended with the error

    cc1: error: argument to '-O' should be a non-negative integer, 'g', 's' or 'fast'
        /home/hbank/Documents/cython/cython/.tox/py34/lib/python3.4/site-packages/setuptools/dist.py:282: UserWarning: Normalizing '0.23dev' to '0.23.dev0'
          normalized_version,
        error: command 'i686-linux-gnu-gcc' failed with exit status 1

while "python runtests.py -vv" runs without a problem (there are failed tests, but that’s another problem).

After inspecting tox.ini I think I know the problem. The line

    setenv = CFLAGS="-O0 -ggdb"

results in "0 -ggdb" being treated as value for the "-O" flag, but really they should be two separated flags "-O0" and "-ggdb". After changing it to

    setenv = CFLAGS=-O0 -ggdb

tox runs as expected.

Is there anyone having the same problem, and is my solution legit? Thanks.


Regards,

TP

--

---
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.
Oskar Maier | 19 May 17:15 2015
Picon

Importing variable into Cython declared in other Cython module.

Dear Cython mailinglist,

I am pretty sure I just overlooked something, but I simply fail to succeed to import a variable from one Cython module into another. I hope the following toy example illustrates my problem.

First, I have the (external and unalterable) library, which I have as as compiled library.so module with associated library.pxd Cython header file:

library.pyx
--------------
cdef double VAR1 = 1.0
cdef double VAR2 = 2.0
   
library.pxd
--------------
cdef double VAR1



Then there is my own application, with two possible includes:

application.pyx
---------------------
from library cimport VAR1

A: from library cimport VAR2
B: cdef extern double VAR2

print VAR1
print VAR2


VAR1 prints fine, VAR2 not. Using A, Cython fails to compile the file, claiming that
> application.pyx:2:0: 'VAR2.pxd' not found
> Name 'VAR2' not declared in module 'library'
which seems reasonable to me, as cimport causes Cython to look up the imported object in the header file library.pxd.

Using solution B, on the other hand, compiles fine with Cython and gcc, but causes an error upon importing the module
> ./application.so: undefined symbol: VAR2

I am aware that Cython must somehow now about the definition of VAR2, but not sure how to point it to it. The application.so is in the same folder as the application.pyx, btw.

Best,
Oskar

--

---
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.
Oskar Maier | 20 May 13:24 2015
Picon

Using imported cdef class without gil in another cython module

Dear cython-users mailing list,

I've lately been fighting with trying to use one Cython class (cdef extension type) defined in a compiled module from another. Is this at all possible? And if yes, how?

Toy-example
###########

Files
=====

lib.pxd
-------
cdef class Cla:
    cdef int a
    
lib.pyx
-------
cdef class Cla:
    def __cinit__(self, int a):
        self.a = a
        
app.pxd
-------
cdef extern class lib.Cla:
    cdef int a

cdef class Test:
    cdef Cla obj
    cdef void test(self) nogil
    
app.pyx
-------
cdef class Test:
    def __cinit__(self):
        self.obj = Cla(2)
    
    cdef void test(self) nogil:
        cdef Cla obj = self.obj


Error on `cython app.pyx`
=========================
Error compiling Cython file:
------------------------------------------------------------
...
cdef class Test:
    def __cinit__(self):
        self.obj = Cla(2)
    
    cdef void test(self) nogil:
        cdef Cla obj = self.obj
            ^
------------------------------------------------------------

app.pyx:6:13: Assignment of Python object not allowed without gil

Error compiling Cython file:
------------------------------------------------------------
...
cdef class Test:
    def __cinit__(self):
        self.obj = Cla(2)
    
    cdef void test(self) nogil:
        ^
------------------------------------------------------------

app.pyx:5:9: Function declared nogil has Python locals or temporaries

Error compiling Cython file:
------------------------------------------------------------
...
cdef class Test:
    def __cinit__(self):
        self.obj = Cla(2)
    
    cdef void test(self) nogil:
        cdef Cla obj = self.obj
                          ^
------------------------------------------------------------

app.pyx:6:27: Creating temporary Python reference not allowed without gil



Is there some way use the cython (cdef, cpdef) parts of the class Cla without gil?  Maybe by declaring Cla public in lib.pxd and treating is as C-function?

Best,
Oskar

--

---
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.
Giuseppe Attardi | 16 May 10:25 2015
Picon

Compiler crash

This file

cimport numpy as np
cdef class Converter(object):
    cdef np.ndarray[np.int_t,ndim=1] get_padding_left(self):
        return None
cdef class Trainer(object):
    def __init__(self, Converter converter):
       self.padding_left = converter.get_padding_left()

compiles correctly, while if I change the last line to

       padding_left = converter.get_padding_left()

the compiler crashes:

foo.pyx:13:21: Compiler crash in AnalyseExpressionsTransform

ModuleNode.body = StatListNode(foo.pyx:2:0)
StatListNode.stats[3] = StatListNode(foo.pyx:10:5)
StatListNode.stats[0] = CClassDefNode(foo.pyx:10:5,
    as_name = u'Trainer',
    class_name = u'Trainer',
    module_name = u'',
    visibility = u'private')
CClassDefNode.body = StatListNode(foo.pyx:12:4)
StatListNode.stats[0] = DefNode(foo.pyx:12:4,
    modifiers = [...]/0,
    name = u'__init__',
    num_required_args = 2,
    py_wrapper_required = True,
    reqd_kw_flags_cname = '0',
    used = True)
File 'Nodes.py', line 420, in analyse_expressions: StatListNode(foo.pyx:13:49)
File 'Nodes.py', line 4685, in analyse_expressions: SingleAssignmentNode(foo.py\
x:13:49)
File 'Nodes.py', line 4800, in analyse_types: SingleAssignmentNode(foo.pyx:13:4\
9)
File 'ExprNodes.py', line 1768, in analyse_target_types: NameNode(foo.pyx:13:21\
,
    cf_is_null = True,
    cf_maybe_null = True,

--

---
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 | 19 May 04:29 2015
Picon

boundscheck=False not implemented for memoryview slicing?

Consider the following example:

#cython: boundscheck=False, wraparound=False
cdef foo(double[:, ::1] t):
    cdef int i, j
    for i in range(t.shape[0]):
        bar(t[i])

cdef bar(double[::1] t):
    pass

A quick look at the output of cython -a (v0.22) shows that there is still bounds-checking when creating the t[i] slice.  Is there a way to disable that check too?

Thanks,

Antony Lee

--

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