Michael Hamann | 22 Aug 17:06 2014

Templated class causes duplicate __pyx_convert_vector_to_py_double declaration

Hi,

when I try to use a templated C++ class that returns a vector<double> in 
Cython, I get a (gcc) compilation error because of a duplicate 
__pyx_convert_vector_to_py_double declaration when there is more than one 
function returning a vector[double]. I've put together a minimal example at 
https://gist.github.com/michitux/1650cd0e1474c8a59a14. The problem does not 
exist when I declare the cpp class in Cython with fixed template parameters (as 
shown in fixedTest.pyx).

I'm using Cython 0.20.1 with gcc 4.8.1 and Python 3.3.5.

Michael

--

-- 

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

larsmans | 22 Aug 14:37 2014
Picon

cythonize doesn't seem to get language="c++"

Hi all,


I was using Cython 0.20.2 to compile some C++ code, and it looks like cythonize doesn't work as documented. The docs [1] say I should be able to compile this:


cdef extern:
    cppclass Foo:
        Foo()

def hello():
    cdef Foo *foo = new Foo()


... using:


from distutils.core import setup
from Cython.Build import cythonize

setup(
  ext_modules = cythonize("hello.pyx", language="c++"),
)


... but that fails:


Error compiling Cython file:
------------------------------------------------------------
...
cdef extern:
    cppclass Foo:
        Foo()

def hello():
    cdef Foo *foo = new Foo()
                       ^
------------------------------------------------------------

hello.pyx:6:24: Operation only allowed in c++


I.e., language="c++" isn't being picked up and I need to use a magic "distutils: language = c++" comment in the source file. Is this a known issue?

Regards,
Lars


[1] http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html#specify-c-language-in-setup-py

--

---
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.
Jorge Onieva | 20 Aug 18:17 2014
Picon

Problem with XCode 5 and Canopy

Hi!

It seems there is a problem when using Cython with Mavericks 10.9, XCode 5 and Entough Canopy. I am building a Cython wrapper for a cpp library. Everything works fine if I use Apple's default Python-Cython version, but not if I use Canopy. I guess it's a problem related with the use of different versions of the compiler, I'm wondering if someone has solved it. These are my Python/Cython versions:
- "Canopy":  Enthought Canopy Python 2.7.6 | 64-bit | (default, Jun  4 2014, 16:42:26) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin.  Cython version 0.20.2
- "Apple": Python 2.7.5 (default, Mar  9 2014, 22:15:05)  [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin.  Cython version 0.20.2


When I install Cython as a Canopy's package, I have realised that the commands that the compilers use when building Cython modules are different, and this module crashes when I try to import it in Python. In concrete, I have realised that the problem seems to come from the first command, when building the .o library. 

I have also isolated one of the symbols that is failing when doing the Python import. 

These are the data that I have collected so far that I think they can be useful:

- "Canopy" commands:
/usr/bin/cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -DNDEBUG -g -O3 -arch x86_64 -I/Users/Jorge/Projects/BWH/CIP/Common/ -I/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/include/python2.7 -c /Users/Jorge/Projects/BWH/CIP/cip_python/wrap_ChestConventions.cpp -o build/temp.macosx-10.6-x86_64-2.7/Users/Jorge/Projects/BWH/CIP/cip_python/wrap_ChestConventions.o  -stdlib=libstdc++ -mmacosx-version-min=10.6

/usr/bin/c++ -bundle -undefined dynamic_lookup -g -arch x86_64 -headerpad_max_install_names -arch x86_64 build/temp.macosx-10.6-x86_64-2.7/Users/Jorge/Projects/BWH/CIP/cip_python/wrap_ChestConventions.o -L/Users/Jorge/Projects/BWH/CIP-Build/lib -lChestConventions -o /Users/Jorge/Projects/BWH/CIP/cip_python/ChestConventions.so

- "Apple" commands:
/usr/bin/cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -I/Users/Jorge/Projects/BWH/CIP/Common/ -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c /Users/Jorge/Projects/BWH/CIP/cip_python/wrap_ChestConventions.cpp -o build/temp.macosx-10.9-intel-2.7/Users/Jorge/Projects/BWH/CIP/cip_python/wrap_ChestConventions.o

/usr/bin/c++ -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.9-intel-2.7/Users/Jorge/Projects/BWH/CIP/cip_python/wrap_ChestConventions.o -L/Users/Jorge/Projects/BWH/CIP-Build/lib -lChestConventions -o /Users/Jorge/Projects/BWH/CIP/cip_python/ChestConventions.so
ld: warning: ignoring file /Users/Jorge/Projects/BWH/CIP-Build/lib/libChestConventions.a, file was built for archive which is not the architecture being linked (i386): /Users/Jorge/Projects/BWH/CIP-Build/lib/libChestConventions.a


- As an example, one of the symbols that are not found is my property "IsPhenotypeName". If I inspect the table of symbols in both versions, I cans ee:
- "Canopy":
      0000000000011990 T __ZNK3cip16ChestConventions15IsPhenotypeNameENSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE
               U __ZNK3cip16ChestConventions15IsPhenotypeNameESs
 
 - "Apple": 00000000000107c0 T __ZNK3cip16ChestConventions15IsPhenotypeNameENSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE
 
So I don't know why, but Python is looking for  "__ZNK3cip16ChestConventions15IsPhenotypeNameESs" symbol, which is undefined.


- If I inspect the dependencies with otool in the ChestConventions.so file, I have a difference:
- "Canopy": /usr/lib/libstdc++.6.dylib (compatibility version 1.0.0, current version 120.0.0)
- "Apple": /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)



