Ryan Lewis | 10 Oct 05:51 2014
Picon

Cython

Hi,

I am a researcher and I develop high performance  c++ software written with the generic programming paradigm for use in data analysis. I really would like an interpreter so that I can test ideas with my library in "real" time. Python itself has a massive amount of tools which would be useful when ingesting data as well as processing and visualizing results. 

I'm trying to evaluate the difficulty of using cython to take my heavily templated header only c++ code, data structures, and all, and get it working with cython? 

In particular:

1) http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html <-- this mentions that cython can "now deal with templates" although I don't see an example. Can anyone show me how that works? In particular, how about calling functions in C++ with arbitrary template parameters? Ideally there is some sort of caching of precompiled .so's so that this work is never repeated...

2) When bringing C++ structs/classes into Cython, is it necessary to write what looks like boilerplate: http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html#templates ? or does some code auto generate this?

I'll probably have more questions, but, i'll wait incase I didn't ask a well formed one so far. 

--

---
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.
Joakim Bø | 9 Oct 10:58 2014
Picon

Importing external types in cython

Hi guys!

I need som help applying Cython here; I'm a both a Cython and a C/C++ newbie, my programming has mostly been done in Python.

So, I want to speed up a for loop applying Cython. For my purpose I need to import some packages from an external library. In C++ one would do

#include <dolfin.h>,

then apply

using namespace dolfin;

When this has been done one could use the types in dolfin straightforwardly (e.g. Mesh, Function, Cell and so on..). Now my problem is to get these types into my Cython file, any ideas on how I can do this? I've tried searching around a lot but couldn't find anything.

Thanks in advance!

Joakim

--

---
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.
Phillip Middleton | 9 Oct 03:16 2014
Picon

Cython 0.21 compilation/installation error on Linux (Mint 17)

I have been fighting recently (never a previous problem) with upgrading Cython to v 0.21, eventually uninstalling it and trying a fresh install. The upgrade issue appeared to be due to something odd with setuptools (attribute error: no module 'Distutils' ..etc), or how it interacted with Cython during installation. 

I've posted the issue in StackExchange .  This is on Mint 17 using Python 2.7.6, gcc 4.8.4, setuptools 6.0.7 (now that I upgraded it)

In sum, I was attempting to upgrade several packages using pip, many among them which have Cython as a dependency. During that time I received the above attribute error, and found info that led me to believe setuptools required reinstallation. Did that. 
Upon trying to upgrade the packages again, I received errors from things like lxml, matplotlib, psycopg2, MarkupSafe, and a number of others the following complaint: 
ImportError: cannot import name load_ipython_extension.

The issue seemed calls to import Cython (which I had uninstalled). When I attempted install of Cython 0.21 (using pip, easy_install, and manual dl and build approaches) I got the error: 
[Errno 34]: numerical value out of range.

See this in more detail in the above link. 

Ok so I get it, it's an overflow problem. I could understand this if it were a program I was compiling, but I was simply building Cython itself. I did note that the Cython build seems to take various chunks from a zip file and makes this awful looking chain of paths with temp directories. I haven't a clue what it's trying to do. The error appears to occur during the final set of tasks wherein os.getpwdu() is called. I recall in the past that really long path names would bork it in 2.4-5, but I figured that it had been fixed.  What I cannot figure out is, what changed where I cannot install Cython? 

I was recommended to compile with --no-cython-compile, but a pure python implementation isn't what it was truly meant, so I fail to see the benefit. Still, I haven't tried checking whether this works yet or no, just for bug tracking. 

Also, I don't see a way to post bug candidates in Trac on cython.org (if this is indeed the case). Are these supposed to be directed to python.org?

thanks!

Phillip

--

---
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.
CW | 8 Oct 10:00 2014
Picon

Cythonize problem in Cython 0.21

Hi All,

I recently upgraded to Cython 0.21 and ran into trouble when running my setup.py script. The problem is in my call to Cythonize which is:

cythonize(["my.pyx"], include_path=["."],include_dirs=[numpy.get_include()],pyrex_gdb=True)

