From stefan_ml at behnel.de Sat May 1 23:11:19 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 01 May 2010 23:11:19 +0200 Subject: [Cython] coercion of char/Py_UNICODE to Python objects - string or integer? In-Reply-To: <4BD3FD96.7080803@behnel.de> References: <4BCFE07F.70307@behnel.de> <6F4F2615-4B5B-4DAC-9089-15776CFECE29@math.washington.edu> <4BD3D308.6090509@behnel.de> <4BD3FD96.7080803@behnel.de> Message-ID: <4BDC98F7.7080405@behnel.de> Stefan Behnel, 25.04.2010 10:30: > Stefan Behnel, 25.04.2010 07:28: >> the question is just if we want >> >> py_int_val = uval >> py_ustr_val =uval >> >> or >> >> py_int_val =uval >> py_ustr_val = uval >> >> My gut feeling is that the coercion to strings would be more straight >> forward. It would also clean up the compiler code a bit as implicit >> coercions (e.g. for comparisons) would then work out-of-the-box in both >> ways. Currently, "Py_UNICODE in unicode" must be special cased (which it >> still would in the future, but only for optimisation purposes, not to make >> it work at all). > > Given that only char->bytes breaks backwards compatibility, since > Py_UNICODE wasn't supported at all until now - could we agree on making > Py_UNICODE->unicode the default behaviour and leaving char->PyInt as is for > the time being? We can still decide to break backwards compatibility later > on, and we can always support the explicit > > py_s =char_val > py_i =pyunicode_val > > safely, so users can just rely on that if they need safe behaviour. > > The 'reasoning' would be that a plain 'char' is a bit too generic to map it > to a Python bytes string (note that 'char*' isn't), whereas Py_UNICODE is > something that only really makes sense in the context of a Python unicode > string, so it's a lot less surprising if it also maps to a Python unicode > string. ... and this even matches the behaviour of the 'bytes' type in Python 3 which really returns integer values on indexing/iteration, whereas the 'str' (i.e. 'unicode') type returns substrings. I've implemented the explicit (char)->bytes and default Py_UNICODE->unicode coercions and updated the documentation chapter on string handling accordingly. http://hg.cython.org/cython-docs/rev/e712d9647f47 Stefan From dalcinl at gmail.com Sun May 2 23:49:04 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sun, 2 May 2010 18:49:04 -0300 Subject: [Cython] ssize_t_T399 test failing in Py2.4 In-Reply-To: <4BDC60A0.6020701@behnel.de> References: <4BDC60A0.6020701@behnel.de> Message-ID: On 1 May 2010 14:10, Stefan Behnel wrote: > Hi Lisandro, > > I get this in Py2.4 after your last commit. Can you take a look? > Is that machine a 64bits one? In such case, the test is broken, because of this line: SSIZE_T_MAX = ((-1)>>1) I've pushed a quick fix: http://hg.cython.org/cython-devel/rev/66bc28d5c751 PS: Can you see now why I was no so happy about using Py_ssize_t? Do you think that my original way of defining SSIZE_T_MAX was a nonsense? We should not enforce ssize_t meaning Py_ssize_t, but in case we do it anyway, we should provide users a last chance to change our decision (i.e, add an indirection and #define __Pyx_ssize_t Py_ssize_t). > > > Traceback (most recent call last): > ?File > "/home/scoder/hudson/jobs/py24-svn/workspace/INSTALL/py24/lib/python2.4/doctest.py", > line 2157, in runTest > ? ?raise self.failureException(self.format_failure(new.getvalue())) > AssertionError: Failed doctest test for ssize_t_T399 > ?File > "/mnt/usb1/scratch/hudson/jobs/cython-devel-tests-py24-c/workspace/BUILD/run/c/ssize_t_T399.so", > line 27, in ssize_t_T399 > > ---------------------------------------------------------------------- > File > "/mnt/usb1/scratch/hudson/jobs/cython-devel-tests-py24-c/workspace/BUILD/run/c/ssize_t_T399.so", > line 45, in ssize_t_T399 > Failed example: > ? ?test(SSIZE_T_MAX+1) #doctest: +ELLIPSIS > Expected: > ? ?Traceback (most recent call last): > ? ? ? ?... > ? ?OverflowError: ... > Got: > ? ?0 > ---------------------------------------------------------------------- > File > "/mnt/usb1/scratch/hudson/jobs/cython-devel-tests-py24-c/workspace/BUILD/run/c/ssize_t_T399.so", > line 49, in ssize_t_T399 > Failed example: > ? ?test(SSIZE_T_MIN-1) #doctest: +ELLIPSIS > Expected: > ? ?Traceback (most recent call last): > ? ? ? ?... > ? ?OverflowError: ... > Got: > ? ?-1 > > -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From dalcinl at gmail.com Mon May 3 00:45:11 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sun, 2 May 2010 19:45:11 -0300 Subject: [Cython] coercion of char/Py_UNICODE to Python objects - string or integer? In-Reply-To: <4BDC98F7.7080405@behnel.de> References: <4BCFE07F.70307@behnel.de> <6F4F2615-4B5B-4DAC-9089-15776CFECE29@math.washington.edu> <4BD3D308.6090509@behnel.de> <4BD3FD96.7080803@behnel.de> <4BDC98F7.7080405@behnel.de> Message-ID: On 1 May 2010 18:11, Stefan Behnel wrote: > ... and this even matches the behaviour of the 'bytes' type in Python 3 > which really returns integer values on indexing/iteration, whereas the > 'str' (i.e. 'unicode') type returns substrings. VERY good point... -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From baihaoyu at gmail.com Mon May 3 12:19:40 2010 From: baihaoyu at gmail.com (Haoyu Bai) Date: Mon, 3 May 2010 18:19:40 +0800 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: References: <4BD86899.6090402@behnel.de> Message-ID: On Thu, Apr 29, 2010 at 1:14 AM, Craig Citro wrote: >>> The list of accepted applications for Google Summer of Code 2010 were >>> just announced yesterday, and Haoyu Bai's Cython application was >>> officially accepted. Congratulations, and we're looking forward to a >>> lot of great stuff happing this summer. >> >> Happy to read this. Congratulations! >> > > Ditto -- between this and several of us having other responsibilities > off our shoulders, it should be an exciting summer for Cython. ;) > > -cc Thank you all! I'm excited about the summer, too! :) Craig and I have discussed about the workflow. I'll use some local hg branches to maintain the patches and submit the patches to trac. Hopefully I can start to work on Cython sooner. -- Haoyu BAI School of Computing, National University of Singapore. From kwmsmith at gmail.com Mon May 3 17:34:02 2010 From: kwmsmith at gmail.com (Kurt Smith) Date: Mon, 3 May 2010 10:34:02 -0500 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: References: <4BD86899.6090402@behnel.de> Message-ID: On Mon, May 3, 2010 at 5:19 AM, Haoyu Bai wrote: > On Thu, Apr 29, 2010 at 1:14 AM, Craig Citro wrote: >>>> The list of accepted applications for Google Summer of Code 2010 were >>>> just announced yesterday, and Haoyu Bai's Cython application was >>>> officially accepted. Congratulations, and we're looking forward to a >>>> lot of great stuff happing this summer. >>> >>> Happy to read this. Congratulations! >>> >> >> Ditto -- between this and several of us having other responsibilities >> off our shoulders, it should be an exciting summer for Cython. ;) >> >> -cc > > Thank you all! I'm excited about the summer, too! :) > > Craig and I have discussed about the workflow. I'll use some local hg > branches to maintain the patches and submit the patches to trac. > Hopefully I can start to work on Cython sooner. Just a suggestion, take it or leave it: For my GSoC work I found google's codereview to be a very helpful tool. http://code.google.com/p/rietveld/wiki/CodeReviewHelp It allows you to submit patches that are presented in an app-engine GUI. Reviewers can make comments & suggestions that are local to each change in the patch. Perhaps it would be easier to use for interactive patch review than trac. (It works seamlessly with mercurial, too). Good luck! Kurt From craigcitro at gmail.com Mon May 3 17:40:32 2010 From: craigcitro at gmail.com (Craig Citro) Date: Mon, 3 May 2010 08:40:32 -0700 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: References: <4BD86899.6090402@behnel.de> Message-ID: > Just a suggestion, take it or leave it: > > For my GSoC work I found google's codereview to be a very helpful tool. > > http://code.google.com/p/rietveld/wiki/CodeReviewHelp > > It allows you to submit patches that are presented in an app-engine > GUI. ?Reviewers can make comments & suggestions that are local to each > change in the patch. > > Perhaps it would be easier to use for interactive patch review than > trac. (It works seamlessly with mercurial, too). > +10 -- we should *totally* start using rietveld. (Plus, in a month or two, Robert and I will be totally in love with it.) -cc From robertwb at math.washington.edu Mon May 3 19:58:59 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 3 May 2010 10:58:59 -0700 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: References: <4BD86899.6090402@behnel.de> Message-ID: <1FBF84E4-2FDE-41C3-A009-8A95BD693053@math.washington.edu> On May 3, 2010, at 8:40 AM, Craig Citro wrote: >> Just a suggestion, take it or leave it: >> >> For my GSoC work I found google's codereview to be a very helpful >> tool. >> >> http://code.google.com/p/rietveld/wiki/CodeReviewHelp >> >> It allows you to submit patches that are presented in an app-engine >> GUI. Reviewers can make comments & suggestions that are local to >> each >> change in the patch. >> >> Perhaps it would be easier to use for interactive patch review than >> trac. (It works seamlessly with mercurial, too). >> > > +10 -- we should *totally* start using rietveld. (Plus, in a month or > two, Robert and I will be totally in love with it.) I already am :). It may be good to put up a repo on hg.cython.org (so it's easy for people to sync up with what you have to try it out and play with it). Also, did you set up a blog yet? - Robert From marien.zwart at gmail.com Mon May 3 20:22:30 2010 From: marien.zwart at gmail.com (Marien Zwart) Date: Mon, 03 May 2010 20:22:30 +0200 Subject: [Cython] Missed optimization for list.pop Message-ID: <1272910950.5314.29.camel@cyclops> Hi, http://trac.cython.org/cython_trac/ticket/447 describes an added optimization for calls to list.pop(). Somewhat counter-intuitively this optimization is only applied if pop() is called on things of type "object", not if it is called on things explicitly typed as "list". Compare the following (silly) examples: def f(): cdef list l = [] l.append(0) l.pop() return l def f(): cdef object l = [] l.append(0) l.pop() return l Using either Cython 0.12.1 or cython-devel the second one generates calls to __Pyx_Object_Append and __Pyx_Object_Pop, which take fast paths if called on a list. The first one generates a direct to PyList_Append, but then PyObject_GetAttr and PyObject_Call for pop(). It might be nice to add: _handle_simple_method_list_pop = _handle_simple_method_object_pop somewhere in Cython/Compiler/Optimize.py, which at least makes Cython not generate worse code for the more restrictively typed list (tested it briefly, the resulting code looked reasonable and compiled). From stefan_ml at behnel.de Tue May 4 07:30:30 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 04 May 2010 07:30:30 +0200 Subject: [Cython] Missed optimization for list.pop In-Reply-To: <1272910950.5314.29.camel@cyclops> References: <1272910950.5314.29.camel@cyclops> Message-ID: <4BDFB0F6.9030801@behnel.de> Marien Zwart, 03.05.2010 20:22: > http://trac.cython.org/cython_trac/ticket/447 describes an added > optimization for calls to list.pop(). Somewhat counter-intuitively this > optimization is only applied if pop() is called on things of type > "object", not if it is called on things explicitly typed as "list". > Compare the following (silly) examples: > > def f(): > cdef list l = [] > l.append(0) > l.pop() > return l > > def f(): > cdef object l = [] > l.append(0) > l.pop() > return l > > Using either Cython 0.12.1 or cython-devel the second one generates > calls to __Pyx_Object_Append and __Pyx_Object_Pop, which take fast paths > if called on a list. The first one generates a direct to PyList_Append, > but then PyObject_GetAttr and PyObject_Call for pop(). Yes, I stumbled over that, too, but didn't care to fix it so far. I'll look into it. Stefan From stefan_ml at behnel.de Tue May 4 07:57:28 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 04 May 2010 07:57:28 +0200 Subject: [Cython] Missed optimization for list.pop In-Reply-To: <1272910950.5314.29.camel@cyclops> References: <1272910950.5314.29.camel@cyclops> Message-ID: <4BDFB748.1070605@behnel.de> Marien Zwart, 03.05.2010 20:22: > It might be nice to add: > _handle_simple_method_list_pop = _handle_simple_method_object_pop > > somewhere in Cython/Compiler/Optimize.py, which at least makes Cython > not generate worse code for the more restrictively typed list (tested it > briefly, the resulting code looked reasonable and compiled). That's also the right thing to do. The resulting code is just about as fast as a specialised function for typed lists, so it's not worth doing anything more than that. Thanks! Stefan From stefan_ml at behnel.de Tue May 4 11:16:52 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 04 May 2010 11:16:52 +0200 Subject: [Cython] 'private' extension classes (ticket 263) Message-ID: <4BDFE604.3030708@behnel.de> Hi, the last discussion on this dates back to 2008, and I'd like to finally get this finished up. What would be a good syntax for extension types that are not visible from Python space? I guess a class decorator would make sense, so what about @cython.python_visible(False) cdef class MyType: ... ? Or should we extend the proposed 'cclass' decorator in pure mode? @cython.cclass(python_visible=False) class MyType: ... or both? Stefan From dalcinl at gmail.com Tue May 4 14:47:35 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Tue, 4 May 2010 09:47:35 -0300 Subject: [Cython] 'private' extension classes (ticket 263) In-Reply-To: <4BDFE604.3030708@behnel.de> References: <4BDFE604.3030708@behnel.de> Message-ID: On 4 May 2010 06:16, Stefan Behnel wrote: > > @cython.cclass(python_visible=False) > class MyType: > ? ? ... > I like the second, because could even think about extending it to: @cython.cclass(export=True, api=True) class MyType: ... or something on that line, in order to fix the overloaded meaning of "public" and also turn on API generation. However, the concept of "python_visible" could also apply to enum's, and even struct's (provided we can ever manage to fully automate Py<->C conversion). So perhaps we should think about something more generic than "cclass" ? -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From gabriele.lanaro at gmail.com Tue May 4 15:36:07 2010 From: gabriele.lanaro at gmail.com (Gabriele Lanaro) Date: Tue, 4 May 2010 15:36:07 +0200 Subject: [Cython] building cython modules in another position Message-ID: Hi! In the project I'm working on there is a splitting between extension source files and pure python source files. I've some problems in compiling correctly the extensions: Src/cython/ one.pyx one.pxd two.pyx two.pxd ... Package/ __init__.py stuff.py ... one,two etc are dependent each other ("two" has a cimport statement in it) When compiling the situation should be: Package/ __init__.py stuff.py one.so two.so ... When importing two.so there's an import error like this (name are different but the concept is the same): File "primitive_gto.pxd", line 18, in contracted_gto (Src/PyQuante/contracted_gto.c:1843) ImportError: No module named primitive_gto If I move the .pyx and .pxd files in Package the compilation goes ok. How can I obtain a correct compilation using the first package structure? (I really need that, it's not my choice) - Gabriele -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20100504/4dd1f57f/attachment.htm From kwmsmith at gmail.com Tue May 4 17:22:14 2010 From: kwmsmith at gmail.com (Kurt Smith) Date: Tue, 4 May 2010 10:22:14 -0500 Subject: [Cython] building cython modules in another position In-Reply-To: References: Message-ID: On Tue, May 4, 2010 at 8:36 AM, Gabriele Lanaro wrote: > Hi! > In the project I'm working on there is a splitting between extension source > files and pure python source files. I've some problems in compiling > correctly the extensions: > Src/cython/ > ? ? ? ?? one.pyx > ? ? ? ?? one.pxd > ? ? ? ?? two.pyx > ???????? two.pxd > ???????? ... > Package/ > ???????? __init__.py > ???????? stuff.py > ???????? ... > > one,two etc are dependent each other ("two" has a cimport statement in it) > When compiling the situation should be: > > Package/ > ????? __init__.py > ????? stuff.py > ????? one.so > ????? two.so > ????? ... > > When importing two.so there's an import error like this (name are different > but the concept is the same): > > File "primitive_gto.pxd", line 18, in contracted_gto > (Src/PyQuante/contracted_gto.c:1843) > ImportError: No module named primitive_gto > > If I move the .pyx and .pxd files in Package the compilation goes ok. How > can I obtain a correct compilation using the first package structure? > > (I really need that, it's not my choice) Looks like Cython (and Cython's distutils) needs to know about the package structure at compile time to get everything setup right. One solution would be the following. Arrange your directory structure like this: . |-- Makefile |-- Package | |-- __init__.py | `-- stuff.py `-- src |-- Package | |-- __init__.py | |-- one.pxd | |-- one.pyx | |-- two.pxd | `-- two.pyx `-- setup.py Essentially you create a parallel package structure with the cython sources, and tell distutils to put the compiled extension modules in the right place. Here's the contents of the makefile: $ cat Makefile all: (cd src && python setup.py build_ext -b ..) clean: -rm -r src/build -rm Package/*.so -rm src/Package/*.c I've attached this solution to the email -- hopefully it gives you the idea. Kurt -------------- next part -------------- A non-text attachment was scrubbed... Name: test_cython_compile.tgz Type: application/x-gzip Size: 1082 bytes Desc: not available Url : http://codespeak.net/pipermail/cython-dev/attachments/20100504/22758ff4/attachment.bin From gabriele.lanaro at gmail.com Tue May 4 18:36:32 2010 From: gabriele.lanaro at gmail.com (Gabriele Lanaro) Date: Tue, 4 May 2010 18:36:32 +0200 Subject: [Cython] building cython modules in another position In-Reply-To: References: Message-ID: Thank you very much for pointing this out and giving me the example, now I've solved my problem. It also work by putting setup.py script one level up. I also want to reinforce that the __init__.py file in src/Package is required (for other people searching for a solution). Thanks again, - Gabriele 2010/5/4 Kurt Smith > On Tue, May 4, 2010 at 8:36 AM, Gabriele Lanaro > wrote: > > Hi! > > In the project I'm working on there is a splitting between extension > source > > files and pure python source files. I've some problems in compiling > > correctly the extensions: > > Src/cython/ > > one.pyx > > one.pxd > > two.pyx > > two.pxd > > ... > > Package/ > > __init__.py > > stuff.py > > ... > > > > one,two etc are dependent each other ("two" has a cimport statement in > it) > > When compiling the situation should be: > > > > Package/ > > __init__.py > > stuff.py > > one.so > > two.so > > ... > > > > When importing two.so there's an import error like this (name are > different > > but the concept is the same): > > > > File "primitive_gto.pxd", line 18, in contracted_gto > > (Src/PyQuante/contracted_gto.c:1843) > > ImportError: No module named primitive_gto > > > > If I move the .pyx and .pxd files in Package the compilation goes ok. How > > can I obtain a correct compilation using the first package structure? > > > > (I really need that, it's not my choice) > > Looks like Cython (and Cython's distutils) needs to know about the > package structure at compile time to get everything setup right. > > One solution would be the following. Arrange your directory structure > like this: > > . > |-- Makefile > |-- Package > | |-- __init__.py > | `-- stuff.py > `-- src > |-- Package > | |-- __init__.py > | |-- one.pxd > | |-- one.pyx > | |-- two.pxd > | `-- two.pyx > `-- setup.py > > Essentially you create a parallel package structure with the cython > sources, and tell distutils to put the compiled extension modules in > the right place. > > Here's the contents of the makefile: > > $ cat Makefile > all: > (cd src && python setup.py build_ext -b ..) > > clean: > -rm -r src/build > -rm Package/*.so > -rm src/Package/*.c > > I've attached this solution to the email -- hopefully it gives you the > idea. > > Kurt > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20100504/738b081f/attachment-0001.htm From binet at cern.ch Tue May 4 20:43:09 2010 From: binet at cern.ch (Sebastien Binet) Date: Tue, 4 May 2010 20:43:09 +0200 Subject: [Cython] json to .pxd - autogen cython declaration code In-Reply-To: References: <1271407753-sup-9628@farnsworth> <1271760467-sup-7955@farnsworth> Message-ID: <1272998114-sup-4328@farnsworth> Excerpts from David Cournapeau's message of 2010-04-22 05:09:43 +0200: > On Tue, Apr 20, 2010 at 7:53 PM, Sebastien Binet wrote: > > Excerpts from David Cournapeau's message of 2010-04-20 12:06:17 +0200: > >> On Tue, Apr 20, 2010 at 12:57 AM, Haoyu Bai wrote: > >> > >> > Hi, > >> > > >> > I just found a project on GitHub which might do the thing you want: > >> > > >> > http://github.com/cournape/cython-codegen > >> > >> That code is horrible though :) > > > > don't worry about that, I am dealing with high energy physicists (C++ > > and python) code on a daily basis :) > > I love the researchers/C++ combination, always full of surprises :) > > I mostly meant that something reusable should not be based on this > code at all - neither the implementation nor the idea of reusing > gccxml makes much sense for something meant to be used in the long > term. Gccxml is not that great, because it is not really maintained, a > PITA to build, and you cannot force C mode (which was the biggest > issue in my case, and I guess an issue for many cython users). > > > > > thanks for the link. > > llvm/clang was on my radar (I played a bit w/ llvm-py) but this > > tutorial will most definitely help ! > > Yes, unfortunately, there is no python API, and llvm is not as mature > as I had hoped (the API has significantly changed since this tutorial, > for example). OTOH, for C++, llvm code is relatively readable, and > there are also an ocaml interface and a haskell one > (http://augustss.blogspot.com/) - maybe a good excuse to learn > haskell. > > It took me half a day to be able to implement a basic pre-processor in > C++ with llvm, so anyone more familiar with C++ (and parsing > techniques) should be able to implement something useful in a short > amount of time, ok... let me push something out of the door: http://bitbucket.org/binet/cylon/src/tip/ext/clang/genjson/ the code is still *very* crappy and it seems I managed to make the clang plugin loader crash when STL headers are included in someone's source code... but it would be a start. in that directory you'll find a dumb Makefile which should: - compile the CLang plugin library - run the plugin on the utest.cxx file (through run.py) - which will create a utest_ast.py file - and then create a utest_ast.json file from it now that I know a bit more my way around CLang's source code, I shall re-do the exercize using the ast-print-xml plugin as inspiration (for some reason, that plugin crashes or just creates corrupted xml files...) I mainly put the utest_ast.{py,json} as a tentative start for feedback on what and how types,fcts,... should be exposed. (a proper python API to manipulate those ast/json structures should also be devised) cheers, sebastien. -- ######################################### # Dr. Sebastien Binet # Laboratoire de l'Accelerateur Lineaire # Universite Paris-Sud XI # Batiment 200 # 91898 Orsay ######################################### From dalcinl at gmail.com Wed May 5 17:23:08 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 5 May 2010 12:23:08 -0300 Subject: [Cython] legacy pxd's in Cython/Includes Message-ID: How are we going to manage these old, deprecated pxd's? I would Like to move all them to other place (let say Cython/IncludesOld) and add that dir to the default search path for a few releases. No idea how to generate a deprecation warning, though. -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From dalcinl at gmail.com Wed May 5 19:02:21 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 5 May 2010 14:02:21 -0300 Subject: [Cython] going to add POSIX pxd's, needing a little help from your side Message-ID: I'm in the process of adding some pxd's in Cython/Includes for POSIX (up to now, I've implemented 'fcntl' and 'unistd'). I want to add some tests, I've started implementing a context manager for temporarily stdout redirection to /dev/null in order to call a noisy, external C function with lots of hard-wired 'printf' calls. But these tests will not run on Windows. Could any of you fix runtests.py to filter testcases with 'posix' in their name if os.name()!='posix' ? I could do it myself after some research, but I bet Stefan/Robert can implement it in 5 seconds :-) After that, I could push my POSIX stuff. PS: Cython's testsuite is running on Windows (Vista+MSVC|MinGW) with 0(zero) failures! And I do not want to push things that could change that ;-) -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From dagss at student.matnat.uio.no Wed May 5 19:06:40 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 05 May 2010 19:06:40 +0200 Subject: [Cython] going to add POSIX pxd's, needing a little help from your side In-Reply-To: References: Message-ID: <4BE1A5A0.2030405@student.matnat.uio.no> Lisandro Dalcin wrote: > I'm in the process of adding some pxd's in Cython/Includes for POSIX > (up to now, I've implemented 'fcntl' and 'unistd'). I want to add some > tests, I've started implementing a context manager for temporarily > stdout redirection to /dev/null in order to call a noisy, external C > function with lots of hard-wired 'printf' calls. > > But these tests will not run on Windows. Could any of you fix > runtests.py to filter testcases with 'posix' in their name if > os.name()!='posix' ? I could do it myself after some research, but I > bet Stefan/Robert can implement it in 5 seconds :-) After that, I > could push my POSIX stuff. I don't have time now, but you could add the pattern to EXT_DEP_MODULES at the top of runtests.py; conditional on the import of the fcntl module. -- Dag Sverre From dagss at student.matnat.uio.no Wed May 5 19:08:55 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 05 May 2010 19:08:55 +0200 Subject: [Cython] going to add POSIX pxd's, needing a little help from your side In-Reply-To: <4BE1A5A0.2030405@student.matnat.uio.no> References: <4BE1A5A0.2030405@student.matnat.uio.no> Message-ID: <4BE1A627.1020500@student.matnat.uio.no> Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: >> I'm in the process of adding some pxd's in Cython/Includes for POSIX >> (up to now, I've implemented 'fcntl' and 'unistd'). I want to add some >> tests, I've started implementing a context manager for temporarily >> stdout redirection to /dev/null in order to call a noisy, external C >> function with lots of hard-wired 'printf' calls. >> >> But these tests will not run on Windows. Could any of you fix >> runtests.py to filter testcases with 'posix' in their name if >> os.name()!='posix' ? I could do it myself after some research, but I >> bet Stefan/Robert can implement it in 5 seconds :-) After that, I >> could push my POSIX stuff. > > I don't have time now, but you could add the pattern to EXT_DEP_MODULES > at the top of runtests.py; conditional on the import of the fcntl module. > Also, going offtopic for the benefit of anyone who might struggle with the fcntl module: flock is bad. lockf is good. At least in the context of programming on a cluster. (Yes, there are two of them, and I wasted some hours before I discovered that.) -- Dag Sverre From dalcinl at gmail.com Wed May 5 19:42:20 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 5 May 2010 14:42:20 -0300 Subject: [Cython] going to add POSIX pxd's, needing a little help from your side In-Reply-To: <4BE1A627.1020500@student.matnat.uio.no> References: <4BE1A5A0.2030405@student.matnat.uio.no> <4BE1A627.1020500@student.matnat.uio.no> Message-ID: On 5 May 2010 14:08, Dag Sverre Seljebotn wrote: > > Also, going offtopic for the benefit of anyone who might struggle with > the fcntl module: > > flock is bad. lockf is good. At least in the context of programming on a > cluster. (Yes, there are two of them, and I wasted some hours before I > discovered that.) > So MPI_File_xxx API's are not useful for your? -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From dalcinl at gmail.com Wed May 5 19:49:12 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 5 May 2010 14:49:12 -0300 Subject: [Cython] going to add POSIX pxd's, needing a little help from your side In-Reply-To: <4BE1A5A0.2030405@student.matnat.uio.no> References: <4BE1A5A0.2030405@student.matnat.uio.no> Message-ID: On 5 May 2010 14:06, Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: >> I'm in the process of adding some pxd's in Cython/Includes for POSIX >> (up to now, I've implemented 'fcntl' and 'unistd'). I want to add some >> tests, I've started implementing a context manager for temporarily >> stdout redirection to /dev/null in order to call a noisy, external C >> function with lots of hard-wired 'printf' calls. >> >> But these tests will not run on Windows. Could any of you fix >> runtests.py to filter testcases with 'posix' in their name if >> os.name()!='posix' ? I could do it myself after some research, but I >> bet Stefan/Robert can implement it in 5 seconds :-) ?After that, I >> could push my POSIX stuff. > > I don't have time now, but you could add the pattern to EXT_DEP_MODULES > at the top of runtests.py; conditional on the import of the fcntl module. > Yes, I now see that's the way, though I'll make it conditional on the import of the 'posix' module. -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From dalcinl at gmail.com Wed May 5 20:52:47 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 5 May 2010 15:52:47 -0300 Subject: [Cython] going to add POSIX pxd's, needing a little help from your side In-Reply-To: References: Message-ID: On 5 May 2010 14:02, Lisandro Dalcin wrote: > I'm in the process of adding some pxd's in Cython/Includes for POSIX > (up to now, I've implemented 'fcntl' and 'unistd'). http://hg.cython.org/cython-devel/rev/9dc7e1a2d56a -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From dagss at student.matnat.uio.no Wed May 5 21:10:12 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 05 May 2010 21:10:12 +0200 Subject: [Cython] going to add POSIX pxd's, needing a little help from your side In-Reply-To: References: <4BE1A5A0.2030405@student.matnat.uio.no> <4BE1A627.1020500@student.matnat.uio.no> Message-ID: <4BE1C294.4060207@student.matnat.uio.no> Lisandro Dalcin wrote: > On 5 May 2010 14:08, Dag Sverre Seljebotn wrote: >> Also, going offtopic for the benefit of anyone who might struggle with >> the fcntl module: >> >> flock is bad. lockf is good. At least in the context of programming on a >> cluster. (Yes, there are two of them, and I wasted some hours before I >> discovered that.) >> > > So MPI_File_xxx API's are not useful for your? Well, if I can avoid writing at that low level I do so (and I haven't had the need yet). I prefer working with a self-annotating file format of some sort, either HDF5 or FITS. HDF5 does support MPI-IO, but the available Python wrappers doesn't follow through currently... Luckily my applications are not anywhere close to be filesystem IO bound. Locking with lockf then opening the file using h5py or PyTables is convenient for some isolated purposes (but the occasions IO is needed must be few, or else the processes will just sit and wait for locks...). -- Dag Sverre From wing1127aishi at gmail.com Wed May 5 23:46:48 2010 From: wing1127aishi at gmail.com (Leon Sit) Date: Wed, 5 May 2010 16:46:48 -0500 Subject: [Cython] Status of closure Message-ID: Hi all, I have been following the dev mailing list and got the impression that closure will likely to be merged to the next release. Is it still the case? If this is the case, what branch should I pull to test-run the closure code? I have some mount of code that make heavy use of itertools and would like to test the new features against my code. Thanks. Leon From craigcitro at gmail.com Thu May 6 00:19:16 2010 From: craigcitro at gmail.com (Craig Citro) Date: Wed, 5 May 2010 15:19:16 -0700 Subject: [Cython] Status of closure In-Reply-To: References: Message-ID: Hi Leon, > I have been following the dev mailing list and got the impression that > closure will likely to be merged to the next release. Is it still the > case? If this is the case, what branch should I pull to test-run the > closure code? I have some mount of code that make heavy use of > itertools and would like to test the new features against my code. > The plan is still to include closures in 0.13 -- it's currently long-delayed, but it will happen. I'm the release manager, but I've been horribly busy with the rest of life. In the interim, you can just clone the closures branch: http://hg.cython.org/cython-closures/ which also has the most recent cython-devel merged, too. Give it a go, and definitely let us know if you run into any troubles. Warning: closures are supported, but generators/yield are still not, unless Stefan's been doing more than I think. ;) -cc From robertwb at math.washington.edu Sat May 8 21:39:29 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 8 May 2010 12:39:29 -0700 Subject: [Cython] legacy pxd's in Cython/Includes In-Reply-To: References: Message-ID: <621B3AAC-F69A-4BED-83EA-5016A7F57EDC@math.washington.edu> On May 5, 2010, at 8:23 AM, Lisandro Dalcin wrote: > How are we going to manage these old, deprecated pxd's? I would Like > to move all them to other place (let say Cython/IncludesOld) and add > that dir to the default search path for a few releases. Or maybe even Cython/Includes/deprecated (where one would still be able to look them up as if they were top level with a warning 'till their gone). > No idea how to generate a deprecation warning, though. Maybe in the lookup module code, where it tries to locate the pxd, if all else fails it could try that directory (hard coded in) and raise a deprecation warning before failing. Somehow it'd be nice for the message to tell it where to actually look. - Robert From robertwb at math.washington.edu Sat May 8 23:34:15 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 8 May 2010 14:34:15 -0700 Subject: [Cython] Fwd: AttributeError: 'CppClassScope' object has no attribute 'add_include_file' References: <87ljbuyvkn.fsf@tiny.univ-orleans.fr> Message-ID: <055E14CF-0761-470C-83BF-7A3F68BA5C2C@math.washington.edu> Here's a message from a user who had his email bounce because he's not signed up to the list. > From: Denys Duchier > Subject: AttributeError: 'CppClassScope' object has no attribute > 'add_include_file' > To: cython-dev at codespeak.net > Date: Sat, 08 May 2010 20:56:50 +0200 > > not sure where to submit this bug report/fix, so here goes: > > I am using cython-devel, and "extern +" annotations on methods of a > "cdef cppclass" declaration dont currently compile due to the > following > error: > > File "/home/denys/lib/python/Cython/Compiler/Nodes.py", line 575, > in analyse > env.add_include_file('stdexcept') > AttributeError: 'CppClassScope' object has no attribute > 'add_include_file' > > I managed to make it compile happily with the following patch: > > diff -r 85ae5e1b7fb9 Cython/Compiler/Symtab.py > --- a/Cython/Compiler/Symtab.py Thu May 06 08:27:37 2010 +0200 > +++ b/Cython/Compiler/Symtab.py Sat May 08 20:44:51 2010 +0200 > @@ -643,6 +643,9 @@ > else: > return outer.is_cpp() > > + def add_include_file(self, filename): > + self.outer_scope.add_include_file(filename) > + > class PreImportScope(Scope): > > namespace_cname = Naming.preimport_cname > > Cheers, > > --Denys > ---------- From dalcinl at gmail.com Sun May 9 00:30:33 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sat, 8 May 2010 19:30:33 -0300 Subject: [Cython] Fwd: AttributeError: 'CppClassScope' object has no attribute 'add_include_file' In-Reply-To: <055E14CF-0761-470C-83BF-7A3F68BA5C2C@math.washington.edu> References: <87ljbuyvkn.fsf@tiny.univ-orleans.fr> <055E14CF-0761-470C-83BF-7A3F68BA5C2C@math.washington.edu> Message-ID: On 8 May 2010 18:34, Robert Bradshaw wrote: > Here's a message from a user who had his email bounce because he's not > signed up to the list. > >> From: Denys Duchier >> Subject: AttributeError: 'CppClassScope' object has no attribute >> 'add_include_file' >> To: cython-dev at codespeak.net >> Date: Sat, 08 May 2010 20:56:50 +0200 >> >> not sure where to submit this bug report/fix, so here goes: >> >> I am using cython-devel, and "extern +" annotations on methods of a >> "cdef cppclass" declaration dont currently compile due to the >> following >> error: >> >> ?File "/home/denys/lib/python/Cython/Compiler/Nodes.py", line 575, >> in analyse >> ? ?env.add_include_file('stdexcept') >> AttributeError: 'CppClassScope' object has no attribute >> 'add_include_file' >> >> I managed to make it compile happily with the following patch: >> >> diff -r 85ae5e1b7fb9 Cython/Compiler/Symtab.py >> --- a/Cython/Compiler/Symtab.py ? ? ? Thu May 06 08:27:37 2010 +0200 >> +++ b/Cython/Compiler/Symtab.py ? ? ? Sat May 08 20:44:51 2010 +0200 >> @@ -643,6 +643,9 @@ >> ? ? ? ? else: >> ? ? ? ? ? ? return outer.is_cpp() >> >> + ? ?def add_include_file(self, filename): >> + ? ? ? ?self.outer_scope.add_include_file(filename) >> + >> class PreImportScope(Scope): >> >> ? ? namespace_cname = Naming.preimport_cname >> >> Cheers, >> >> --Denys >> ---------- > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > A slightly different approach (add the missing method to CppClassScope), and a few tests: http://hg.cython.org/cython-devel/rev/e14fe9894ca9 Many thanks to Denys for reporting the issue. -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From ademan555 at gmail.com Sun May 9 08:12:58 2010 From: ademan555 at gmail.com (Dan Roberts) Date: Sat, 8 May 2010 23:12:58 -0700 Subject: [Cython] __Pyx_GetException() and friends In-Reply-To: References: Message-ID: The code that Cython generates for numpy/random/mtrand/mtrand.pyx contains several __Pyx_*() functions that muck about in the PyThreadState object (which isn't standard) but each seems to have a sanctioned equivalent provided in the official C API, listed here: http://docs.python.org/c-api/exceptions.html This is important because non-CPython interpreters likely won't expose that struct, and indeed PyPy does not, and it would be cumbersome to do so. So I suppose my question, then, is, is there a reason why those functions are implemented? I'm asking here before filing a bug report in case there's a good reason for this that I'm oblivious to. Me being oblivious is not unheard of... Cheers, Dan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20100508/ba9b2285/attachment.htm From stefan_ml at behnel.de Sun May 9 12:48:52 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 09 May 2010 12:48:52 +0200 Subject: [Cython] __Pyx_GetException() and friends In-Reply-To: References: Message-ID: <4BE69314.1030607@behnel.de> Dan Roberts, 09.05.2010 08:12: > The code that Cython generates for numpy/random/mtrand/mtrand.pyx contains > several __Pyx_*() functions that muck about in the PyThreadState object > (which isn't standard) Well, it's not an object, first of all, but IMHO, it's pretty much standard for CPython. And it's not Cython's fault that other runtimes refuse to implement it. > but each seems to have a sanctioned equivalent > provided in the official C API, listed here: > http://docs.python.org/c-api/exceptions.html I think "seems" is the right word here. They are either not exactly equivalent or have CPython version portability constrains, or they're simply not fast enough. Without looking closer, any subset of those three properties will likely hold for each of them. Note that exception handling in Py3 is handled very differently from that in Py2, simply because Py3 has suitable C-API functions that Py2 lacks, or that behave sufficiently different in Py2 to render them useless to Cython. > This is important because non-CPython interpreters likely won't expose that > struct, and indeed PyPy does not, and it would be cumbersome to do so. I don't expect much Cython code to run on PyPy anyway. The exception handling is only one reason why this won't easily work. That being said, I think this is absolutely worth a closer look. I wouldn't mind adding compatibility #define/#ifdef blocks to Cython to support PyPy or IronPython explicitly, as long as this doesn't get too ugly. Especially for the case of exception handling, the respective code may look yet another bit different for other runtimes. We have all sorts of portability code for various CPython versions in there anyway, and most of the relevant code is written down in separate utility functions instead of being generated line by line, so this shouldn't be too hard to integrate. Any volunteers? Stefan From ademan555 at gmail.com Mon May 10 23:12:08 2010 From: ademan555 at gmail.com (Dan Roberts) Date: Mon, 10 May 2010 14:12:08 -0700 Subject: [Cython] __Pyx_GetException() and friends In-Reply-To: References: <4BE69314.1030607@behnel.de> Message-ID: Hi Stefan, Thanks for getting back to me. I've been digging pretty deep to try and see what's so special about __Pyx_GetException() and the only thing I see is that it copies curexc_* fields into exc_* fields. I've dug around in the CPython source and I'm having a hard time figuring out the importance of exc_* If we could establish that, we could build a new __Pyx_GetException() that only relies on PyErr_Fetch(). (The only other thing is __Pyx_GetException() deals with refcounts too, but that could be added easily) I'm glad you're open to having multiple implementations, that way everyone is happy :-) I suppose since I've brought this up, and I'm most immediately affected, it falls to me to implement. That's fine as long as it doesn't take my whole summer :-p. And hopefully someone will be willing to guide me and answer my possibly dumb questions. I see that cython has a healthy heaping of tests too, which should help in determining compliance. I think I'm up to the challenge... I think... Thanks, Dan On May 9, 2010 3:49 AM, "Stefan Behnel" wrote: Dan Roberts, 09.05.2010 08:12: > The code that Cython generates for numpy/random/mtrand/mtrand.pyx contains > several __Pyx_*() fun... Well, it's not an object, first of all, but IMHO, it's pretty much standard for CPython. And it's not Cython's fault that other runtimes refuse to implement it. > but each seems to have a sanctioned equivalent > provided in the official C API, listed here: > ... I think "seems" is the right word here. They are either not exactly equivalent or have CPython version portability constrains, or they're simply not fast enough. Without looking closer, any subset of those three properties will likely hold for each of them. Note that exception handling in Py3 is handled very differently from that in Py2, simply because Py3 has suitable C-API functions that Py2 lacks, or that behave sufficiently different in Py2 to render them useless to Cython. > This is important because non-CPython interpreters likely won't expose that > struct, and indeed... I don't expect much Cython code to run on PyPy anyway. The exception handling is only one reason why this won't easily work. That being said, I think this is absolutely worth a closer look. I wouldn't mind adding compatibility #define/#ifdef blocks to Cython to support PyPy or IronPython explicitly, as long as this doesn't get too ugly. Especially for the case of exception handling, the respective code may look yet another bit different for other runtimes. We have all sorts of portability code for various CPython versions in there anyway, and most of the relevant code is written down in separate utility functions instead of being generated line by line, so this shouldn't be too hard to integrate. Any volunteers? Stefan _______________________________________________ Cython-dev mailing list Cython-dev at codespeak.net http://codespeak.net/mailman/listinfo/cython-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20100510/643d6e3d/attachment-0001.htm From pfh at logarithmic.net Tue May 11 02:27:58 2010 From: pfh at logarithmic.net (Paul Harrison) Date: Tue, 11 May 2010 10:27:58 +1000 Subject: [Cython] Problem with string literals containing newline in Cython 12.1 Message-ID: Hello, I found a problem in Cython 12.1 (with Python 2.6.1). If you try to compile the following: str1 = 'a' str2 = 'a\n' It produces the following code, which will not compile: static char __pyx_k__a[] = "a"; static char __pyx_k__a [] = "a\n"; Also, I find I can no longer cast str to char* (again with Python 2.6.1). The documentation seems to indicate this should only be a problem in Python 3, or have I missed something? regards, Paul Harrison Victorian Bioinformatics Consortium / Monash University pfh at logarithmic.net jabber pfh at gristle.org http://www.logarithmic.net/pfh/ From robertwb at math.washington.edu Tue May 11 06:16:01 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 10 May 2010 21:16:01 -0700 Subject: [Cython] Problem with string literals containing newline in Cython 12.1 In-Reply-To: References: Message-ID: On May 10, 2010, at 5:27 PM, Paul Harrison wrote: > Hello, > > I found a problem in Cython 12.1 (with Python 2.6.1). If you try to > compile the following: > > str1 = 'a' > str2 = 'a\n' > > It produces the following code, which will not compile: > > static char __pyx_k__a[] = "a"; > static char __pyx_k__a > [] = "a\n"; I thought C was whitespace agnostic. What compiler are you using? In any case, it's probably a trivial fix. > Also, I find I can no longer cast str to char* (again with Python > 2.6.1). The documentation seems to indicate this should only be a > problem in Python 3, or have I missed something? Cython is super strict about this right now even if you're only using Py2 (too strict in my opinion, but that's a whole can of worms there that we're not going to re-visit at this time...) Cast to an object first, i.e. if x is a str, do char* s = x (Short of type checking, is there a good way to encode in 3.x and still allow str in 2.x?) Also, you might consider whether it is worth declaring your variable to be of type str--are you using this fact anywhere? - Robert From pfh at logarithmic.net Tue May 11 06:54:07 2010 From: pfh at logarithmic.net (Paul Harrison) Date: Tue, 11 May 2010 14:54:07 +1000 Subject: [Cython] Problem with string literals containing newline in Cython 12.1 In-Reply-To: References: Message-ID: On Tue, May 11, 2010 at 2:16 PM, Robert Bradshaw wrote: > On May 10, 2010, at 5:27 PM, Paul Harrison wrote: > >> Hello, >> >> I found a problem in Cython 12.1 (with Python 2.6.1). If you try to >> compile the following: >> >> str1 = 'a' >> str2 = 'a\n' >> >> It produces the following code, which will not compile: >> >> static char __pyx_k__a[] = "a"; >> static char __pyx_k__a >> [] = "a\n"; > > I thought C was whitespace agnostic. What compiler are you using? In > any case, it's probably a trivial fix. > The problem is the duplicated name __pyx_k__a. The C compiler (gcc) ignores the newline, which is probably why this hasn't caused a problem in the past. You need the two similar string constants in order for there to be a problem. >> Also, I find I can no longer cast str to char* (again with Python >> 2.6.1). The documentation seems to indicate this should only be a >> problem in Python 3, or have I missed something? > > > Cython is super strict about this right now even if you're only using > Py2 (too strict in my opinion, but that's a whole can of worms there > that we're not going to re-visit at this time...) Cast to an object > first, i.e. if x is a str, do > > ? ? char* s = x > Ah, thanks. This fixes the error, which only occurs when the variable is declared to be a str. I take it the correct idiom is to do everything with bytes. > (Short of type checking, is there a good way to encode in 3.x and > still allow str in 2.x?) Also, you might consider whether it is worth > declaring your variable to be of type str--are you using this fact > anywhere? > I was hoping for a speed increase from declaring it as str so that I could get its length and contents quickly. This worked in Cython 0.11, but stopped working when I upgraded to 0.12.1. Thanks for the quick answer. -- Paul Harrison Victorian Bioinformatics Consortium / Monash University pfh at logarithmic.net jabber pfh at gristle.org http://www.logarithmic.net/pfh/ From robertwb at math.washington.edu Tue May 11 07:20:49 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 10 May 2010 22:20:49 -0700 Subject: [Cython] Problem with string literals containing newline in Cython 12.1 In-Reply-To: References: Message-ID: <1B0A5DBC-D0C6-449E-BDF9-9E54623D61C0@math.washington.edu> On May 10, 2010, at 9:54 PM, Paul Harrison wrote: > On Tue, May 11, 2010 at 2:16 PM, Robert Bradshaw > wrote: >> On May 10, 2010, at 5:27 PM, Paul Harrison wrote: >> >>> Hello, >>> >>> I found a problem in Cython 12.1 (with Python 2.6.1). If you try to >>> compile the following: >>> >>> str1 = 'a' >>> str2 = 'a\n' >>> >>> It produces the following code, which will not compile: >>> >>> static char __pyx_k__a[] = "a"; >>> static char __pyx_k__a >>> [] = "a\n"; >> >> I thought C was whitespace agnostic. What compiler are you using? In >> any case, it's probably a trivial fix. >> > > The problem is the duplicated name __pyx_k__a. The C compiler (gcc) > ignores the newline, which is probably why this hasn't caused a > problem in the past. You need the two similar string constants in > order for there to be a problem. Ah, that's pretty subtle. > > >>> Also, I find I can no longer cast str to char* (again with Python >>> 2.6.1). The documentation seems to indicate this should only be a >>> problem in Python 3, or have I missed something? >> >> >> Cython is super strict about this right now even if you're only using >> Py2 (too strict in my opinion, but that's a whole can of worms there >> that we're not going to re-visit at this time...) Cast to an object >> first, i.e. if x is a str, do >> >> char* s = x >> > > Ah, thanks. This fixes the error, which only occurs when the variable > is declared to be a str. I take it the correct idiom is to do > everything with bytes. > >> (Short of type checking, is there a good way to encode in 3.x and >> still allow str in 2.x?) Also, you might consider whether it is worth >> declaring your variable to be of type str--are you using this fact >> anywhere? >> > > I was hoping for a speed increase from declaring it as str so that I > could get its length and contents quickly. This worked in Cython 0.11, > but stopped working when I upgraded to 0.12.1. Yes, see http://wiki.cython.org/enhancements/stringliterals . You could use bytes instead of str everywhere, because that's essentially what you have. > > > Thanks for the quick answer. No problem--please let us know if you find any other issues. - Robert From stefan_ml at behnel.de Tue May 11 08:06:26 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 11 May 2010 08:06:26 +0200 Subject: [Cython] Problem with string literals containing newline in Cython 12.1 In-Reply-To: References: Message-ID: <4BE8F3E2.3090906@behnel.de> Robert Bradshaw, 11.05.2010 06:16: > On May 10, 2010, at 5:27 PM, Paul Harrison wrote: >> Also, I find I can no longer cast str to char* (again with Python >> 2.6.1). The documentation seems to indicate this should only be a >> problem in Python 3, or have I missed something? Regardless of any Py2/Py3 portability issues, you have to take care what type of string you use for what purpose. Python 2 and earlier Cython versions that targeted Py2 have been very lax here, that's why a lot of code has been written that has problems (not only in Py3, see the infamous UnicodeEncodeError in Py2). They inevitably show when migrating to Py3, which is rather late for most current users. Cython has therefore opted to follow Py3 in some major aspects to make it easier for users to write correct and portable code. This is very important for Cython code, which is supposed to run on Py2 and Py3 platforms without regenerating the C code. > Cython is super strict about this right now even if you're only using > Py2 (too strict in my opinion, but that's a whole can of worms there > that we're not going to re-visit at this time...) Cast to an object > first, i.e. if x is a str, do > > char* s =x That's a hack. In any case, it won't work in Py3. > (Short of type checking, is there a good way to encode in 3.x and > still allow str in 2.x?) Given that Py2 tries auto-conversion between byte strings and unicode strings, you can do byte_string = some_string.encode('ASCII') This will fail for byte strings in Py3 and work for ASCII-only unicode strings. In Py2, it will work identically for unicode strings, but it will implicitly auto-decode a byte string to unicode before it gets encoded. This is horribly wasteful, but it works for ASCII strings on any Python runtime that has an ASCII compatible default encoding - implying that it will not work on some runtimes if the default encoding is *not* ASCII compatible, but that's rare enough. It's a "mostly good enough" trick in doctests, for example. Given how wasteful the above is in Py2 and the fact that it isn't even 100% portable, my general answer to this question is "no". It's truly a good thing to be explicit about the type of string you are dealing with. Avoids a lot of problems, now and later, and keeps you from writing error prone code. Stefan From chemejosh at gmail.com Tue May 11 18:03:02 2010 From: chemejosh at gmail.com (Josh Allen) Date: Tue, 11 May 2010 12:03:02 -0400 Subject: [Cython] Method overriding in pure Python mode Message-ID: <4BE97FB6.60301@gmail.com> I have been using Cython's pure Python mode for a while now, and have generally been quite pleased with it. Now I am trying to use it with a more complex codebase, which has led me to encounter some "rough around the edges" features. I am using Cython 0.12.1 with Python 2.6.5. This particular bug has to do with method overriding in a derived class. Consider the Python file foo.py containing a base class Foo and derived class Bar, with the method hello() implemented differently in each class: class Foo: def hello(self): print 'Hello from Foo.hello()' class Bar(Foo): def hello(self): print 'Hello from Bar.hello()' The associated foo.pxd header file is: cdef class Foo: cpdef hello(self) cdef class Bar(Foo): cpdef hello(self) My test script is as follows: from foo import Foo, Bar f = Foo() f.hello() # Should print 'Hello from Foo.hello()' b = Bar() b.hello() # Should print 'Hello from Bar.hello()' Before compiling, the test script works as expected. However, after compiling, a TypeError is raised: Traceback (most recent call last): File "test.py", line 7, in f.hello() File "foo.py", line 6, in foo.Foo.hello (foo.c:512) def hello(self): TypeError: Cannot convert foo.Foo to foo.Bar I'd be happy to provide the generated C code as well. This seems to be the offending line: if (!(likely(((__pyx_v_self) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_self, __pyx_ptype_3foo_Bar))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} From what I can tell, this only allows objects of type Bar to continue, and not those of type Foo, despite being a method of the Foo class. Oddly enough, the line above was duplicated in the generated C code; I wonder if one of them should test for __pyx_ptype_3foo_Foo instead, but I don't know much about the Cython internals so I may be way off base. Note that this is a follow-up and clarification to http://codespeak.net/pipermail/cython-dev/2009-September/006846.html which seems to have not been fully addressed. From dalcinl at gmail.com Tue May 11 22:01:01 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Tue, 11 May 2010 17:01:01 -0300 Subject: [Cython] Method overriding in pure Python mode In-Reply-To: <4BE97FB6.60301@gmail.com> References: <4BE97FB6.60301@gmail.com> Message-ID: On 11 May 2010 13:03, Josh Allen wrote: > I have been using Cython's pure Python mode for a while now, and have > generally been quite pleased with it. Now I am trying to use it with a > more complex codebase, which has led me to encounter some "rough around > the edges" features. I am using Cython 0.12.1 with Python 2.6.5. > > This particular bug has to do with method overriding in a derived class. > Consider the Python file foo.py containing a base class Foo and derived > class Bar, with the method hello() implemented differently in each class: > > class Foo: > ? ? def hello(self): > ? ? ? ? print 'Hello from Foo.hello()' > class Bar(Foo): > ? ? def hello(self): > ? ? ? ? print 'Hello from Bar.hello()' > > The associated foo.pxd header file is: > > cdef class Foo: > ? ? cpdef hello(self) > cdef class Bar(Foo): > ? ? cpdef hello(self) > > My test script is as follows: > > from foo import Foo, Bar > f = Foo() > f.hello() # Should print 'Hello from Foo.hello()' > b = Bar() > b.hello() # Should print 'Hello from Bar.hello()' > > Before compiling, the test script works as expected. However, after > compiling, a TypeError is raised: > > Traceback (most recent call last): > ? File "test.py", line 7, in > ? ? f.hello() > ? File "foo.py", line 6, in foo.Foo.hello (foo.c:512) > ? ? def hello(self): > TypeError: Cannot convert foo.Foo to foo.Bar > > I'd be happy to provide the generated C code as well. This seems to be > the offending line: > > ? if (!(likely(((__pyx_v_self) == Py_None) || > likely(__Pyx_TypeTest(__pyx_v_self, __pyx_ptype_3foo_Bar))))) > {__pyx_filename = __pyx_f[0]; __pyx_lineno = 6; __pyx_clineno = > __LINE__; goto __pyx_L1_error;} > > ?From what I can tell, this only allows objects of type Bar to continue, > and not those of type Foo, despite being a method of the Foo class. > Oddly enough, the line above was duplicated in the generated C code; I > wonder if one of them should test for __pyx_ptype_3foo_Foo instead, but > I don't know much about the Cython internals so I may be way off base. > > Note that this is a follow-up and clarification to > > http://codespeak.net/pipermail/cython-dev/2009-September/006846.html > > which seems to have not been fully addressed. > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > It seems there is a bug somewhere, unfortunately I was not able to catch it. I've attached a testcase showing that the behaviour of def vs. cpdef methods is different. -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 l -------------- next part -------------- A non-text attachment was scrubbed... Name: methinherit.pyx Type: application/octet-stream Size: 620 bytes Desc: not available Url : http://codespeak.net/pipermail/cython-dev/attachments/20100511/cd59d327/attachment.obj From ademan555 at gmail.com Thu May 13 02:44:32 2010 From: ademan555 at gmail.com (Dan Roberts) Date: Wed, 12 May 2010 17:44:32 -0700 Subject: [Cython] __Pyx_GetException() and friends In-Reply-To: References: <4BE69314.1030607@behnel.de> Message-ID: While we're talking about this sort of thing, in Cython/Compiler/ModuleNode.py around line 1073 ++Py_REFCNT(o) and --Py_REFCNT(o) are generated than Py_INCREF(o) and Py_DECREF(o) respectively. I realize it may not be desirable for some reason that I'm unaware of, so I'll leave it up to you guys to change at your discretion. Cheers, Dan P.S. What would be the ideal way for me to contribute things back in the future? With a bitbucket account maybe? > > On May 9, 2010 3:49 AM, "Stefan Behnel" wrote: > > Dan Roberts, 09.05.201... > > > The code that Cython generates for numpy/random/mtrand/mtrand.pyx contains > several __Pyx_*() fun... > > Well, it's not an object, first of all, but IMHO, it's pretty much standard > for CPython. And ... > > > > > but each seems to have a sanctioned equivalent > > provided in the official C API, listed ... > ... > > I think "seems" is the right word here. They are either not exactly > equivalent or have CPytho... > > > > > This is important because non-CPython interpreters likely won't expose that > struct, and indeed... > > I don't expect much Cython code to run on PyPy anyway. The exception > handling is only one rea... -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20100512/f6ceba1c/attachment.htm From robertwb at math.washington.edu Thu May 13 05:24:24 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 12 May 2010 20:24:24 -0700 Subject: [Cython] __Pyx_GetException() and friends In-Reply-To: References: <4BE69314.1030607@behnel.de> Message-ID: On May 12, 2010, at 5:44 PM, Dan Roberts wrote: > While we're talking about this sort of thing, in Cython/Compiler/ > ModuleNode.py around line 1073 ++Py_REFCNT(o) and --Py_REFCNT(o) are > generated than Py_INCREF(o) and Py_DECREF(o) respectively. I > realize it may not be desirable for some reason that I'm unaware of, > so I'll leave it up to you guys to change at your discretion. > Py_DECREF checks to see if the refcount is 0 and if so invokes the deallocation methods. This is in the deallocation method, so we wouldn't want that. (The refcount is temporarily bumped up so that it doesn't go to 0 while executing the body of the function.) > Cheers, > Dan > > P.S. What would be the ideal way for me to contribute things back in > the future? With a bitbucket account maybe? > Yes, that would work well. You could also post patches to http://trac.cython.org/cython_trac (just send one of us an htpasswd entry offlist for an account). > >> >> > >> > On May 9, 2010 3:49 AM, "Stefan Behnel" >> wrote: >> > >> > Dan Roberts, 09.05.201... >> >> >> > >> > > The code that Cython generates for numpy/random/mtrand/ >> mtrand.pyx contains >> >> > several __Pyx_*() fun... >> >> >> > >> > Well, it's not an object, first of all, but IMHO, it's pretty >> much standard >> > for CPython. And ... >> >> >> > >> > >> > >> > > but each seems to have a sanctioned equivalent >> > > provided in the official C API, listed ... >> >> > ... >> >> >> > >> > I think "seems" is the right word here. They are either not exactly >> > equivalent or have CPytho... >> >> >> > >> > >> > >> > > This is important because non-CPython interpreters likely won't >> expose that >> >> > struct, and indeed... >> >> >> > >> > I don't expect much Cython code to run on PyPy anyway. The >> exception >> > handling is only one rea... >> > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev From stefan_ml at behnel.de Thu May 13 08:44:56 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 13 May 2010 08:44:56 +0200 Subject: [Cython] __Pyx_GetException() and friends In-Reply-To: References: <4BE69314.1030607@behnel.de> Message-ID: <4BEB9FE8.2090003@behnel.de> Dan Roberts, 10.05.2010 23:12: > I've been digging pretty deep to try and > see what's so special about __Pyx_GetException() and the only thing I see is > that it copies curexc_* fields into exc_* fields. I've dug around in the > CPython source and I'm having a hard time figuring out the importance of > exc_* curexc_* holds the exception that is currently being raised, so it signals an uncaught exception. exc_* is what you see in sys.exc_info(). Basically, the exception is being moved there when it's getting caught somewhere. A newly raised exception inside of an except block would then land in curexc_*, so that both the old and the new one stay available. Only exc_* is readable from Python space, curexc_* is hidden behind the raise and except statements. In Python3, there are some additional features that make old exceptions available as part of a newly raised exception ('cause' and friends), and that remove an exception from exc_* when the except block that caught it is being left. This kind of differences makes it tricky to work on that code, but the Py3 exception handling code in Cython was certainly simplified a lot by moving back to standard C-API functions. > If we could establish that, we could build a new __Pyx_GetException() > that only relies on PyErr_Fetch(). (The only other thing is > __Pyx_GetException() deals with refcounts too, but that could be added > easily) Right, PyErr_Fetch() is only manually inlined here since the code needs to access the PyThreadState fields anyway. I don't think __Pyx_GetException() is sufficiently performance critical in its current form to merit this kind of inlining, though, and PyErr_Fetch() hasn't changed between Py2.3 and Py3k HEAD, so I'm fine with a cleanup. There's also a code duplication in the exception fetch/restore code, which is basically done for C inlining since this can happen a lot, e.g. during 'finally' statements. I think that code is fine and should stay as is, with the obvious fallback to the normal C-API functions on non-CPython runtimes. I haven't looked at the exception raising code yet, but I'm pretty sure there are issues, too. > I'm glad you're open to having multiple implementations, that way everyone > is happy :-) I suppose since I've brought this up, and I'm most immediately > affected, it falls to me to implement. That's fine as long as it doesn't > take my whole summer :-p. And hopefully someone will be willing to guide me > and answer my possibly dumb questions. I see that cython has a healthy > heaping of tests too, which should help in determining compliance. I think > I'm up to the challenge... I think... Thanks for volunteering, and for bringing these issues up in the first place. Stefan From ademan555 at gmail.com Thu May 13 09:44:51 2010 From: ademan555 at gmail.com (Dan Roberts) Date: Thu, 13 May 2010 00:44:51 -0700 Subject: [Cython] __Pyx_GetException() and friends In-Reply-To: References: Message-ID: Thanks for the reply. Of course you're right, Py_DECREF() might cause infinite recursion. (At least the docs say Py_DECREF() calls tp_dealloc when the refcount reaches 0) I'm a bit confused as to why we manipulate the refcount at all. Since this is the dealloc method isn't the refcount 0 already? And the object is freed at the end of the method unconditionally too, so there's no chance of resurrection, right? I realize I might be missing some important CPython implementation details (I try to look them up before I blurt everything out at least) so I appreciate that you guys are humoring my questions. Thanks, Dan On May 12, 2010 8:25 PM, "Robert Bradshaw" wrote: On May 12, 2010, at 5:44 PM, Dan Roberts wrote: > While we're talking about this sort of thing, in C... Py_DECREF checks to see if the refcount is 0 and if so invokes the deallocation methods. This is in the deallocation method, so we wouldn't want that. (The refcount is temporarily bumped up so that it doesn't go to 0 while executing the body of the function.) > Cheers, > Dan > > P.S. What would be the ideal way for me to contribute things back in > the fu... Yes, that would work well. You could also post patches to http://trac.cython.org/cython_trac (just send one of us an htpasswd entry offlist for an account). > >> >> > >> > On May 9, 2010 3:49 AM, "Stefan Behnel" >> wrote: >> > >> > ... > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.n... -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20100513/a20b2968/attachment.htm From dagss at student.matnat.uio.no Thu May 13 10:05:22 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 13 May 2010 10:05:22 +0200 Subject: [Cython] __Pyx_GetException() and friends In-Reply-To: References: Message-ID: <4BEBB2C2.7040906@student.matnat.uio.no> Dan Roberts wrote: > > Thanks for the reply. Of course you're right, Py_DECREF() might cause > infinite recursion. (At least the docs say Py_DECREF() calls > tp_dealloc when the refcount reaches 0) I'm a bit confused as to why > we manipulate the refcount at all. Since this is the dealloc method > isn't the refcount 0 already? And the object is freed at the end of > the method unconditionally too, so there's no chance of resurrection, > right? > > I realize I might be missing some important CPython implementation > details (I try to look them up before I blurt everything out at least) > so I appreciate that you guys are humoring my questions. > If this is what I'm thinking it is: def printsomething(x): y = x # incref from 0 to 1 print y # here, decref y => infinite recursion cdef class A: cdef __dealloc__(self): # refcount of self is 0 (without workaround) printsomething(self) Dag Sverre > Thanks, > Dan > >> On May 12, 2010 8:25 PM, "Robert Bradshaw" >> > >> wrote: >> >> On May 12, 2010, at 5:44 PM, Dan Roberts wrote: >> > While we're talking about this sort of thing, in C... >> >> Py_DECREF checks to see if the refcount is 0 and if so invokes the >> deallocation methods. This is in the deallocation method, so we >> wouldn't want that. (The refcount is temporarily bumped up so that it >> doesn't go to 0 while executing the body of the function.) >> >> >> > Cheers, >> > Dan >> > >> > P.S. What would be the ideal way for me to contribute things back in >> > the fu... >> >> Yes, that would work well. You could also post patches to >> http://trac.cython.org/cython_trac >> (just send one of us an htpasswd entry offlist for an account). >> >> >> > >> >> >> >> > >> >> > On May 9, 2010 3:49 AM, "Stefan Behnel" > > >> >> wrote: >> >> > >> >> > ... >> >> > _______________________________________________ >> > Cython-dev mailing list >> > Cython-dev at codespeak.n... >> > ------------------------------------------------------------------------ > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > From ademan555 at gmail.com Thu May 13 11:18:53 2010 From: ademan555 at gmail.com (Dan Roberts) Date: Thu, 13 May 2010 02:18:53 -0700 Subject: [Cython] __Pyx_GetException() and friends In-Reply-To: References: <4BEBB2C2.7040906@student.matnat.uio.no> Message-ID: Egh, yep you guys are right again. In this case the only thing I can think of is to just forego the --Py_REFCNT(o) line altogether, which should work, and shouldn't affect the execution of the program at all. (That is... unless tp_free checks the refcount, which may be...) Even if it wouldn't affect anything, it still would make me feel a bit dirty... On May 13, 2010 1:05 AM, "Dag Sverre Seljebotn" wrote: Dan Roberts wrote: > > Thanks for the reply. Of course you're right, Py_DECREF() might cause > inf... If this is what I'm thinking it is: def printsomething(x): y = x # incref from 0 to 1 print y # here, decref y => infinite recursion cdef class A: cdef __dealloc__(self): # refcount of self is 0 (without workaround) printsomething(self) Dag Sverre > Thanks, > Dan > >> On May 12, 2010 8:25 PM, "Robert Bradshaw" >> > >> wrote: >> >> On May 12, 2010, at 5:44 PM, Dan Roberts wrote: >> > While we're talking about this ... >> > >> >> wrote: >> >> > >> >> > ... >> >> > _______________________________________________ >> > Cython... > ------------------------------------------------------------------------ > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > ________________... Cython-dev mailing list Cython-dev at codespeak.net http://codespeak.net/mailman/listinfo/cython-dev -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20100513/45c6ea91/attachment-0001.htm From daviebdawg at gmail.com Thu May 13 20:20:00 2010 From: daviebdawg at gmail.com (David Barnett) Date: Thu, 13 May 2010 14:20:00 -0400 Subject: [Cython] C++ failures / tests Message-ID: Hi, I noticed two failures to compile that I think are bugs: - "ctypedef Foo[int] Bar" gives a syntax error (i.e., there doesn't seem to be any way to typedef a templated type). - Defining a struct in a namespace and trying to convert it to a Python dict doesn't work. Instead you get nasty "__pyx_convert__to_py_THENAMESPACE" errors from the C++ compiler (it doesn't mangle the cname properly and tries to define __pyx_convert__to_py_THENAMESPACE::THESTRUCT). I made a patch to *add tests* for the two bugs (not fix them). (BTW, is creating Trac tickets closed to the general public?) David -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20100513/6c942519/attachment.htm -------------- next part -------------- A non-text attachment was scrubbed... Name: cpp_tests.patch Type: text/x-patch Size: 986 bytes Desc: not available Url : http://codespeak.net/pipermail/cython-dev/attachments/20100513/6c942519/attachment.bin From ademan555 at gmail.com Fri May 14 05:43:44 2010 From: ademan555 at gmail.com (Dan Roberts) Date: Thu, 13 May 2010 20:43:44 -0700 Subject: [Cython] __Pyx_GetException() and friends In-Reply-To: References: <4BEBB2C2.7040906@student.matnat.uio.no> Message-ID: It seems like the only way to make this work is to Py_INCREF() but don't decref, the CPython guys I talked to seem to think this is ok because we always tp_free and tp_free shouldn't resurrect. If you guys know of a reason why this solution won't work, I'd like to know why. Otherwise that's how I'm going to proceed with this issue. I'll put up a bitbucket repository as soon as school is out, and hopefully some of the code will be acceptable to you :-) Thanks for your patience, Dan On May 13, 2010 2:18 AM, "Dan Roberts" wrote: Egh, yep you guys are right again. In this case the only thing I can think of is to just forego the --Py_REFCNT(o) line altogether, which should work, and shouldn't affect the execution of the program at all. (That is... unless tp_free checks the refcount, which may be...) Even if it wouldn't affect anything, it still would make me feel a bit dirty... > > On May 13, 2010 1:05 AM, "Dag Sverre Seljebotn" < dagss at student.matnat.uio.no> wrote: > > Dan Roberts wrote: > > > > Thanks for the reply. Of course you're right, Py_DECREF() might cause > inf... > > If this is what I'm thinking it is: > > def printsomething(x): > y = x # incref from 0 to 1 ... > > >> wrote: > >> > >> On May 12, 2010, at 5:44 PM, Dan Roberts wrote: >> > While we're talking about this ... > > >> > >> >> wrote: >> >> > >> >> > ... >> >> > _______________________________________________ >> > Cython... > > > ------------------------------------------------------------------------ > > > > ____________... -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20100513/7b26ce53/attachment.htm From dalcinl at gmail.com Fri May 14 16:21:35 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 14 May 2010 11:21:35 -0300 Subject: [Cython] __Pyx_GetException() and friends In-Reply-To: References: <4BEBB2C2.7040906@student.matnat.uio.no> Message-ID: On 14 May 2010 00:43, Dan Roberts wrote: > It seems like the only way to make this work is to Py_INCREF() but don't > decref, the CPython guys I talked to seem to think this is ok because we > always tp_free and tp_free shouldn't resurrect. If you guys know of a reason > why this solution won't work, I'd like to know why. If you do not call Py_DECREF, then you will be in charge of decrementing the various reference counter tracking mechanisms, like _Py_RefTotal global counter, and inc_count(PyTypeObject *)/dec_count(PyTypeObject *) -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From stefan_ml at behnel.de Sat May 15 11:13:23 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 15 May 2010 11:13:23 +0200 Subject: [Cython] Indexing and looping over bytes literals Message-ID: <4BEE65B3.3070705@behnel.de> Hi, latest cython-devel can infer the type of a for-loop variable when iterating over C arrays, C pointers and Python strings. It will infer Py_UNICODE for unicode strings, but plain 'object' for a bytes string, as this returns sliced strings in Py2 and integers in Py3, so there is no common C type. So the following will infer c to be a plain Python object: cdef bytes s = b'abcdefg' c = s[4] for c in s: pass However, this: c = b'abcdefg'[4] for c in b'abcdefg': pass will infer 'char' for c, as the bytes literal starts off as a char* string. The main problem here is that 'char' does not behave like a Python bytes object at all. I doubt that iterating over bytes literals is a common use case, but I'm not sure about the 'least surprising' thing to do here. Should we special case this to prevent breaking Python-2 semantics, or should we expect that users will usually want 'char' as a result anyway? Both behaviours are easy to get with a simple cast, so this is really only a matter of consistency and least surprise. The thing that really bites me here is that the bytes type in Py3 *does* return integers on iteration. So returning 'char' on indexing and iteration would be both more efficient and more future proof. But it would also be impossible to keep consistent in Python-2, as faking it would mean that an untyped bytes object would return a substring, whereas a typed one would return an integer. And I don't really want to inject a type check branch into each getitem call to override that behaviour... So ISTM that the only way to make this consistent is to follow Python 2 for now, including literals, and to accept the different (but also consistent) behaviour when running in Python 3. Opinions? Stefan From dagss at student.matnat.uio.no Sat May 15 11:28:34 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 15 May 2010 11:28:34 +0200 Subject: [Cython] Indexing and looping over bytes literals In-Reply-To: <4BEE65B3.3070705@behnel.de> References: <4BEE65B3.3070705@behnel.de> Message-ID: <4BEE6942.4020704@student.matnat.uio.no> Stefan Behnel wrote: > Hi, > > latest cython-devel can infer the type of a for-loop variable when > iterating over C arrays, C pointers and Python strings. It will infer > Py_UNICODE for unicode strings, but plain 'object' for a bytes string, as > this returns sliced strings in Py2 and integers in Py3, so there is no > common C type. So the following will infer c to be a plain Python object: > > cdef bytes s = b'abcdefg' > > c = s[4] > for c in s: > pass > > However, this: > > c = b'abcdefg'[4] > for c in b'abcdefg': > pass > > will infer 'char' for c, as the bytes literal starts off as a char* string. > The main problem here is that 'char' does not behave like a Python bytes > object at all. I doubt that iterating over bytes literals is a common use > case, but I'm not sure about the 'least surprising' thing to do here. > > Should we special case this to prevent breaking Python-2 semantics, or > should we expect that users will usually want 'char' as a result anyway? > > Both behaviours are easy to get with a simple cast, so this is really only > a matter of consistency and least surprise. The thing that really bites me > here is that the bytes type in Py3 *does* return integers on iteration. So > returning 'char' on indexing and iteration would be both more efficient and > more future proof. But it would also be impossible to keep consistent in > Python-2, as faking it would mean that an untyped bytes object would return > a substring, whereas a typed one would return an integer. And I don't > really want to inject a type check branch into each getitem call to > override that behaviour... > > So ISTM that the only way to make this consistent is to follow Python 2 for > now, including literals, and to accept the different (but also consistent) > behaviour when running in Python 3. > > Opinions? > "In the face of ambiguity, refuse the temptation to guess"? I.e., I'd just disallow it from the language (that is, require a cast), because of this issue. I don't see iterating over string literals as important enough that one can't require a cast. Dag Sverre From stefan_ml at behnel.de Sat May 15 12:38:05 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 15 May 2010 12:38:05 +0200 Subject: [Cython] Indexing and looping over bytes literals In-Reply-To: <4BEE6942.4020704@student.matnat.uio.no> References: <4BEE65B3.3070705@behnel.de> <4BEE6942.4020704@student.matnat.uio.no> Message-ID: <4BEE798D.4060605@behnel.de> Dag Sverre Seljebotn, 15.05.2010 11:28: > Stefan Behnel wrote: >> latest cython-devel can infer the type of a for-loop variable when >> iterating over C arrays, C pointers and Python strings. It will infer >> Py_UNICODE for unicode strings, but plain 'object' for a bytes string, as >> this returns sliced strings in Py2 and integers in Py3, so there is no >> common C type. So the following will infer c to be a plain Python object: >> >> cdef bytes s = b'abcdefg' >> >> c = s[4] >> for c in s: >> pass >> >> However, this: >> >> c = b'abcdefg'[4] >> for c in b'abcdefg': >> pass >> >> will infer 'char' for c, as the bytes literal starts off as a char* string. >> The main problem here is that 'char' does not behave like a Python bytes >> object at all. I doubt that iterating over bytes literals is a common use >> case, but I'm not sure about the 'least surprising' thing to do here. >> >> Should we special case this to prevent breaking Python-2 semantics, or >> should we expect that users will usually want 'char' as a result anyway? >> >> Both behaviours are easy to get with a simple cast, so this is really only >> a matter of consistency and least surprise. The thing that really bites me >> here is that the bytes type in Py3 *does* return integers on iteration. So >> returning 'char' on indexing and iteration would be both more efficient and >> more future proof. But it would also be impossible to keep consistent in >> Python-2, as faking it would mean that an untyped bytes object would return >> a substring, whereas a typed one would return an integer. And I don't >> really want to inject a type check branch into each getitem call to >> override that behaviour... >> >> So ISTM that the only way to make this consistent is to follow Python 2 for >> now, including literals, and to accept the different (but also consistent) >> behaviour when running in Python 3. >> > "In the face of ambiguity, refuse the temptation to guess"? I'm not sure this applies here. We have existing Python semantics for this, after all. They just differ between Python 2 and Python 3. This is just a case where we can't easily guarantee one specific behaviour as we do not control the type's implementation. > I.e., I'd just disallow it from the language (that is, require a cast), > because of this issue. I don't see iterating over string literals as > important enough that one can't require a cast. Indexing based on a dynamically calculated index may be somewhat more important though, and a cast makes that a lot more ugly. Also, requiring a cast would prevent us from compiling Python code that uses this (I guess that makes a case for following the Py2 semantics). Stefan From robertwb at math.washington.edu Sat May 15 22:32:03 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 15 May 2010 13:32:03 -0700 Subject: [Cython] Indexing and looping over bytes literals In-Reply-To: <4BEE798D.4060605@behnel.de> References: <4BEE65B3.3070705@behnel.de> <4BEE6942.4020704@student.matnat.uio.no> <4BEE798D.4060605@behnel.de> Message-ID: On May 15, 2010, at 3:38 AM, Stefan Behnel wrote: > Dag Sverre Seljebotn, 15.05.2010 11:28: >> Stefan Behnel wrote: >>> latest cython-devel can infer the type of a for-loop variable when >>> iterating over C arrays, C pointers and Python strings. It will >>> infer >>> Py_UNICODE for unicode strings, but plain 'object' for a bytes >>> string, as >>> this returns sliced strings in Py2 and integers in Py3, so there >>> is no >>> common C type. So the following will infer c to be a plain Python >>> object: >>> >>> cdef bytes s = b'abcdefg' >>> >>> c = s[4] >>> for c in s: >>> pass >>> >>> However, this: >>> >>> c = b'abcdefg'[4] >>> for c in b'abcdefg': >>> pass >>> >>> will infer 'char' for c, as the bytes literal starts off as a >>> char* string. >>> The main problem here is that 'char' does not behave like a Python >>> bytes >>> object at all. I doubt that iterating over bytes literals is a >>> common use >>> case, but I'm not sure about the 'least surprising' thing to do >>> here. >>> >>> Should we special case this to prevent breaking Python-2 >>> semantics, or >>> should we expect that users will usually want 'char' as a result >>> anyway? >>> >>> Both behaviours are easy to get with a simple cast, so this is >>> really only >>> a matter of consistency and least surprise. The thing that really >>> bites me >>> here is that the bytes type in Py3 *does* return integers on >>> iteration. So >>> returning 'char' on indexing and iteration would be both more >>> efficient and >>> more future proof. But it would also be impossible to keep >>> consistent in >>> Python-2, as faking it would mean that an untyped bytes object >>> would return >>> a substring, whereas a typed one would return an integer. And I >>> don't >>> really want to inject a type check branch into each getitem call to >>> override that behaviour... >>> >>> So ISTM that the only way to make this consistent is to follow >>> Python 2 for >>> now, including literals, and to accept the different (but also >>> consistent) >>> behaviour when running in Python 3. >>> >> "In the face of ambiguity, refuse the temptation to guess"? > > I'm not sure this applies here. We have existing Python semantics > for this, > after all. They just differ between Python 2 and Python 3. This is > just a > case where we can't easily guarantee one specific behaviour as we do > not > control the type's implementation. Sounds like a perfect example of where the -3 flag should be used. >> I.e., I'd just disallow it from the language (that is, require a >> cast), >> because of this issue. I don't see iterating over string literals as >> important enough that one can't require a cast. > > Indexing based on a dynamically calculated index may be somewhat more > important though, and a cast makes that a lot more ugly. Also, > requiring a > cast would prevent us from compiling Python code that uses this (I > guess > that makes a case for following the Py2 semantics). +1 - Robert From robertwb at math.washington.edu Sat May 15 22:37:12 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 15 May 2010 13:37:12 -0700 Subject: [Cython] __Pyx_GetException() and friends In-Reply-To: References: <4BEBB2C2.7040906@student.matnat.uio.no> Message-ID: <861D60D7-8A1B-475C-B29D-AEEF41749B39@math.washington.edu> On May 14, 2010, at 7:21 AM, Lisandro Dalcin wrote: > On 14 May 2010 00:43, Dan Roberts wrote: >> It seems like the only way to make this work is to Py_INCREF() but >> don't >> decref, the CPython guys I talked to seem to think this is ok >> because we >> always tp_free and tp_free shouldn't resurrect. If you guys know of >> a reason >> why this solution won't work, I'd like to know why. > > If you do not call Py_DECREF, then you will be in charge of > decrementing the various reference counter tracking mechanisms, like > _Py_RefTotal global counter, and inc_count(PyTypeObject > *)/dec_count(PyTypeObject *) Good point, this is starting to sound really messy (possibly even more invasive and fragile than reaching into Py_REFCNT). It might be better to conditionally incref/decref this slot (if we're not compiling against CPython)? - Robert From robertwb at math.washington.edu Sat May 15 22:51:42 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 15 May 2010 13:51:42 -0700 Subject: [Cython] C++ failures / tests In-Reply-To: References: Message-ID: <88388CC7-DB76-405F-A01C-FBCFEEF2ED52@math.washington.edu> On May 13, 2010, at 11:20 AM, David Barnett wrote: > Hi, > > I noticed two failures to compile that I think are bugs: > - "ctypedef Foo[int] Bar" gives a syntax error (i.e., there doesn't > seem to be any way to typedef a templated type). Yes, that is a bug (there are several C++ features that are not implemented in as much generality as they could be yet). > - Defining a struct in a namespace and trying to convert it to a > Python dict doesn't work. Instead you get nasty > "__pyx_convert__to_py_THENAMESPACE" errors from the C++ compiler (it > doesn't mangle the cname properly and tries to define > __pyx_convert__to_py_THENAMESPACE::THESTRUCT). > > I made a patch to *add tests* for the two bugs (not fix them). Thanks! Pushed. > (BTW, is creating Trac tickets closed to the general public?) Yeah, it used to be open, but keeping up with the spam got to be too big of a task. We could look into some kind of a capatcha system, as we're not that big of a target. - Robert From stefan_ml at behnel.de Sun May 16 22:32:00 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 16 May 2010 22:32:00 +0200 Subject: [Cython] Hudson-CI server now publicly available Message-ID: <4BF05640.40908@behnel.de> Hi, the Hudson CI server for Cython is now running on a publicly visible port of the sage server: https://sage.math.washington.edu:8091/hudson/ It uses HTTPS and any configuration changes require authentication against a local user account, so the setup should be safe enough to make it public. There isn't currently a Mercurial push trigger, but Hudson polls the repos every couple of minutes, so a push to cython-devel or cython-closures will be followed by a rebuild and test runs in a timely fashion. It also polls the python.org SVN repos every 24 hours, so that our test suite always runs against the latest Py2/Py3 trunks as well as the supported maintenance branches. I still didn't find the time to get lxml build correctly on that server, but I would suggest adding other projects to the continuous integration builds as well. The Sage library is certainly worth integrating, as might be other projects that use Cython intensively and that have a sufficiently large test suite. Please make suggestions. Have fun, Stefan From dalcinl at gmail.com Mon May 17 00:47:19 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sun, 16 May 2010 19:47:19 -0300 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF05640.40908@behnel.de> References: <4BF05640.40908@behnel.de> Message-ID: On 16 May 2010 17:32, Stefan Behnel wrote: > Hi, > > the Hudson CI server for Cython is now running on a publicly visible port > of the sage server: > > https://sage.math.washington.edu:8091/hudson/ > > It uses HTTPS and any configuration changes require authentication against > a local user account, so the setup should be safe enough to make it public. > > There isn't currently a Mercurial push trigger, but Hudson polls the repos > every couple of minutes, so a push to cython-devel or cython-closures will > be followed by a rebuild and test runs in a timely fashion. It also polls > the python.org SVN repos every 24 hours, so that our test suite always runs > against the latest Py2/Py3 trunks as well as the supported maintenance > branches. > > I still didn't find the time to get lxml build correctly on that server, > but I would suggest adding other projects to the continuous integration > builds as well. The Sage library is certainly worth integrating, as might > be other projects that use Cython intensively and that have a sufficiently > large test suite. Please make suggestions. > Many thanks for this! I would like to integrate mpi4py. Would it be possible to have any MPI implementation installed on the server? If not, mpi4py can still build without MPI, but this would just test Cython + C compilation, the testsuite cannot run at all (every call would trigger a NotImplemented error at runtime). petsc4py would also qualify, but the dependency on numpy and core PETSc could make it more cumbersome. -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From baihaoyu at gmail.com Mon May 17 13:09:22 2010 From: baihaoyu at gmail.com (Haoyu Bai) Date: Mon, 17 May 2010 19:09:22 +0800 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: <1FBF84E4-2FDE-41C3-A009-8A95BD693053@math.washington.edu> References: <4BD86899.6090402@behnel.de> <1FBF84E4-2FDE-41C3-A009-8A95BD693053@math.washington.edu> Message-ID: On Tue, May 4, 2010 at 1:58 AM, Robert Bradshaw wrote: > On May 3, 2010, at 8:40 AM, Craig Citro wrote: > >>> Just a suggestion, take it or leave it: >>> >>> For my GSoC work I found google's codereview to be a very helpful >>> tool. >>> >>> http://code.google.com/p/rietveld/wiki/CodeReviewHelp >>> >>> It allows you to submit patches that are presented in an app-engine >>> GUI. ?Reviewers can make comments & suggestions that are local to >>> each >>> change in the patch. >>> >>> Perhaps it would be easier to use for interactive patch review than >>> trac. (It works seamlessly with mercurial, too). >>> >> >> +10 -- we should *totally* start using rietveld. (Plus, in a month or >> two, Robert and I will be totally in love with it.) > > > I already am :). It may be good to put up a repo on hg.cython.org (so > it's easy for people to sync up with what you have to try it out and > play with it). Also, did you set up a blog yet? > > - Robert > Hi, My blog that dedicated to the Cython GSoC work has been set up at here: http://haoyugsoc.wordpress.com/ I'll post weekly update onto this blog. It would be cool for me to have a repo on hg.cython.org, though Craig and me were thinking that since the work involves many small patches so it would be a lot of lightweight branches inside the repo, which would be not easy for others to try it out. However, a repo would be good to host and backup my work and help me sync among my computers. So, then how to get the repo setup? Meanwhile I have play around rietveld. An issue for Cython ticket #422 is created here: (with a revised patch) http://codereview.appspot.com/1228043/show Seems there is no tight integration of trac and rietveld. For now I will have the issue description in rietveld be a url point to Cython trac issue. I'll see if I can have some simple scripts to automate the workflow a bit more. :) Thanks! -- Haoyu BAI School of Computing, National University of Singapore. From robertwb at math.washington.edu Mon May 17 18:19:13 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 17 May 2010 09:19:13 -0700 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: References: <4BF05640.40908@behnel.de> Message-ID: <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> On May 16, 2010, at 3:47 PM, Lisandro Dalcin wrote: > On 16 May 2010 17:32, Stefan Behnel wrote: >> Hi, >> >> the Hudson CI server for Cython is now running on a publicly >> visible port >> of the sage server: >> >> https://sage.math.washington.edu:8091/hudson/ >> >> It uses HTTPS and any configuration changes require authentication >> against >> a local user account, so the setup should be safe enough to make it >> public. >> >> There isn't currently a Mercurial push trigger, but Hudson polls >> the repos >> every couple of minutes, so a push to cython-devel or cython- >> closures will >> be followed by a rebuild and test runs in a timely fashion. It also >> polls >> the python.org SVN repos every 24 hours, so that our test suite >> always runs >> against the latest Py2/Py3 trunks as well as the supported >> maintenance >> branches. >> >> I still didn't find the time to get lxml build correctly on that >> server, >> but I would suggest adding other projects to the continuous >> integration >> builds as well. The Sage library is certainly worth integrating, as >> might >> be other projects that use Cython intensively and that have a >> sufficiently >> large test suite. Please make suggestions. >> > > Many thanks for this! Yes, this is very cool. We should get Sage in there for sure--it doesn't build with the current cython-devel, but Craig is sitting on some patches that as I understand fix the issue and get almost all doctests to pass. > I would like to integrate mpi4py. Would it be possible to have any MPI > implementation installed on the server? If not, mpi4py can still build > without MPI, but this would just test Cython + C compilation, the > testsuite cannot run at all (every call would trigger a NotImplemented > error at runtime). I think this is reasonable. > petsc4py would also qualify, but the dependency on numpy and core > PETSc could make it more cumbersome. Could either of these be installed in, and run from, your home directory? That would make things much easier (no root/admin privileges required). - Robert From robertwb at math.washington.edu Mon May 17 18:29:55 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 17 May 2010 09:29:55 -0700 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: References: <4BD86899.6090402@behnel.de> <1FBF84E4-2FDE-41C3-A009-8A95BD693053@math.washington.edu> Message-ID: <476BCF97-6648-4B57-BBEA-F0DD245E6BFA@math.washington.edu> On May 17, 2010, at 4:09 AM, Haoyu Bai wrote: > On Tue, May 4, 2010 at 1:58 AM, Robert Bradshaw > wrote: >> On May 3, 2010, at 8:40 AM, Craig Citro wrote: >> >>>> Just a suggestion, take it or leave it: >>>> >>>> For my GSoC work I found google's codereview to be a very helpful >>>> tool. >>>> >>>> http://code.google.com/p/rietveld/wiki/CodeReviewHelp >>>> >>>> It allows you to submit patches that are presented in an app-engine >>>> GUI. Reviewers can make comments & suggestions that are local to >>>> each >>>> change in the patch. >>>> >>>> Perhaps it would be easier to use for interactive patch review than >>>> trac. (It works seamlessly with mercurial, too). >>>> >>> >>> +10 -- we should *totally* start using rietveld. (Plus, in a month >>> or >>> two, Robert and I will be totally in love with it.) >> >> >> I already am :). It may be good to put up a repo on hg.cython.org (so >> it's easy for people to sync up with what you have to try it out and >> play with it). Also, did you set up a blog yet? >> >> - Robert >> > > Hi, > > My blog that dedicated to the Cython GSoC work has been set up at > here: > > http://haoyugsoc.wordpress.com/ > > I'll post weekly update onto this blog. Excellent. > It would be cool for me to have a repo on hg.cython.org, though Craig > and me were thinking that since the work involves many small patches > so it would be a lot of lightweight branches inside the repo, which > would be not easy for others to try it out. However, a repo would be > good to host and backup my work and help me sync among my computers. > So, then how to get the repo setup? Done. http://hg.cython.org/gsoc-haoyu/ You can push using the same password that was set up for trac. > Meanwhile I have play around rietveld. An issue for Cython ticket #422 > is created here: (with a revised patch) > http://codereview.appspot.com/1228043/show > > Seems there is no tight integration of trac and rietveld. For now I > will have the issue description in rietveld be a url point to Cython > trac issue. Or vice-versa would be fine as well. > I'll see if I can have some simple scripts to automate the > workflow a bit more. :) That would be good. - Robert From dalcinl at gmail.com Mon May 17 18:55:38 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Mon, 17 May 2010 13:55:38 -0300 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> Message-ID: On 17 May 2010 13:19, Robert Bradshaw wrote: > On May 16, 2010, at 3:47 PM, Lisandro Dalcin wrote: > >> On 16 May 2010 17:32, Stefan Behnel wrote: >>> Hi, >>> >>> the Hudson CI server for Cython is now running on a publicly >>> visible port >>> of the sage server: >>> >>> https://sage.math.washington.edu:8091/hudson/ >>> >>> It uses HTTPS and any configuration changes require authentication >>> against >>> a local user account, so the setup should be safe enough to make it >>> public. >>> >>> There isn't currently a Mercurial push trigger, but Hudson polls >>> the repos >>> every couple of minutes, so a push to cython-devel or cython- >>> closures will >>> be followed by a rebuild and test runs in a timely fashion. It also >>> polls >>> the python.org SVN repos every 24 hours, so that our test suite >>> always runs >>> against the latest Py2/Py3 trunks as well as the supported >>> maintenance >>> branches. >>> >>> I still didn't find the time to get lxml build correctly on that >>> server, >>> but I would suggest adding other projects to the continuous >>> integration >>> builds as well. The Sage library is certainly worth integrating, as >>> might >>> be other projects that use Cython intensively and that have a >>> sufficiently >>> large test suite. Please make suggestions. >>> >> >> Many thanks for this! > > Yes, this is very cool. We should get Sage in there for sure--it > doesn't build with the current cython-devel, but Craig is sitting on > some patches that as I understand fix the issue and get almost all > doctests to pass. > >> I would like to integrate mpi4py. Would it be possible to have any MPI >> implementation installed on the server? If not, mpi4py can still build >> without MPI, but this would just test Cython + C compilation, the >> testsuite cannot run at all (every call would trigger a NotImplemented >> error at runtime). > > I think this is reasonable. > >> petsc4py would also qualify, but the dependency on numpy and core >> PETSc could make it more cumbersome. > > Could either of these be installed in, and run from, your home > directory? That would make things much easier (no root/admin > privileges required). > Of course, they can be installed at any place. However, the idea is to also test against multiple Python versions, right? Then numpy should also be available across Python versions ... -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From baihaoyu at gmail.com Mon May 17 19:39:13 2010 From: baihaoyu at gmail.com (Haoyu Bai) Date: Tue, 18 May 2010 01:39:13 +0800 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: <476BCF97-6648-4B57-BBEA-F0DD245E6BFA@math.washington.edu> References: <4BD86899.6090402@behnel.de> <1FBF84E4-2FDE-41C3-A009-8A95BD693053@math.washington.edu> <476BCF97-6648-4B57-BBEA-F0DD245E6BFA@math.washington.edu> Message-ID: On Tue, May 18, 2010 at 12:29 AM, Robert Bradshaw wrote: > On May 17, 2010, at 4:09 AM, Haoyu Bai wrote: > >> On Tue, May 4, 2010 at 1:58 AM, Robert Bradshaw >> wrote: >>> On May 3, 2010, at 8:40 AM, Craig Citro wrote: >>> >>>>> Just a suggestion, take it or leave it: >>>>> >>>>> For my GSoC work I found google's codereview to be a very helpful >>>>> tool. >>>>> >>>>> http://code.google.com/p/rietveld/wiki/CodeReviewHelp >>>>> >>>>> It allows you to submit patches that are presented in an app-engine >>>>> GUI. ?Reviewers can make comments & suggestions that are local to >>>>> each >>>>> change in the patch. >>>>> >>>>> Perhaps it would be easier to use for interactive patch review than >>>>> trac. (It works seamlessly with mercurial, too). >>>>> >>>> >>>> +10 -- we should *totally* start using rietveld. (Plus, in a month >>>> or >>>> two, Robert and I will be totally in love with it.) >>> >>> >>> I already am :). It may be good to put up a repo on hg.cython.org (so >>> it's easy for people to sync up with what you have to try it out and >>> play with it). Also, did you set up a blog yet? >>> >>> - Robert >>> >> >> Hi, >> >> My blog that dedicated to the Cython GSoC work has been set up at >> here: >> >> http://haoyugsoc.wordpress.com/ >> >> I'll post weekly update onto this blog. > > Excellent. > >> It would be cool for me to have a repo on hg.cython.org, though Craig >> and me were thinking that since the work involves many small patches >> so it would be a lot of lightweight branches inside the repo, which >> would be not easy for others to try it out. However, a repo would be >> good to host and backup my work and help me sync among my computers. >> So, then how to get the repo setup? > > Done. http://hg.cython.org/gsoc-haoyu/ You can push using the same > password that was set up for trac. > Thank you! Is it cloned from cython-devel? I'd prefer to work based on cython-closures since some of my work is related to closure support and it is not merged to cython-devel yet. So I guess a hg pull from cython-closures by myself should be OK? -- Haoyu BAI School of Computing, National University of Singapore. From robertwb at math.washington.edu Mon May 17 19:45:33 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 17 May 2010 10:45:33 -0700 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: References: <4BD86899.6090402@behnel.de> <1FBF84E4-2FDE-41C3-A009-8A95BD693053@math.washington.edu> <476BCF97-6648-4B57-BBEA-F0DD245E6BFA@math.washington.edu> Message-ID: On May 17, 2010, at 10:39 AM, Haoyu Bai wrote: > On Tue, May 18, 2010 at 12:29 AM, Robert Bradshaw > wrote: >> On May 17, 2010, at 4:09 AM, Haoyu Bai wrote: >> >>> On Tue, May 4, 2010 at 1:58 AM, Robert Bradshaw >>> wrote: >>>> On May 3, 2010, at 8:40 AM, Craig Citro wrote: >>>> >>>>>> Just a suggestion, take it or leave it: >>>>>> >>>>>> For my GSoC work I found google's codereview to be a very helpful >>>>>> tool. >>>>>> >>>>>> http://code.google.com/p/rietveld/wiki/CodeReviewHelp >>>>>> >>>>>> It allows you to submit patches that are presented in an app- >>>>>> engine >>>>>> GUI. Reviewers can make comments & suggestions that are local to >>>>>> each >>>>>> change in the patch. >>>>>> >>>>>> Perhaps it would be easier to use for interactive patch review >>>>>> than >>>>>> trac. (It works seamlessly with mercurial, too). >>>>>> >>>>> >>>>> +10 -- we should *totally* start using rietveld. (Plus, in a month >>>>> or >>>>> two, Robert and I will be totally in love with it.) >>>> >>>> >>>> I already am :). It may be good to put up a repo on hg.cython.org >>>> (so >>>> it's easy for people to sync up with what you have to try it out >>>> and >>>> play with it). Also, did you set up a blog yet? >>>> >>>> - Robert >>>> >>> >>> Hi, >>> >>> My blog that dedicated to the Cython GSoC work has been set up at >>> here: >>> >>> http://haoyugsoc.wordpress.com/ >>> >>> I'll post weekly update onto this blog. >> >> Excellent. >> >>> It would be cool for me to have a repo on hg.cython.org, though >>> Craig >>> and me were thinking that since the work involves many small patches >>> so it would be a lot of lightweight branches inside the repo, which >>> would be not easy for others to try it out. However, a repo would be >>> good to host and backup my work and help me sync among my computers. >>> So, then how to get the repo setup? >> >> Done. http://hg.cython.org/gsoc-haoyu/ You can push using the same >> password that was set up for trac. >> > > Thank you! Is it cloned from cython-devel? Yes. > I'd prefer to work based on > cython-closures since some of my work is related to closure support > and it is not merged to cython-devel yet. So I guess a hg pull from > cython-closures by myself should be OK? Yep, just pull cython-closures into your branch. I'm guessing the merge should be fairly inconsequential. - Robert From baihaoyu at gmail.com Mon May 17 20:49:54 2010 From: baihaoyu at gmail.com (Haoyu Bai) Date: Tue, 18 May 2010 02:49:54 +0800 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: References: <1FBF84E4-2FDE-41C3-A009-8A95BD693053@math.washington.edu> <476BCF97-6648-4B57-BBEA-F0DD245E6BFA@math.washington.edu> Message-ID: On Tue, May 18, 2010 at 1:45 AM, Robert Bradshaw wrote: > On May 17, 2010, at 10:39 AM, Haoyu Bai wrote: > >> On Tue, May 18, 2010 at 12:29 AM, Robert Bradshaw >> wrote: >>> On May 17, 2010, at 4:09 AM, Haoyu Bai wrote: >>> >>>> On Tue, May 4, 2010 at 1:58 AM, Robert Bradshaw >>>> wrote: >>>>> On May 3, 2010, at 8:40 AM, Craig Citro wrote: >>>>> >>>>>>> Just a suggestion, take it or leave it: >>>>>>> >>>>>>> For my GSoC work I found google's codereview to be a very helpful >>>>>>> tool. >>>>>>> >>>>>>> http://code.google.com/p/rietveld/wiki/CodeReviewHelp >>>>>>> >>>>>>> It allows you to submit patches that are presented in an app- >>>>>>> engine >>>>>>> GUI. ?Reviewers can make comments & suggestions that are local to >>>>>>> each >>>>>>> change in the patch. >>>>>>> >>>>>>> Perhaps it would be easier to use for interactive patch review >>>>>>> than >>>>>>> trac. (It works seamlessly with mercurial, too). >>>>>>> >>>>>> >>>>>> +10 -- we should *totally* start using rietveld. (Plus, in a month >>>>>> or >>>>>> two, Robert and I will be totally in love with it.) >>>>> >>>>> >>>>> I already am :). It may be good to put up a repo on hg.cython.org >>>>> (so >>>>> it's easy for people to sync up with what you have to try it out >>>>> and >>>>> play with it). Also, did you set up a blog yet? >>>>> >>>>> - Robert >>>>> >>>> >>>> Hi, >>>> >>>> My blog that dedicated to the Cython GSoC work has been set up at >>>> here: >>>> >>>> http://haoyugsoc.wordpress.com/ >>>> >>>> I'll post weekly update onto this blog. >>> >>> Excellent. >>> >>>> It would be cool for me to have a repo on hg.cython.org, though >>>> Craig >>>> and me were thinking that since the work involves many small patches >>>> so it would be a lot of lightweight branches inside the repo, which >>>> would be not easy for others to try it out. However, a repo would be >>>> good to host and backup my work and help me sync among my computers. >>>> So, then how to get the repo setup? >>> >>> Done. http://hg.cython.org/gsoc-haoyu/ You can push using the same >>> password that was set up for trac. >>> >> >> Thank you! Is it cloned from cython-devel? > > Yes. > >> I'd prefer to work based on >> cython-closures since some of my work is related to closure support >> and it is not merged to cython-devel yet. So I guess a hg pull from >> cython-closures by myself should be OK? > > Yep, just pull cython-closures into your branch. I'm guessing the > merge should be fairly inconsequential. > > - Robert > Hi, Is http://hg.cython.org/gsoc-haoyu/ the right address to push? I got "abort: HTTP Error 500: Internal Server Error" when pushing. -- Haoyu BAI School of Computing, National University of Singapore. From robertwb at math.washington.edu Mon May 17 22:52:04 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 17 May 2010 13:52:04 -0700 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: References: <1FBF84E4-2FDE-41C3-A009-8A95BD693053@math.washington.edu> <476BCF97-6648-4B57-BBEA-F0DD245E6BFA@math.washington.edu> Message-ID: <47038417-CBED-46CA-B841-8D75F40F46A5@math.washington.edu> On May 17, 2010, at 11:49 AM, Haoyu Bai wrote: > Hi, > > Is http://hg.cython.org/gsoc-haoyu/ the right address to push? Yes. > I got "abort: HTTP Error 500: Internal Server Error" when pushing. Ah, filesystems permissions issue. Try pushing again now. - Robert From baihaoyu at gmail.com Tue May 18 06:37:16 2010 From: baihaoyu at gmail.com (Haoyu Bai) Date: Tue, 18 May 2010 12:37:16 +0800 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: <47038417-CBED-46CA-B841-8D75F40F46A5@math.washington.edu> References: <1FBF84E4-2FDE-41C3-A009-8A95BD693053@math.washington.edu> <476BCF97-6648-4B57-BBEA-F0DD245E6BFA@math.washington.edu> <47038417-CBED-46CA-B841-8D75F40F46A5@math.washington.edu> Message-ID: On Tue, May 18, 2010 at 4:52 AM, Robert Bradshaw wrote: > On May 17, 2010, at 11:49 AM, Haoyu Bai wrote: > >> Hi, >> >> Is http://hg.cython.org/gsoc-haoyu/ the right address to push? > > Yes. > >> I got "abort: HTTP Error 500: Internal Server Error" when pushing. > > Ah, filesystems permissions issue. Try pushing again now. > > - Robert > It's OK now. Thanks! -- Haoyu BAI School of Computing, National University of Singapore. From stefan_ml at behnel.de Tue May 18 06:51:37 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 18 May 2010 06:51:37 +0200 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: <476BCF97-6648-4B57-BBEA-F0DD245E6BFA@math.washington.edu> References: <4BD86899.6090402@behnel.de> <1FBF84E4-2FDE-41C3-A009-8A95BD693053@math.washington.edu> <476BCF97-6648-4B57-BBEA-F0DD245E6BFA@math.washington.edu> Message-ID: <4BF21CD9.8040307@behnel.de> Robert Bradshaw, 17.05.2010 18:29: > On May 17, 2010, at 4:09 AM, Haoyu Bai wrote: >> Seems there is no tight integration of trac and rietveld. For now I >> will have the issue description in rietveld be a url point to Cython >> trac issue. > > Or vice-versa would be fine as well. I prefer having the 'real' ticket description in trac. That's where people will look for it. Stefan From stefan_ml at behnel.de Tue May 18 06:59:38 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 18 May 2010 06:59:38 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> Message-ID: <4BF21EBA.5050406@behnel.de> Lisandro Dalcin, 17.05.2010 18:55: > On 17 May 2010 13:19, Robert Bradshaw wrote: >> On May 16, 2010, at 3:47 PM, Lisandro Dalcin wrote: >>> petsc4py would also qualify, but the dependency on numpy and core >>> PETSc could make it more cumbersome. >> >> Could either of these be installed in, and run from, your home >> directory? That would make things much easier (no root/admin >> privileges required). > > Of course, they can be installed at any place. However, the idea is to > also test against multiple Python versions, right? Then numpy should > also be available across Python versions ... Currently, we just pass tgz archives of the installed build results between build jobs. Adding a NumPy install step to that shouldn't be hard. It's used in a lot of Cython code, so it certainly qualifies as a standard dependency. If you can give me a Linux bash script that runs a cmmi build for your external libraries to install them into a suitable subdirectory, and get your code to pick it up from another subdirectory (in a different build job) afterwards (maybe using LD_LIBRARY_PATH and friends), I'll set up a Hudson build job that runs it for you. Stefan From stefan_ml at behnel.de Tue May 18 11:42:10 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 18 May 2010 11:42:10 +0200 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: References: <4BD86899.6090402@behnel.de> <1FBF84E4-2FDE-41C3-A009-8A95BD693053@math.washington.edu> <476BCF97-6648-4B57-BBEA-F0DD245E6BFA@math.washington.edu> Message-ID: <4BF260F2.8030105@behnel.de> Robert Bradshaw, 17.05.2010 19:45: > On May 17, 2010, at 10:39 AM, Haoyu Bai wrote: >> I'd prefer to work based on >> cython-closures since some of my work is related to closure support >> and it is not merged to cython-devel yet. So I guess a hg pull from >> cython-closures by myself should be OK? > > Yep, just pull cython-closures into your branch. I'm guessing the > merge should be fairly inconsequential. I'm keeping cython-closures up-to-date with cython-devel, assuming that it will get merged in somewhat soon. Actually, given that it has proven rather safe with respect to existing Cython code, and the closures feature appears to be stable as well, is there any reason why we are still delaying the merge? Haoyu, I'll also create Hudson build jobs for your branch as soon as you start working on it, so that you can get timely feedback on the build status. Stefan From dalcinl at gmail.com Tue May 18 15:38:29 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Tue, 18 May 2010 10:38:29 -0300 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF21EBA.5050406@behnel.de> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> Message-ID: On 18 May 2010 01:59, Stefan Behnel wrote: > Lisandro Dalcin, 17.05.2010 18:55: >> On 17 May 2010 13:19, Robert Bradshaw wrote: >>> On May 16, 2010, at 3:47 PM, Lisandro Dalcin wrote: >>>> petsc4py would also qualify, but the dependency on numpy and core >>>> PETSc could make it more cumbersome. >>> >>> Could either of these be installed in, and run from, your home >>> directory? That would make things much easier (no root/admin >>> privileges required). >> >> Of course, they can be installed at any place. However, the idea is to >> also test against multiple Python versions, right? Then numpy should >> also be available across Python versions ... > > Currently, we just pass tgz archives of the installed build results between > build jobs. Adding a NumPy install step to that shouldn't be hard. It's > used in a lot of Cython code, so it certainly qualifies as a standard > dependency. > > If you can give me a Linux bash script that runs a cmmi build for your > external libraries to install them into a suitable subdirectory, and get > your code to pick it up from another subdirectory (in a different build > job) afterwards (maybe using LD_LIBRARY_PATH and friends), I'll set up a > Hudson build job that runs it for you. > Isn't any MPI implementation, like MPICH2 or Open MPI, available as a package from the distro Hudson runs? I would prefer such option, as building any of these MPI from sources takes time, it will load the machine paying very little to us. -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From stefan_ml at behnel.de Tue May 18 15:55:46 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 18 May 2010 15:55:46 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> Message-ID: <4BF29C62.3010407@behnel.de> Lisandro Dalcin, 18.05.2010 15:38: > On 18 May 2010 01:59, Stefan Behnel wrote: >> Lisandro Dalcin, 17.05.2010 18:55: >>> On 17 May 2010 13:19, Robert Bradshaw wrote: >>>> On May 16, 2010, at 3:47 PM, Lisandro Dalcin wrote: >>>>> petsc4py would also qualify, but the dependency on numpy and core >>>>> PETSc could make it more cumbersome. >>>> >>>> Could either of these be installed in, and run from, your home >>>> directory? That would make things much easier (no root/admin >>>> privileges required). >>> >>> Of course, they can be installed at any place. However, the idea is to >>> also test against multiple Python versions, right? Then numpy should >>> also be available across Python versions ... >> >> Currently, we just pass tgz archives of the installed build results between >> build jobs. Adding a NumPy install step to that shouldn't be hard. It's >> used in a lot of Cython code, so it certainly qualifies as a standard >> dependency. >> >> If you can give me a Linux bash script that runs a cmmi build for your >> external libraries to install them into a suitable subdirectory, and get >> your code to pick it up from another subdirectory (in a different build >> job) afterwards (maybe using LD_LIBRARY_PATH and friends), I'll set up a >> Hudson build job that runs it for you. >> > > Isn't any MPI implementation, like MPICH2 or Open MPI, available as a > package from the distro Hudson runs? Quite likely - maybe someone can install it. Which one would be better for you? Or would it help (and be possible) to install both in parallel? > I would prefer such option, as > building any of these MPI from sources takes time, it will load the > machine paying very little to us. Hudson only has to do it once, so that the packaged binary becomes available. Artifacts created in one build job can be reused in another, and Hudson keeps a trace back to the original build job that the artifact originated from. Stefan From dagss at student.matnat.uio.no Tue May 18 16:13:25 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Tue, 18 May 2010 16:13:25 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF29C62.3010407@behnel.de> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> <4BF29C62.3010407@behnel.de> Message-ID: <4BF2A085.7060107@student.matnat.uio.no> Stefan Behnel wrote: > Lisandro Dalcin, 18.05.2010 15:38: > >> On 18 May 2010 01:59, Stefan Behnel wrote: >> >>> Lisandro Dalcin, 17.05.2010 18:55: >>> >>>> On 17 May 2010 13:19, Robert Bradshaw wrote: >>>> >>>>> On May 16, 2010, at 3:47 PM, Lisandro Dalcin wrote: >>>>> >>>>>> petsc4py would also qualify, but the dependency on numpy and core >>>>>> PETSc could make it more cumbersome. >>>>>> >>>>> Could either of these be installed in, and run from, your home >>>>> directory? That would make things much easier (no root/admin >>>>> privileges required). >>>>> >>>> Of course, they can be installed at any place. However, the idea is to >>>> also test against multiple Python versions, right? Then numpy should >>>> also be available across Python versions ... >>>> >>> Currently, we just pass tgz archives of the installed build results between >>> build jobs. Adding a NumPy install step to that shouldn't be hard. It's >>> used in a lot of Cython code, so it certainly qualifies as a standard >>> dependency. >>> >>> If you can give me a Linux bash script that runs a cmmi build for your >>> external libraries to install them into a suitable subdirectory, and get >>> your code to pick it up from another subdirectory (in a different build >>> job) afterwards (maybe using LD_LIBRARY_PATH and friends), I'll set up a >>> Hudson build job that runs it for you. >>> >>> >> Isn't any MPI implementation, like MPICH2 or Open MPI, available as a >> package from the distro Hudson runs? >> > > Quite likely - maybe someone can install it. Which one would be better for > you? Or would it help (and be possible) to install both in parallel? > > > >> I would prefer such option, as >> building any of these MPI from sources takes time, it will load the >> machine paying very little to us. >> > > Hudson only has to do it once, so that the packaged binary becomes > available. Artifacts created in one build job can be reused in another, and > Hudson keeps a trace back to the original build job that the artifact > originated from. > > If Sage is built in such a job (the Sage distro, not the library, but the latter cannot build without the former), then NumPy is available in Sage by default. OpenMPI is also (if this is not outdated information) available as an SPKG, and so easily installable in Sage through ./sage -i openmpi or something like that. Dag Sverre From stefan_ml at behnel.de Tue May 18 19:02:22 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 18 May 2010 19:02:22 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF2A085.7060107@student.matnat.uio.no> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> <4BF29C62.3010407@behnel.de> <4BF2A085.7060107@student.matnat.uio.no> Message-ID: <4BF2C81E.5030705@behnel.de> Dag Sverre Seljebotn, 18.05.2010 16:13: > Stefan Behnel wrote: >> Lisandro Dalcin, 18.05.2010 15:38: >>> building any of these MPI from sources takes time, it will load the >>> machine paying very little to us. >> >> Hudson only has to do it once, so that the packaged binary becomes >> available. Artifacts created in one build job can be reused in another, and >> Hudson keeps a trace back to the original build job that the artifact >> originated from. > > If Sage is built in such a job (the Sage distro, not the library, but > the latter cannot build without the former) I didn't know that. Does this mean we have to build basically-all-of Sage before we can build the sagelib to test Cython with it? Or can we cut down the dependencies to something smaller and more interesting? (I guess 'interesting' is pretty relative here, though...) > then NumPy is available in Sage by default. > > OpenMPI is also (if this is not outdated information) available as an > SPKG, and so easily installable in Sage through > > ./sage -i openmpi > > or something like that. It would also need the -devel packages (header files & friends), no idea how those are installed. Stefan From robertwb at math.washington.edu Tue May 18 19:04:27 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Tue, 18 May 2010 10:04:27 -0700 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF2C81E.5030705@behnel.de> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> <4BF29C62.3010407@behnel.de> <4BF2A085.7060107@student.matnat.uio.no> <4BF2C81E.5030705@behnel.de> Message-ID: <76F82B62-CFA7-4620-B2AA-82EB49B40847@math.washington.edu> On May 18, 2010, at 10:02 AM, Stefan Behnel wrote: > Dag Sverre Seljebotn, 18.05.2010 16:13: >> Stefan Behnel wrote: >>> Lisandro Dalcin, 18.05.2010 15:38: >>>> building any of these MPI from sources takes time, it will load the >>>> machine paying very little to us. >>> >>> Hudson only has to do it once, so that the packaged binary becomes >>> available. Artifacts created in one build job can be reused in >>> another, and >>> Hudson keeps a trace back to the original build job that the >>> artifact >>> originated from. >> >> If Sage is built in such a job (the Sage distro, not the library, but >> the latter cannot build without the former) > > I didn't know that. Does this mean we have to build basically-all-of > Sage > before we can build the sagelib to test Cython with it? Or can we > cut down > the dependencies to something smaller and more interesting? (I guess > 'interesting' is pretty relative here, though...) What I propose is that we just take a build Sage library, and to test it we just re-install Cython and re-build the Sage library. (I've got a setup to do this, but can't log into Hudson to try it out). - Robert From dalcinl at gmail.com Tue May 18 19:45:34 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Tue, 18 May 2010 14:45:34 -0300 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF29C62.3010407@behnel.de> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> <4BF29C62.3010407@behnel.de> Message-ID: On 18 May 2010 10:55, Stefan Behnel wrote: > Lisandro Dalcin, 18.05.2010 15:38: >> On 18 May 2010 01:59, Stefan Behnel wrote: >>> Lisandro Dalcin, 17.05.2010 18:55: >>>> On 17 May 2010 13:19, Robert Bradshaw wrote: >>>>> On May 16, 2010, at 3:47 PM, Lisandro Dalcin wrote: >>>>>> petsc4py would also qualify, but the dependency on numpy and core >>>>>> PETSc could make it more cumbersome. >>>>> >>>>> Could either of these be installed in, and run from, your home >>>>> directory? That would make things much easier (no root/admin >>>>> privileges required). >>>> >>>> Of course, they can be installed at any place. However, the idea is to >>>> also test against multiple Python versions, right? Then numpy should >>>> also be available across Python versions ... >>> >>> Currently, we just pass tgz archives of the installed build results between >>> build jobs. Adding a NumPy install step to that shouldn't be hard. It's >>> used in a lot of Cython code, so it certainly qualifies as a standard >>> dependency. >>> >>> If you can give me a Linux bash script that runs a cmmi build for your >>> external libraries to install them into a suitable subdirectory, and get >>> your code to pick it up from another subdirectory (in a different build >>> job) afterwards (maybe using LD_LIBRARY_PATH and friends), I'll set up a >>> Hudson build job that runs it for you. >>> >> >> Isn't any MPI implementation, like MPICH2 or Open MPI, available as a >> package from the distro Hudson runs? > > Quite likely - maybe someone can install it. Which one would be better for > you? Or would it help (and be possible) to install both in parallel? > Well, having MPICH2 and Open MPI in parallel would be nice, however the distro has to provide good support for this (e.g. environmental modules support, "module load something"). If parallel installs are not possible, then I would prefer MPICH2, but Open MPI would work, too. > >> I would prefer such option, as >> building any of these MPI from sources takes time, it will load the >> machine paying very little to us. > > Hudson only has to do it once, so that the packaged binary becomes > available. Artifacts created in one build job can be reused in another, and > Hudson keeps a trace back to the original build job that the artifact > originated from. > Sorry, could you point me to some docs about this infrastructure? Or examples of some build that depends on external libraries? I'm a bit lost about this. -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From dagss at student.matnat.uio.no Tue May 18 20:37:44 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Tue, 18 May 2010 20:37:44 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF2C81E.5030705@behnel.de> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> <4BF29C62.3010407@behnel.de> <4BF2A085.7060107@student.matnat.uio.no> <4BF2C81E.5030705@behnel.de> Message-ID: <4BF2DE78.3050903@student.matnat.uio.no> Stefan Behnel wrote: > Dag Sverre Seljebotn, 18.05.2010 16:13: >> Stefan Behnel wrote: >>> Lisandro Dalcin, 18.05.2010 15:38: >>>> building any of these MPI from sources takes time, it will load the >>>> machine paying very little to us. >>> Hudson only has to do it once, so that the packaged binary becomes >>> available. Artifacts created in one build job can be reused in another, and >>> Hudson keeps a trace back to the original build job that the artifact >>> originated from. >> If Sage is built in such a job (the Sage distro, not the library, but >> the latter cannot build without the former) > > I didn't know that. Does this mean we have to build basically-all-of Sage > before we can build the sagelib to test Cython with it? Or can we cut down > the dependencies to something smaller and more interesting? (I guess > 'interesting' is pretty relative here, though...) > > >> then NumPy is available in Sage by default. This might not be the best idea -- Sage only works for one Python version at the time (currently 2.6), while we want NumPy to be present on all Python versions, in particular we want to test NumPy+Cython+Python 3.x way before Sage takes the leap to 3.x. >> >> OpenMPI is also (if this is not outdated information) available as an >> SPKG, and so easily installable in Sage through >> >> ./sage -i openmpi >> >> or something like that. > > It would also need the -devel packages (header files & friends), no idea > how those are installed. I'm pretty sure SPKGs include that stuff by default (they end up in the-sage/local/include). -- Dag Sverre From jah.mailinglist at gmail.com Tue May 18 23:55:33 2010 From: jah.mailinglist at gmail.com (jah) Date: Tue, 18 May 2010 14:55:33 -0700 Subject: [Cython] Help generalizing working-simple-quick initial port. Message-ID: Long post, but I hoped to be thorough. I'm having some trouble generalizing a simple Cython implementation that made feasible a previously infeasible Python implementation. The problem can be cast as follows: Let f(x,p) be a function, for example f(x,p) = sin(p*x). Pick a range of values for p, call this: pvalues Then, in pseudocode: for p in pvalues: xn = x0 for i in range(n): # this could benefit from ticket #474 xn = f(xn, p) # increment count for bin at (xn, p) # ... return bincounts I'm following the technique in the Cython tutorial that was written for Scipy 2009, and I have the following extension class defined: ctypedef np.float_t FTYPE_t cdef class MyFunction: cpdef FTYPE_t evaluate(self, FTYPE_t x) This gives me the flexibility to define the function in Python space as well (which is desirable). So I've coded this function as above, making sure to provide types for everything, with the following call signature: @cython.boundscheck(False) @cython.wraparound(False) def histogram(MyFunction func not None, np.ndarray[FTYPE_t, ndim=1] pvalues, FTYPE_t x0, int n, int bins): Then the fundamental line which exists in the inner loop is: xn = func.evaluate(xn, p) Everything works and is quick. Now, I'm having trouble generalising this so that both x and p can be vectors of arbitrary (but fixed) length. My understanding says that I must go from cpdef to just def (due to ticket #177): ctypedef np.float_t FTYPE_t cdef class MyFunction: def evaluate(self, np.ndarray[FTYPE_t, ndim=1, mode="c"] x, np.ndarray[FTYPE_t, ndim=1, mode="c"] p): Of course, the problem now is that I have making a Python call inside a doubly nested forloop and things get much slower. I can see that p would be fixed in the inner loop, but I'd still have to deal with the fact that xn is changing each time. So how can I implement this quickly and generally? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20100518/8458d721/attachment.htm From robertwb at math.washington.edu Wed May 19 06:36:08 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Tue, 18 May 2010 21:36:08 -0700 Subject: [Cython] Help generalizing working-simple-quick initial port. In-Reply-To: References: Message-ID: <50DC74B6-41A8-40F7-BACA-A441F6D004A0@math.washington.edu> On May 18, 2010, at 2:55 PM, jah wrote: > Long post, but I hoped to be thorough. > > I'm having some trouble generalizing a simple Cython implementation > that made feasible a previously infeasible Python implementation. > The problem can be cast as follows: > > Let f(x,p) be a function, for example f(x,p) = sin(p*x). > Pick a range of values for p, call this: pvalues > Then, in pseudocode: > > for p in pvalues: > xn = x0 > for i in range(n): > # this could benefit from ticket #474 > xn = f(xn, p) > # increment count for bin at (xn, p) > # ... > return bincounts > > I'm following the technique in the Cython tutorial that was written > for Scipy 2009, and I have the following extension class defined: > > ctypedef np.float_t FTYPE_t > cdef class MyFunction: > cpdef FTYPE_t evaluate(self, FTYPE_t x) > > This gives me the flexibility to define the function in Python space > as well (which is desirable). So I've coded this function as above, > making sure to provide types for everything, with the following call > signature: > > @cython.boundscheck(False) > @cython.wraparound(False) > def histogram(MyFunction func not None, > np.ndarray[FTYPE_t, ndim=1] pvalues, > FTYPE_t x0, > int n, > int bins): > > Then the fundamental line which exists in the inner loop is: > > xn = func.evaluate(xn, p) > > Everything works and is quick. Now, I'm having trouble generalising > this so that both x and p can be vectors of arbitrary (but fixed) > length. My understanding says that I must go from cpdef to just def > (due to ticket #177): > > ctypedef np.float_t FTYPE_t > cdef class MyFunction: > def evaluate(self, np.ndarray[FTYPE_t, ndim=1, mode="c"] x, > np.ndarray[FTYPE_t, ndim=1, mode="c"] p): > > Of course, the problem now is that I have making a Python call > inside a doubly nested forloop and things get much slower. I can > see that p would be fixed in the inner loop, but I'd still have to > deal with the fact that xn is changing each time. > > So how can I implement this quickly and generally? Thanks! One of the justifications (meaning we'd like to fix this, but it's been lower priority than other stuff) for only implementing buffer types in def (rather than cdef) calls is that usually if you're passing a whole array into a function, the relative overhead of calling the function is less significant compared to what's going on inside. Of course, this is not always the case. Is your evaluate really fast compared to the overhead of a Python function call? - Robert From dagss at student.matnat.uio.no Wed May 19 08:33:48 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 19 May 2010 08:33:48 +0200 Subject: [Cython] Help generalizing working-simple-quick initial port. In-Reply-To: References: Message-ID: <4BF3864C.2070606@student.matnat.uio.no> jah wrote: > Long post, but I hoped to be thorough. > > I'm having some trouble generalizing a simple Cython implementation > that made feasible a previously infeasible Python implementation. The > problem can be cast as follows: > > Let f(x,p) be a function, for example f(x,p) = sin(p*x). > Pick a range of values for p, call this: pvalues > Then, in pseudocode: > > for p in pvalues: > xn = x0 > for i in range(n): > # this could benefit from ticket #474 > xn = f(xn, p) > # increment count for bin at (xn, p) > # ... > return bincounts > > I'm following the technique in the Cython tutorial that was written > for Scipy 2009, and I have the following extension class defined: > > ctypedef np.float_t FTYPE_t > cdef class MyFunction: > cpdef FTYPE_t evaluate(self, FTYPE_t x) > > This gives me the flexibility to define the function in Python space > as well (which is desirable). So I've coded this function as above, > making sure to provide types for everything, with the following call > signature: > > @cython.boundscheck(False) > @cython.wraparound(False) > def histogram(MyFunction func not None, > np.ndarray[FTYPE_t, ndim=1] pvalues, > FTYPE_t x0, > int n, > int bins): > > Then the fundamental line which exists in the inner loop is: > > xn = func.evaluate(xn, p) When turning this into using arrays, consider having an out-argument instead of returning something, to avoid memory allocation on every iteration. I.e. func.evaluate(xn, p, xn) > > Everything works and is quick. Now, I'm having trouble generalising > this so that both x and p can be vectors of arbitrary (but fixed) > length. My understanding says that I must go from cpdef to just def > (due to ticket #177): > > ctypedef np.float_t FTYPE_t > cdef class MyFunction: > def evaluate(self, np.ndarray[FTYPE_t, ndim=1, mode="c"] x, > np.ndarray[FTYPE_t, ndim=1, mode="c"] p): > > Of course, the problem now is that I have making a Python call inside > a doubly nested forloop and things get much slower. I can see that p > would be fixed in the inner loop, but I'd still have to deal with the > fact that xn is changing each time. > > So how can I implement this quickly and generally? Thanks! You basically have to stoop down to using C pointers: cpdef evaluate(FTYPE_t *x, FTYPE_t *p, FTYPE_t* out, Py_ssize_t len): # Access x[i], p[i] Then call like this: func.evaluate(x.data, p.data, ...) Note that this relies on mode='c' bit for correctness! Dag Sverre From stefan_ml at behnel.de Wed May 19 09:50:53 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 19 May 2010 09:50:53 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF21EBA.5050406@behnel.de> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> Message-ID: <4BF3985D.50107@behnel.de> Stefan Behnel, 18.05.2010 06:59: > Lisandro Dalcin, 17.05.2010 18:55: >> On 17 May 2010 13:19, Robert Bradshaw wrote: >>> On May 16, 2010, at 3:47 PM, Lisandro Dalcin wrote: >>>> petsc4py would also qualify, but the dependency on numpy and core >>>> PETSc could make it more cumbersome. >>> >>> Could either of these be installed in, and run from, your home >>> directory? That would make things much easier (no root/admin >>> privileges required). >> >> Of course, they can be installed at any place. However, the idea is to >> also test against multiple Python versions, right? Then numpy should >> also be available across Python versions ... > > Currently, we just pass tgz archives of the installed build results between > build jobs. Adding a NumPy install step to that shouldn't be hard. It's > used in a lot of Cython code, so it certainly qualifies as a standard > dependency. I added an intermediate step into the build pipelines of Python 2.4 through Py2-trunk that takes the freshly built CPython installation and installs "distribute", "pip" and "numpy" into it and then repackages it as tar.gz, so that the subsequent Cython build/test jobs can use it. Any other packages that should go in? The problem I'm currently facing with this is that the NumPy tests now crash, e.g. here: https://sage.math.washington.edu:8091/hudson/view/cython-devel/job/cython-devel-tests-py2-trunk-c/270/console Could someone with NumPy experience take a look? The corresponding NumPy 1.4.1 build log is here: https://sage.math.washington.edu:8091/hudson/job/py2-trunk-ext-svn/2/consoleFull It obviously lacks all external libraries, could that be a problem? I'll remove the NumPy install for now, so that we get the tests back to normal. The installation is done in the script /scratch/hudson/Scripts/install_ext_packages.sh Stefan From dagss at student.matnat.uio.no Wed May 19 10:00:07 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 19 May 2010 10:00:07 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF3985D.50107@behnel.de> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> <4BF3985D.50107@behnel.de> Message-ID: <4BF39A87.4030808@student.matnat.uio.no> Stefan Behnel wrote: > Stefan Behnel, 18.05.2010 06:59: > >> Lisandro Dalcin, 17.05.2010 18:55: >> >>> On 17 May 2010 13:19, Robert Bradshaw wrote: >>> >>>> On May 16, 2010, at 3:47 PM, Lisandro Dalcin wrote: >>>> >>>>> petsc4py would also qualify, but the dependency on numpy and core >>>>> PETSc could make it more cumbersome. >>>>> >>>> Could either of these be installed in, and run from, your home >>>> directory? That would make things much easier (no root/admin >>>> privileges required). >>>> >>> Of course, they can be installed at any place. However, the idea is to >>> also test against multiple Python versions, right? Then numpy should >>> also be available across Python versions ... >>> >> Currently, we just pass tgz archives of the installed build results between >> build jobs. Adding a NumPy install step to that shouldn't be hard. It's >> used in a lot of Cython code, so it certainly qualifies as a standard >> dependency. >> > > I added an intermediate step into the build pipelines of Python 2.4 through > Py2-trunk that takes the freshly built CPython installation and installs > "distribute", "pip" and "numpy" into it and then repackages it as tar.gz, > so that the subsequent Cython build/test jobs can use it. Any other > packages that should go in? > > The problem I'm currently facing with this is that the NumPy tests now > crash, e.g. here: > > https://sage.math.washington.edu:8091/hudson/view/cython-devel/job/cython-devel-tests-py2-trunk-c/270/console > > Could someone with NumPy experience take a look? > > The corresponding NumPy 1.4.1 build log is here: > > https://sage.math.washington.edu:8091/hudson/job/py2-trunk-ext-svn/2/consoleFull > > It obviously lacks all external libraries, could that be a problem? > No, it shouldn't cause a crash, and doesn't matter for our purposes. I've read through it and nothing comes to mind. Are there any results for stable Py2.6, did the same thing happen then? 2.7 is not officially supported by NumPy after all... Dag Sverre From stefan_ml at behnel.de Wed May 19 10:37:01 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 19 May 2010 10:37:01 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF39A87.4030808@student.matnat.uio.no> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> <4BF3985D.50107@behnel.de> <4BF39A87.4030808@student.matnat.uio.no> Message-ID: <4BF3A32D.7010307@behnel.de> Dag Sverre Seljebotn, 19.05.2010 10:00: > Stefan Behnel wrote: >> The problem I'm currently facing with this is that the NumPy tests now >> crash, e.g. here: >> >> https://sage.math.washington.edu:8091/hudson/view/cython-devel/job/cython-devel-tests-py2-trunk-c/270/console >> >> Could someone with NumPy experience take a look? >> >> The corresponding NumPy 1.4.1 build log is here: >> >> https://sage.math.washington.edu:8091/hudson/job/py2-trunk-ext-svn/2/consoleFull >> >> It obviously lacks all external libraries, could that be a problem? >> > No, it shouldn't cause a crash, and doesn't matter for our purposes. > > I've read through it and nothing comes to mind. Are there any results > for stable Py2.6, did the same thing happen then? 2.7 is not officially > supported by NumPy after all... Yes, same thing for the latest 2.6 branch. Stefan From jah.mailinglist at gmail.com Wed May 19 11:05:03 2010 From: jah.mailinglist at gmail.com (jah) Date: Wed, 19 May 2010 02:05:03 -0700 Subject: [Cython] Help generalizing working-simple-quick initial port. In-Reply-To: <4BF3864C.2070606@student.matnat.uio.no> References: <4BF3864C.2070606@student.matnat.uio.no> Message-ID: On Tue, May 18, 2010 at 11:33 PM, Dag Sverre Seljebotn < dagss at student.matnat.uio.no> wrote: > You basically have to stoop down to using C pointers: > > > cpdef evaluate(FTYPE_t *x, FTYPE_t *p, FTYPE_t* out, Py_ssize_t len): > # Access x[i], p[i] > > > Then call like this: > > func.evaluate(x.data, p.data, ...) > > Note that this relies on mode='c' bit for correctness! > > > Looks great! Is it correct that you meant "cdef" rather than "cpdef"? My cython complains about not being able to convert "FTYPE_t *" to a "Python object" otherwise. So I had to do: cdef _evaluate(self, FTYPE_t *x, FTYPE_t *p, FTYPE_t *out, Py_ssize_t len): # ... def evaluate(self, np.ndarray[FTYPE_t, ndim=1, mode="c"] x, np.ndarray[FTYPE_t, ndim=1, mode="c"] p, np.ndarray[FTYPE_t, ndim=1, mode="c"] out Py_ssize_t len): self._evaluate(x.data, y.datat, out.data, len(x)) return out Which seems to work, but how can I get this to work for a Python subclass of this extension? The subclass would redefine evaluate() but my innerloop would only be calling _evaluate(). I guess this was the purpose of cpdef. Is there a way around this? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20100519/30f74f19/attachment.htm From dagss at student.matnat.uio.no Wed May 19 11:48:06 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 19 May 2010 11:48:06 +0200 Subject: [Cython] Help generalizing working-simple-quick initial port. In-Reply-To: References: <4BF3864C.2070606@student.matnat.uio.no> Message-ID: <4BF3B3D6.40403@student.matnat.uio.no> jah wrote: > On Tue, May 18, 2010 at 11:33 PM, Dag Sverre Seljebotn > > wrote: > > You basically have to stoop down to using C pointers: > > > cpdef evaluate(FTYPE_t *x, FTYPE_t *p, FTYPE_t* out, Py_ssize_t len): > # Access x[i], p[i] > > > Then call like this: > > func.evaluate(x.data, p.data, ...) > > Note that this relies on mode='c' bit for correctness! > > > > Looks great! Is it correct that you meant "cdef" rather than > "cpdef"? My cython complains about not being able to convert "FTYPE_t > *" to a "Python object" otherwise. So I had to do: Ah right. Doing this fully featured can be a little tricky, you basically need to reimplement the "cpdef" functionality: cdef fast_evaluate(self, double* x, ...): if is_overridden_in_python(self): # Create NumPy arrays from ptrs, see e.g. PyArray_CreateXXX (or was it NewXXX) functions). Then: return self.evaluate(xarr) # default computation cpdef evaluate(self, np.ndarray[...] x): fast_evaluate(x.data, ...) Then, is_overridden_in_python contains this in C: return Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0; This is taken from the implementation of cpdef in Cython; it basically checks whether the object has a dict (= overriden in Python space). I can't translate that to Cython off the top of my head, but you may be able to just include it as a macro in a C file if you can't figure out how: // In foo.h: #define is_overridden_in_python(x) (Py_TYPE(((PyObject *)x))->tp_dictoffset != 0) cdef extern from "foo.h: cdef bint is_overridden_in_python(object) Perhaps there's a Python C API function to do this as well. Dag Sverre From dagss at student.matnat.uio.no Wed May 19 11:49:05 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 19 May 2010 11:49:05 +0200 Subject: [Cython] Help generalizing working-simple-quick initial port. In-Reply-To: <4BF3B3D6.40403@student.matnat.uio.no> References: <4BF3864C.2070606@student.matnat.uio.no> <4BF3B3D6.40403@student.matnat.uio.no> Message-ID: <4BF3B411.9050909@student.matnat.uio.no> Dag Sverre Seljebotn wrote: > jah wrote: >> On Tue, May 18, 2010 at 11:33 PM, Dag Sverre Seljebotn >> > >> wrote: >> >> You basically have to stoop down to using C pointers: >> >> >> cpdef evaluate(FTYPE_t *x, FTYPE_t *p, FTYPE_t* out, Py_ssize_t >> len): >> # Access x[i], p[i] >> >> >> Then call like this: >> >> func.evaluate(x.data, p.data, ...) >> >> Note that this relies on mode='c' bit for correctness! >> >> >> >> Looks great! Is it correct that you meant "cdef" rather than >> "cpdef"? My cython complains about not being able to convert >> "FTYPE_t *" to a "Python object" otherwise. So I had to do: > Ah right. Doing this fully featured can be a little tricky, you > basically need to reimplement the "cpdef" functionality: > > cdef fast_evaluate(self, double* x, ...): > if is_overridden_in_python(self): > # Create NumPy arrays from ptrs, see e.g. PyArray_CreateXXX (or > was it NewXXX) functions). Then: > return self.evaluate(xarr) > # default computation > > cpdef evaluate(self, np.ndarray[...] x): > fast_evaluate(x.data, ...) > > Then, is_overridden_in_python contains this in C: > > return Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0; > > This is taken from the implementation of cpdef in Cython; it basically > checks whether the object has a dict (= overriden in Python space). I > can't translate that to Cython off the top of my head, but you may be > able to just include it as a macro in a C file if you can't figure out > how: > > // In foo.h: > #define is_overridden_in_python(x) (Py_TYPE(((PyObject > *)x))->tp_dictoffset != 0) > > cdef extern from "foo.h: > cdef bint is_overridden_in_python(object) > > Perhaps there's a Python C API function to do this as well. > BTW, there are features planned which would make all of this much much easier and friendlier, but don't expect them to show up soon. Dag Sverre From stefan_ml at behnel.de Wed May 19 16:23:18 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 19 May 2010 16:23:18 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> <4BF29C62.3010407@behnel.de> Message-ID: <4BF3F456.3000301@behnel.de> Lisandro Dalcin, 18.05.2010 19:45: > Sorry, could you point me to some docs about this infrastructure? Or > examples of some build that depends on external libraries? I'm a bit > lost about this. I'm not saying that this is the perfect solution, but what I do for the lxml builds (or the libxml2/libxslt libraries respectively) is this: configure --prefix=$WORKSPACE/installroot ... make -j8 & make install Then, fix the absolute paths in the installed bin/*-config scripts to point to the "$WORKSPACE" variable instead of the absolute path, and tar-gz the installroot directory. In the job config, let Hudson know that the archive is the result so that it can archive it. In another build job, copy over the archived tar-gz and unpack it. Configure Hudson to fingerprint it so that it knows that this file was reused in the current job. Then, use the bin/*-config scripts to configure the setup.py script. Either use an absolute rpath during the build, or set LD_LIBRARY_PATH appropriately at runtime. Voil?. Since you can't currently change the config yourself, I can set this up if you can send me a script that exercises a build using such an archive. Stefan From baihaoyu at gmail.com Wed May 19 18:47:19 2010 From: baihaoyu at gmail.com (Haoyu Bai) Date: Thu, 20 May 2010 00:47:19 +0800 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: <4BF21CD9.8040307@behnel.de> References: <4BD86899.6090402@behnel.de> <1FBF84E4-2FDE-41C3-A009-8A95BD693053@math.washington.edu> <476BCF97-6648-4B57-BBEA-F0DD245E6BFA@math.washington.edu> <4BF21CD9.8040307@behnel.de> Message-ID: On Tue, May 18, 2010 at 12:51 PM, Stefan Behnel wrote: > Robert Bradshaw, 17.05.2010 18:29: >> On May 17, 2010, at 4:09 AM, Haoyu Bai wrote: >>> Seems there is no tight integration of trac and rietveld. For now I >>> will have the issue description in rietveld be a url point to Cython >>> trac issue. >> >> Or vice-versa would be fine as well. > > I prefer having the 'real' ticket description in trac. That's where people > will look for it. > > Stefan Ok, I'll have the ticket description on trac and a link point to rietveld. -- Haoyu BAI School of Computing, National University of Singapore. From baihaoyu at gmail.com Wed May 19 18:52:14 2010 From: baihaoyu at gmail.com (Haoyu Bai) Date: Thu, 20 May 2010 00:52:14 +0800 Subject: [Cython] Haoyu Bai's application accepted for GSoC In-Reply-To: <4BF260F2.8030105@behnel.de> References: <1FBF84E4-2FDE-41C3-A009-8A95BD693053@math.washington.edu> <476BCF97-6648-4B57-BBEA-F0DD245E6BFA@math.washington.edu> <4BF260F2.8030105@behnel.de> Message-ID: On Tue, May 18, 2010 at 5:42 PM, Stefan Behnel wrote: > Robert Bradshaw, 17.05.2010 19:45: >> On May 17, 2010, at 10:39 AM, Haoyu Bai wrote: >>> I'd prefer to work based on >>> cython-closures since some of my work is related to closure support >>> and it is not merged to cython-devel yet. So I guess a hg pull from >>> cython-closures by myself should be OK? >> >> Yep, just pull cython-closures into your branch. I'm guessing the >> merge should be fairly inconsequential. > > I'm keeping cython-closures up-to-date with cython-devel, assuming that it > will get merged in somewhat soon. Actually, given that it has proven rather > safe with respect to existing Cython code, and the closures feature appears > to be stable as well, is there any reason why we are still delaying the merge? > > Haoyu, I'll also create Hudson build jobs for your branch as soon as you > start working on it, so that you can get timely feedback on the build status. > > Stefan I already started working. Please create the Hudson job for me. Thank you! :) Oh, will the Hudson job checkout the tip of my repo? Would be better if it switch to the 'default' branch of my repo, as I'll have many branches in my repo and the 'default' branch will serve as a integration of the other branches. -- Haoyu BAI School of Computing, National University of Singapore. From jah.mailinglist at gmail.com Thu May 20 06:41:15 2010 From: jah.mailinglist at gmail.com (jah) Date: Wed, 19 May 2010 21:41:15 -0700 Subject: [Cython] Help generalizing working-simple-quick initial port. In-Reply-To: <4BF3B411.9050909@student.matnat.uio.no> References: <4BF3864C.2070606@student.matnat.uio.no> <4BF3B3D6.40403@student.matnat.uio.no> <4BF3B411.9050909@student.matnat.uio.no> Message-ID: On Wed, May 19, 2010 at 2:49 AM, Dag Sverre Seljebotn < dagss at student.matnat.uio.no> wrote: > > > > // In foo.h: > > #define is_overridden_in_python(x) (Py_TYPE(((PyObject > > *)x))->tp_dictoffset != 0) > > > > cdef extern from "foo.h: > > cdef bint is_overridden_in_python(object) > > > > Perhaps there's a Python C API function to do this as well. > > > BTW, there are features planned which would make all of this much much > easier and friendlier, but don't expect them to show up soon. > > That was a learning experience for me! Since this is my first time diving into buffers with Cython and also my first time using the NumPy C API, I was hoping you guys could comment on how I implemented this---letting me know if I have done anything really wrong. I mostly followed the pseudocode described here: # http://docs.cython.org/src/userguide/pyrex_differences.html#cpdef-functions The function is simple, but I think it successfully does what cpdef would have done had I not been using buffers. In particular, I am curious about whether I should be doing Py_INCREF. From what I read, since I am not using PyArray_NewFromDescror PyArray_Newthere is no need for me to increment the reference. Also, please check my macros: // helper.h #define could_be_overridden_in_python(x) (Py_TYPE((x))->tp_dictoffset != 0) #define is_overridden_in_python(method, pfmethod) \ ( !PyCFunction_Check(method) || \ (PyCFunction_GET_FUNCTION(method) != (void *)&pfmethod ) \ ) Note that I removed the explicit casts to PyObject * since Cython was already inserting it. Unwise? Finally, here is my complete working example. Its a bit silly but it gets the point across and could be useful to others. import cython cimport cython import numpy as np cimport numpy as np from numpy cimport PyArray_DATA, npy_intp, NPY_DOUBLE FTYPE = np.float ITYPE = np.int ctypedef np.float_t FTYPE_t ctypedef np.int_t ITYPE_t cdef extern from "numpy/arrayobject.h": cdef void import_array() object PyArray_SimpleNewFromData(int nd, npy_intp* dims, int typenum, void* data) object PyArray_EMPTY(int nd, npy_intp* dims, int type_num, int fortran) cdef extern from "helper.h": cdef bint could_be_overridden_in_python(object) cdef bint is_overridden_in_python(object, object) import_array() cdef class MyFunction: def quadruple(self, np.ndarray[FTYPE_t, ndim=1, mode="c"] x, np.ndarray[FTYPE_t, ndim=1, mode="c"] out=None): if out is None: out = PyArray_EMPTY(1, (&x.shape[0]), NPY_DOUBLE, 0) self._quadruple(PyArray_DATA(x), PyArray_DATA(out), x.shape[0], 1) return out cdef void _quadruple(self, FTYPE_t *x, FTYPE_t *out, Py_ssize_t xlen, int skip_dispatch=0): cdef np.ndarray[FTYPE_t, ndim=1, mode="c"] xarr cdef np.ndarray[FTYPE_t, ndim=1, mode="c"] outarr if not skip_dispatch and could_be_overridden_in_python(self): if is_overridden_in_python(self.quadruple, MyFunction.quadruple): # Create arrays from pointer and call overridden method. xarr = PyArray_SimpleNewFromData(1, (&xlen), NPY_DOUBLE, x) outarr = PyArray_SimpleNewFromData(1, (&xlen), NPY_DOUBLE, out) self.quadruple(xarr, outarr) # Method definition cdef Py_ssize_t i for i in range(xlen): out[i] = 4 * x[i] -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20100519/ab919a74/attachment-0001.htm From dagss at student.matnat.uio.no Thu May 20 09:10:07 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 20 May 2010 09:10:07 +0200 Subject: [Cython] Help generalizing working-simple-quick initial port. In-Reply-To: References: <4BF3864C.2070606@student.matnat.uio.no> <4BF3B3D6.40403@student.matnat.uio.no> <4BF3B411.9050909@student.matnat.uio.no> Message-ID: <4BF4E04F.3070802@student.matnat.uio.no> jah wrote: > On Wed, May 19, 2010 at 2:49 AM, Dag Sverre Seljebotn > > wrote: > > > > > // In foo.h: > > #define is_overridden_in_python(x) (Py_TYPE(((PyObject > > *)x))->tp_dictoffset != 0) > > > > cdef extern from "foo.h: > > cdef bint is_overridden_in_python(object) > > > > Perhaps there's a Python C API function to do this as well. > > > BTW, there are features planned which would make all of this much much > easier and friendlier, but don't expect them to show up soon. > > > That was a learning experience for me! Since this is my first time > diving into buffers with Cython and also my first time using the NumPy > C API, I was hoping you guys could comment on how I implemented > this---letting me know if I have done anything really wrong. I mostly > followed the pseudocode described here: > # > http://docs.cython.org/src/userguide/pyrex_differences.html#cpdef-functions > > The function is simple, but I think it successfully does what cpdef > would have done had I not been using buffers. In particular, I am > curious about whether I should be doing Py_INCREF. From what I read, > since I am not using PyArray_NewFromDescr > > or PyArray_New > > there is no need for me to increment the reference. Also, please > check my macros: Yes, the NumPy functions are a bit strange regarding references, but the ones you use don't take any Python objects so you're safe. It all looks good to me. What's performance hit do you get from the extra check, is it noticeable? > > // helper.h > > #define could_be_overridden_in_python(x) (Py_TYPE((x))->tp_dictoffset > != 0) > > #define is_overridden_in_python(method, pfmethod) \ > ( !PyCFunction_Check(method) || \ > (PyCFunction_GET_FUNCTION(method) != (void *)&pfmethod ) \ > ) > > Note that I removed the explicit casts to PyObject * since Cython was > already inserting it. Unwise? No, that's OK. > > > Finally, here is my complete working example. Its a bit silly but it > gets the point across and could be useful to others. > > > > > import cython > cimport cython > > import numpy as np > cimport numpy as np > from numpy cimport PyArray_DATA, npy_intp, NPY_DOUBLE > > FTYPE = np.float > ITYPE = np.int > ctypedef np.float_t FTYPE_t > ctypedef np.int_t ITYPE_t > > cdef extern from "numpy/arrayobject.h": > cdef void import_array() > object PyArray_SimpleNewFromData(int nd, npy_intp* dims, int > typenum, void* data) > object PyArray_EMPTY(int nd, npy_intp* dims, int type_num, int > fortran) > > cdef extern from "helper.h": > cdef bint could_be_overridden_in_python(object) > cdef bint is_overridden_in_python(object, object) > > import_array() > > cdef class MyFunction: > def quadruple(self, np.ndarray[FTYPE_t, ndim=1, mode="c"] x, > np.ndarray[FTYPE_t, ndim=1, mode="c"] out=None): > if out is None: > out = PyArray_EMPTY(1, (&x.shape[0]), > NPY_DOUBLE, 0) It's a bit more readable to simply pass "x.shape" without &..[0] and the cast, you should be able to do that. Anyway, looks great! Dag Sverre From jah.mailinglist at gmail.com Thu May 20 10:02:13 2010 From: jah.mailinglist at gmail.com (jah) Date: Thu, 20 May 2010 01:02:13 -0700 Subject: [Cython] Help generalizing working-simple-quick initial port. In-Reply-To: <4BF4E04F.3070802@student.matnat.uio.no> References: <4BF3864C.2070606@student.matnat.uio.no> <4BF3B3D6.40403@student.matnat.uio.no> <4BF3B411.9050909@student.matnat.uio.no> <4BF4E04F.3070802@student.matnat.uio.no> Message-ID: On Thu, May 20, 2010 at 12:10 AM, Dag Sverre Seljebotn < dagss at student.matnat.uio.no> wrote: > Yes, the NumPy functions are a bit strange regarding references, but the > ones you use don't take any Python objects so you're safe. It all looks > good to me. > > What's performance hit do you get from the extra check, is it noticeable? > > The hit is really minimal for me. In [5]: timeit test.quadruple(x, out) 1000000 loops, best of 3: 811 ns per loop In [6]: timeit test.quadruple2(x, out) 1000000 loops, best of 3: 798 ns per loop Where quadruple2 had the "if out is None" check and empty array creation commented out. Of course, having to create the array did cause a slowdown. In [7]: timeit test.quadruple(x) 1000000 loops, best of 3: 1.3 us per loop But even then it wasn't much. Perhaps it will scale differently. > out = PyArray_EMPTY(1, (&x.shape[0]), > > NPY_DOUBLE, 0) > It's a bit more readable to simply pass "x.shape" without &..[0] and the > cast, you should be able to do that. > > Aha. Thanks again for all your help. There is no way I would have done this so quickly, easily otherwise. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20100520/459cfebb/attachment.htm From dagss at student.matnat.uio.no Thu May 20 12:26:56 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 20 May 2010 12:26:56 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF3985D.50107@behnel.de> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> <4BF3985D.50107@behnel.de> Message-ID: <4BF50E70.6020104@student.matnat.uio.no> Stefan Behnel wrote: > Stefan Behnel, 18.05.2010 06:59: > >> Lisandro Dalcin, 17.05.2010 18:55: >> >>> On 17 May 2010 13:19, Robert Bradshaw wrote: >>> >>>> On May 16, 2010, at 3:47 PM, Lisandro Dalcin wrote: >>>> >>>>> petsc4py would also qualify, but the dependency on numpy and core >>>>> PETSc could make it more cumbersome. >>>>> >>>> Could either of these be installed in, and run from, your home >>>> directory? That would make things much easier (no root/admin >>>> privileges required). >>>> >>> Of course, they can be installed at any place. However, the idea is to >>> also test against multiple Python versions, right? Then numpy should >>> also be available across Python versions ... >>> >> Currently, we just pass tgz archives of the installed build results between >> build jobs. Adding a NumPy install step to that shouldn't be hard. It's >> used in a lot of Cython code, so it certainly qualifies as a standard >> dependency. >> > > I added an intermediate step into the build pipelines of Python 2.4 through > Py2-trunk that takes the freshly built CPython installation and installs > "distribute", "pip" and "numpy" into it and then repackages it as tar.gz, > so that the subsequent Cython build/test jobs can use it. Any other > packages that should go in? > > The problem I'm currently facing with this is that the NumPy tests now > crash, e.g. here: > > https://sage.math.washington.edu:8091/hudson/view/cython-devel/job/cython-devel-tests-py2-trunk-c/270/console > > Could someone with NumPy experience take a look? > The first thing I'd try is to set OPT and CFLAGS to -O0, and possibly remove -march=nocona as well. Alternatively, if you just make Hudson's python2.6-bin.tar.gz available to me (I don't have read access to "/scratch/hudson/jobs", so if you just copy it to your home dir (/home/stefan?) and chmod it...) I can play around with getting a working NumPy in my own home directory and see what happens. Dag Sverre From stefan_ml at behnel.de Thu May 20 12:47:42 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 20 May 2010 12:47:42 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF50E70.6020104@student.matnat.uio.no> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> <4BF3985D.50107@behnel.de> <4BF50E70.6020104@student.matnat.uio.no> Message-ID: <4BF5134E.9010306@behnel.de> Dag Sverre Seljebotn, 20.05.2010 12:26: > The first thing I'd try is to set OPT and CFLAGS to -O0, and possibly > remove -march=nocona as well. I had already removed the "nocona" option and used -O2, that didn't change anything. > Alternatively, if you just make Hudson's python2.6-bin.tar.gz available > to me You can download it directly from Hudson. Just click on a test job that failed, e.g. https://sage.math.washington.edu:8091/hudson/view/cython-devel/job/cython-devel-tests-py26-c/330/ Then, follow the links under "changed dependencies", i.e. build "#11" of "py26-ext-svn" in this case, and click on the build artifacts. That will give you exactly the artifact that was used in the failed build. Same for the Cython build. > (I don't have read access to "/scratch/hudson/jobs" That should also work now. Stefan From dagss at student.matnat.uio.no Thu May 20 13:52:07 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 20 May 2010 13:52:07 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF5134E.9010306@behnel.de> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> <4BF3985D.50107@behnel.de> <4BF50E70.6020104@student.matnat.uio.no> <4BF5134E.9010306@behnel.de> Message-ID: <4BF52267.4040002@student.matnat.uio.no> Stefan Behnel wrote: > Dag Sverre Seljebotn, 20.05.2010 12:26: > >> The first thing I'd try is to set OPT and CFLAGS to -O0, and possibly >> remove -march=nocona as well. >> > > I had already removed the "nocona" option and used -O2, that didn't change > anything. > > > >> Alternatively, if you just make Hudson's python2.6-bin.tar.gz available >> to me >> > > You can download it directly from Hudson. Just click on a test job that > failed, e.g. > > https://sage.math.washington.edu:8091/hudson/view/cython-devel/job/cython-devel-tests-py26-c/330/ > > Then, follow the links under "changed dependencies", i.e. build "#11" of > "py26-ext-svn" in this case, and click on the build artifacts. That will > give you exactly the artifact that was used in the failed build. Same for > the Cython build. > Sweet :-) OK, simply untarring that, and running runtests.py on a trunk Cython, gives segfaults on NumPy import. However, if I build NumPy myself and install it ("../py26-ext/bin/python setup.py install"): No segfaults. Can you think of anything in the build environments that is different? NumPy + distutils is (naturally) a rather entagled mess. How is the build launched? I'd make sure that "/the/python setup.py install" is launched from the shell, and not through any fancy distribute/setuptools features. Dag Sverre From stefan_ml at behnel.de Thu May 20 14:05:37 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 20 May 2010 14:05:37 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF52267.4040002@student.matnat.uio.no> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> <4BF3985D.50107@behnel.de> <4BF50E70.6020104@student.matnat.uio.no> <4BF5134E.9010306@behnel.de> <4BF52267.4040002@student.matnat.uio.no> Message-ID: <4BF52591.4010800@behnel.de> Dag Sverre Seljebotn, 20.05.2010 13:52: > Stefan Behnel wrote: >> Dag Sverre Seljebotn, 20.05.2010 12:26: >>> Alternatively, if you just make Hudson's python2.6-bin.tar.gz available >>> to me >> >> You can download it directly from Hudson. Just click on a test job that >> failed, e.g. >> >> https://sage.math.washington.edu:8091/hudson/view/cython-devel/job/cython-devel-tests-py26-c/330/ >> >> Then, follow the links under "changed dependencies", i.e. build "#11" of >> "py26-ext-svn" in this case, and click on the build artifacts. That will >> give you exactly the artifact that was used in the failed build. Same for >> the Cython build. >> > Sweet :-) Totally. > OK, simply untarring that, and running runtests.py on a trunk Cython, > gives segfaults on NumPy import. > > However, if I build NumPy myself and install it ("../py26-ext/bin/python > setup.py install"): No segfaults. > > Can you think of anything in the build environments that is different? > > NumPy + distutils is (naturally) a rather entagled mess. How is the > build launched? I'd make sure that "/the/python setup.py install" is > launched from the shell, and not through any fancy distribute/setuptools > features. Ok, I was installing it using pip - that may make a difference. I'll update the script to download it manually and install it with plain setup.py. Thanks! Stefan From stefan_ml at behnel.de Thu May 20 14:49:38 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 20 May 2010 14:49:38 +0200 Subject: [Cython] Hudson-CI server now publicly available In-Reply-To: <4BF52591.4010800@behnel.de> References: <4BF05640.40908@behnel.de> <0AEF997F-0D37-402A-90E2-C69CF6373EBE@math.washington.edu> <4BF21EBA.5050406@behnel.de> <4BF3985D.50107@behnel.de> <4BF50E70.6020104@student.matnat.uio.no> <4BF5134E.9010306@behnel.de> <4BF52267.4040002@student.matnat.uio.no> <4BF52591.4010800@behnel.de> Message-ID: <4BF52FE2.6080702@behnel.de> Stefan Behnel, 20.05.2010 14:05: > Dag Sverre Seljebotn, 20.05.2010 13:52: >> NumPy + distutils is (naturally) a rather entagled mess. How is the >> build launched? I'd make sure that "/the/python setup.py install" is >> launched from the shell, and not through any fancy distribute/setuptools >> features. > > I'll update the script to download it manually and install it with plain > setup.py. Tried that, didn't work. Same crash as before. Stefan From baihaoyu at gmail.com Thu May 20 18:54:48 2010 From: baihaoyu at gmail.com (Haoyu Bai) Date: Fri, 21 May 2010 00:54:48 +0800 Subject: [Cython] Nonlocal, closure and refnanny Message-ID: Hi, While I get the the nonlocal keyword implemented, now the inner function is able to write to the closure. This cause refnanny lost tracking on the closure variables when following the refcounting rules described at http://wiki.cython.org/refcounting . For example: def foo(): x=0 # INCREF(0), 0 get traced by refnanny def bar(): # DECREF(x) refnanny complains since x is not got tracked yet # INCREF(1) x=1 # refnanny complains since there is no giveref for 1 bar() # refnanny complains since 0 is not giveref-ed and 1 got giveref-ed instead For the inner function bar() it is easy to fix. But for the outer function, since the thing x referenced to can be changed at every point now, it will not work correctly to giveref at the end of function. Since the rule is that closure variables are owned by scope object and not managed by refnanny. So my idea to fix this is to wrap every assignment to closure object by a pair of GOTREF and GIVEREF. So when you do x=1, these will happen: GOTREF(x) DECREF(x) INCREF(1) x=1 GIVEREF(x) Then refnanny will be happy. I implemented this, and got all the closure related tests passed without refnanny complaining. This generate a bit more codes but I think should be ok. Since refnanny is for debug so performance at here would not be a concern. Any comments? -- Haoyu BAI School of Computing, National University of Singapore. From dalcinl at gmail.com Thu May 20 19:26:16 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Thu, 20 May 2010 14:26:16 -0300 Subject: [Cython] Nonlocal, closure and refnanny In-Reply-To: References: Message-ID: On 20 May 2010 13:54, Haoyu Bai wrote: > Hi, > > While I get the the nonlocal keyword implemented, now the inner > function is able to write to the closure. This cause refnanny lost > tracking on the closure variables when following the refcounting rules > described at http://wiki.cython.org/refcounting . For example: > > def foo(): > ? ?x=0 # INCREF(0), 0 get traced by refnanny > ? ?def bar(): > ? ? ? ?# DECREF(x) ?refnanny complains since x is not got tracked yet > ? ? ? ?# INCREF(1) > ? ? ? ?x=1 > ? ? ? ?# refnanny complains since there is no giveref for 1 > ? ?bar() > ? ?# refnanny complains since 0 is not giveref-ed and 1 got giveref-ed instead > > > For the inner function bar() it is easy to fix. But for the outer > function, since the thing x referenced to can be changed at every > point now, it will not work correctly to giveref at the end of > function. > > Since the rule is that closure variables are owned by scope object and > not managed by refnanny. So my idea to fix this is to wrap every > assignment to closure object by a pair of GOTREF and GIVEREF. So when > you do x=1, these will happen: > > GOTREF(x) > DECREF(x) > INCREF(1) > x=1 > GIVEREF(x) > > Then refnanny will be happy. > Looks good ... > I implemented this, and got all the closure related tests passed > without refnanny complaining. > > This generate a bit more codes but I think should be ok. Since > refnanny is for debug so performance at here would not be a concern. > Of course, never mind about these extra lines... -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From baihaoyu at gmail.com Thu May 20 19:39:17 2010 From: baihaoyu at gmail.com (Haoyu Bai) Date: Fri, 21 May 2010 01:39:17 +0800 Subject: [Cython] Nonlocal, closure and refnanny In-Reply-To: References: Message-ID: On Fri, May 21, 2010 at 1:26 AM, Lisandro Dalcin wrote: > On 20 May 2010 13:54, Haoyu Bai wrote: >> Hi, >> >> While I get the the nonlocal keyword implemented, now the inner >> function is able to write to the closure. This cause refnanny lost >> tracking on the closure variables when following the refcounting rules >> described at http://wiki.cython.org/refcounting . For example: >> >> def foo(): >> ? ?x=0 # INCREF(0), 0 get traced by refnanny >> ? ?def bar(): >> ? ? ? ?# DECREF(x) ?refnanny complains since x is not got tracked yet >> ? ? ? ?# INCREF(1) >> ? ? ? ?x=1 >> ? ? ? ?# refnanny complains since there is no giveref for 1 >> ? ?bar() >> ? ?# refnanny complains since 0 is not giveref-ed and 1 got giveref-ed instead >> >> >> For the inner function bar() it is easy to fix. But for the outer >> function, since the thing x referenced to can be changed at every >> point now, it will not work correctly to giveref at the end of >> function. >> >> Since the rule is that closure variables are owned by scope object and >> not managed by refnanny. So my idea to fix this is to wrap every >> assignment to closure object by a pair of GOTREF and GIVEREF. So when >> you do x=1, these will happen: >> >> GOTREF(x) >> DECREF(x) >> INCREF(1) >> x=1 >> GIVEREF(x) >> >> Then refnanny will be happy. >> > > Looks good ... > >> I implemented this, and got all the closure related tests passed >> without refnanny complaining. >> >> This generate a bit more codes but I think should be ok. Since >> refnanny is for debug so performance at here would not be a concern. >> > > Of course, never mind about these extra lines... > > > > -- > Lisandro Dalcin Thanks! :) BTW, just spotted a closure bug, this won't compile (reports '__pyx_outer_scope' redeclared): def nested1(): def f(): def g1(): pass def nested2(): def f(): def g2(): pass Seems some name mangling problem. I traced to CreateClosureClasses.create_class_from_scope() in ParseTreeTransform.py then didn't get the idea yet. Anyone want to look into it? Should I file it to issue tracker? -- Haoyu BAI School of Computing, National University of Singapore. From stefan_ml at behnel.de Thu May 20 21:14:31 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 20 May 2010 21:14:31 +0200 Subject: [Cython] Nonlocal, closure and refnanny In-Reply-To: References: Message-ID: <4BF58A17.6060205@behnel.de> Haoyu Bai, 20.05.2010 18:54: > def foo(): > x=0 # INCREF(0), 0 get traced by refnanny > def bar(): > # DECREF(x) refnanny complains since x is not got tracked yet > # INCREF(1) > x=1 > # refnanny complains since there is no giveref for 1 > bar() > # refnanny complains since 0 is not giveref-ed and 1 got giveref-ed instead > > Since the rule is that closure variables are owned by scope object and > not managed by refnanny. So my idea to fix this is to wrap every > assignment to closure object by a pair of GOTREF and GIVEREF. So when > you do x=1, these will happen: > > GOTREF(x) > DECREF(x) > INCREF(1) > x=1 > GIVEREF(x) Yes, that's how it's supposed to work. Stefan From dalcinl at gmail.com Thu May 20 21:16:42 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Thu, 20 May 2010 16:16:42 -0300 Subject: [Cython] Nonlocal, closure and refnanny In-Reply-To: References: Message-ID: On 20 May 2010 14:39, Haoyu Bai wrote: > On Fri, May 21, 2010 at 1:26 AM, Lisandro Dalcin wrote: >> On 20 May 2010 13:54, Haoyu Bai wrote: >>> Hi, >>> >>> While I get the the nonlocal keyword implemented, now the inner >>> function is able to write to the closure. This cause refnanny lost >>> tracking on the closure variables when following the refcounting rules >>> described at http://wiki.cython.org/refcounting . For example: >>> >>> def foo(): >>> ? ?x=0 # INCREF(0), 0 get traced by refnanny >>> ? ?def bar(): >>> ? ? ? ?# DECREF(x) ?refnanny complains since x is not got tracked yet >>> ? ? ? ?# INCREF(1) >>> ? ? ? ?x=1 >>> ? ? ? ?# refnanny complains since there is no giveref for 1 >>> ? ?bar() >>> ? ?# refnanny complains since 0 is not giveref-ed and 1 got giveref-ed instead >>> >>> >>> For the inner function bar() it is easy to fix. But for the outer >>> function, since the thing x referenced to can be changed at every >>> point now, it will not work correctly to giveref at the end of >>> function. >>> >>> Since the rule is that closure variables are owned by scope object and >>> not managed by refnanny. So my idea to fix this is to wrap every >>> assignment to closure object by a pair of GOTREF and GIVEREF. So when >>> you do x=1, these will happen: >>> >>> GOTREF(x) >>> DECREF(x) >>> INCREF(1) >>> x=1 >>> GIVEREF(x) >>> >>> Then refnanny will be happy. >>> >> >> Looks good ... >> >>> I implemented this, and got all the closure related tests passed >>> without refnanny complaining. >>> >>> This generate a bit more codes but I think should be ok. Since >>> refnanny is for debug so performance at here would not be a concern. >>> >> >> Of course, never mind about these extra lines... >> >> >> >> -- >> Lisandro Dalcin > > Thanks! :) > > BTW, just spotted a closure bug, this won't compile (reports > '__pyx_outer_scope' redeclared): > > def nested1(): > ? ?def f(): > ? ? ? ?def g1(): > ? ? ? ? ? ?pass > > def nested2(): > ? ?def f(): > ? ? ? ?def g2(): > ? ? ? ? ? ?pass > > Seems some name mangling problem. I traced to > CreateClosureClasses.create_class_from_scope() in > ParseTreeTransform.py then didn't get the idea yet. > Does this occur if you write def f2(): ... (instead of def f():...) in nested2() ? Could the bug be related to f()'s having the same name? -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From jah.mailinglist at gmail.com Thu May 20 22:40:45 2010 From: jah.mailinglist at gmail.com (jah) Date: Thu, 20 May 2010 13:40:45 -0700 Subject: [Cython] Seeking explanation: ctypedef class numpy.ndarray [object PyArrayObject] Message-ID: Hi, I'm reading through numpy.pxd and trying to understand the following: ctypedef class numpy.ndarray [object PyArrayObject] Probably, I have made some wrong conclusions and was hoping for an explanation. Sorry if these are simple questions, but I wasn't able to find info on this in the docs (links are appreciated). 0) What does the above statement mean, in words? 1) Previously, I thought I understood what the keyword "object" meant. I believed it to be a synonmyn for PyObject*, but the above usage makes me question that conclusion. So what is "object" really? 2) In the above, I am having trouble seeing what is the original type and the new type, as in "typedef oldtypename newtypename". When I read the above code, it seems as if there is no "second argument". Help. Relatedly, I was wondering how best to use an object member. For instance, cdef Klass: cdef object x def __init__(self, np.ndarray[FTYPE_t, ndim=1, mode="c"] x): self.x = x def func(self): cdef np.ndarray[FTYPE_t, ndim=1, mode="c"] x = self.x # ...use x instead of self.x for fast access so that # (self.x.shape[0] is operating on a Python tuple) When I examine the C code, I see that x (the __init__ method parameter) has type PyArrayObject* while self.x has PyObject*. No problem. In func(), if I want to have fast access to self.x, is the recommended way to do this as I did above? I wasn't sure if I should instead do something like: def func(self): cdef PyArrayObject* x = (self.x) # ...use x instead of self.x for fast access Thanks in advance. From baihaoyu at gmail.com Fri May 21 05:46:25 2010 From: baihaoyu at gmail.com (Haoyu Bai) Date: Fri, 21 May 2010 11:46:25 +0800 Subject: [Cython] Nonlocal, closure and refnanny In-Reply-To: References: Message-ID: On Fri, May 21, 2010 at 3:16 AM, Lisandro Dalcin wrote: >> BTW, just spotted a closure bug, this won't compile (reports >> '__pyx_outer_scope' redeclared): >> >> def nested1(): >> ? ?def f(): >> ? ? ? ?def g1(): >> ? ? ? ? ? ?pass >> >> def nested2(): >> ? ?def f(): >> ? ? ? ?def g2(): >> ? ? ? ? ? ?pass >> >> Seems some name mangling problem. I traced to >> CreateClosureClasses.create_class_from_scope() in >> ParseTreeTransform.py then didn't get the idea yet. >> > > Does this occur if you write def f2(): ... (instead of def f():...) > in nested2() ? Could the bug be related to f()'s having the same name? > > > Yes, the two f() have the same cname. Probably need to mangle the cname at here. -- Haoyu BAI School of Computing, National University of Singapore. From dalcinl at gmail.com Fri May 21 21:24:58 2010 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 21 May 2010 16:24:58 -0300 Subject: [Cython] Seeking explanation: ctypedef class numpy.ndarray [object PyArrayObject] In-Reply-To: References: Message-ID: On 20 May 2010 17:40, jah wrote: > Hi, > > I'm reading through numpy.pxd and trying to understand the following: > > ? ?ctypedef class numpy.ndarray [object PyArrayObject] > > Probably, I have made some wrong conclusions and was hoping for an > explanation. ?Sorry if these are simple questions, but I wasn't able > to find info on this in the docs (links are appreciated). > > 0) What does the above statement mean, in words? > 1) There is an extension type called "ndarray" in module "numpy" 2) The object structure (i.e. a C struct that has extra slots extending the core Python's PyObject structure) is called PyArrayObject 3) the "ctypedef" bit means that generated C code will use plain "PyArrayObject" for declaring structs, whild if you do cdef class ...., the generated C code will use "struct PyArrayObject". In the specific case of numpy, look at the header "numpy/arrayobject.h", you should see "typedef struct PyArrayObject { ...} PyArrayObject"... As PyArrayObject end-up being a C typedef, in Cython side you have declare with "ctypedef". Pretty obvious, right? ;-) > 1) ?Previously, I thought I understood what the keyword "object" > meant. ?I believed it to be a synonmyn for PyObject*, but the above > usage makes me question that conclusion. ?So what is "object" really? > > 2) In the above, I am having trouble seeing what is the original type > and the new type, as in "typedef oldtypename newtypename". ?When I > read the above code, it seems as if there is no "second argument". > Help. > > Relatedly, I was wondering how best to use an object member. For instance, > > cdef Klass: > ? cdef object x > ? def __init__(self, np.ndarray[FTYPE_t, ndim=1, mode="c"] x): > ? ? ? self.x = x > ? def func(self): > ? ? ? cdef np.ndarray[FTYPE_t, ndim=1, mode="c"] x = self.x > ? ? ? # ...use x instead of self.x for fast access so that > ? ? ? # (self.x.shape[0] is operating on a Python tuple) > > When I examine the C code, I see that x (the __init__ method parameter) has > type PyArrayObject* while self.x has PyObject*. ?No problem. In func(), > if I want to have fast access to self.x, is the recommended > way to do this as I did above? ?I wasn't sure if I should instead do > something like: > > ? def func(self): > ? ? ? ?cdef PyArrayObject* x = (self.x) > ? ? ? ?# ...use x instead of self.x for fast access > You could: cdef Klass: ? cdef np.ndarray x I think you still have to: def func(self): cdef np.ndarray[FTYPE_t, ndim=1, mode="c"] x = self.x -- Lisandro Dalcin --------------- CIMEC (INTEC/CONICET-UNL) Predio CONICET-Santa Fe Colectora RN 168 Km 472, Paraje El Pozo Tel: +54-342-4511594 (ext 1011) Tel/Fax: +54-342-4511169 From jah.mailinglist at gmail.com Sat May 22 05:14:16 2010 From: jah.mailinglist at gmail.com (jah) Date: Fri, 21 May 2010 20:14:16 -0700 Subject: [Cython] Seeking explanation: ctypedef class numpy.ndarray [object PyArrayObject] In-Reply-To: References: Message-ID: On Fri, May 21, 2010 at 12:24 PM, Lisandro Dalcin wrote: > On 20 May 2010 17:40, jah wrote: >> Hi, >> >> I'm reading through numpy.pxd and trying to understand the following: >> >> ? ?ctypedef class numpy.ndarray [object PyArrayObject] >> > >> Probably, I have made some wrong conclusions and was hoping for an >> explanation. ?Sorry if these are simple questions, but I wasn't able >> to find info on this in the docs (links are appreciated). >> >> 0) What does the above statement mean, in words? >> > > 1) There is an extension type called "ndarray" in module "numpy" > > 2) The object structure (i.e. a C struct that has extra slots > extending the core Python's PyObject structure) is called > PyArrayObject > > 3) the "ctypedef" bit means that generated C code will use plain > "PyArrayObject" for declaring structs, whild if you do cdef class > ...., the generated C code will use "struct PyArrayObject". In the > specific case of numpy, look at the header "numpy/arrayobject.h", you > should see "typedef struct PyArrayObject { ...} PyArrayObject"... As > PyArrayObject end-up being a C typedef, in Cython side you have > declare with "ctypedef". > > Pretty obvious, right? ;-) > Very helpful. I was able to figure out the third point by looking at the generated code. But I'm still confused on one other issue. In numpy.pxd, the ctypedef used "numpy.ndarray" in the declaration, but in the same file, "ndarray" is used without qualification (inside the ctypedef block). Is this just how it is? It seemed a bit like magic that "ndarray" can be used without the namespace before the ctypedef has been fully defined. For example, I see: def __getbuffer__(ndarray self, Py_buffer* info, int flags): rather than def __getbuffer__(numpy.ndarray self, Py_buffer* info, int flags): I'm not too worried about it, but it was a sticking point for me that caused mental confusion. From luper.rouch at gmail.com Mon May 24 00:07:44 2010 From: luper.rouch at gmail.com (luper rouch) Date: Mon, 24 May 2010 00:07:44 +0200 Subject: [Cython] [Bug] Can't access C members in extension types special methods Message-ID: Hi, It seems there is a problem when attempting to access C members of an extension type in special methods, such as __mul__ : -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- cdef extern from "btQuaternion.h": cdef cppclass btQuaternion: btQuaternion(float, float, float, float) btQuaternion operator*(float) float x() float y() float z() float w() cdef class Quaternion: cdef btQuaternion *wrapped def __init__(self, x, y, z, w): self.wrapped = new btQuaternion(x, y, z, w) def __dealloc__(self): del self.wrapped def __mul__(self, float other): return from_c_obj(self.wrapped[0] * other) # Cannot convert # Python object to # 'btQuaternion' cdef from_c_obj(btQuaternion quat): """ Construct a Quaternion instance from its C++ counterpart. """ return Quaternion(quat.x(), quat.y(), quat.z(), quat.w()) -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- Changing this code to something like : -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- def __mul(self, float other): return from_c_obj(self.wrapped[0] * other) def __mul__(self, float other): return self.__mul(other) -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- Gives no error, and the code works as expected (all of this was tested on the latest dev branch). Cheers, -- Lup From stefan_ml at behnel.de Mon May 24 09:44:21 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 24 May 2010 09:44:21 +0200 Subject: [Cython] [Bug] Can't access C members in extension types special methods In-Reply-To: References: Message-ID: <4BFA2E55.1070503@behnel.de> luper rouch, 24.05.2010 00:07: > It seems there is a problem when attempting to access C members of an > extension type in special methods, such as __mul__ : Hi, you should avoid claiming to have found a bug just because you didn't read the documentation. http://docs.cython.org/src/userguide/special_methods.html#arithmetic-methods Stefan From luper.rouch at gmail.com Mon May 24 13:43:51 2010 From: luper.rouch at gmail.com (luper rouch) Date: Mon, 24 May 2010 13:43:51 +0200 Subject: [Cython] [Bug] Can't access C members in extension types special methods In-Reply-To: <4BFA2E55.1070503@behnel.de> References: <4BFA2E55.1070503@behnel.de> Message-ID: 2010/5/24 Stefan Behnel : > luper rouch, 24.05.2010 00:07: >> It seems there is a problem when attempting to access C members of an >> extension type in special methods, such as __mul__ : > > Hi, > > you should avoid claiming to have found a bug just because you didn't read > the documentation. > > http://docs.cython.org/src/userguide/special_methods.html#arithmetic-methods > Yes I certainly missed that in the docs, sorry. So, arithmetic operators are some kind of static methods, is the following the right way to implement them ? def __mul__(op1, op2): if isinstance(op1, Quaternion): return from_c_obj((op1).wrapped[0] * op2) else: return from_c_obj((op2).wrapped[0] * op1) And for intransitive operations like __div__ return NotImplemted in the reversed case : def __div__(op1, op2): if isinstance(op1, Quaternion): return from_c_obj((op1).wrapped[0] / op2) else: return NotImplemented -- Lup From stefan_ml at behnel.de Mon May 24 13:50:36 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 24 May 2010 13:50:36 +0200 Subject: [Cython] loop variables in generator expressions Message-ID: <4BFA680C.2040402@behnel.de> Hi, the current closures branch has limited support for inlined generator expressions, i.e. you can write any(x == 5 for x in some_seq) and Cython will generate an inlined loop for it that short circuits properly on the first hit. To get this working correctly, I fixed the scoping behaviour of the loop variable by giving generator expressions their own scope, so that x won't leak into the surrounding scope in the above example. However, this introduces a pretty annoying problem: you can't type the loop variable any more. Any cdef declaration will only apply to the surrounding scope, not to the scope of the generator expression. This may be acceptable in some cases where Cython can properly infer a type for it, but in other cases, explicit typing is required to make the expression work correctly and/or efficiently. Does anyone have an idea how we can let users provide an explicit type for x in the above example? Maybe with a cast like this? any(x == 5 for x in some_seq) Any other ideas? Second question: should this be enabled for list/set/dict comprehensions in Cython 0.13 as well? I think we already agreed that the leaking loop variables should be considered a bug that rarely has an impact on existing code. In Py2, only list comprehensions leak their variable, whereas genexps have their own scope. In Py3, all comprehensions and genexps have their own scope. I would prefer unifying the scoping rules in Cython 0.13 as well. (It's already implemented in cython-closures, although disabling it would be trivial). Stefan From stefan_ml at behnel.de Mon May 24 14:04:04 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 24 May 2010 14:04:04 +0200 Subject: [Cython] [Bug] Can't access C members in extension types special methods In-Reply-To: References: <4BFA2E55.1070503@behnel.de> Message-ID: <4BFA6B34.1030501@behnel.de> luper rouch, 24.05.2010 13:43: > 2010/5/24 Stefan Behnel: >> luper rouch, 24.05.2010 00:07: >>> It seems there is a problem when attempting to access C members of an >>> extension type in special methods, such as __mul__ : >> >> you should avoid claiming to have found a bug just because you didn't read >> the documentation. >> >> http://docs.cython.org/src/userguide/special_methods.html#arithmetic-methods > > Yes I certainly missed that in the docs, sorry. So, arithmetic > operators are some kind of static methods, is the following the right > way to implement them ? > > def __mul__(op1, op2): > if isinstance(op1, Quaternion): > return from_c_obj((op1).wrapped[0] *op2) > else: > return from_c_obj((op2).wrapped[0] *op1) Assuming that you want a TypeError to be raised for any second operand that can't be converted to a C float value, that should work. Note that float coercion will be handled by the Python runtime, so any (numeric or non-numeric) type that can convert itself into a float value will work here. You can also write "float(op2)", which will do the same thing. > And for intransitive operations like __div__ return NotImplemted in > the reversed case : > > def __div__(op1, op2): > if isinstance(op1, Quaternion): > return from_c_obj((op1).wrapped[0] /op2) > else: > return NotImplemented Looks ok. Note that the cython-users mailing list would have been more appropriate for this thread. Stefan From robertwb at math.washington.edu Mon May 24 17:59:14 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 24 May 2010 08:59:14 -0700 Subject: [Cython] [Bug] Can't access C members in extension types special methods In-Reply-To: <4BFA6B34.1030501@behnel.de> References: <4BFA2E55.1070503@behnel.de> <4BFA6B34.1030501@behnel.de> Message-ID: <8FD0C1A5-9873-42AB-9CD2-174C05CBC24F@math.washington.edu> On May 24, 2010, at 5:04 AM, Stefan Behnel wrote: > luper rouch, 24.05.2010 13:43: >> 2010/5/24 Stefan Behnel: >>> luper rouch, 24.05.2010 00:07: >>>> It seems there is a problem when attempting to access C members >>>> of an >>>> extension type in special methods, such as __mul__ : >>> >>> you should avoid claiming to have found a bug just because you >>> didn't read >>> the documentation. >>> >>> http://docs.cython.org/src/userguide/special_methods.html#arithmetic-methods >> >> Yes I certainly missed that in the docs, sorry. Yep. We should probably try to feature that more prominently, as it's one of the most significant differences between cdef classes in Cython and pure Python and often trips newcomers up. >> So, arithmetic >> operators are some kind of static methods, is the following the right >> way to implement them ? >> >> def __mul__(op1, op2): >> if isinstance(op1, Quaternion): >> return from_c_obj((op1).wrapped[0] >> *op2) >> else: >> return from_c_obj((op2).wrapped[0] >> *op1) > > Assuming that you want a TypeError to be raised for any second > operand that > can't be converted to a C float value, that should work. > > Note that float coercion will be handled by the Python runtime, so any > (numeric or non-numeric) type that can convert itself into a float > value > will work here. You can also write "float(op2)", which will do the > same thing. Well, I would recommend using a cast over a call, unless you want >>> my_object * "1.23" to work. - Robert From robertwb at math.washington.edu Mon May 24 18:03:47 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 24 May 2010 09:03:47 -0700 Subject: [Cython] loop variables in generator expressions In-Reply-To: <4BFA680C.2040402@behnel.de> References: <4BFA680C.2040402@behnel.de> Message-ID: On May 24, 2010, at 4:50 AM, Stefan Behnel wrote: > Hi, > > the current closures branch has limited support for inlined generator > expressions, i.e. you can write > > any(x == 5 for x in some_seq) > > and Cython will generate an inlined loop for it that short circuits > properly on the first hit. To get this working correctly, I fixed the > scoping behaviour of the loop variable by giving generator expressions > their own scope, so that x won't leak into the surrounding scope in > the > above example. However, this introduces a pretty annoying problem: you > can't type the loop variable any more. Any cdef declaration will > only apply > to the surrounding scope, not to the scope of the generator > expression. > > This may be acceptable in some cases where Cython can properly infer > a type > for it, but in other cases, explicit typing is required to make the > expression work correctly and/or efficiently. > > Does anyone have an idea how we can let users provide an explicit > type for > x in the above example? Maybe with a cast like this? > > any(x == 5 for x in some_seq) > > Any other ideas? That seems reasonable to me, and also goes well with, e.g., the proposed syntax for typing varargs. > Second question: should this be enabled for list/set/dict > comprehensions in > Cython 0.13 as well? I think we already agreed that the leaking loop > variables should be considered a bug that rarely has an impact on > existing > code. In Py2, only list comprehensions leak their variable, whereas > genexps > have their own scope. In Py3, all comprehensions and genexps have > their own > scope. I would prefer unifying the scoping rules in Cython 0.13 as > well. > (It's already implemented in cython-closures, although disabling it > would > be trivial). I think we should strive for Py2 compatibility, even in corner cases. With the -3 flag, we should behave as Python 3 (i.e. not leaking variables as you suggest). - Robert From jah.mailinglist at gmail.com Mon May 24 19:27:44 2010 From: jah.mailinglist at gmail.com (jah) Date: Mon, 24 May 2010 10:27:44 -0700 Subject: [Cython] pointer arithmetic Message-ID: I need to write to arbitrary portions of an array. If I know they are both one-dimensional, then I can do something like: cdef void func(self, double *x, double *out, Py_ssize_t i=0): out[i] = x[i] + 1 out[i+1] = x[i+1] + 2 What I'd really like to do is pointer arithmetic, cdef void func(self, double *x, double *out): *out = *x + 1 *(out+1) = *(x+1) + 2 Here, "out" could also be a two-dimensional array and func() is writing only to a particular row of the matrix. Ideally, I'd like to have one function that can handle when "x" and "out" point to data of arbitrary dimensions as func() doesn't care about the dimension. How can I accomplish this? Do I have to write this in C and then do a "cdef extern from ..." or can it be done in Cython? From jah.mailinglist at gmail.com Mon May 24 19:35:48 2010 From: jah.mailinglist at gmail.com (jah) Date: Mon, 24 May 2010 10:35:48 -0700 Subject: [Cython] pointer arithmetic In-Reply-To: References: Message-ID: On Mon, May 24, 2010 at 10:27 AM, jah wrote: > I need to write to arbitrary portions of an array. ?If I know they are > both one-dimensional, then I can do something like: > > cdef void func(self, double *x, double *out, Py_ssize_t i=0): > ? out[i] = x[i] + 1 > ? out[i+1] = x[i+1] + 2 > > What I'd really like to do is pointer arithmetic, > > cdef void func(self, double *x, double *out): > ? *out = *x + 1 > ? *(out+1) = *(x+1) + 2 > > Here, "out" could also be a two-dimensional array and func() is > writing only to a particular row of the matrix. ?Ideally, I'd like to > have one function that can handle when "x" and "out" point to data of > arbitrary dimensions as func() doesn't care about the dimension. ?How > can I accomplish this? ?Do I have to write this in C and then do a > "cdef extern from ..." or can it be done in Cython? > Nevermind, I forgot that x was the result of PyArray_DATA(x). So I can access all the data with a single index. I just need to pass in indexes for x and out, separately. From dagss at student.matnat.uio.no Mon May 24 19:47:46 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Mon, 24 May 2010 19:47:46 +0200 Subject: [Cython] loop variables in generator expressions In-Reply-To: References: <4BFA680C.2040402@behnel.de> Message-ID: <4BFABBC2.9090303@student.matnat.uio.no> Robert Bradshaw wrote: > On May 24, 2010, at 4:50 AM, Stefan Behnel wrote: > > >> Hi, >> >> the current closures branch has limited support for inlined generator >> expressions, i.e. you can write >> >> any(x == 5 for x in some_seq) >> >> and Cython will generate an inlined loop for it that short circuits >> properly on the first hit. To get this working correctly, I fixed the >> scoping behaviour of the loop variable by giving generator expressions >> their own scope, so that x won't leak into the surrounding scope in >> the >> above example. However, this introduces a pretty annoying problem: you >> can't type the loop variable any more. Any cdef declaration will >> only apply >> to the surrounding scope, not to the scope of the generator >> expression. >> >> This may be acceptable in some cases where Cython can properly infer >> a type >> for it, but in other cases, explicit typing is required to make the >> expression work correctly and/or efficiently. >> >> Does anyone have an idea how we can let users provide an explicit >> type for >> x in the above example? Maybe with a cast like this? >> >> any(x == 5 for x in some_seq) >> >> Any other ideas? >> > > That seems reasonable to me, and also goes well with, e.g., the > proposed syntax for typing varargs. > How about some kind of builtin type for a typed iterator, e.g. any(x == 5 for x in some_seq) # or cython.iterable This has two advantages: a) Using a call instead of a cast, it would work in pure Python mode b) It is probably rather useful in a lot of other situations: def f(iterable[int] x): ... cdef iterable[int] y = ... def f(x: iterable[int]): ... Or, perhaps there is some Python 3 Abstract Base Class stuff we could use for this concept? Dag Sverre From dagss at student.matnat.uio.no Mon May 24 19:52:32 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Mon, 24 May 2010 19:52:32 +0200 Subject: [Cython] loop variables in generator expressions In-Reply-To: <4BFABBC2.9090303@student.matnat.uio.no> References: <4BFA680C.2040402@behnel.de> <4BFABBC2.9090303@student.matnat.uio.no> Message-ID: <4BFABCE0.5040403@student.matnat.uio.no> Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: > >> On May 24, 2010, at 4:50 AM, Stefan Behnel wrote: >> >> >> >>> Hi, >>> >>> the current closures branch has limited support for inlined generator >>> expressions, i.e. you can write >>> >>> any(x == 5 for x in some_seq) >>> >>> and Cython will generate an inlined loop for it that short circuits >>> properly on the first hit. To get this working correctly, I fixed the >>> scoping behaviour of the loop variable by giving generator expressions >>> their own scope, so that x won't leak into the surrounding scope in >>> the >>> above example. However, this introduces a pretty annoying problem: you >>> can't type the loop variable any more. Any cdef declaration will >>> only apply >>> to the surrounding scope, not to the scope of the generator >>> expression. >>> >>> This may be acceptable in some cases where Cython can properly infer >>> a type >>> for it, but in other cases, explicit typing is required to make the >>> expression work correctly and/or efficiently. >>> >>> Does anyone have an idea how we can let users provide an explicit >>> type for >>> x in the above example? Maybe with a cast like this? >>> >>> any(x == 5 for x in some_seq) >>> >>> Any other ideas? >>> >>> >> That seems reasonable to me, and also goes well with, e.g., the >> proposed syntax for typing varargs. >> >> > How about some kind of builtin type for a typed iterator, e.g. > > any(x == 5 for x in some_seq) # or cython.iterable > > This has two advantages: > > a) Using a call instead of a cast, it would work in pure Python mode > b) It is probably rather useful in a lot of other situations: > > def f(iterable[int] x): ... > cdef iterable[int] y = ... > > def f(x: iterable[int]): ... > > Or, perhaps there is some Python 3 Abstract Base Class stuff we could > use for this concept? > > BTW, thanks a lot for an awesome feature! Dag Sverre From stefan_ml at behnel.de Mon May 24 20:13:33 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 24 May 2010 20:13:33 +0200 Subject: [Cython] loop variables in generator expressions In-Reply-To: References: <4BFA680C.2040402@behnel.de> Message-ID: <4BFAC1CD.6080208@behnel.de> Robert Bradshaw, 24.05.2010 18:03: > On May 24, 2010, at 4:50 AM, Stefan Behnel wrote: >> Second question: should this be enabled for list/set/dict >> comprehensions in >> Cython 0.13 as well? I think we already agreed that the leaking loop >> variables should be considered a bug that rarely has an impact on >> existing >> code. In Py2, only list comprehensions leak their variable, whereas >> genexps >> have their own scope. In Py3, all comprehensions and genexps have >> their own >> scope. I would prefer unifying the scoping rules in Cython 0.13 as >> well. >> (It's already implemented in cython-closures, although disabling it >> would be trivial). > > I think we should strive for Py2 compatibility, even in corner cases. > With the -3 flag, we should behave as Python 3 (i.e. not leaking > variables as you suggest). I know. However, Py2 doesn't have set/dict comprehensions (yet), and both are defined in Py3 as not leaking variables. So we already violate existing Python behaviour anyway. Although it's certainly not hard to argue that, if all three kinds of comprehensions existed in Py2, they'd behave all the same way. My main concern isn't even breaking code by ripping out the loop variable(s), which most code won't rely upon anyway. It's the fact that the behaviour will change with the -3 switch because type declarations will disappear from the genexpr scope. That will break code in a much more subtle way, and may lead to hard to find/understand changes in behaviour. We can warn about it, but I always find it better to prevent non-future proof code from getting written as early as possible. Can we at least emit a warning that there is a better way to do it, when we find that a comprehension is based on a cdef-ed variable? Stefan From robertwb at math.washington.edu Mon May 24 20:44:29 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 24 May 2010 11:44:29 -0700 Subject: [Cython] loop variables in generator expressions In-Reply-To: <4BFAC1CD.6080208@behnel.de> References: <4BFA680C.2040402@behnel.de> <4BFAC1CD.6080208@behnel.de> Message-ID: <2F11517E-EA16-48A9-848E-9BC52F159F2D@math.washington.edu> On May 24, 2010, at 11:13 AM, Stefan Behnel wrote: > Robert Bradshaw, 24.05.2010 18:03: >> On May 24, 2010, at 4:50 AM, Stefan Behnel wrote: >>> Second question: should this be enabled for list/set/dict >>> comprehensions in >>> Cython 0.13 as well? I think we already agreed that the leaking loop >>> variables should be considered a bug that rarely has an impact on >>> existing >>> code. In Py2, only list comprehensions leak their variable, whereas >>> genexps >>> have their own scope. In Py3, all comprehensions and genexps have >>> their own >>> scope. I would prefer unifying the scoping rules in Cython 0.13 as >>> well. >>> (It's already implemented in cython-closures, although disabling it >>> would be trivial). >> >> I think we should strive for Py2 compatibility, even in corner cases. >> With the -3 flag, we should behave as Python 3 (i.e. not leaking >> variables as you suggest). > > I know. However, Py2 doesn't have set/dict comprehensions (yet), and > both > are defined in Py3 as not leaking variables. So we already violate > existing > Python behaviour anyway. Although it's certainly not hard to argue > that, if > all three kinds of comprehensions existed in Py2, they'd behave all > the > same way. That's a good point, it would probably make more sense for them to all be consistent. > My main concern isn't even breaking code by ripping out the loop > variable(s), which most code won't rely upon anyway. It's the fact > that the > behaviour will change with the -3 switch because type declarations > will > disappear from the genexpr scope. That will break code in a much more > subtle way, and may lead to hard to find/understand changes in > behaviour. > We can warn about it, but I always find it better to prevent non- > future > proof code from getting written as early as possible. Leaking vs. non-leaking loop variables, though I'd hope it isn't counted on much, can be a subtle difference too. I think the most important barrier to lower is the pure vs. compiled one for straight Python. > Can we at least emit a warning that there is a better way to do it, > when we > find that a comprehension is based on a cdef-ed variable? Yes, we should probably omit a warning. Another idea to throw out there is that we could borrow the type from the containing scope, if any, just not alter its value. Thinking of it, I've actually used this a lot: cdef int i L = [foo[i] for i in range(...)] or other more complicated expressions. -1 to changing it and making all such loops slow Python loops. - Robert From greg.ewing at canterbury.ac.nz Tue May 25 02:12:05 2010 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 25 May 2010 12:12:05 +1200 Subject: [Cython] loop variables in generator expressions In-Reply-To: <4BFA680C.2040402@behnel.de> References: <4BFA680C.2040402@behnel.de> Message-ID: <4BFB15D5.5080007@canterbury.ac.nz> Stefan Behnel wrote: > any(x == 5 for x in some_seq) > > Any other ideas? any(x == 5 for cdef int x in some_seq) -- Greg From greg.ewing at canterbury.ac.nz Tue May 25 02:22:26 2010 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 25 May 2010 12:22:26 +1200 Subject: [Cython] pointer arithmetic In-Reply-To: References: Message-ID: <4BFB1842.207@canterbury.ac.nz> jah wrote: > What I'd really like to do is pointer arithmetic, > > cdef void func(self, double *x, double *out): > *out = *x + 1 > *(out+1) = *(x+1) + 2 Not sure if it exactly answers your question, but you can write the above as cdef void func(self, double *x, double *out): out[0] = x[0] + 1 out[1] = x[1] + 2 -- Greg From stefan_ml at behnel.de Tue May 25 09:07:27 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 25 May 2010 09:07:27 +0200 Subject: [Cython] loop variables in generator expressions In-Reply-To: <2F11517E-EA16-48A9-848E-9BC52F159F2D@math.washington.edu> References: <4BFA680C.2040402@behnel.de> <4BFAC1CD.6080208@behnel.de> <2F11517E-EA16-48A9-848E-9BC52F159F2D@math.washington.edu> Message-ID: <4BFB772F.9010903@behnel.de> Robert Bradshaw, 24.05.2010 20:44: > On May 24, 2010, at 11:13 AM, Stefan Behnel wrote: >> My main concern isn't even breaking code by ripping out the loop >> variable(s), which most code won't rely upon anyway. It's the fact >> that the >> behaviour will change with the -3 switch because type declarations >> will >> disappear from the genexpr scope. That will break code in a much more >> subtle way, and may lead to hard to find/understand changes in >> behaviour. >> We can warn about it, but I always find it better to prevent non- >> future >> proof code from getting written as early as possible. > > Leaking vs. non-leaking loop variables, though I'd hope it isn't > counted on much, can be a subtle difference too. I've reverted the change for comprehensions, they behave as before. BTW, there's also a related bug: the loop variable shows up in locals(), which it does not in CPython. >> Can we at least emit a warning that there is a better way to do it, >> when we find that a comprehension is based on a cdef-ed variable? > > Yes, we should probably omit a warning. Another idea to throw out > there is that we could borrow the type from the containing scope, if > any, just not alter its value. Thinking of it, I've actually used this > a lot: > > cdef int i > L = [foo[i] for i in range(...)] > > or other more complicated expressions. -1 to changing it and making > all such loops slow Python loops. I agree that that's a major concern. Taking the declaration from the surrounding scope may actually be the simplest way to fix it, especially since this will also work in pure mode. Stefan From stefan_ml at behnel.de Tue May 25 10:15:48 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 25 May 2010 10:15:48 +0200 Subject: [Cython] loop variables in generator expressions In-Reply-To: <4BFB772F.9010903@behnel.de> References: <4BFA680C.2040402@behnel.de> <4BFAC1CD.6080208@behnel.de> <2F11517E-EA16-48A9-848E-9BC52F159F2D@math.washington.edu> <4BFB772F.9010903@behnel.de> Message-ID: <4BFB8734.4040701@behnel.de> Stefan Behnel, 25.05.2010 09:07: > Robert Bradshaw, 24.05.2010 20:44: >> On May 24, 2010, at 11:13 AM, Stefan Behnel wrote: >>> Can we at least emit a warning that there is a better way to do it, >>> when we find that a comprehension is based on a cdef-ed variable? >> >> Yes, we should probably omit a warning. Another idea to throw out >> there is that we could borrow the type from the containing scope, if >> any, just not alter its value. Thinking of it, I've actually used this >> a lot: >> >> cdef int i >> L = [foo[i] for i in range(...)] >> >> or other more complicated expressions. -1 to changing it and making >> all such loops slow Python loops. > > I agree that that's a major concern. Taking the declaration from the > surrounding scope may actually be the simplest way to fix it, especially > since this will also work in pure mode. The behaviour I now implemented in cython-closures is this: 1) all comprehensions continue to leak loop variables 2) genexps have their own scope and do not leak variables 3) if the outer scope of a genexp has a type declaration for a variable defined in the inner scope, the type is inherited by the inner scope This keeps backwards compatibility with existing code like above, and makes it easy to declare the type of a loop variable for generator expressions in both Cython code and pure Python code. Stefan From f_krull at gmx.de Tue May 25 19:35:51 2010 From: f_krull at gmx.de (fk) Date: Tue, 25 May 2010 19:35:51 +0200 Subject: [Cython] [Bug] Can't access C members in extension types special methods In-Reply-To: References: <4BFA2E55.1070503@behnel.de> Message-ID: <4BFC0A77.1000405@gmx.de> Am 24.05.2010 13:43, schrieb luper rouch: > Yes I certainly missed that in the docs, sorry. So, arithmetic > operators are some kind of static methods, is the following the right > way to implement them ? > > def __mul__(op1, op2): > if isinstance(op1, Quaternion): > return from_c_obj((op1).wrapped[0] * op2) > else: > return from_c_obj((op2).wrapped[0] * op1) > > And for intransitive operations like __div__ return NotImplemted in > the reversed case : > > def __div__(op1, op2): > if isinstance(op1, Quaternion): > return from_c_obj((op1).wrapped[0] / op2) > else: > return NotImplemented > Slightly-or-not-so-slightly off-topic, but are you by any chance wrapping Bullet? I also started with that [1] (unfortunately, my dedication has already begun to decline). D'you have any code or site online somewhere? Regards, Felix -- [1] http://bitbucket.org/fk/python-bullet From dplepage at gmail.com Tue May 25 20:57:00 2010 From: dplepage at gmail.com (Daniel Lepage) Date: Tue, 25 May 2010 14:57:00 -0400 Subject: [Cython] [Bug] Python functions with nogil Message-ID: If you declare a python function as nogil, Cython throws an internal error. For example, compiling def f() nogil: print 'hello, world' yields a large traceback ending in File "Parsing.py", line 2431, in Cython.Compiler.Parsing.p_def_statement (./build/cython/Cython/Compiler/Parsing.c:44712) AttributeError: 'Cython.Compiler.Scanning.PyrexScanner' object has no attribute 'pos' Thanks, Dan Lepage From stefan_ml at behnel.de Tue May 25 21:10:03 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 25 May 2010 21:10:03 +0200 Subject: [Cython] [Bug] Python functions with nogil In-Reply-To: References: Message-ID: <4BFC208B.1060209@behnel.de> Daniel Lepage, 25.05.2010 20:57: > If you declare a python function as nogil, Cython throws an internal > error. For example, compiling > > def f() nogil: print 'hello, world' > > yields a large traceback ending in > > File "Parsing.py", line 2431, in > Cython.Compiler.Parsing.p_def_statement > (./build/cython/Cython/Compiler/Parsing.c:44712) > AttributeError: 'Cython.Compiler.Scanning.PyrexScanner' object has no > attribute 'pos' Hi, thanks for the report. This works for me with the latest cython-devel developer sources. You can get it from here: http://hg.cython.org/cython-devel Stefan From luper.rouch at gmail.com Wed May 26 00:02:27 2010 From: luper.rouch at gmail.com (luper rouch) Date: Wed, 26 May 2010 00:02:27 +0200 Subject: [Cython] [Bug] Can't access C members in extension types special methods In-Reply-To: <4BFC0A77.1000405@gmx.de> References: <4BFA2E55.1070503@behnel.de> <4BFC0A77.1000405@gmx.de> Message-ID: 2010/5/25 fk : > Am 24.05.2010 13:43, schrieb luper rouch: >> Yes I certainly missed that in the docs, sorry. So, arithmetic >> operators are some kind of static methods, is the following the right >> way to implement them ? >> >> ? ?def __mul__(op1, op2): >> ? ? ? ?if isinstance(op1, Quaternion): >> ? ? ? ? ? ?return from_c_obj((op1).wrapped[0] * op2) >> ? ? ? ?else: >> ? ? ? ? ? ?return from_c_obj((op2).wrapped[0] * op1) >> >> And for intransitive operations like __div__ return NotImplemted in >> the reversed case : >> >> ? ?def __div__(op1, op2): >> ? ? ? ?if isinstance(op1, Quaternion): >> ? ? ? ? ? ?return from_c_obj((op1).wrapped[0] / op2) >> ? ? ? ?else: >> ? ? ? ? ? ?return NotImplemented >> > > Slightly-or-not-so-slightly off-topic, but are you by any chance > wrapping Bullet? I also started with that [1] (unfortunately, my > dedication has already begun to decline). D'you have any code or site > online somewhere? > Yes I just started a wrapper for Bullet : http://github.com/flupke/ballistics It looks very similar to yours, except that I try to closely stick to the C++ API (names, modules organisation, etc...), so I can avoid rewriting the whole documentation :) (I will eventually add helpers to ease setting up objects) For now, I ported the Hello World example from the tutorial (see ballistics/tests/dynamics/world/test_discrete.py) and got a ball bouncing... There is still a long way before wrapping the whole API ! Cheers, -- Lup From robertwb at math.washington.edu Wed May 26 01:59:00 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Tue, 25 May 2010 16:59:00 -0700 Subject: [Cython] loop variables in generator expressions In-Reply-To: <4BFB8734.4040701@behnel.de> References: <4BFA680C.2040402@behnel.de> <4BFAC1CD.6080208@behnel.de> <2F11517E-EA16-48A9-848E-9BC52F159F2D@math.washington.edu> <4BFB772F.9010903@behnel.de> <4BFB8734.4040701@behnel.de> Message-ID: <02B00638-608D-46AF-A8D0-7E22BC2C7CD8@math.washington.edu> On May 25, 2010, at 1:15 AM, Stefan Behnel wrote: > Stefan Behnel, 25.05.2010 09:07: >> Robert Bradshaw, 24.05.2010 20:44: >>> On May 24, 2010, at 11:13 AM, Stefan Behnel wrote: >>>> Can we at least emit a warning that there is a better way to do it, >>>> when we find that a comprehension is based on a cdef-ed variable? >>> >>> Yes, we should probably omit a warning. Another idea to throw out >>> there is that we could borrow the type from the containing scope, if >>> any, just not alter its value. Thinking of it, I've actually used >>> this >>> a lot: >>> >>> cdef int i >>> L = [foo[i] for i in range(...)] >>> >>> or other more complicated expressions. -1 to changing it and making >>> all such loops slow Python loops. >> >> I agree that that's a major concern. Taking the declaration from the >> surrounding scope may actually be the simplest way to fix it, >> especially >> since this will also work in pure mode. > > The behaviour I now implemented in cython-closures is this: > > 1) all comprehensions continue to leak loop variables > 2) genexps have their own scope and do not leak variables > 3) if the outer scope of a genexp has a type declaration for a > variable > defined in the inner scope, the type is inherited by the inner scope > > This keeps backwards compatibility with existing code like above, > and makes > it easy to declare the type of a loop variable for generator > expressions in > both Cython code and pure Python code. Sounds good. - Robert From stefan_ml at behnel.de Wed May 26 13:23:12 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 26 May 2010 13:23:12 +0200 Subject: [Cython] Stupid benchmark for inlined sum(genexp) Message-ID: <4BFD04A0.8020002@behnel.de> Hi, I got sum(genexp) working in cython-closures (not pushed yet), so here are some timings. The Cython code (of this pretty bad benchmark) is: def return_range_sum(int N): return sum(i for i in range(N)) timeit "sum(i for i in xrange(10000))" 1000 loops, best of 3: 584 usec per loop timeit "return_range_sum(10000)" 1000 loops, best of 3: 235 usec per loop Note that the generated C code runs the loop in C but does the addition in Python objects. I haven't found an easy way to drop this into C yet (the transformation is done before type analysis), but given that it's faster already, I think it's still worth it - and it adds a feature that we currently don't support at all. Stefan From dagss at student.matnat.uio.no Thu May 27 09:43:13 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 27 May 2010 09:43:13 +0200 Subject: [Cython] On "typeof" Message-ID: <4BFE2291.2050309@student.matnat.uio.no> I recognized typeof in a recent commit by Robert. Is this a new feature in 0.13 or has it been in for some time? If it is new: What I'm wondering is whether typeof should perhaps, in the spirit of Python, return a descriptive object instead of a string. (It could even return a ctypes object describing the type, if that is powerful enough for us). In particular, it should be possible to do introspection about structs and so on, so that it is easy to build serializers etc. using "typeof" information. (Buffers already put some RTTI about structs to the C file BTW, in order to parse buffer format strings.) This is thinking long-term; but I'm wondering whether the current typeof should be renamed e.g. "nameoftype", in order to maintain backwards compatability if or when somebody decides to make a more powerful typeof. Thoughts? Dag Sverre From robertwb at math.washington.edu Thu May 27 10:01:44 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 27 May 2010 01:01:44 -0700 Subject: [Cython] On "typeof" In-Reply-To: <4BFE2291.2050309@student.matnat.uio.no> References: <4BFE2291.2050309@student.matnat.uio.no> Message-ID: On May 27, 2010, at 12:43 AM, Dag Sverre Seljebotn wrote: > I recognized typeof in a recent commit by Robert. Is this a new > feature > in 0.13 or has it been in for some time? It's been around since last fall--I just needed something quick for writing tests for type inference, so typeof was born. > If it is new: > > What I'm wondering is whether typeof should perhaps, in the spirit of > Python, return a descriptive object instead of a string. (It could > even > return a ctypes object describing the type, if that is powerful enough > for us). > > In particular, it should be possible to do introspection about structs > and so on, so that it is easy to build serializers etc. using "typeof" > information. (Buffers already put some RTTI about structs to the C > file > BTW, in order to parse buffer format strings.) > > This is thinking long-term; but I'm wondering whether the current > typeof > should be renamed e.g. "nameoftype", in order to maintain backwards > compatability if or when somebody decides to make a more powerful > typeof. I was thinking of that at first, but I really can't think of much one would do with it--it's not giving anything that's not known at compile time, it's just a way to make sure the compiler thinks the type is what you think it is. Even with templates, it would return the template parameter, not the resolved type. For testing purposes, a string is very nice. - Robert From dagss at student.matnat.uio.no Thu May 27 10:08:34 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 27 May 2010 10:08:34 +0200 Subject: [Cython] On "typeof" In-Reply-To: References: <4BFE2291.2050309@student.matnat.uio.no> Message-ID: <4BFE2882.60802@student.matnat.uio.no> Robert Bradshaw wrote: > On May 27, 2010, at 12:43 AM, Dag Sverre Seljebotn wrote: > > >> I recognized typeof in a recent commit by Robert. Is this a new >> feature >> in 0.13 or has it been in for some time? >> > > It's been around since last fall--I just needed something quick for > writing tests for type inference, so typeof was born. > OK, then this doesn't need to be discussed now at any rate. I'll just make a quick comment below and then hope the thread dies. > >> If it is new: >> >> What I'm wondering is whether typeof should perhaps, in the spirit of >> Python, return a descriptive object instead of a string. (It could >> even >> return a ctypes object describing the type, if that is powerful enough >> for us). >> >> In particular, it should be possible to do introspection about structs >> and so on, so that it is easy to build serializers etc. using "typeof" >> information. (Buffers already put some RTTI about structs to the C >> file >> BTW, in order to parse buffer format strings.) >> >> This is thinking long-term; but I'm wondering whether the current >> typeof >> should be renamed e.g. "nameoftype", in order to maintain backwards >> compatability if or when somebody decides to make a more powerful >> typeof. >> > > I was thinking of that at first, but I really can't think of much one > would do with it--it's not giving anything that's not known at compile > time, it's just a way to make sure the compiler thinks the type is > what you think it is. Even with templates, it would return the > template parameter, not the resolved type. For testing purposes, a > string is very nice. > cdef persist_struct_to_xml(void* data, object typeinfo, object filename): ... cdef StructA a a.b = 2 a.c = 4 persist_struct_to_xml(&a, typeof(StructA), 'a.dat') cdef StructB b b.foo = 2 b.bar = 4.5 persist_struct_to_xml(&b, typeof(StructB), 'b.dat') Basically, the type information for structs should be a tree, containing names and *offsets* and types. persist_struct_to_xml needs to have special-case if-tests on all the primitive types, but structs can be dealt with through pointer manipulation and offsets. Offsets can trivially be resolved by the C compiler during C compilation and put into the type information then (in fact, I already do in the buffer RTTI, which is used for validating buffer data format strings). Of course, it's just a convenience, but if you need this, a very big one. Dag Sverre From dagss at student.matnat.uio.no Thu May 27 10:11:21 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 27 May 2010 10:11:21 +0200 Subject: [Cython] On "typeof" In-Reply-To: <4BFE2882.60802@student.matnat.uio.no> References: <4BFE2291.2050309@student.matnat.uio.no> <4BFE2882.60802@student.matnat.uio.no> Message-ID: <4BFE2929.1080703@student.matnat.uio.no> Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: > >> On May 27, 2010, at 12:43 AM, Dag Sverre Seljebotn wrote: >> >> >> >>> I recognized typeof in a recent commit by Robert. Is this a new >>> feature >>> in 0.13 or has it been in for some time? >>> >>> >> It's been around since last fall--I just needed something quick for >> writing tests for type inference, so typeof was born. >> >> > OK, then this doesn't need to be discussed now at any rate. > > I'll just make a quick comment below and then hope the thread dies. > >> >> >>> If it is new: >>> >>> What I'm wondering is whether typeof should perhaps, in the spirit of >>> Python, return a descriptive object instead of a string. (It could >>> even >>> return a ctypes object describing the type, if that is powerful enough >>> for us). >>> >>> In particular, it should be possible to do introspection about structs >>> and so on, so that it is easy to build serializers etc. using "typeof" >>> information. (Buffers already put some RTTI about structs to the C >>> file >>> BTW, in order to parse buffer format strings.) >>> >>> This is thinking long-term; but I'm wondering whether the current >>> typeof >>> should be renamed e.g. "nameoftype", in order to maintain backwards >>> compatability if or when somebody decides to make a more powerful >>> typeof. >>> >>> >> I was thinking of that at first, but I really can't think of much one >> would do with it--it's not giving anything that's not known at compile >> time, it's just a way to make sure the compiler thinks the type is >> what you think it is. Even with templates, it would return the >> template parameter, not the resolved type. For testing purposes, a >> string is very nice. >> >> > cdef persist_struct_to_xml(void* data, object typeinfo, object > filename): ... > > cdef StructA a > a.b = 2 > a.c = 4 > persist_struct_to_xml(&a, typeof(StructA), 'a.dat') > > cdef StructB b > b.foo = 2 > b.bar = 4.5 > persist_struct_to_xml(&b, typeof(StructB), 'b.dat') > Here's a better example that I'd actually find useful now and then: cdef struct Particle: double x, y, z, vx, vy, vz cdef np.ndarray[Particle] arr = np.zeros(100, dtype=cython_type_to_numpy_dtype(typeof(Particle))) Dag Sverre From stefan_ml at behnel.de Thu May 27 10:12:25 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 27 May 2010 10:12:25 +0200 Subject: [Cython] On "typeof" In-Reply-To: <4BFE2882.60802@student.matnat.uio.no> References: <4BFE2291.2050309@student.matnat.uio.no> <4BFE2882.60802@student.matnat.uio.no> Message-ID: <4BFE2969.2010808@behnel.de> Dag Sverre Seljebotn, 27.05.2010 10:08: > cdef persist_struct_to_xml(void* data, object typeinfo, object > filename): ... > > cdef StructA a > a.b = 2 > a.c = 4 > persist_struct_to_xml(&a, typeof(StructA), 'a.dat') > > cdef StructB b > b.foo = 2 > b.bar = 4.5 > persist_struct_to_xml(&b, typeof(StructB), 'b.dat') > > Basically, the type information for structs should be a tree, containing > names and *offsets* and types. persist_struct_to_xml needs to have > special-case if-tests on all the primitive types, but structs can be > dealt with through pointer manipulation and offsets. > > Offsets can trivially be resolved by the C compiler during C compilation > and put into the type information then (in fact, I already do in the > buffer RTTI, which is used for validating buffer data format strings). > > Of course, it's just a convenience, but if you need this, a very big one. I think overriding type() for C types can still provide what you want, but that's a different feature. Stefan From dagss at student.matnat.uio.no Thu May 27 10:14:08 2010 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 27 May 2010 10:14:08 +0200 Subject: [Cython] On "typeof" In-Reply-To: <4BFE2969.2010808@behnel.de> References: <4BFE2291.2050309@student.matnat.uio.no> <4BFE2882.60802@student.matnat.uio.no> <4BFE2969.2010808@behnel.de> Message-ID: <4BFE29D0.4040803@student.matnat.uio.no> Stefan Behnel wrote: > Dag Sverre Seljebotn, 27.05.2010 10:08: > >> cdef persist_struct_to_xml(void* data, object typeinfo, object >> filename): ... >> >> cdef StructA a >> a.b = 2 >> a.c = 4 >> persist_struct_to_xml(&a, typeof(StructA), 'a.dat') >> >> cdef StructB b >> b.foo = 2 >> b.bar = 4.5 >> persist_struct_to_xml(&b, typeof(StructB), 'b.dat') >> >> Basically, the type information for structs should be a tree, containing >> names and *offsets* and types. persist_struct_to_xml needs to have >> special-case if-tests on all the primitive types, but structs can be >> dealt with through pointer manipulation and offsets. >> >> Offsets can trivially be resolved by the C compiler during C compilation >> and put into the type information then (in fact, I already do in the >> buffer RTTI, which is used for validating buffer data format strings). >> >> Of course, it's just a convenience, but if you need this, a very big one. >> > > I think overriding type() for C types can still provide what you want, but > that's a different feature. > Good point. Yes, I was only concerned about names and future backwards compatability with such a feature at this point, so the fact that it has been around since autumn makes the point completely moot. And you're right, we could use type() for it, so it is double-moot. Dag Sverre From robertwb at math.washington.edu Thu May 27 10:22:01 2010 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 27 May 2010 01:22:01 -0700 Subject: [Cython] On "typeof" In-Reply-To: <4BFE2882.60802@student.matnat.uio.no> References: <4BFE2291.2050309@student.matnat.uio.no> <4BFE2882.60802@student.matnat.uio.no> Message-ID: <4F66F8A8-B29A-4FD9-8109-19B1FF66E43E@math.washington.edu> On May 27, 2010, at 1:08 AM, Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: >> On May 27, 2010, at 12:43 AM, Dag Sverre Seljebotn wrote: >> >> >>> I recognized typeof in a recent commit by Robert. Is this a new >>> feature >>> in 0.13 or has it been in for some time? >>> >> >> It's been around since last fall--I just needed something quick for >> writing tests for type inference, so typeof was born. >> > OK, then this doesn't need to be discussed now at any rate. > > I'll just make a quick comment below and then hope the thread dies. >> >>> If it is new: >>> >>> What I'm wondering is whether typeof should perhaps, in the spirit >>> of >>> Python, return a descriptive object instead of a string. (It could >>> even >>> return a ctypes object describing the type, if that is powerful >>> enough >>> for us). >>> >>> In particular, it should be possible to do introspection about >>> structs >>> and so on, so that it is easy to build serializers etc. using >>> "typeof" >>> information. (Buffers already put some RTTI about structs to the C >>> file >>> BTW, in order to parse buffer format strings.) >>> >>> This is thinking long-term; but I'm wondering whether the current >>> typeof >>> should be renamed e.g. "nameoftype", in order to maintain backwards >>> compatability if or when somebody decides to make a more powerful >>> typeof. >>> >> >> I was thinking of that at first, but I really can't think of much one >> would do with it--it's not giving anything that's not known at >> compile >> time, it's just a way to make sure the compiler thinks the type is >> what you think it is. Even with templates, it would return the >> template parameter, not the resolved type. For testing purposes, a >> string is very nice. >> > cdef persist_struct_to_xml(void* data, object typeinfo, object > filename): ... > > cdef StructA a > a.b = 2 > a.c = 4 > persist_struct_to_xml(&a, typeof(StructA), 'a.dat') > > cdef StructB b > b.foo = 2 > b.bar = 4.5 > persist_struct_to_xml(&b, typeof(StructB), 'b.dat') > > Basically, the type information for structs should be a tree, > containing > names and *offsets* and types. persist_struct_to_xml needs to have > special-case if-tests on all the primitive types, but structs can be > dealt with through pointer manipulation and offsets. > > Offsets can trivially be resolved by the C compiler during C > compilation > and put into the type information then (in fact, I already do in the > buffer RTTI, which is used for validating buffer data format strings). > > Of course, it's just a convenience, but if you need this, a very big > one. Ah, that is a nice use case. As Stefan mentioned, plain old type will (someday) probably work well here. - Robert From stefan_ml at behnel.de Thu May 27 18:46:45 2010 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 27 May 2010 18:46:45 +0200 Subject: [Cython] Stupid benchmark for inlined sum(genexp) In-Reply-To: <4BFD04A0.8020002@behnel.de> References: <4BFD04A0.8020002@behnel.de> Message-ID: <4BFEA1F5.1060808@behnel.de> Stefan Behnel, 26.05.2010 13:23: > I got sum(genexp) working in cython-closures (not pushed yet), so here are > some timings. The Cython code (of this pretty bad benchmark) is: > > def return_range_sum(int N): > return sum(i for i in range(N)) > > timeit "sum(i for i in xrange(10000))" > 1000 loops, best of 3: 584 usec per loop > > timeit "return_range_sum(10000)" > 1000 loops, best of 3: 235 usec per loop > > Note that the generated C code runs the loop in C but does the addition in > Python objects. ... and the obvious little update on the last sentence: def range_sum_typed(int N): cdef int result = sum(i for i in range(N)) return result timeit "range_sum_typed(10000)" 100000 loops, best of 3: 2 usec per loop Now, that's better. ;) Stefan