- In case it helps, I can use both Canopy and Apple Python version and everything works fine, as far as I run the "Apple Cython" setup.


Any ideas?

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.
Guy Streeter | 19 Aug 22:31 2014
Picon

bogus "relative import" failure with Cython3/Python3

My .pxy file imports an external python module. This works fine on Cython/Python2, but on 3 I get:

SystemError: Parent module '' not loaded, cannot perform relative import

but this is not a relative import. Anybody else see this happen?

thanks,
--Guy

--

---
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.
ruoyu zhang | 17 Aug 02:03 2014
Picon

Cannot assign type 'double (*)(double)' to 'double (double)'

Cython can't compile following code, it reports Cannot assign type 'double (*)(double)' to 'double (double)'

from libc.stdio cimport printf cdef double square(double x): return x*x cdef void test1(double f(double), double x): printf("test1=%g\n", f(x)) cdef void test2(double (*f)(double), double x): printf("test2=%g\n", f(x)) def test(): cdef double(*fp)(double) fp = square test1(fp, 3.0) #<- this line report the error test2(fp, 3.0)

But the same C code works well.

--

---
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.
Daπid | 15 Aug 23:12 2014
Picon

Trouble compiling with gdb activated

Hi,

I have the attached setup.py script. I am trying to debug a program, but when I activate gdb, the compilation fails. But, if I remove gdb, recompile, and bring it back, it compiles without error. Is this a bug?

I am on Fedora using Cython 0.20.2 and 0.21.b1, yielding different errors.


Thanks,

/David.


import os
import numpy

from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize


extensions = [Extension('g_rC', ['g_rC.pyx'])]

module = 'g_rC'
setup(name=module,
      ext_modules=cythonize(extensions, gdb_debug=True),
      include_dirs=[numpy.get_include(),
                    os.path.join(numpy.get_include(), 'numpy')]
      )


#################################

Error code with gdb and Cython 0.20:

