Stefan Behnel | 21 Feb 2013 07:46
Picon
Favicon

[Cython] Sage build broken

Hi,

I just noticed that the Sage build is broken:

"""
gcc -pthread -shared -L/jenkins/sage/sage-5.2/local/lib
build/temp.linux-x86_64-2.7/sage/rings/polynomial/polydict.o
-L/jenkins/sage/sage-5.2/local/lib -L/release/merger/sage-5.2/local/lib
-lcsage -lstdc++ -lntl -lpython2.7 -o
build/lib.linux-x86_64-2.7/sage/rings/polynomial/polydict.so

/usr/bin/ld: build/temp.linux-x86_64-2.7/sage/rings/polynomial/polydict.o:
relocation R_X86_64_PC32 against `__Pyx_PyDict_IterItems' can not be used
when making a shared object; recompile with -fPIC

/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
command 'gcc' failed with exit status 1
"""

Looks like a problem in Sage to me, the gcc command really lacks the -fPIC
here.

Stefan
Sturla Molden | 18 Feb 2013 19:32
Picon
Gravatar

[Cython] PR on refcounting memoryview buffers

As Stefan suggested, I have posted a PR for a better fix for the issue 
when MinGW for some reason emits the symbol "__synch_fetch_and_add_4" 
instead of generating atomic opcode for the __synch_fetch_and_add builtin.

The PR is here:
https://github.com/cython/cython/pull/185

The discussion probably belongs on this list instead og Cython user:

The problem this addresses is when GCC does not use atomic builtins and 
emits __synch_fetch_and_add_4 and __synch_fetch_and_sub_4 when Cython 
are internally refcounting memoryview buffers. For some reason it can 
even happen on x86 and amd64.

My PR undos Marks quick fix that always uses PyThread_acquire_lock on 
MinGW. PyThread_acquire_lock uses a kernel object (semaphore) on Windows 
and is not very efficient. I want slicing memoryviews to be fast, and 
that means PyThread_acquire_lock must go. My PR uses Windows API atomic 
function InterlockedAdd to implement the semantics of 
__synch_fetch_and_add_4 and __synch_fetch_and_sub_4 instead of using a 
Python lock.

Usually MinGW is configured to compile GNU atomic builtins correctly. I 
have yet to see a case where it is not. But obviously one user (JF 
Gallant) has encountered it. I don't think it is a MinGW specific 
problem, but currently it has only been seen on MinGW and the fix is 
MinGW specific (well, it should work on Cygwin too). But whenever MinGW 
does use atomic builtins it just uses them. So it incurs no speed 
penalty on well-behaved MinGW builds.

(Continue reading)

Dag Sverre Seljebotn | 13 Feb 2013 20:04
Picon
Picon
Gravatar

[Cython] cldoc

Just a heads up about this project; there's bound to be something useful 
there for auto-wrapping.

http://jessevdk.github.com/cldoc/

Dag Sverre
David Hirschfeld | 9 Feb 2013 14:03
Picon

[Cython] Fwd: MemoryView.is_f_contig sometimes not defined?

Reposting because I think my original got blocked because of
attachments. Apologies if this appears twice.

I want to allow arbitrary C/F contiguous arrays as input to a cdef
class so I can dispatch to a different calculation method in each
case, avoiding a potentially costly copy.
Unfortunately, it appears that cython is generating incorrect code.
The following minimal example reproduces the problem:

cimport cython

cdef class TestContig:

    cdef cython.bint contig

    def __init__(self, double[:,:] y):
        if y.is_c_contig():
            self.contig = 1
        elif y.is_f_contig():
            self.contig = 1
        else:
            self.contig = 0

    property contig:
        def __get__(self):
            return self.contig

#

C:\temp> python setup.py build_ext --inplace
(Continue reading)

Stefan Behnel | 9 Feb 2013 10:44
Picon
Favicon

[Cython] How does a fused function differ from an overloaded function?

Hi,

I noticed that Cython currently fails to do this:

   cdef int (*int_abs)(int x)
   cdef object py_abs
   py_abs = int_abs = abs

Here, abs() is an overloaded function with a couple of C signatures (fabs()
and friends) and a Python signature (the builtin). While there is code in
NameNode.coerce_to() that figures out that the RHS can be replaced by the
Python builtin, the same is lacking for the general case of overloaded entries.

