Agrima Srivastava | 20 Apr 13:14 2016
Picon

Running cython with arguments

This is the main code "helloperson.pyx"import optparse
def main(): p = optparse.OptionParser() p.add_option('--person', '-p', default="world") options, arguments = p.parse_args() print 'Hello %s' % options.person if __name__ == '__main__': main()
The setup.py file is as follows:from distutils.core import setup from Cython.Build import cythonize setup( ext_modules=cythonize("helloperson.pyx"),)


I have used python setup.py build_ext --inplaceto get the helloperson.so fileThis code however takes an argument i.e. the person's name.How do I run the .so file ?

--

---
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.
Mike Busch | 19 Apr 02:31 2016
Picon

Wrapping C code that expects unsigned int **

I'm trying to re-purpose some older C code and use it with my shiny, new Python 3.5 program but passing pointers is giving me headaches. I was able to work my way through a simpler set of function calls but now I seem to have hit a wall.

From the C's .h file:

typedef unsigned long long KEY_T ;
typedef KEY_T * KEY_PTR ;
typedef unsigned int VALUE_T;
typedef VALUE_T * VALUE_PTR ;


and


void createHashTable(KEY_PTR d_keys,VALUE_PTR d_values, unsigned int length, KEY_PTR * d_TK,VALUE_PTR * d_TV,unsigned int * tableLength, unsigned int ** d_bucketSize,unsigned int * bucketCount);


my .pxd:

cdef extern from "common.h":
ctypedef unsigned long long int KEY_T
ctypedef unsigned long long int * KEY_PTR
ctypedef unsigned long long int VALUE_T
ctypedef unsigned long long int * VALUE_PTR

cdef extern from "gpuhash.h":
void createHashTable(
KEY_PTR d_keys,
VALUE_PTR d_values,
unsigned int length,
KEY_PTR * d_TK,
VALUE_PTR * d_TV,
unsigned int * tableLength,
unsigned int ** d_bucketSize,
unsigned int * bucketCount);


and my .pyx:

cimport pygpuhash
#from pygpuhash cimport createHashTable


def create_hash_table(
KEY_T[::1] d_keys,
VALUE_T[::1] d_values,
unsigned int length,
KEY_T[::1] *d_TK, # I've tried a wide variety of things on these 2 lines, including 2D arrays, 2 pointers, etc.
VALUE_T[::1] *d_TV,
unsigned int[::1] tableLength,
unsigned int[:,::1] d_bucketSize,
unsigned int[::1] bucketCount):
return pygpuhash.createHashTable(
&d_keys[0],
&d_values[0],
length,
&d_TK[0], # Can't figure out what this call should be
&d_TV[0],
&tableLength[0],
&d_bucketSize[0,0], # nor this one
&bucketCount[0])

and my errors are:

running build_ext
cythoning pygpuhash
.pyx to pygpuhash.c


Error compiling Cython file:
------------------------------------------------------------
...
       
unsigned int[::1] bucketCount):
   
