Shriramana Sharma | 19 May 2013 13:46
Picon

Cythonize is special?

Hello. How exactly is:

from distutils.core import setup
from Cython.Build import cythonize
setup(
    name = "My hello app",
    ext_modules = cythonize('hello.pyx'), # accepts a glob pattern
)

different from:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup (
	ext_modules = [ Extension ( "hello", [ "hello.pyx" ] ) ],
	cmdclass    = { "build_ext" : build_ext }
)

Is it just that the former is somewhat shorter, especially seeing as
the docstring for cythonize says: ""Compile a set of source modules
into C/C++ files and return a list of distutils Extension objects for
them.""

Or is there any other essential difference that makes using Cythonize
preferable to manually specifying the Extension params?

Thanks.

--

-- 
(Continue reading)

杨雪峰 | 18 May 2013 17:54
Picon

Win7 Python 2.7 Cython helloworld example compile error ! help ,please

Hi all:


     I am a new user of Cython. I install it by the Anaconda package. When i try the example on the website, i get the following problem !

Setup.py 
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = [Extension("helloworld", ["helloworld.pyx"])]
)

the pyx file is just a print 'hello world' 

the Error :

running build_ext
skipping 'helloworld.c' Cython extension (up-to-date)
building 'helloworld' extension
C:\MinGW\bin\gcc.exe -DMS_WIN64 -mdll -O -Wall -IC:\Anaconda\include -IC:\Anaconda\PC -c helloworld.c -o build\temp.win-amd64-2.7\Release\helloworld.o
writing build\temp.win-amd64-2.7\Release\helloworld.def
creating build\lib.win-amd64-2.7
C:\MinGW\bin\gcc.exe -DMS_WIN64 -shared -s build\temp.win-amd64-2.7\Release\helloworld.o build\temp.win-amd64-2.7\Release\helloworld.def -LC:\Anaconda\libs -LC:\Anaconda\PCbuild\amd64 -lpython27 -lmsvcr90 -o build\lib.win-amd64-2.7\helloworld.pyd
build\temp.win-amd64-2.7\Release\helloworld.o:helloworld.c:(.text+0x85): undefined reference to `_imp__PyOS_snprintf'
build\temp.win-amd64-2.7\Release\helloworld.o:helloworld.c:(.text+0x8d): undefined reference to `_imp__Py_GetVersion'
build\temp.win-amd64-2.7\Release\helloworld.o:helloworld.c:(.text+0x108): undefined reference to `_imp__PyOS_snprintf'
build\temp.win-amd64-2.7\Release\helloworld.o:helloworld.c:(.text+0x129): undefined reference to `_imp__PyErr_WarnEx'
build\temp.win-amd64-2.7\Release\helloworld.o:helloworld.c:(.text+0x146): undefined reference to `_imp__PyTuple_New'
build\temp.win-amd64-2.7\Release\helloworld.o:helloworld.c:(.text+0x170): undefined reference to `_imp__PyString_FromStringAndSize'
many undefined reference like the things above  and the final line is as following:
collect2: ld ¨Z¨e¨[¨n 1
error: command 'gcc' failed with exit status 1

Can anybody help me ? i know little about the gcc compiler. i supposed the problem may be caused by the mingw.

thanks !!

--
 
---
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/groups/opt_out.
 
 
杨雪峰 | 18 May 2013 20:22
Picon

Cython c compiler setting

Hi all

       I follow the instruction from http://wiki.cython.org/64BitCythonExtensionsOnWindows  try to use windows c compiler to build python extension. but cython are still using mingw gcc to compile my files which cause many undefined reference errors.

      it became green words after i command setenv /x64 /release

C:\Users\Yang Xuefeng\Dropbox\workspaces\pythonxy\autoencoders\Cythonlearning\te st>python setup.py build_ext running build_ext skipping 'helloworld.c' Cython extension (up-to-date) building 'helloworld' extension C:\MinGW\bin\gcc.exe -DMS_WIN64 -mdll -O -Wall -IC:\Anaconda\include -IC:\Anacon da\PC -c helloworld.c -o build\temp.win-amd64-2.7\Release\helloworld.o writing build\temp.win-amd64-2.7\Release\helloworld.def C:\MinGW\bin\gcc.exe -DMS_WIN64 -shared -s build\temp.win-amd64-2.7\Release\hell oworld.o build\temp.win-amd64-2.7\Release\helloworld.def -LC:\Anaconda\libs -LC: \Anaconda\PCbuild\amd64 -lpython27 -lmsvcr90 -o build\lib.win-amd64-2.7\hellowor ld.pyd build\temp.win-amd64-2.7\Release\helloworld.o:helloworld.c:(.text+0x85): undefin ed reference to `_imp__PyOS_snprintf'

please , help me !


regards

Yang Xuefeng

--
 
---
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/groups/opt_out.
 
 
Aidin Hasanzadeh | 18 May 2013 14:05
Picon

First Cython ModuleI

Hey,


I am new with Cython and starting my first module. I am using eclipse/Ubunty. I installed cython and tried to implement the very first example, Hello world.


I made the setup file, but importing Cython.Distutils could not be resolved.

from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext setup( cmdclass = {'build_ext': build_ext}, ext_modules = [Extension("helloworld", ["helloworld.pyx"])])


Thanks for any help
Aidin

--
 
---
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/groups/opt_out.
 
 
Pedro Camargo | 19 May 2013 02:33
Picon

Type error

Hi guys,

                  I’m working on a fairly long code that is compiling correctly, but giving an error when it runs.

 

                I’m working on Windows 64 bits, Python 2.7 (last installer made available) and the last versions of the installers for Numpy/Scipy/Cython  made by Chris Gohlke.

 

Thanks for the help,

               

Pedro

 

The error is:

 

File "Assignment2.pyx", line 493, in Assignment._Ordering_and_Forward_Star (Assignment2.c:6242)

    cdef _Ordering_and_Forward_Star(np.ndarray[ITYPE_t, ndim=2, mode='c'] graph, #A_Node/B_Node

ValueError: Buffer dtype mismatch, expected 'ITYPE_t' but got 'long long'

 

 

 

It points to this header:

 

cdef _Ordering_and_Forward_Star(np.ndarray[ITYPE_t, ndim=2, mode='c'] graph, #A_Node/B_Node

                    np.ndarray[ITYPE_t, ndim=2, mode='c'] g_aux,

                    np.ndarray[DTYPE_t, ndim=2, mode='c'] graph_data,

                    np.ndarray[DTYPE_t, ndim=2, mode='c'] g_aux2,

                    np.ndarray[ITYPE_t, ndim=1, mode='c'] ind,

                    np.ndarray[ITYPE_t, ndim=1, mode='c'] graph_fs):

 

 

And the matrices are dimensioned and the function called this way:

 

graph=np.zeros((l,2), dtype=ITYPE) #Holds node of origin and node of destination

graph_fs=np.zeros(nodes+1, dtype=ITYPE)  #Holds the Forward star for the graph

graph_data=np.zeros((l,2), dtype=DTYPE) #Holds data for the graph. First column is the nested utility and the second the utility used for Shortest path

g_aux=graph.copy() #to sort the indices

g_aux2=graph_data.copy()

 

_Ordering_and_Forward_Star(graph,

                               g_aux,

                               graph_data,

                               g_aux2,

                                ind,

                                graph_fs)

 

Searching the problem I saw references to a problem of 32 Vs. 64 bits, but when I tried with 32 bits I get this:

 

C:\Users\Pedro\Desktop\Paths test>c:\Python27\python setup_Assignment.py build_e

xt --inplace

running build_ext

skipping 'Assignment2.c' Cython extension (up-to-date)

building 'Assignment' extension

Traceback (most recent call last):

  File "setup_Assignment.py", line 23, in <module>

    include_dirs=[np.get_include()])

  File "c:\Python27\lib\distutils\core.py", line 152, in setup

    dist.run_commands()

  File "c:\Python27\lib\distutils\dist.py", line 953, in run_commands

    self.run_command(cmd)

  File "c:\Python27\lib\distutils\dist.py", line 972, in run_command

    cmd_obj.run()

  File "c:\Python27\lib\site-packages\Cython\Distutils\build_ext.py", line 163,

in run

    _build_ext.build_ext.run(self)

  File "c:\Python27\lib\distutils\command\build_ext.py", line 339, in run

    self.build_extensions()

  File "c:\Python27\lib\site-packages\Cython\Distutils\build_ext.py", line 171,

in build_extensions

    self.build_extension(ext)

  File "c:\Python27\lib\distutils\command\build_ext.py", line 498, in build_exte

nsion

    depends=ext.depends)

  File "c:\Python27\lib\distutils\msvc9compiler.py", line 473, in compile

    self.initialize()

  File "c:\Python27\lib\distutils\msvc9compiler.py", line 383, in initialize

    vc_env = query_vcvarsall(VERSION, plat_spec)

  File "c:\Python27\lib\distutils\msvc9compiler.py", line 299, in query_vcvarsal

l

    raise ValueError(str(list(result.keys())))

ValueError: [u'path']

 

C:\Users\Pedro\Desktop\Paths test>

--
 
---
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/groups/opt_out.
 
 
Josh Ayers | 19 May 2013 02:01
Picon

for loop with variable step not optimized

I just noticed that a for-loop using the standard Python range construct isn't optimized to C-code if the step is a run-time variable.  It is optimized if the step parameter is a compile-time constant, or if the old Pyrex style for-loop syntax is used.  I tested with Cython 0.18 and 0.19.1 and both behaved the same way.

Here's a minimal example.

DEF STEP = 2

def loops():
    cdef int i, start = 0, stop = 10, step = 2

    for i in range(start, stop, step): # generates Python loop
        print(i)

    for i in range(start, stop, STEP): # generates C loop
        print(i)

    for i from start <= i < stop by step: # generates C loop
        print(i)

Is this a bug?

Thanks,
Josh Ayers

--
 
---
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/groups/opt_out.
 
 
Shriramana Sharma | 18 May 2013 08:37
Picon

Spiro Python interface using Cython

Spiro is an algorithm for producing smooth splines given a set of
on-curve control points. I am working on polishing the library. I
wrote a Python interface using Cython (thanks to all those who develop
it!).

The Spiro library uses callbacks, hence my recent in doing that in
Cython. I am happy to say I have been successful. The attached code
demonstrates it to whoever can spend the time to read it. The code is
under the GPLv3+. (Note: you don't need to worry about the internals
of spiro.c -- just look at spiro.h and bezctx.h to understand the
library being wrapped.)

I have one question: Clang generates the warning:

spiro_cy.c:653:1: warning: declaration does not declare anything
[-Wmissing-declarations]
spiro_cp;
^~~~~~~~
1 warning generated.

Why is this and what should I do to fix it? Thanks.

-- 
Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा

--

-- 

--- 
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/groups/opt_out.

Attachment (spiro-cython.tar.gz): application/x-gzip, 9 KiB
Justin Israel | 18 May 2013 03:55
Picon
Gravatar

OSX 10.8: setuptools generates gcc command that wants to use to use .c instead of .cpp

This is a strange issue that happens for my project only when someone with OSX 10.8 (mountain lion) tries to build the extension. I don't have 10.8 so I am still waiting on a colleague to forward me a dump of the literal failure, but I figured I could start the question now and provide more info if needed.


The issue is pretty straight forward. On <=10.7.x, when building the extension in place, it properly respects the language="c++" Extension attribute. It cythonizes the pyx => cpp, and runs the proper gcc command to build.

On 10.8.x, it seems it is cythonizing the cpp file just fine, but then it generates a gcc command that is trying to compile a .c that does not exist, obviously. The way I can get it to succeed is if I modify my setup file to not use cython. Then I manually cythonize the pyx => cpp, and have it use the cpp source directly in the setuptools Extension (I have one of those common use_cython style flag setups that I just force to False). 

Does anyone offhand know what might be an issue on osx 10.8? I know apple mucked with the compiler setups a whole bunch, and have seen my fair share of posts containing "problems compiling XYZ on 10.8", requiring some special adjustment. I know that the person who encountered this error had freshly installed the xcode command-line tools to get their compilers, and had no previous setup for building from source code until they were trying to build my extension.

Example setup.py code looks like:

...
cmdclass = {}
if use_cython:
    SRC = 'foo.pyx'
    cmdclass['build_ext'] = build_ext
else:
    SRC = 'foo.cpp'
...
ext = Extension('plow.client.plow',
    [SRC],
    language="c++",
    libraries=[...], 
    extra_compile_args=cflags,
    extra_link_args=ldflags,
    define_macros=[...]
)
...
setup(
   ...
    ext_modules = [ext],
    cmdclass=cmdclass,
   ...
)

--
 
---
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/groups/opt_out.
 
 
Pedro Camargo | 17 May 2013 02:06
Picon

Sorting algorithm

xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

Hi,

                I’m currently working on a cdef function inside a cython (indexing numpy arrays) module and I need to sort a numpy array (actually need the argsort). How can I proceed?

 

Can I just call array_index=np.argsort(array). Wouldn’t it defeat the purpose of array indexing?  Does anybody have a sorting algorithm in Cython they could share? Couldn’t find anything online.

 

Thanks,

Pedro

--
 
---
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/groups/opt_out.
 
 
Nils Bruin | 16 May 2013 19:18
Picon

cython's property and nondata descriptors

Two questions about cython's "property:" directive.

1] In python, a nondata descriptor is a descriptor that doesn't have
its '__set__' slot filled. Such descriptors can be overridden by
entries in the instance '__dict__'. One might expect that specifying a
cython "property" without giving a "__set__" method would lead to such
an entry, but it doesn't: It leads to a datadescriptor that cannot be
overridden by instance attributes:

%cython
cdef class T(object):
    property B:
        def __get__(self):
            return 1

>>> class S(T): pass
>>> s=S()
>>> s.B=10
AttributeError: attribute 'B' of 'T' objects is not writable

This mirrors the  <at> property decorator in python but it makes it hard to
specify nondata descriptors. Are there thoughts about how to make it
more convenient to declare nondata descriptors

2] Using the  <at> property decorator in a cdef class works, but leads to
less efficient code:

%cython
cdef class T(object):
    property B:
        def __get__(self):
            return 1
     <at> property
    def C(self):
        return 1

>>> t=T()
>>> timeit("t.B")
625 loops, best of 3: 78.6 ns per loop
>>> timeit("t.C")
625 loops, best of 3: 275 ns per loop

would it be desirable to automatically transcribe " <at> property" to
"property .."? Perhaps not, since the semantics of the two are
different and both are valid, but I expect it's a common pitfall for
people who try to translate python to cython 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/groups/opt_out.

Ecython | 16 May 2013 03:54
Picon

static typing of mpf type variables in cython

Hello,


I am a new user of cython. I am working with mpf variables in python
but would like to know its static version in cython for speed up.

For example I was looking for something similar like the following:

python: N=10                                     static typing via cython: cdef int N=10

Is there a similar way to do this with mpf variables? something like:

python:                                              What would be the equivalent static
                                                         version in cython?
from mpmath import mpf
N=mpf(10)                                          cdef mpf_t N=10 ? (but this doesn't work?)

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/groups/opt_out.
 
 

Gmane