gary thompson | 22 Mar 23:10 2015
Picon

public api in a sub package

Dear All

I am having a problem with exporting a public  api with the right package loading code

specifically I have something like the following in setup.py


ext_modules = [Extension("yy.xx",  ['yy.xx.pyx'],
                         define_macros = [('CPLUSPLUS', '1') ,
                                          ('USE_CDS_NAMESPACE', '1') ,
                                          ('OLD_ENSEMBLE_INTERFACE',old_ensemble_interface)],

                         language="c++",
                         extra_compile_args=extra_compile_args,
                         extra_link_args=extra_link_args,
                         include_dirs=include_dirs)]

setup(
    package_dir = {'yy':''},
    ext_modules=cythonize(ext_modules[0:1]),
    cmdclass = {'build_ext': build_ext},
)


and yy.xx.py has 

cdef public api double zz(object self, int i, ...):

..... some very interesting cython code

now when I do the build everything cython goes in the right pace and looks good (ie we have a yy directory with an xx in it

Howvere, now I expect to have a file called


yy.xx_api.h but I am just getting a file called xx_api.h furthermore inside I get

import_xx() 

not 

import_yy__xx()

could someone tell me what I am doing wrong and how to solve it?

regards

gary






--

---
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.
Abhishek Agrawal | 22 Mar 12:40 2015
Picon

Optimizing generated file size

Hi
I am a newbie to cython and I am working on a project of rewriting a c module to cython. I want to minimize the size of generated c files as much as possible. Is there any blog or documentation link on which can help me. Also if you can tell about new cython features which can make the module run faster, that would be of great help.
Please reply ASAP...!!!

Regards,
Abhishek Agarwal

--

---
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.
Abbeville | 22 Mar 12:24 2015
Picon

Windows 8.1 + Anaconda 2.1 + Cython 0.22 compile error

Not sure if this is an Anaconda or Cython problem and posted a similar note on Anaconda list. 

Installed Python Anaconda 2.1 64-bit on Windows 8.1. Created "setup.py" to compile a .pyx as:

import numpy
 
from distutils.core import setup
from Cython.Build import cythonize
 
extensions = cythonize(["my.pyx"])
 
setup(
    ext_modules = extensions, 
    include_dirs=[numpy.get_include()]
    )

The my.pyx includes the imports:

import cython
import numpy
cimport numpy

> python setup.py build_ext --inplace
 
Traceback (most recent call last):
  File "setup.py", line 2, in <module>
    from Cython.Build import cythonize
  File "C:\Anaconda\lib\site-packages\Cython\Build\__init__.py", line 1, in <mod
ule>
    from .Dependencies import cythonize
  File "C:\Anaconda\lib\site-packages\Cython\Build\Dependencies.py", line 166, i
n <module>
    <at> cython.locals(start=long, end=long)
AttributeError: 'module' object has no attribute 'locals'

What is the problem?

Btw, it didn't work for Anaconda 2.1 32-bit either.

--

---
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.
Jérôme Kieffer | 22 Mar 11:54 2015

Export cdef class methods ...

Dear Cython users,

I am trying to share a cdef class defined in one cython module into another one ...
While sharing attributes looks ok, any cdef (or cpdef) method seems to be an issue.

Maybe I am not trying the good way?

I would like to do (in another cython module):

from ary cimport Ary

cdef:
    Ary ary = Ary(data)
    int x, y, local_max
for x in prange(ary.height, nogil=True):
  for y in range(ary.width):
     local_max = ary.c_local_maxi(x,y)

################################################################################
ary.pxd:

cdef class Ary:
    cdef readonly float[:, :] data
    cdef readonly int width, height

    cdef int c_local_maxi(self, int, int)

################################################################################
ary.pyx:

import numpy

cdef class Ary:
    def __cinit__(self, data not None):
        assert data.ndim == 2
        self.width = data.shape[1]
        self.height = data.shape[0]
        self.data = numpy.ascontiguousarray(data, dtype=numpy.float32)

    cdef int local_maxi(self, int x, int y) nogil:
        cdef:
            float value, current, tmp
            int ix, iy
            int start_x, stop_x, start_y, stop_y
        value = self.data[y, x]
        current = value - 1.0
        while value > current:
            current = value
            start_x = max(0, x - 1)
            stop_x = min(x + 1, self.width - 1)
            start_y = max(0, y - 1)
            stop_y = min(x + 1, self.width -1)
            for iy in range(start_y, stop_y):
                for ix in range(start_x, stop_x):
                    tmp = self.data[iy, ix]
                    if tmp > value:
                        x, y = ix, iy
                        value = tmp
        return x + self.width * y

-- 
Jérôme 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.

Jeroen Demeyer | 21 Mar 23:56 2015
Picon

How to make a .pxi file explicitly depend on some other file

Hello,

is there a mechanism to add a dependency of foo.pxi on someheader.h, 
such that every file which includes foo.pxi will automatically depend on 
someheader.h?

I have tried the obvious
# distutils: depends = someheader.h
in the .pxi file, but that didn't work.

I know I could make the dependency explicit with

cdef extern from "someheader.h":
     pass

but then I have no control on the order of the #includes in the 
Cython-generated .c file. I have a bunch of header files and they need 
to be included in a specific order.

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

Stefan Behnel | 21 Mar 14:31 2015
Picon

multiple extension modules in one shared library file

Hi,

I was just made aware of this change in Python 3.4 and thought it might
also be useful for others:

https://bugs.python.org/issue16421

It allows to link multiple extension modules into one shared library file,
and then importing each of them separately. This can be helpful when
multiple modules need to link statically against the same external library,
for example.

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.

Jeroen Demeyer | 20 Mar 18:15 2015
Picon

Why does Cython always generate declarations for api/public functions?

Consider a file foo.pyx:

   cimport othermodule

And then a file othermodule.pxd:

   cdef void a()
   cdef public void b()
   cdef api void c()

Note that foo.pyx absolutely doesn't use anything from othermodule, it's 
just one cimport statement.

Now the generated C code foo.c has

   /* Module declarations from 'othermodule' */
   static void (*__pyx_f_11othermodule_b)(void); /*proto*/
   static void (*__pyx_f_11othermodule_c)(void); /*proto*/

Why are these declarations there?

I would rather *not* have these automatic declarations since they 
conflict with the use of "othermodule_api.h" by a header file included 
by foo.pyx. Alternatively, you could use a different mangling scheme for 
othermodule_api.h such that these don't conflict.

--

-- 

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

Kolja Es | 20 Mar 15:39 2015
Picon

Method taking pointer to abstract base class.

Problem

I have a base class LinkPredictor and a sub class KatzIndex which derives from LinkPredictor in C++. Now I have another class which needs in its constructor a pointer to a LinkPredictor.

I want to wrap those classes in Cython to make them available in Python.

My try

CPP:

class LinkPredictor { ... } class KatzIndex : public LinkPredictor { ... } class KFoldCrossValidator { public: KFoldCrossValidator(LinkPredictor* lp) { ... } }

Cython:

cdef extern from ".../LinkPredictor.h": cdef cppclass _LinkPredictor: _LinkPredictor(...) except + cdef class LinkPredictor: def __cinit__(self): return cdef extern from ".../KatzIndex.h": cdef cppclass _KatzIndex(_LinkPredictor): _KatzIndex(...) except + ... cdef class KatzIndex(LinkPredictor): cdef _KatzIndex* _this ... cdef extern from ".../KFoldCrossValidator.h": cdef cppclass _KFoldCrossValidator: _KFoldCrossValidator(_LinkPredictor* linkPredictor) except + ... cdef class KFoldCrossValidator: cdef _KFoldCrossValidator* _this def __cinit__(LinkPredictor linkPredictor): self._this = new _KFoldCrossValidator(linkPredictor._this) ...

Question

The approach above is not working. Cython throws the following error message:

Error compiling Cython file: ------------------------------------------------------------ ... """ """ cdef _KFoldCrossValidator* _this def __cinit__(self, Graph G, LinkPredictor linkPredictor, EvaluationCurve evaluator): self._this = new _KFoldCrossValidator(G._this, linkPredictor._this, evaluator._this) ^ ------------------------------------------------------------ .../project.pyx:X:Y: Cannot convert Python object to '_LinkPredictor *'

I think this happens because as _this is only declared in KatzIndex it has the type _KatzIndex* instead of _LinkPredictor*. Now I tried to declare the inheritance-relationship from _LinkPredictor and _KatzIndex (by declaring _KatzIndex(_LinkPredictor)) and hoped that Cython would accept _this with type _LinkPredictor* as _KatzIndex derives from _LinkPredictor. But that doesn't seem to be the case.

Is this not possible right now with Cython or is my approach just flawed?

--

---
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.
Michael Helmling | 20 Mar 09:53 2015

language_level=3 does not enable float division

Not sure if this is a bug or feature, but apparently setting the
language_level=3
does not enable float division:

%%cython
cimport cython
<at> cython.language_level(3)
def test(int a, int b):
   
return a / b


Now test(1, 2) results in 0 instead of 0.5. Is this intended behavior? If so, it should at least be documented in the caveats section of the docs – it cost me some headache to find the source of a bug in this division problem! ;-)

