Markus Brachner | 3 Jul 16:19 2015
Picon

Bug when creating vector object in prange loop

I think I found some bug.
I use the current release version of Cython 0.22.1

For me this minimal example leads to a compilation error:
from cython.parallel import prange
from libcpp.vector cimport vector

ctypedef vector[float] pointvector
        
def test_parallel():
    cdef Py_ssize_t j
    cdef pointvector *pv
    
    for j in prange(0,10,nogil=True):
        pv = new pointvector()

The problem is the creation of the pointvector object with the libcpp vector. In a normal range loop the same compiles fine with Cython. It works fine with prange, if I use my own vector wrapper:
cdef extern from "<vector>" namespace "std":
    cpdef cppclass vector[T]:
        cppclass iterator:
            T operator*()
            iterator operator++()
            bint operator==(iterator)
            bint operator!=(iterator)
        vector() nogil
        void push_back(T&) nogil
        T& operator[](int)
        T& at(int)
        iterator begin()
        iterator end()
Can sombebody reproduce 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.
Jeroen Demeyer | 3 Jul 15:56 2015
Picon

Cython looks for .pxd files everywhere?

Hello Cython-users,

when I cythonize a file /path/to/package/foo.pyx, then Cython 
automatically looks for anything_in_sys_path/package/foo.pxd

I know this is documented behaviour, but I consider it a bug anyway.

More explanation:

There are two kinds of cimporting:
* implicit cimporting: when cythonizing foo.pyx, Cython looks for foo.pxd
* explicit cimporting: when the code contains "cimport"

It seems that Cython currently treats both of these in the same way. 
However, I do not understand why the implicit cimporting looks all over 
sys.path for the .pxd file. Is there an actual use case for that?

Here is my problem: If I install a .pxd file and then change my mind and 
delete that .pxd file from my source files, the installed .pxd file is 
still there and will be automatically cimported. I know that .so and .py 
files and everything are also kept in the installation directory even if 
I remove the corresponding sources. But those files are unlikely to 
break anything. But unwanted .pxd files do break stuff.

Jeroen.

--

-- 

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

Hiroaki Nakamura | 3 Jul 14:59 2015
Picon

How to return a new instance of a cdef'ed class?

Hi all,

I started learning Cython and tried to write a Python binding for
"groonga/groonga" https://github.com/groonga/groonga
using Cython.

However when I tried to return a new instance of a cdef'ed class,
I got a "Cannot convert '~~~' to Python object" error.

I have read Cython document http://docs.cython.org/index.html
and the Cython book from O'reilly, but I cannot find a way to fix this error.

Could you please help me how to fix this?

My source codes are at:
https://github.com/hnakamur/cygroonga/commit/3b2378597427d00af15e41eb35eb2090eba378f9
I copied full error messages to the commit message.

The groonga C header file's source code is at:
https://github.com/groonga/groonga/blob/v5.0.5/include/groonga/groonga.h

Any help or comment is welcome.

Thanks in advance!

---
Hiroaki Nakamura

--

---
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.
Ana Marija Sokovic | 2 Jul 22:08 2015
Picon

Cython + OpenMP

I have a quick question about using prange in my code:

# for a given integer p
# find all integer combinations of a b c for which
# a*a+b*b=c*c
# a+b+c=p
# where a<b<c

from cython.parallel import prange

def find_num_solutions(int p):
    cdef int a,b,c,n
    n=0
    for a in prange(1,p/2,nogil=True,schedule="guided"):

        for b in prange(a,p/2):
            c=p-a-b
            if(a*a+b*b==c*c):
                n=n+1

    return n

when I compile it via: python setup.py build_ext --inplace
I got error:local variable 'n' referenced before assignment

while when I use: for b in range(a,p/2) instead the code compiles without problem. So in this situation when I have nested loop can I use prange twice and how?

--

---
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 | 2 Jul 19:44 2015
Picon

Using Cython as a Boost.Python replacement for C++ libraries?

Awhile ago I asked on comp.lang.python about using cffi as an interface to C++ libraries. Lele Gaifax pointed me to Cython. I glanced quickly at the doc page Lele referenced:

http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html

then got onto other things, and let that lay for awhile, but just bumped into some bogosities in some Boost.Python wrappers which made me think I should take a more serious look.

I just reread the above page. It's not at all clear to me how I'm supposed to create an interface to an existing C++ library. I don't want to compile the source to the library, just reveal some classes (and part of their public interfaces) to my Python code. I've used Cython up to this point to lightly boost some existing Python code, but haven't yet used it as a replacement for writing an extension module. I have pretty much zero experience with setup.py, even less with C++ or Boost.Python. I'm just looking for an easier way to write an extension module interfacing to some C++ libraries. Extension modules I can write, but I'm lazy, and was hoping Cython would offer a more Pythonic alternative. Any tutorials which reference this process appreciated. Maybe something like the Rectangle.cpp/h example which assumes that the C++ class code is external? I suspect it's right in front of my face, but I'm not looking at things in the right way.

Thanks,

Skip Montanaro

--

---
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.
Ian Bell | 2 Jul 19:36 2015
Picon

C++11 & Cython & windows & python 2.7

I have a new project that I am developing, to which I would like to ultimately build a cython wrapper.  In the past I have used only non-C++11 constructs to be able to compile with VS2008 to be able to support python 2.7.  shared_ptr are basically the end of VS2008's support for new things in the C++ dialect.