While working on fixing this problem (and after turning ProxyNode into an
actual node proxy when it comes to coercion), I thought it would be a good
idea to make NameNode generally aware of alternative entries and just build
a new NameNode with the right entry in its coerce_to() method. Then I
noticed that the generic coerce_to() contains this code:

    if src_type.is_fused or dst_type.is_fused:
        # See if we are coercing a fused function to a pointer to a
        # specialized function
        if (src_type.is_cfunction and not dst_type.is_fused and
                dst_type.is_ptr and dst_type.base_type.is_cfunction):

            dst_type = dst_type.base_type
            for signature in src_type.get_all_specialized_function_types():
                if signature.same_as(dst_type):
                    src.type = signature
                    src.entry = src.type.entry
(Continue reading)

Dave Hirschfeld | 8 Feb 2013 17:54
Picon

[Cython] Fused types don't work with cdef classes?

Is this a bug?
The following code fails to compile on windows VS2012, 32bit Python2.7 with a 
recent 0.19-pre github cython:

cimport cython

ctypedef fused char_or_float:
    cython.char
    cython.float

cdef class FusedExample:

    def __init__(self, char_or_float x):
        pass
#

Resulting in the following exception:

C:\temp>C:\dev\bin\Python27\python.exe setup.py build_ext --inplace --
compiler=msvc
Compiling example.pyx because it changed.
Cythonizing example.pyx
running build_ext
building 'example' extension
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\BIN\cl.exe 
    /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I. 
    -IC:\dev\code\Gazprom.MT\pricing\gazprom\mt\pricing 
    -IC:\dev\bin\Python27\lib\site-packages\numpy\core\include 
    "-IC:\dev\lib\Intel\Composer XE 2013\mkl\include" 
    -IC:\dev\bin\Python27\include 
(Continue reading)

Stefan Behnel | 7 Feb 2013 18:32
Picon
Favicon

[Cython] analyse_types() refactoring

Hi,

I finally found the time to refactor the analysis phase.

https://github.com/cython/cython/commit/f9c385e08401ed96b5b0afb8411480037dc772b9

The methods now return a node, which allows them to replace themselves with
a different implementation.

Note that the relatively large code impact of this change also means that
you might easily run into merge conflicts with your own local changes, so
here's how to fix them. The transformation pattern is pretty straight
forward. The "analyse_types()" method returns "self", unless it wants to
replace itself, i.e. this

    def analyse_types(self, env):
        self.index.analyse_types(env)

becomes

    def analyse_types(self, env):
        self.index = self.index.analyse_types(env)
        return self

The "analyse_target_types()" method works the same, but because it calls
"analyse_types()" internally in most cases, it's more likely to look like this:

    def analyse_target_types(self, env):
        self.analyse_types(env)
        if self.type.is_pyobject:
(Continue reading)

Samuele Kaplun | 7 Feb 2013 10:16
Picon
Picon

[Cython] Possible bug when using cython -Wextra

Hello,

I am not sure if this is a bug or it is the intended behaviour, however, 
consider for example this snippet:

[...]
def test():
    cdef int i
    for i from 0 <= i < 10:
        print "foo"
[...]

If I save it into x.pyx and compile it with:

$ cython -Wextra x.pyx

I obtain the warning:
[...]
warning: x.pyx:2:13: Unused entry 'i'
[...]

IMHO, this is a false positive since the i variable is indeed used as a 
counter in the loop. I guess cython considers it unused due to the fact that 
it does not appear on the right hand side of an assignment nor it is further 
used as an argument in a function, isn’t it?

Best regards,
	Samuele
--

-- 
Samuele Kaplun
(Continue reading)

J Robert Ray | 5 Feb 2013 20:56
Picon

[Cython] SIGSEGV in __Pyx_CyFunction_traverse

I was getting a crash during module init of a cython module if a garbage collection happens between a call to __Pyx_CyFunction_InitDefaults and the code to populate the defaults.

The attached patch fixes the crash. This bug affects at least Cython 0.18 and 0.17.1.

__Pyx_CyFunction_InitDefaults was not completely zeroing the newly allocated 'defaults' buffer.
Attachment (cython.patch): application/octet-stream, 540 bytes
<div><div dir="ltr">
<span>I was getting a crash during module init of a cython module if a garbage collection happens between a call to __Pyx_CyFunction_InitDefaults and the code to populate the defaults.</span><div>