--

---
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 | 19 Mar 16:52 2015
Picon

Passing C arguments to object creation

Hi,

In our codebase[0], in many cases we create objects by passing them
some arguments[1], while creating the object first then calling an init
method is much faster and allows C arguments passing without an
expensive conversion.

I wrote a testcase[2] demonstrating the performance benefits of that
change, here is a run of it on my system:
 Test0 1.283716981997713 pure python class
 Test1 0.506477493006969 cython class with __cinit__
 Test2 0.344539249985246 cython class with __init__
 Test3 0.290088731999276 cython class with another method call

We can see in the generated C code that calling init() induces no
conversion for the integers, and this improvement benefits even more
other data structures that don’t need to be boxed, like pointers or
structs.

My suggestion would be to compile a Test2() invokation in a similar
fashion to a Test3() one, since __pyx_pf_4test_5Test2___init__() and
__pyx_f_4test_5Test3_init() are already almost exactly the same
function.  This could lead to the addition of an init field to the
__pyx_obj_4test_Test2 struct to make that call even more efficient.

What do you think of that proposal? :)

[0] http://pytouhou.linkmauve.fr/
[1] http://hg.linkmauve.fr/touhou/file/tip/pytouhou/game/effect.pyx
[2] http://linkmauve.fr/files/init.pyx