[david <at> LCARS functions]$ python setup.py build_ext --inplace
Compiling g_rC.pyx because it changed.
Cythonizing g_rC.pyx
Traceback (most recent call last):
  File "setup.py", line 18, in <module>
    ext_modules=cythonize(extensions, gdb_debug=True),
  File "/usr/lib64/python2.7/site-packages/Cython/Build/Dependencies.py", line 798, in cythonize
    cythonize_one(*args[1:])
  File "/usr/lib64/python2.7/site-packages/Cython/Build/Dependencies.py", line 898, in cythonize_one
    result = compile([pyx_file], options)
  File "/usr/lib64/python2.7/site-packages/Cython/Compiler/Main.py", line 608, in compile
    return compile_multiple(source, options)
  File "/usr/lib64/python2.7/site-packages/Cython/Compiler/Main.py", line 586, in compile_multiple
    result = run_pipeline(source, options, context=context)
  File "/usr/lib64/python2.7/site-packages/Cython/Compiler/Main.py", line 430, in run_pipeline
    pipeline = Pipeline.create_pyx_pipeline(context, options, result)
  File "/usr/lib64/python2.7/site-packages/Cython/Compiler/Pipeline.py", line 231, in create_pyx_pipeline
    options.output_dir)
AttributeError: 'CompilationOptions' object has no attribute 'output_dir'


For Cython 0.21:

[david <at> LCARS functions]$ python setup.py build_ext -i
Compiling g_rC.pyx because it changed.
Cythonizing g_rC.pyx
Traceback (most recent call last):
  File "setup.py", line 18, in <module>
    ext_modules=cythonize(extensions, gdb_debug=True),
  File "/usr/lib64/python2.7/site-packages/Cython/Build/Dependencies.py", line 812, in cythonize
    cythonize_one(*args[1:])
  File "/usr/lib64/python2.7/site-packages/Cython/Build/Dependencies.py", line 914, in cythonize_one
    result = compile([pyx_file], options)
  File "/usr/lib64/python2.7/site-packages/Cython/Compiler/Main.py", line 624, in compile
    return compile_multiple(source, options)
  File "/usr/lib64/python2.7/site-packages/Cython/Compiler/Main.py", line 602, in compile_multiple
    result = run_pipeline(source, options, context=context)
  File "/usr/lib64/python2.7/site-packages/Cython/Compiler/Main.py", line 436, in run_pipeline
    pipeline = Pipeline.create_pyx_pipeline(context, options, result)
  File "/usr/lib64/python2.7/site-packages/Cython/Compiler/Pipeline.py", line 231, in create_pyx_pipeline
    options.output_dir)
  File "/usr/lib64/python2.7/site-packages/Cython/Debugger/DebugWriter.py", line 45, in __init__
    self.output_dir = os.path.join(output_dir, 'cython_debug')
  File "/usr/lib64/python2.7/posixpath.py", line 77, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'

--

---
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.
Skip Montanaro | 15 Aug 17:43 2014
Picon

Problem moving Cython-based module from Linux to Solaris

I have a Cython-based module which has been working fine for me on Linux. Today I tried to migrate it to a Solaris system, and while it built okay, when I ran the corresponding program, it complained 

...
 File "voltau.pyx", line 132, in voltau.VolTau.configure (voltau.c:2464)
 File "/opt/local/lib/python2.7/site-packages/tradelink/snake/v11_2/snake/utils/clock.py", line 695, in connect
    (func.func_name, Clock.datetime()))
AttributeError: 'cython_binding_builtin_function_or_method' object has no attribute 'func_name'

I don't know how all this works under the covers. I do notice that on my Linux system 0.17.1 is the installed version, while 0.14.1 is installed on Solaris. I know neither of these are the latest-up-to-datest versions, but is it likely that a bug fix between those two versions solved the problem? (I will see about making 0.17.1 the default on our Solaris systems. Going beyond that will be a challenge in the near term.)

Thanks,

Skip

--

---
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 | 14 Aug 18:29 2014
Picon

Guido on type annotations in Py3

He's picked up the idea from a recent keynote talk at EuroPython that
there's this thing called mypy that provides type annotations.