C++11 has a lot of nifty features that I would like to access in my new code, and I before I start doing that, I wanted to see what my options are in windows.  As I understand it, MINGW compilation would be my only option in windows for python 2.7, as there is no way to use C++11 in VS2008 (for python 2.7) or VS2010 (for python 3.4).

Anyone have experience with this?  Is this a MINGW-only solution on windows?  If so, that's a pity, since MINGW is much slower than VS for the technical computing I am doing.

--

---
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.
Daniil Pakhomov | 2 Jul 11:07 2015
Picon

Thread local variables in prange.

Hello.

I would be very glad if someone will help me to solve this problem.
I want to use thread-local variables in a prange loop.

Why it's not possible to use cython.parallel.threadlocal like it's mentioned here
https://github.com/cython/cython/wiki/enhancements-prange ?

Is this the only possible workaround by now:
https://groups.google.com/forum/#!topic/cython-users/Ady-DdWu6rE ?

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.
kloffy | 2 Jul 09:07 2015
Picon

libcpp - Any plans to add <memory> header?

Hi,

My understanding is that C++11 is still largely unsupported, but certain library features can already be implemented and would be *really* nice to have. I imagine smart pointers would be fairly high on the wishlist for many. Any plans for adding a memory header along the lines of the attached? (It contains some hacks and limitations, but it is mostly usable. Suggestions for improvement are welcome.)

Cheers,
kloffy

--

---
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.
Attachment (memory.pxd): application/octet-stream, 2520 bytes
Marcel Martin | 1 Jul 11:47 2015
Picon

Unable to deduce type parameters in global function

Hi,

I’m trying to wrap a heavily templatized C++ library that uses classes 
and global functions acting on them.

I would like to know why, in the following example, the last line gives 
me the error 'Unable to deduce type parameters' whereas I get no 
complaints about the line preceding it:

cdef extern from "file.h":
   cdef cppclass Container[T]:
     pass

   T get_first[T](Container[T])
   T get[T](Container[T], size_t)

cdef Container[int] c
get_first(c)
get(c, 1)

I’m just starting to use templates in Cython, so I wonder if I’m doing 
something wrong or whether this is just not supported.

Regards,
Marcel

--

-- 

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

Marcel Martin | 1 Jul 11:28 2015
Picon

Compiler crash

Hi,

using 'cython --cplus' to cythonize the following code results in a 
compiler crash in Cython 0.22.1:

cdef extern from "...":
   cppclass Container[T]:
     Container()

   T get[T](Container[T])

cdef Container[int]* c = new Container()
get(c)

Regards,
Marcel

[...]
crash.pyx:8:3: Compiler crash in AnalyseExpressionsTransform

File 'Nodes.py', line 421, in analyse_expressions: 
StatListNode(crash.pyx:1:0)
File 'Nodes.py', line 4662, in analyse_expressions: 
ExprStatNode(crash.pyx:8:3)
File 'ExprNodes.py', line 434, in analyse_expressions: 
SimpleCallNode(crash.pyx:8:3,
     analysed = True,
     use_managed_ref = True)
File 'ExprNodes.py', line 4540, in analyse_types: 
SimpleCallNode(crash.pyx:8:3,
     analysed = True,
     use_managed_ref = True)
File 'ExprNodes.py', line 4593, in analyse_c_function_call: 
SimpleCallNode(crash.pyx:8:3,
     analysed = True,
     use_managed_ref = True)

Compiler crash traceback from this point on:
   File 
"/home/user/.local/lib/python3.4/site-packages/Cython/Compiler/ExprNodes.py", 
line 4593, in analyse_c_function_call
     entry = PyrexTypes.best_match(args, alternatives, self.pos, env)
   File 
"/home/user/.local/lib/python3.4/site-packages/Cython/Compiler/PyrexTypes.py", 
line 3963, in best_match
     [pattern.type.deduce_template_params(actual) for (pattern, actual) 
in zip(func_type.args, arg_types)],
   File 
"/home/user/.local/lib/python3.4/site-packages/Cython/Compiler/PyrexTypes.py", 
line 3963, in <listcomp>
     [pattern.type.deduce_template_params(actual) for (pattern, actual) 
in zip(func_type.args, arg_types)],
   File 
"/home/user/.local/lib/python3.4/site-packages/Cython/Compiler/PyrexTypes.py", 
line 3442, in deduce_template_params
     elif self.empty_declaration_code() == 
actual.template_type.empty_declaration_code():
AttributeError: 'CPtrType' object has no attribute 'template_type'

--

-- 

--- 
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 | 1 Jul 08:52 2015
Picon

help needed to verify MSVC preprocessor check in memoryview code

Hi,

I stumbled over this code in MemoryView_C.c, line 36:

"""
#elif CYTHON_ATOMICS && MSC_VER
"""

Shouldn't this spell "defined(_MSV_VER)" ? Mind the leading underscore.

Could one of the MSVC users please verify with some memoryview code whether
this works or needs fixing? There is a macro "__PYX_DEBUG_ATOMICS" that you
can #define to make the C compiler issue a 'warning' for the code it uses
here, namely "Using MSVC atomics". Otherwise, you would see "Not using
atomics".

I considered simply changing it, but in the worst case, this might be code
that has never been used, so it might just break when enabling it. If both
versions work, I'd still like to change it because "_MSC_VER" is used
everywhere else and thus keeps the surprise level low.

Thanks!

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.


Gmane