-- 
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.
Courtenay Godshall | 19 Mar 03:18 2015

ANN: SciPy 2015 Call for Proposals & Registration Open - tutorial & talk submissions due April 1st

Wanted to share the Call for Proposals and registration info about the 2015 SciPy Conference (below) - more info on the conference website at http://scipy2015.scipy.org. Hope we'll have some Cython users / contributors participate!

Courtenay Godshall, SciPy 2015 Communications Co-Chair 

------------------

SciPy 2015 Conference (Scientific Computing with Python) Call for Proposals: Submit Your Tutorial and Talk Ideas by April 1, 2015


SciPy 2015, the fourteenth annual Scientific Computing with Python conference, will be held July 6-12, 2015 in Austin, Texas. SciPy is a community dedicated to the advancement of scientific computing through open source Python software for mathematics, science, and engineering. The annual SciPy Conference brings together over 500 participants from industry, academia, and government to showcase their latest projects, learn from skilled users and developers, and collaborate on code development. The full program will consist of two days of tutorials by followed by three days of presentations, and concludes with two days of developer sprints. More info available on the conference website: http://scipy2015.scipy.org; you can also sign up for mailing list updates or follow <at> scipyconf on Twitter and Google+.


We encourage you to submit tutorial or talk proposals in the categories below; please also share with others who you’d like to see participate!


We hope you’ll join us - early bird registration is open until May 15, 2015.

SCIPY TUTORIAL SESSION PROPOSALS – DEADLINE EXTENDED TO WED APRIL 1, 2015

The SciPy experience kicks off with two days of tutorials. These sessions provide extremely affordable access to expert training, and consistently receive fantastic feedback from participants. We're looking for submissions on topics from introductory to advanced - we'll have attendees across the gamut looking to learn. Whether you are a major contributor to a scientific Python library or an expert-level user, this is a great opportunity to share your knowledge and stipends are available. Submit Your Tutorial Proposal on the SciPy 2015 website: http://scipy2015.scipy.org

SCIPY TALK AND POSTER SUBMISSIONS – DUE APRIL 1, 2015

SciPy 2015 will include 3 major topic tracks and 7 mini-symposia tracks.  Submit Your Talk Proposal on the SciPy 2015 website: http://scipy2015.scipy.org

Major topic tracks include:

  • Scientific Computing in Python (General track)

  • Python in Data Science

  • Quantitative and Computational Social Sciences

Mini-symposia will include the applications of Python in:

  • Astronomy and astrophysics

  • Computational life and medical sciences

  • Engineering

  • Geographic information systems (GIS)

  • Geophysics

  • Oceanography and meteorology

  • Visualization, vision and imaging


If you have any questions or comments, feel free to contact us at: scipy-organizers <at> scipy.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.

Gmane