http://thread.gmane.org/gmane.comp.python.ideas/28619

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.

Joon Ro | 14 Aug 18:03 2014
Picon

Cython code slow in GNU/Linux when pyrex_gdb=True is used

I found the same Cython code becomes much slower when pyrex_gdb=True is used it setup.py in GNU/Linux, while the speed is the same in Windows.
I generated the following simple example:

playground.pyx:

#cython: profile=False #cython: boundscheck=True #cython: wraparound=False #cython: cdivision=True from __future__ import division cimport cython def calc(): cdef: double x = 0 int i, j for i in range(1000): for j in range(1000): x += i return(x)

setup.py:

from distutils.core import setup from Cython.Distutils import Extension from Cython.Distutils import build_ext def init_Extension(name_module, names_pyx): return_obj = Extension( name_module, names_pyx, #pyrex_gdb=True, ) return(return_obj) ext_modules = [] ext_modules.append(init_Extension("_playground", ["playground.pyx"])) setup(cmdclass={'build_ext': build_ext}, ext_modules=ext_modules, )

where currently pyrex_gdb=True is commeted out.

In Windows, with TDM-GCC 64bit,

without pyrex_gdb=True:

In [2]: %timeit _playground.calc() 1000 loops, best of 3: 818 µs per loop

With pyrex_gdb=True, the same speed:

In [2]: %timeit _playground.calc() 1000 loops, best of 3: 821 µs per loop

However, in GNU/Linux (openSUSE),

without pyrex_gdb=True:

In [2]: %timeit _playground.calc() 1000 loops, best of 3: 862 µs per loop

With pyrex_gdb=True, it becomes much slower:

In [2]: %timeit _playground.calc() 100 loops, best of 3: 2.58 ms per loop

--

---
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.
Julien Delafontaine | 14 Aug 14:40 2014
Picon

Profiling: I/O operation on closed file

Hi,
I am trying the profiling as described in http://docs.cython.org/src/tutorial/profiling_tutorial.html.
I copied almost exactly the script from the tutorial:

#!/usr/bin/env python
import pstats, cProfile
import pyximport
pyximport.install()
from mymodule import mymodule_main

cProfile.runctx("mymodule_main(a,b,c)", globals(), locals(), "Profile.prof")
s = pstats.Stats("Profile.prof")
s.strip_dirs().sort_stats("time").print_stats()

and it returns me

$ python profiling.py
<normal program output is here !>
Traceback (most recent call last):
  File "profiling.py", line 10, in <module>
    s.strip_dirs().sort_stats("time").print_stats()
  File "/software/lib64/python2.7/pstats.py", line 341, in print_stats
    print >> self.stream, filename
ValueError: I/O operation on closed file

If I remove `.print_stats()` it does nothing. Trying to `print s` anywhere gives the same I/O error.
What did I do wrong?

--

---
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.
Stephen Tu | 13 Aug 07:38 2014
Picon

bug with embedsignature=True and lambda functions at module level

Here is a simple test case:

bug.pyx:
# cython: embedsignature=True

foo = lambda x: 10
bar = lambda x: 20
 
setup.py:
from distutils.core import setup
from Cython.Build import cythonize
import cython
print cython.__version__
setup(
    name = "foobar",
    ext_modules = cythonize('bug.pyx'),
)

(menv)stephentu <at> fender bug$ python setup.py build_ext --inplace
0.20.2
running build_ext
building 'bug' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/stephentu/miniconda/envs/menv/include/python2.7 -c bug.c -o build/temp.linux-x86_64-2.7/bug.o
bug.c:761:13: error: redefinition of 'None'
 static char None[] = "<lambda>(x)";
             ^
bug.c:724:13: note: previous definition of 'None' was here
 static char None[] = "<lambda>(x)";
             ^
error: command 'gcc' failed with exit status 1


Apologies if the mailing list is not the right place to report bugs.

--

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