return pygpuhash.createHashTable(
       
&d_keys[0],
       
&d_values[0],
        length
,
       
&d_TK[0],
       
^
------------------------------------------------------------


pygpuhash
.pyx:20:8: Cannot take address of memoryview slice


Error compiling Cython file:
------------------------------------------------------------
...
   
return pygpuhash.createHashTable(
       
&d_keys[0],
       
&d_values[0],
        length
,
       
&d_TK[0],
       
&d_TV[0],
       
^
------------------------------------------------------------


pygpuhash
.pyx:21:8: Cannot take address of memoryview slice


Error compiling Cython file:
------------------------------------------------------------
...
       
&d_values[0],
        length
,
       
&d_TK[0],
       
&d_TV[0],
       
&tableLength[0],
       
&d_bucketSize[0,0],
       
^
------------------------------------------------------------


pygpuhash
.pyx:23:8: Cannot assign type 'unsigned int *' to 'unsigned int **'






Any help would be appreciated!

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/d/optout.
Logan Page | 17 Apr 19:07 2016
Picon

Announcing pytest plugin (pytest-cython)

pytest plugin (pytest-cython) for the doctesting of C extension modules:
https://github.com/lgpage/pytest-cython

--

---
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.
Ecolss Logan | 17 Apr 03:12 2016
Picon

line profiling of cdef functions

I wonder is there any tool to profile each line of the cdef functions.

I found this line_profiler tool and a tutorial, but seems cannot print any stats on cdef functions.

http://nbviewer.jupyter.org/gist/tillahoffmann/296501acea231cbdf5e7

--

-- 

--- 
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.
Manoj Kumar | 15 Apr 22:36 2016
Picon
Gravatar

fused types for np.ndarray for cdef

Hello Cython developers,

Are there plans to support using numpy arrays with fused types that can be called as arguments in cdef?

cdef func(np.ndarray[floating, ndim=1] X_data):

--

---
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.
Logan Page | 15 Apr 22:33 2016
Picon

Python3 build: .so filename question

Im curious about something:

When I build a Cython module with Python3 it creates for example a "mymodule.cpython-34m.so" filename and extension.
What is the purpose of the ".cpython-34m" part of the filename?
And is there a way I can stop Cython from added this?

--

---
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.
jose mario pareja zapata | 15 Apr 17:03 2016
Picon

really newbie question: how to create a .pyx file?

i am trying to use cython but i cannot make it work, just when i am trying to do the helloworld tutorial, i dont know how to save the helloworld.pyx file, i tryed changing the name but it just changed to helloworld.pyx.py 

i am using anaconda 2

--

---
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.
Kyung Min Park | 15 Apr 05:25 2016
Picon

cython coroutine object does not have 'cr_code' and 'cr_frame' attributes.

Hello, 

Here is my test code

import asyncio

async def co_test():
    await asyncio.sleep(1)

def main():
    coro = co_test()
    print(asyncio.coroutines._format_coroutine(coro))

    loop = asyncio.get_event_loop()
    loop.run_until_complete(coro)
    loop.close()

if __name__ == '__main__':
    main()

( I use python 3.5.1 x86, cython 0.24 on Windows 10. )


If I run above code after cythonizing it, it gives

Traceback (most recent call last):
  File "D:\Work\Python351\lib\asyncio\coroutines.py", line 276, in _format_coroutine
    coro_code = coro.gi_code
AttributeError: 'coroutine' object has no attribute 'gi_code'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 19, in <module>
    test.y.main()
  File "test\y.py", line 8, in test.y.main (Z:\cython_test\test\y.c:1088)
    print(asyncio.coroutines._format_coroutine(coro))
  File "D:\Work\Python351\lib\asyncio\coroutines.py", line 278, in _format_coroutine
    coro_code = coro.cr_code
AttributeError: 'coroutine' object has no attribute 'cr_code'



My guest is that coroutine object should have 'cr_code' attribute and 'cr_frame' attribute, but cython coroutine object does not.

Any help appreciated.
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/d/optout.
nerdydad | 15 Apr 05:19 2016
Picon

Does anyone else try to run Python and Cython off identical source?

I've developed a little script called cyrun.py . It creates all the cython temporary files I need. If I am running a program called foo.py, then special comments in it are directives to cyrun.py to make cython code.

What all this means is that I can run either python or cython the same source code, i.e. I can type either type:

$ python foo.py

or

$ python cyrun.py foo.py

Admittedly my cython use is pretty modest, mainly using cdef and cpdef. But for many of my uses it gives me a lot of speedup for very little effort.

Has anyone else done this, and if not, would there be any interest in me releasing 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.
Emmanuel Gil Peyrot | 14 Apr 20:17 2016
Picon

Compiler crash when using an enum imported from another pxd

Hello,

When I cythonize a module using a cimported cdef enum from a different
pxd, I get a compiler crash in AnalyseExpressionsTransform (see
attached traceback).

Here is the code:

# package/test.pyx

from ._test cimport AnEnum

def func(self):
    print(AnEnum.VALUE)

# package/_test.pxd

cdef enum AnEnum:
    VALUE = 1

-- 
Emmanuel Gil Peyrot

-- 

--- 
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.
% cython package/test.pyx

Error compiling Cython file:
------------------------------------------------------------
...
from ._test cimport AnEnum

def func(self):
    print(AnEnum.VALUE)
               ^
------------------------------------------------------------

package/test.pyx:4:16: Compiler crash in AnalyseExpressionsTransform

ModuleNode.body = StatListNode(test.pyx:1:0)
StatListNode.stats[0] = DefNode(test.pyx:3:0,
    modifiers = [...]/0,
    name = 'func',
    num_required_args = 1,
    py_wrapper_required = True,
    reqd_kw_flags_cname = '0',
    used = True)
File 'Nodes.py', line 429, in analyse_expressions: StatListNode(test.pyx:4:4)
File 'Nodes.py', line 5326, in analyse_expressions: PrintStatNode(test.pyx:4:4,
    append_newline = True)
File 'ExprNodes.py', line 519, in analyse_expressions: TupleNode(test.pyx:4:4,
    is_sequence_constructor = 1,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 7293, in analyse_types: TupleNode(test.pyx:4:4,
    is_sequence_constructor = 1,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 6259, in analyse_types: AttributeNode(test.pyx:4:16,
    attribute = 'VALUE',
    initialized_check = True,
    is_attribute = 1,
    needs_none_check = True,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 6325, in analyse_as_type_attribute: AttributeNode(test.pyx:4:16,
    attribute = 'VALUE',
    initialized_check = True,
    is_attribute = 1,
    needs_none_check = True,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 6368, in as_name_node: AttributeNode(test.pyx:4:16,
    attribute = 'VALUE',
    initialized_check = True,
    is_attribute = 1,
    needs_none_check = True,
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 1902, in analyse_rvalue_entry: NameNode(test.pyx:4:16,
    cf_maybe_null = True,
    is_name = True,
    name = 'VALUE',
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 1935, in analyse_entry: NameNode(test.pyx:4:16,
    cf_maybe_null = True,
    is_name = True,
    name = 'VALUE',
    result_is_used = True,
    use_managed_ref = True)
File 'ExprNodes.py', line 1949, in check_identifier_kind: NameNode(test.pyx:4:16,
    cf_maybe_null = True,
    is_name = True,
    name = 'VALUE',
    result_is_used = True,
    use_managed_ref = True)

Compiler crash traceback from this point on:
  File "/usr/lib/python3.5/site-packages/Cython/Compiler/ExprNodes.py", line 1949, in check_identifier_kind
    if entry.is_type and entry.type.is_extension_type:
AttributeError: 'NoneType' object has no attribute 'is_type'
Emanuel Schorsch | 14 Apr 04:17 2016
Picon

confused about extension type declarations

I apologize if the wording of this question isn't correct. I have looked at the docs but I seem to be missing some piece of the puzzle. The basic idea is that I have a player class and want to be able to type define that Roster.players is a list of players so that operations are faster. Looking around I'm beginning to think that I can't declare a list of players which isn't great but I think I can get most of the benefits by at least type declaring <cur_player> as a Player object. 

Here is the meat of player.pyx
cdef class Player:
    cdef
public name
    cdef
public int age


   
def __init__(self, name="DEFAULT", age=-1):
       
self.name = name
       
self.age = age


My understanding is that the .pyx file is the implementation file and the .pxd file is the declarations file. I first tried having the declarations of name and age only in the .pxd file but it wouldn't compile properly. It seems wrong and redundant to have to declare name and age in both the .pyx and the .pxd file but I can't import Player in Roster.pyx unless I have them defined in the .pxd as well. I've tried a few different ways of importing but none of them seem to work. I wish I had a more articulate question but I just can't seem to make any progress on this. I attached what I believe is a minimal not working example. My instincts tell me that I'm misunderstanding the role of either .pyx or .pxd files or maybe there just isn't a way to do what I'm looking for. 

I'm cythonizing player.pyx and roster.pyx so maybe the obstacle is that I want to be able to initialize player and roster objects in runner.py without cythonizing it. Does the initialization need to be done inside a cythonized file? If so what is the best approach, just bite the bullet and cythonize runner.py or write a thin wrapper in demo/sub1 that is cythonized and allows me still setup in the pure python of runner.py. I appreciate any hints you can give me.

Here is the demo: https://github.com/emschorsch/cython_demo

--

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