stonebig34 | 23 Jul 22:30 2014
Picon

cython windows mingw compilers

Hello,

Sorry if the question has been asked recently.

For Python3.4 32 bit under windows (32bit or 64 bit) + what is the recommanded solution, today  :
- mingW (http://sourceforge.net/projects/mingw/files/) ?
- mingW64 in 32 bit mode (http://mingw-w64.sourceforge.net/) ?

My criterias are :
- stability first,
- performance on 32bit (and old computers) second,
- 64 bit third.

Thanks in advance for your advice

nota : I'm a cython newbye, not even sure mingW64 can work on 32 bit, so that choice exists

--

---
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.
Hamann, Michael (ITI | 23 Jul 10:10 2014

Containers of libc.stdint types cannot be converted from Python

Hi,

I have a problem using the integer definitions like uint64_t from 
libc.stdint as template arguments for c++ container types. When using 
something like vector[uint64_t] as return value, there is no problem. 
The vector is automatically converted to its Python equivalent. However 
when using the same type as argument value in a function, this 
conversion doesn't work. Instead (here for a set instead of a vector) I 
get an error message like

Error compiling Cython file:
------------------------------------------------------------
...
cdef extern from *:
     ctypedef uint64_t X 'uint64_t'
             ^
------------------------------------------------------------

set.from_py:110:13: 'uint64_t' is not a type identifier

The exactly same code works when using "unsigned long" instead of 
"uint64_t".

For a concrete example refer to

https://algohub.iti.kit.edu/parco/NetworKit/NetworKit/files/7b8e87d3688afc9a225185206000dcf91a6354ad/src/python/_NetworKit.pyx#L808 
- we would like to use "uint64_t" (or rather a ctypedef that refers to 
uint64_t) as argument here. The problem persists when the conversion is 
done explicitly in the cdef class (using <node[uint64_t]> 
degreeSequence) and also when the argument type is already declared in 
the method of the cdef class.

A similar problem was already mentioned 8 months ago in this topic: 
https://groups.google.com/forum/#!topic/cython-users/CFlfbOB-wjM

Is this a bug in Cython or is there anything we can do in order to avoid 
this problem? I am using Cython version 0.20.2.

Thank you!

Michael

--

-- 

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

Emil Lerner | 21 Jul 20:35 2014
Picon

ImportError while trying to use "cdef cppclass" in another extension

Hi!

I'm trying to import a cpp class in one extension and then use it in other extension.

I have two extensions, namely ext1 and ext2. I've declared a cpp class MyClass in a h file in ext1, and declared it as cdef cppclass in ext1.pxd . I've checked that I'm able to use it in ext1. Now I've copied ext1.so, ext1.pxd and myclass.h to ext2 folder. But when I'm trying to use MyClass in ext2, it compiles ok, but raises ImportError when importing ext2 in python.

So, I have two folders, ext1/ and ext2/, and files is following:

ext1/myclass.h:
class MyClass {
   
public:
       
int b;
       
MyClass(int b);
       
int sum(int a);
};



ext1/myclass.cpp:
#include "myclass.h"
MyClass::MyClass(int b) {
   
this->b = b;
}

int MyClass::sum(int a) {
   
return a + this->b;
}



ext1/ext1.pxd:
cdef extern from "myclass.h":
    cdef cppclass
MyClass:
       
MyClass(int)
       
int sum(int)



ext1/ext1.pyx:
def test1():
    cdef
:
       
MyClass* x = new MyClass(2)
   
print x.sum(2)



ext1/setup.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext

setup
(
    ext_modules
= cythonize([Extension("*", ["ext1.pyx", "myclass.cpp"], language="c++")]),
)


ext2/ext1.pxd is the same as ext1/ext1.pxd
ext2/myclass.h is the same as ext1/myclass.h
ext2/ext1.so is compiled ext1.so
(actually, previous 3 files are symlinks)

ext2/ext2.pxd:
from ext1 cimport MyClass

ext2/ext2.pyx:
def test2():
    cdef
:
       
MyClass* x = new MyClass(2)
   
print x.sum(2)


ext2/setup.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext

setup
(
    ext_modules
= cythonize([
   
Extension("*", ["ext2.pyx"], language="c++")
   
]),
)


And when I use ext1, it is all ok:
$ python -c 'import ext1; ext1.test1();'
4


And when I use ext2, It doesn't work:
$ python -c 'import ext2; ext2.test1();'
Traceback (most recent call last):
 
File "<string>", line 1, in <module>
ImportError: ./ext2.so: undefined symbol: _ZN7MyClass3sumEi

What I'm doing wrong? I don't want to use wrapper extension class as I'm going to have very large arrays of the classes, so I need to be memory efficient.


--

---
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.
Grzegorz Kowzan | 21 Jul 14:13 2014
Picon

winsock2.h include

Hello,

I have a C++ library which I'd like to work both on Windows and on Linux. The only significant difference between these platforms is location of ntoh procedure, for conversion between big endian and little endian number format, so in my header file I have following code:

#ifdef WIN32
#include <winsock2.h>
#elif LINUX
#include <netinet/in.h>
#endif

For building this library with cython, I have created a distutils setup file, where relevant part is:

    sourcefiles = ["libvipa.pyx",
                   r"<Path to file>\libVIPA.cpp"]
    ext_modules = [
    Extension("libvipa", sourcefiles,
              include_dirs=[r'<path to directory>\vipadll', np.get_include()],
              define_macros=[('WIN32', 1), ('VIPA_EXPORTS', 1)],
              libraries=['ws2_32'],
              extra_compile_args=['-DWIN32'],
              language='c++')]
    setup(ext_modules = cythonize(ext_modules, define_macros=[('WIN32', 1)]))

Unfortunately, cython insist of placing a conditional block of
#ifdef WIN32
...
#include "netinet/in.h"
...
#endif
so everything works fine on Linux, but on Windows it obviously doesn't compile. Should I configure my build system somewhat differently or is this a bug in cython?

Grzegorz

--

---
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.
Jerome Kieffer | 21 Jul 10:53 2014

MacOSX issue

Dear Cython users,

I guess I am not the only one facing some issue with the Clang compiler
provided by default in MacOSX due to the lack of support of OpenMP.

My code fails stupidly with "omp.h" not found.

What solution do you have to "work around" ?
- enforce the use of another compiler ?
- provide a different branch without cython.parallel.prange ?

Do you have another solution because none of them look satisfactory to me.

Cheers,

-- 
Jerome Kieffer <google <at> terre-adelie.org>

--

-- 

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

Kurt Smith | 20 Jul 22:38 2014
Picon

cygdb -- still maintained?

Hello,

Is Cython's gdb support still maintained?  I'm trying to get a simple demo going, and I get (cython) compile-time exeptions.  If I remove the `gdb_debug=True` from `cythonize()`, everything compiles and works fine.

For example:

$ cat setup.py
from distutils.core import setup
from Cython.Build import cythonize

setup(name="debug_me",
      ext_modules=cythonize("debug_me.pyx",
                            gdb_debug=True)
     )

$ python setup.py build_ext -i
Compiling debug_me.pyx because it changed.
Cythonizing debug_me.pyx
Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    setup(name="debug_me", ext_modules=cythonize("debug_me.pyx", gdb_debug=True))
  File "/Users/ksmith/Devel/cython/Cython/Build/Dependencies.py", line 812, in cythonize
    cythonize_one(*args[1:])
  File "/Users/ksmith/Devel/cython/Cython/Build/Dependencies.py", line 914, in cythonize_one
    result = compile([pyx_file], options)
  File "/Users/ksmith/Devel/cython/Cython/Compiler/Main.py", line 624, in compile
    return compile_multiple(source, options)
  File "/Users/ksmith/Devel/cython/Cython/Compiler/Main.py", line 602, in compile_multiple
    result = run_pipeline(source, options, context=context)
  File "/Users/ksmith/Devel/cython/Cython/Compiler/Main.py", line 436, in run_pipeline
    pipeline = Pipeline.create_pyx_pipeline(context, options, result)
  File "/Users/ksmith/Devel/cython/Cython/Compiler/Pipeline.py", line 231, in create_pyx_pipeline
    options.output_dir)
  File "/Users/ksmith/Devel/cython/Cython/Debugger/DebugWriter.py", line 45, in __init__
    self.output_dir = os.path.join(output_dir, 'cython_debug')
  File "/Users/ksmith/Devel/virtualenvs/venv-py2.7-cython-dev/bin/../lib/python2.7/posixpath.py", line 68, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'

--

---
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.
Sturla Molden | 17 Jul 00:25 2014
Picon

Dave Beazley is messing with my brain (again)

Does Cython support this?

https://twitter.com/dabeaz/status/489528443181088768

>>> x = float("nan")
>>> x == x
False
>>> [x] == [x]
True
>>>

Sturla

--

-- 

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

Irwin Zaid | 14 Jul 00:17 2014
Picon

Add dynamic_cast to libcpp?

Hi all,

I just have a small suggestion for an improvement to Cython.

Sometimes the only way to downcast through an inheritance hierarchy is with dynamic_cast. While dynamic_cast isn't available in Cython automatically, it does work simply by doing:

cdef extern from *:
    cdef T dynamic_cast[T](void *) except +

Why don't we add this to Includes/libcpp/__init__.pxd, or some other appropriate place? It is useful just to have it around, as it can be necessary sometimes. We could also add the other casts (static, const, and reinterpret) analogously, although I'm not sure if they have any real use in Cython.

Making dynamic_cast available like this also means anyone else that needs it doesn't need to sort out how to do it.

Cheers,

Irwin

--

---
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.
Valcortez | 13 Jul 18:13 2014
Picon

memoryview leak and bytes object leak with master

Hi,

I've discovered memory leaks in two different circumstances, one involves creating a bytes object in cython, the other involves a memoryview. The test code below demonstrates the issue.

pip show cython
---
Name: Cython
Version: 0.21dev

with python 2.7


in cyplayground.pyx:

from cpython.ref cimport PyObject
from cpython.array cimport array, clone

cdef extern from "Python.h":
    int PyObject_IsTrue(PyObject *)
    PyObject* PyString_FromString(const char *)
    void Py_DECREF(PyObject *)


def get_str(bytes val, dec):
    cdef object buff
    buff = <object>PyString_FromString(val)
    if dec:
        Py_DECREF(<PyObject *>buff)
    return buff


def get_array(int arr_size, dec):
    cdef array ret_array
    cdef char [:] char_view

    ret_array = clone(array('b'), arr_size, True)
    char_view = ret_array
    if dec:
        Py_DECREF(<PyObject *>ret_array)
    return ret_array
 

in playground.py:

from cyplayground import get_array, get_str
import gc
import psutil


def get_mem():
    return psutil.virtual_memory().used / 1024 ** 2

size = 100 * 1024 ** 2
before = get_mem()
get_str('4' * size, True)
gc.collect()

mid = get_mem()
get_str('4' * size, False)
gc.collect()
after = get_mem()

print('string: w/ dec: {}, w/o dec: {}'.format(mid - before, after - mid))


size = 100 * 1024 ** 2
before = get_mem()
get_array(size, True)
gc.collect()

mid = get_mem()
get_array(size, False)
gc.collect()
after = get_mem()

print('array: w/ dec: {}, w/o dec: {}'.format(mid - before, after - mid))

Running it prints:

string: w/ dec: 4, w/o dec: 100
array: w/ dec: 0, w/o dec: 100
 
As you can see, in both situations, unless I manually call Py_DECREF, the objects are leaked.

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.
Zahra Sheikh | 9 Jul 14:28 2014
Picon

Calling a class as an object inside another class

Hi,

I have re-written a python code to improve the speed of my code. I am facing another problem which I reckon is not very complicated as the other one and it is about calling one class as an object in another class and using its instance in the class has been called. So far my code doesn't raise any error during compilation but when I import it normally in python I get the error message that the class hasn't been called properly.

This is my code:

import numpy as np
cimport numpy as np
cpdef double std_G,v_c
std_G=4.3e-9 
v_c = 299792.458 

cdef extern from "math.h":
    double sqrt(double) nogil

cdef extern from "gsl/gsl_math.h":
    ctypedef struct gsl_function:
        double (* function) (double x, void * params)
        void * params

cdef extern from "gsl/gsl_integration.h":
    ctypedef struct gsl_integration_workspace
    gsl_integration_workspace *  gsl_integration_workspace_alloc(size_t n)
    void  gsl_integration_workspace_free(gsl_integration_workspace * w)
    int  gsl_integration_qags(const gsl_function * f, double a, double b, double epsabs, double epsrel, size_t limit, gsl_integration_workspace * workspace, double *result, double *abserr)

cdef double do_callback(double x, void* params): 
     return (<ComovingDistMemoization>params).eval(x) 


cdef class ComovingDistMemoization(cosmology):
     def __init__(self, cosmology):
         self.cosmology = cosmology ####this part
     def __call__(self, double z):
        def eval(z):
            return 1./sqrt(self.cosmology.hubble2(z)) #used here
        cdef gsl_integration_workspace* w =gsl_integration_workspace_alloc(1000)
        cdef gsl_function F            

        F.function = &do_callback 
        F.params = <void*>self 
        cdef double result = 3, error = 5
        cdef double y, err, dist
        gsl_integration_qags (&F, 0, z, 0, 1e-7, 1000, w, &result, &error) 
        y, err = result, error 
       gsl_integration_workspace_free(w) 
    
        dist = self.cosmology.v_c * y  
        return dist


cdef class cosmology(object):
    cdef public double omega_m, omega_l, h, w, omega_r, G, v_c
    def __init__(self, omega_m = 0.3, omega_l = 0.7, h = 0.7, w = -1, omega_r = 0., G = std_G):

        self.omega_m = omega_m
        self.omega_l = omega_l
        self.omega_r = omega_r
        self.h = h
        self.w = w
        self.G = G
        self.v_c = v_c
        self.comovingdist = ComovingDistMemoization(self)  ####this part
    property H0:
        def __get__(self):
            return 100*self.h 
    def hubble2(self, double z):
        cdef double inv_a
        inv_a = 1.+z
        return (self.omega_r*inv_a**4 + self.omega_m*inv_a**3 + \
                  self.omega_l*(inv_a**(3*(1+self.w))) + (1 - self.omega_m - self.omega_l - self.omega_r)*inv_a**2)*self.H0**2

So should all the inputs of the called class being initiated again in the other one to avoid the error message?

Regards,
Zahra

--

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

How to wrap function returning C++ objects allocated on stack?

Hi!
I'm creating a python binding of a cpp library using Cython. (I can't change it's source. I only have headers and .so libraries)

There are two classes, say ClassA and FactoryClassA. They are defined like this:

// start of spam.h:
class ClassA
{
     ClassA();
     //some methods
private:
     ClassA(int)
     //some fields
}
class FactoryClassA{
     FactoryClassA();
     ClassA factory();
     //other methods
}
//EOF spam.h

To create objects of ClassA I can only use FactoryClassA::factory() method (if ClassA objects are created otherwise they become unuseable).
How can I create Cython binding for spam.h?

--

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