20100.delecroix | 28 Feb 12:55 2015
Picon

Trouble with reference count with PyNumber_Coerce

Hello,

I am not sure I am right, but I did some experiments that confirm the behavior below. I want to use the PyNumber_Coerce(PyObject **, PyObject **) from the C-API. This function does increase the reference counts of the arguments. So if I write

def handmade_coerce(x, y):
    PyObject * obj_x = x
    PyObject * obj_y = y
    PyNumber_Coerce(&obj_x, &obj_y)
    return <object> obj_x, <object> obj_y

then the returned values get too much reference countings since the cast <object> also does increase the ob_refcnt. Is there a way to make it work? I first thought of

def handmade_coerce(x,y):
    PyNumber_Coerce(&(<PyObject *> x), &(<PyObject *> y))
    return x,y

but cythonization just fails.

One other way would be to use directly coerce from Python but it does not seem to be cythonized properly. I might end up with fixing this but I would first like to understand if its possible to do a <object> cast without increasing the reference counting.

Thanks
Vincent

--

---
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.
arf1.opensource | 27 Feb 08:27 2015
Picon

cython.parallel: Shared and private variables

Hi,

I am trying to get started with cython.parallel and am trying to wrap my head around its treatment of private and shared variables.

As I understand from the documentation:
 - if a variable is only read from in a prange block, it is shared between threads
 - if a variable is assigned it is lastprivate

I am unclear on which code segments are used to make this determination:
 - only cython code
 - or also external c code

So, if I have the following:
 - variable x is only read from in cython
 - a pointer to it is passed to a function in external c code
 - in this external c function the variable is assigned the pointer

---> What type is x going to be? Shared or lastprivate?

Many thanks,
ARF

--

---
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.
Luc Bourhis | 26 Feb 13:25 2015
Picon

include statement only at module level contrary to documentation

The documentation says: 

“The include statement can appear anywhere in your Cython file and at any indentation level”

at docs/src/reference/language_basics.rst:95.  But cython code itself  only allows include to appear at module level, as per

            if ctx.level not in ('module', 'module_pxd'):
                s
.error("include statement not allowed here")


at Cython/Compiler/Parsing.py:1896. For both code, this is from the master branch as of the time of writing.

Am I missing something or is there indeed a conflict here? If so, which one is correct?

--

---
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.
Noah Carnahan | 26 Feb 19:15 2015
Picon

Do Cython extension types support class attributes?

(cross posting from stack overflow: http://stackoverflow.com/questions/28749209/do-cython-extension-types-support-class-attributes)


Python classes can have class attributes:

class Foo(object): bar = 4

Is there an analogous construct for defining class attributes in Cython extension types? For example, when I try to compile the following cython code

cdef class Foo: cdef int bar bar = 4

I get this error:

thing.c:773:3: error: use of undeclared identifier 'bar' bar = 4; ^ 1 error generated. error: command 'cc' failed with exit status 1

--

---
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.
john | 26 Feb 19:10 2015
Picon

cythonise changes my import paths - erroneously

Hi

I am having trouble with Cython. I have inherited a Cython app and just about kept it building and running for the past year but today it has me absolutely stumped. It has started prepending the current (project root) directory to imports so that when they run the module cannot be found and importing fails. I will give a little more detail below:

projdir/kernel.pyx includes the following import line:


from component cimport Component


In the projdir directory, I run cythonize on kernel.pyx as follows:

extensions = [

Extension("kernel", ["kernel.pyx"],

include_dirs = [get_include()]),

]


setup(

ext_modules = cythonize(extensions)

)


and for the import it yields the followin in kernel.c:


  __pyx_ptype_7bastard_9component_Component = __Pyx_ImportType("projdir.component", "Component", sizeof(struct __pyx_obj_7bastard_9component_Component), 1); if (unlikely(!__pyx_ptype_7bastard_9component_Component)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;}


Note the appearance of "projdir.". When it runs, I get the expected error:


ImportError: No module named projdir.component


I can make this work by changing the string to just "component", recompiling, linking and running the python. But why is this happening? I understand that Cython is trying to support post-compile dynamic importing, but surely it has no business producing any path other than what I have in my original .pyx source file? What is the algorithm in cythonize() that is modifying these import paths? Where is the documentation for it? Why has this been working for ages then suddenly gone 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.
genadijrazdorov | 26 Feb 08:57 2015
Picon

int argument not working

Hi guys,

I just started with cython, and have I problem with int arguments:


def helloworld(int n):
return n

I am on Anaconda python3 win7 64bit system.
distutils build and install works, but when I call halloworld with integer in IPython I get:

TypeError: __int__ returned non-int (type int)

If I change int declaration to double helloworld is working.

Any suggestions?

--

---
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.
Hai Nguyen | 26 Feb 04:39 2015
Picon

Linking time is too slow

hi all, i have been using Cython for wrapping a C++ lib (for data analysis of bimolecular MD simulation). 

https://github.com/pytraj/pytraj (mostly written in Cython)

I think I am in love with Cython (still prefer Cython over Julia). The only problem is the compiling/linking time is too slow (about 4 times slower than compiling the original C++ lib). It takes about 15 minutes to compile. 

So my question is: is there any trick/flag to make this faster? 

Thanks for paying attention to my naïve question. 

Hai

--

---
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.
Curtis M. Faith | 26 Feb 00:19 2015
Picon

Why is it necessary to call auto-generated Cython import functions more than once?

I'm working on the Python bindings for the open-source project OpenCog which are written in Cython. There are two auto generated import functions:

    import_opencog__atomspace();
    import_opencog__agent_finder();

defined in the corresponding api header files.

I appear to need to call the auto-generated import functions several times to avoid crashes when calling into the Cython code marked as "api". I assumed I'd only need to run the code once upon initialization, however, if I only make the calls on startupm I get crashes in code that calls into the Cython defined api later on. The crashes go away if I put another call to:

    import_opencog__agent_finder();

before the Cython api is called from a C++ function in another linux shared library. Why is it necessary to call these import functions more than once?

- Curtis

--

---
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.
Luc Bourhis | 22 Feb 02:02 2015
Picon

Warning: Non-trivial type declarators in shared declaration

Could someone tell me how to disable this warning?

--

---
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.
Rudra Banerjee | 26 Feb 00:10 2015

compile cython generated C code

Hi,

I am very new cython user. My main purpose of using cython is to run the generated C code with fortran.
hence I have generated the C code from pyx and compiled the C code using distutils to generate .so file.

I have tried that so file to be called directly from fortran, which is not working.

So I tried to check the C code itself, with the hope that I can use fortran's C-interoperability.
But the C code is not compiling, giving long list of undefined reference.

I have compiled it using:

gcc  -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python2.7/ src/parse.c 
 
https://drive.google.com/file/d/0B02WblgE6NEvSl82dGp5d3FHdDg/view?usp=sharing  is the pyx file in question.

It will be of immense help if someone kindly show me the way.
Regards,
RB

--

---
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.
Jeroen Demeyer | 25 Feb 14:40 2015
Picon

Accessing Python long type?

Is there any way in Cython to access the Python "long" type?

Essentially, what I'm trying to do is

cdef extern from "longintrepr.h":
     cdef long PyLong_SHIFT
     ctypedef unsigned int digit
     ctypedef class __builtin__.long [object PyLongObject]:
         cdef digit* digits

cdef extern from "Python.h":
     cdef _PyObject_NewVar(type t, Py_ssize_t size)

def foo(s):
     cdef long L = _PyObject_NewVar(long, s)

The problem is that Cython always thinks that "long" means C long, while 
I really want Python long. Is there any solution for 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.


Gmane