Jeroen Demeyer | 25 Apr 23:08 2015
Picon

Testsuite failure

On latest master (commit f571608815beb4bee8b38e8dbeaf68f042d5a831), I get

ERROR: run (__main__.PureDoctestTestCase)
running pure doctests in generators_py
----------------------------------------------------------------------
Traceback (most recent call last):
   File "runtests.py", line 1114, in run
     m = imp.load_source(loaded_module_name, self.module_path)
   File 
"/usr/local/src/sage-config/local/src/cython/tests/run/generators_py.py", line 
9, in <module>
     from collections import Generator
ImportError: cannot import name Generator

--

-- 

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

a.valentino.it | 25 Apr 11:27 2015
Picon

ImportError: undefined symbol

Hi list,
a user of the pyepr package [1] reported an issue related the an installation problem [2].
When the package is installed via pip the user gets an import error due to missing symbols in the python extesion generated by cython.
The issue has been reported to happen with python 2.6 (on CentOS Linux) and python 2.7 (on OSX).
Please note that the source tarball available via PyPI [3] also includes cython pre-geneated .c source of the extension module.
After a few tests I realized that removing the bundled .c source and re-generating it with a local installation of cython fixes the issue.

This feels a little strange to me.
Is is a known issue?
Hints?


[1] https://github.com/avalentino/pyepr
[2] https://github.com/avalentino/pyepr/issues/11
[3] https://pypi.python.org/packages/source/p/pyepr/pyepr-0.9.2.tar.gz#md5=18d5e73acaa1cef408de0b1614b7a186


best regards

--
Antonio Valentino

--

---
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.
Volker Braun | 23 Apr 03:35 2015
Picon

Cythonize memleak

Cythonizing multiple files all runs in a single Python process, and apparently has a memory leak. This is bad for projects with large numbers of extension modules. Is there a particular reason why the Python process is not restarted to guard against memory leaks? Should I open a bug?

In the picture below you see a log for buliding the Sage library (sage -ba) with a single thread. The first 2/3 is cythonizing 411 modules, the last third is compiling (mostly ccache). The memory usage for Cython keeps going up as the files are processed:  

We recently noticed that we can't build Sage with 2GB of physical ram any more due to this, see https://groups.google.com/d/topic/sage-devel/8MYGxWQBEzs/discussion

--

---
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.
Graham Smith | 21 Apr 23:21 2015
Picon

Best way to wrap C library memory initializer

Hello,

I'm having trouble wrapping a library (c-algorithms) that has a memory initialization function that takes arguments. Typically I would call the memory initialization function in __cinit__ as below:

#alg.pyx
cimport calg
#the definitions file that externs from libcalg/hash-table.h

cdef
class HashTable:
    cdef calg
.HashTable *_hash_table

   
def __cinit__(self, calg.HashTableHashFunc hash_func,
            calg
.HashTableEqualFunc equal_func):
       
self._hash_table = calg.hash_table_new(hash_func, equal_func)
       
if self._hash_table is NULL:
           
raise MemoryError("Could not allocate HashTable.")

   
def __dealloc__(self):
       
if self._hash_table is not NULL:
            calg
.hash_table_free(self._hash_table)


This gives me the error "Cannot convert Python object argument to type 'HashTableEqualFunc.'" A little Googling leads me to find that giving typed arguments to __cinit__ is not allowed because the same arguments are also given to __init__ (see https://mail.python.org/pipermail/cython-devel/2012-June/002734.html). However, other Googling leads me to examples where typed arguments to __cinit__ seem to work (see http://stackoverflow.com/questions/7675284/cython-use-of-cinit or Python Cookbook, 3rd Edition, Chapter 15.10 "Wrapping Existing C Code with Cython" [hosted on Safari Books]). 

So two questions:

1) Is it possible to provide typed arguments to __cinit__?

2) If not (and it seems not), then what is the best way to create a wrapper with the same functionality? My current solution is to pull the initializer into a global function, but that seems messy...

cdef newHashTable(calg.HashTableHashFunc hash_func,
                  calg
.HashTableEqualFunc equal_func):
    new_hash_table
= HashTable()
    new_hash_table
._hash_table = calg.hash_table_new(hash_func, equal_func)
   
if new_hash_table._hash_table is NULL:
       
raise MemoryError("Could not allocate HashTable.")
   
return new_hash_table

cdef
class HashTable:
    cdef calg
.HashTable *_hash_table

   
def __dealloc__(self):
       
if self._hash_table is not NULL:
            calg
.hash_table_free(self._hash_table)

Thanks,

Graham

--

---
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.
handloomweaver | 21 Apr 18:35 2015

Scipy heap

Hi

I know there is a cython heap in scipy.sparse_graph.shortest_path. I'm wondering how to expose it to use with numpy arrays but I'm a bit lost. I'm a complete cython noob.

Would anyone be prepared to help me? I just want to take a 1d numpy array and get the index, value of the min value.