<br>
</div>
<div>The attached patch fixes the crash. This bug affects at least Cython 0.18 and 0.17.1.</div>
<div><br></div>

<div>__Pyx_CyFunction_InitDefaults was not completely zeroing the newly allocated 'defaults' buffer.</div>
</div></div>
David Roe | 5 Feb 2013 01:28
Picon

[Cython] Two generators in one function

Hi everyone,
I ran into the following problem using Cython 0.17.4 (current version of Sage).

If you try to compile a file with the following function in it:

def test_double_gen(L):
    a = all(x != 0 for x in L)
    b = all(x != 1 for x in L)
    return a and b

you get errors from the Cython compiler about 'genexpr' being redefined.

Error compiling Cython file:
------------------------------------------------------------
...


def test_double_gen(L):
    a = all(x != 0 for x in L)
    b = all(x != 1 for x in L)
             ^
------------------------------------------------------------

cython_test.pyx:5:14: 'genexpr' already declared

Error compiling Cython file:
------------------------------------------------------------
...


def test_double_gen(L):
    a = all(x != 0 for x in L)
             ^
------------------------------------------------------------

cython_test.pyx:4:14: Previous declaration is here

Error compiling Cython file:
------------------------------------------------------------
...


def test_double_gen(L):
    a = all(x != 0 for x in L)
    b = all(x != 1 for x in L)
             ^
------------------------------------------------------------

cython_test.pyx:5:14: 'genexpr' redeclared

Are you currently only able to use one inline generator pre function?
David

<div><div dir="ltr">
<div>
<div>
<div>
<div>
<div>Hi everyone,<br>
</div>I ran into the following problem using Cython 0.17.4 (current version of Sage).<br><br>
</div>If you try to compile a file with the following function in it:<br><br>def test_double_gen(L):<br>&nbsp;&nbsp;&nbsp; a = all(x != 0 for x in L)<br>&nbsp;&nbsp;&nbsp; b = all(x != 1 for x in L)<br>&nbsp;&nbsp;&nbsp; return a and b<br><br>
</div>you get errors from the Cython compiler about 'genexpr' being redefined.<br><br>Error compiling Cython file:<br>

------------------------------------------------------------<br>...<br><br><br>def test_double_gen(L):<br>&nbsp;&nbsp;&nbsp; a = all(x != 0 for x in L)<br>&nbsp;&nbsp;&nbsp; b = all(x != 1 for x in L)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^<br>------------------------------------------------------------<br><br>cython_test.pyx:5:14: 'genexpr' already declared<br><br>Error compiling Cython file:<br>------------------------------------------------------------<br>...<br><br><br>def test_double_gen(L):<br>&nbsp;&nbsp;&nbsp; a = all(x != 0 for x in L)<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^<br>------------------------------------------------------------<br><br>cython_test.pyx:4:14: Previous declaration is here<br><br>Error compiling Cython file:<br>------------------------------------------------------------<br>

...<br><br><br>def test_double_gen(L):<br>&nbsp;&nbsp;&nbsp; a = all(x != 0 for x in L)<br>&nbsp;&nbsp;&nbsp; b = all(x != 1 for x in L)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^<br>------------------------------------------------------------<br><br>cython_test.pyx:5:14: 'genexpr' redeclared <br><br>
</div>Are you currently only able to use one inline generator pre function?<br>
</div>David<br><div><div><br></div></div>
</div></div>
g b | 31 Jan 2013 17:38
Picon
Favicon

[Cython] embedsignature issue (with both Sphinx and Epydoc)


Hello,

I tried the "embedsignature=True" compilation directive on both Sphinx and Epydoc and it resulted in :
I had to pass a more python compliant signature in the very first line of the docstring for each method of my classes.
See this thread : http://stackoverflow.com/questions/14616882/how-to-make-epydoc-show-parameters-in-function-prototype/14617794#14617794.

Exported signature is of the form : PyLabNode.SetNetwork(self, PyLabNetwork net) 
This has 2 drawback : The dotted notation for the class prefix and the typed parameter.

It seems to me that its feature doesn't do what it was designed for. Or I'm I missing something...

Thanks.


Gmane