and i get the error:
Traceback (most recent call last):
 
File "setup.py", line 588, in <module>
    ext_list
= check_extensions()
 
File "setup.py", line 259, in check_extensions
    ext_list
= cythonize(["assimulo"+O.path.sep+"*.pyx"], include_path=[".","assimulo"],include_dirs=[N.get_include()],pyrex_gdb=debug_flag)
 
File "/usr/local/lib/python2.7/dist-packages/Cython/Build/Dependencies.py", line 704, in cythonize
    c_options
= CompilationOptions(**options)
 
File "/usr/local/lib/python2.7/dist-packages/Cython/Compiler/Main.py", line 501, in __init__
   
', '.join(unknown_options)))
ValueError: got unexpected compilation options: pyrex_gdb, include_dirs

The above command works fine in Cython 0.20 and earlier and I checked the changelog for Cython 0.21 but I couldn't find anything there that would cause this. So, my question is, how can I provide the options (include_dirs and pyrex_gdb) in Cython 0.21 and how can I adapt my command?

Thanks!

Best
/Christian

--

---
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.
yi huang | 8 Oct 05:55 2014
Picon

cython 0.21 "Storing unsafe C derivative of temporary Python reference"

I've met this error when i compiling kivy, i can reproduce it in this minimal code:

def main(s):
    cdef char* p = NULL
    p = <bytes>s[:10]

When compile above code, cython compains "Storing unsafe C derivative of temporary Python reference".

If i re-factor above code to this, cython compile it success:

def main(s):
    cdef char* p = NULL
    s1 = s[:10]
    p = <bytes>s1

Is this considered as a bug of cython or normal behavior, in latter case, i guess we need to begin to refactor some code.

--

---
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.
Brian | 5 Oct 07:20 2014
Picon

Compiler crash in AnalyseExpressionsTransform?

Hi all,

I am getting this error, and I am not sure what to do about it. I hope you can help! Please let me know if there is any other information I can provide to help figure this out.

Brian

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

        res1 = self.calculate_edge_force(avg_RacA_plus1, avg_RhoA_plus1, node_index, node_index_iPlus1, node_coords, initial_edge_length)
            ^
------------------------------------------------------------

cython_cell.pyx:881:13: Compiler crash in AnalyseExpressionsTransform

ModuleNode.body = StatListNode(cython_cell.pyx:7:0)
StatListNode.stats[14] = StatListNode(cython_cell.pyx:48:5)
StatListNode.stats[0] = CClassDefNode(cython_cell.pyx:48:5,
    as_name = u'ExperimentEnvironment',
    class_name = u'ExperimentEnvironment',
    module_name = u'',
    visibility = u'private')
CClassDefNode.body = StatListNode(cython_cell.pyx:49:4)
StatListNode.stats[37] = StatListNode(cython_cell.pyx:836:9)
StatListNode.stats[0] = CFuncDefNode(cython_cell.pyx:836:9,
    args = [...]/19,
    is_c_class_method = 1,
    modifiers = [...]/0,
    visibility = u'private')
File 'Nodes.py', line 392, in analyse_expressions: StatListNode(cython_cell.pyx:838:8,
    is_terminator = True)
File 'Nodes.py', line 392, in analyse_expressions: StatListNode(cython_cell.pyx:881:40)
File 'Nodes.py', line 4628, in analyse_expressions: SingleAssignmentNode(cython_cell.pyx:881:40)
File 'Nodes.py', line 4738, in analyse_types: SingleAssignmentNode(cython_cell.pyx:881:40)
File 'ExprNodes.py', line 1743, in analyse_target_types: NameNode(cython_cell.pyx:881:13,
    cf_is_null = True,
    cf_maybe_null = True,
    cf_state = [...]/0,
    is_name = True,
    name = u'res1',
    result_is_used = True,
    use_managed_ref = True)

Compiler crash traceback from this point on:
  File "/home/brian/anaconda/lib/python2.7/site-packages/Cython/Compiler/ExprNodes.py", line 1743, in analyse_target_types
    Buffer.used_buffer_aux_vars(self.entry)
  File "/home/brian/anaconda/lib/python2.7/site-packages/Cython/Compiler/Buffer.py", line 283, in used_buffer_aux_vars
    buffer_aux.buflocal_nd_var.used = True