Kind thanks
AL


--

---
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.
Nathann Cohen | 20 Apr 10:54 2015
Picon

can cimport'ed functions be inlined?

Hello everybody,

I just wondered if some cdef function with an 'inline' flag can actually be inlined if I cimport it from another module. Or is the first moduled compiled independently and called as a library?

THaaaaaaaaanks,

Nathann

--

---
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.
Hans Müller | 19 Apr 21:52 2015
Picon

How best to wrap C++ classes which uses Eigen?

Hi,

I try to write a wrapper for C++ library which uses Eigen heavily, e.g.

surface.hpp:
#include <Eigen/Core>
#include <Eigen/Geometry>
#include <Eigen/StdVector>

class Surface
{
public:
    std
::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > nodes;
   
virtual void transform(const Eigen::Matrix3d &transformation);
}

What would be the best way to wrap this code? I managed to write the wrapper for the rest of the class, but this eludes me. I googled "cython eigen" but did not find any answer.

Can anyone of you experts point me in the right direction? Thanks.

Hans

--

---
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 | 18 Apr 08:12 2015
Picon

PEP 492 - Coroutines with async and await syntax

Hi!

Looks like there's a new PEP coming up which receives rather strong support:

https://www.python.org/dev/peps/pep-0492/

It proposes new sytax constructs like

    async with EXPR as VAR:
        BLOCK

    async for TARGET in ITER:
        BLOCK

that substantially simplify asynchronous code. Here's the current
discussion thread on python-ideas:

http://comments.gmane.org/gmane.comp.python.ideas/33009

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.

Johannes Kulick | 17 Apr 10:44 2015
Picon

typing python functions to use them as callback

Hi all,

I'm quite new to cython, so apologies for stupid questions...

Here is my problem:

We have a C++ library (which optimizes robot trajectories if that matters), which gets std::function objects as callback. Let's say, they look like this:

class Optimizer {
   
public:
       
void optimize(std::function<double(double)> cost_fnc);
};

Giving it a cython function is easy (as function_pointers get casted to std::function and I can specify the desired signature in cython etc.).

cdef double my_cost_fnc(double x):
   
return x*3

# ...

o
= Optimizer()
o
.optimize(my_cost_fnc)

But now, we would like to give people the possibility to implement pure python functions without rebuilding the cython module and that's where my problem starts. Python functions do of course have not the right signature. The first thought was to make a local cdef and use that:

cdef void optimize_wrapper(func):
    cdef
double func_wrapper(double d):
       
return func(d)
    o
.optimize(func_wrapper)

But local cdef is not allowed. Ok, I thought, than I move it out and use functools.partial

cdef double func_wrapper(double d, func):
   
return func(d)

cdef
void optimizer_wrapper(func):
    wrapped
= functools.partial(func_wrapper, func=func)
    o
.optimize(wrapped)

But then functools.partial returns of course a python object.

In the end I did the closure in C++, and wrapped everything with a void pointer and function pointers:

void optimize_wrapper(void* python_function, double (*cost) (void*, double)) {
  optimize
([](double x) { return cost(python_function, x); });  
}

But then I have to touch the original library (or add another cpp file). Although it works, it feels a bit wrong. Is there any other way to achieve, what I want?

Cheers,
Johannes

--

---
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 | 16 Apr 23:32 2015
Picon

weird shape for memory view

Hi all,

I have been using cython memory view for my projects and so far it's terrific. 

However I still don't understand about the shape of the memory view. Please see the example below

from cpython.array cimport array as pyarray
from cpython cimport array

cdef int w=100, h=100
cdef pyarray arr0 = array.clone(pyarray('d', []), w*h, zero=True)
cdef double[:] myview_0 = arr0
cdef double[:, :] myview_1 = <double[:w, :h]> &myview_0[0]

print (myview_1.shape)

I was expecting to get shape=(100, 100) but I got [100, 100, 0, 0, 0, 0, 0, 0]

info:
python 2 (and 3), cython 0.22pre (and 0.22), Windows (and Linux too).

Did I miss anything?
thanks

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.
Mori B | 16 Apr 15:44 2015
Picon

Using Cython with Asyncio

Did someone managed to make Cython work with an Asyncio coroutine ? I have a very trivial example that works well in Python 3.4, and refuses to work in Cython 0.22 : it's the following single file that I compile with Cython and execute.

The execution starts correctly but fails to run the coroutine. It seems like Cython modifies the type of the "sometask" coroutine, which is then not treated as usual by Asyncio and Inspect.


#!/usr/bin/env python import asyncio <at> asyncio.coroutine def sometask(): counter = 0 while True: print(counter) yield from asyncio.sleep(1) counter += 1 def runloop(): loop = asyncio.get_event_loop() asyncio.async(sometask()) try: print('Start loop') loop.run_forever() except KeyboardInterrupt: print('Aborted by user') loop.close()

--

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