AttributeError: 'NoneType' object has no attribute 'buflocal_nd_var'


--

---
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 | 3 Oct 09:27 2014
Picon

setting C++ mode in cythonize()

Hi,

the documentation suggests to pass language='c++' into cythonize() to
globally enable C++ mode, but AFAICT, this never actually worked. Cython
previously ignored this option, Cython 0.21 rejects it, and we didn't
update the docs, so the current situation is outright confusing.

http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html#specify-c-language-in-setup-py

To me, this option seems the one obvious way to do it, as it mimics the
distutils Extension API most closely. So, I now implemented support for
this, but only for modules found by file name, not for user provided
Extension objects. I think that's a reasonable restriction. If users
construct their own Extension instances anyway, they can just as well set
the 'language' option on them directly (and probably already do so).

https://github.com/cython/cython/commit/88df97f250073d8a06f965d6a7e09d8fe6f4ca63

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.

David Hwu | 1 Oct 03:05 2014
Picon

External Package Best Practice

We are looking at using Cython as the main tech behind our website.  Currently our stack is large with many dependencies.
For example:  Website Core depends on Frameworks A, B, C, D, E, F, G.  Each Framework depends on A-1, A-2, A-3, D-1, D-2, D-3, etc. etc.
This can get fairly large quickly, especially when we have to adopt a new version of framework (ie. B-Prime).

Was looking for feedback how this can be best handled without becoming repeating cost..

There are strong advocates who see the beauty of Cython and static typing feature set to help us write better code (granted using a sledge hammer to address dynamic typing issues).
A purist approach to cythonize all the dependencies outlined earlier is not a feasible solution.

Speed not being the prevailing factor, I am wondering about how others have solved this issue.  Community shared stories mainly around speed and improving the ONLY critical parts of the code as the main Cython workflow and value.

Providing a moat/glue layer between dependent framework and core cythonized code is another possible solution I have used prior.  In this case the framework and their dependencies would be pure open source Python code.

Is there anything I might be missing here?
Thanks!
David


--

---
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.
Yuxiang Wang | 30 Sep 21:39 2014
Picon

Anaconda configuration files?

Hi all,


I tried Anaconda3 (Windows, 64-bit, Python 3.4) earlier today and noticed that it bundles Cython really nice... I am able to use pyximport without specifying parameters. So, instead of

import pyximport 
pyximport.install(setup_args={"script_args":["--compiler=mingw32"], "include_dirs":numpy.get_include()})

I just ran 

import pyximport; pyximport.install()


For example, I used this simple cython code:

test_cy.pyx

import numpy as np

cpdef double [:] func():
    cdef double [:] a = np.arange(10.)
    return a

And then in IPython,

import pyximport; pyximport.install()
import test_cy
a = test_cy.func()
print(list(a))

It just worked.


My question is: how did they do that? Where did they put their configuration files to include np.get_include(), as well as --compiler=mingw32?

Thanks!

-Shawn

--

---
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.
Brian | 28 Sep 03:27 2014
Picon

Relatively simple function that mainly performs arithmetic is called many times - naive optimization using Cython by defining types causes slowdowns. How would I go about properly Cythonizing?

I wrote up my question earlier on the code review stackexchange, so I will link to it: http://codereview.stackexchange.com/questions/64040/relatively-simple-function-that-mainly-performs-arithmetic-is-called-many-times

Please do let me know if there is anything I can do to clarify the question, or any additional information you might require that would help in answering the question. Currently, the code in question takes up about...40% of my runtime. So, learning how to optimize it would be a very big deal for me!

--

---
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.
stonebig34 | 27 Sep 16:18 2014
Picon

LLVM-3.5.0-win32.exe for windows

Hello,

Excuse me in advance if the question is stupid.

On windows, can cython 0.21 use llvm 3.5 instead of mingw32 ? Is there an how-to somewhere ?

--

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