From vel.accel at gmail.com Thu Oct 1 01:42:13 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Wed, 30 Sep 2009 19:42:13 -0400 Subject: [Cython] Updating Documentation In-Reply-To: <4AC39AF8.9010906@student.matnat.uio.no> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <4AC32A6D.7080000@student.matnat.uio.no> <4AC39271.3080300@noaa.gov> <4AC39AF8.9010906@student.matnat.uio.no> Message-ID: <1e52e0880909301642l5d398060w5ef391141ccc1fda@mail.gmail.com> On Wed, Sep 30, 2009 at 1:52 PM, Dag Sverre Seljebotn wrote: > Christopher Barker wrote: >> Dag Sverre Seljebotn wrote: >>> ?- Numerical computations in Cython (a copy of the corresponding paper) >> >>> 4) I think the current Cython/NumPy tutorial should be removed in favour >>> of the above generic tutorial + numerical Cython paper; opinions on that? >> >> Well, one good intro to numpy+cython is better than two that both need >> to be maintained. > > Thanks for your feedback. My thoughts: > > Yes, but the existing intro on numpy+cython: > a) Lacks quite a bit in several areas > b) Is outdated > > While the tutorial + paper is already written now. > >> However, maybe it's my personal use-case bias, but I think that numpy is >> almost a standard part of Cython use -- I can't think of what I'd like >> to optimize that I wouldn't want to use numpy for! And numpy is why I >> skipped past pyrex and straight to Cython. > > Well, take Stefan Behnel, who doesn't use NumPy at all, but rather works > with XML documents. > > Even within science, the whole Sage project (a very important Cython > user) don't use that much NumPy either, and in particular not the > Cython/NumPy features, as they need exact math which isn't covered by > NumPy's dtypes (and also tend to operate on thousands rather than > billions of numbers I think?). > > Then you have any kind of wrappers around native libraries. > > There's enough usecases for Cython without NumPy to make our primary > Cython tutorial generic and not targeted for numerical users IMO. > > And then you have the question of whether one should have *two* > tutorials. Perhaps a very small intro document for numerical users which > links heavily into the other documents... > > > -- > Dag Sverre > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > 1) Minh, I have a now repo[1] at bitbucket where I will push to often. 2) I agree that Numpy should be a seperate TOC entry, because it deserves special, detailed attention. 3) After some thought and review, the current abstract structure of the docs are good. 4) We need to: a) incorporate all the possible new information, b) add lots of (cross)-references c) and lots of integrated (flowing) examples. 4) Refactor and minimize verbosity. 4) Consider the possiblity of a "Quick Ref" section which are essentially an index of "HowTos" for fast look-up (Its nice to immediately put your fingers on something your looking for, without having to have to read half a page of paragraphs). These could simply be an index of links in to the main doc sections.. maybe.. 5) Consider how to incorporate what Python syntax Cython currently optimizes and what it does not. We need to elliminate this frustrating enigma for un-informed users. Also, whats on the near term agenda for new, further optimizations of syntax magic, etc.. [1] http://bitbucket.org/travlr/cython-docs From vel.accel at gmail.com Thu Oct 1 01:57:45 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Wed, 30 Sep 2009 19:57:45 -0400 Subject: [Cython] Updating Documentation In-Reply-To: <1e52e0880909301642l5d398060w5ef391141ccc1fda@mail.gmail.com> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <4AC32A6D.7080000@student.matnat.uio.no> <4AC39271.3080300@noaa.gov> <4AC39AF8.9010906@student.matnat.uio.no> <1e52e0880909301642l5d398060w5ef391141ccc1fda@mail.gmail.com> Message-ID: <1e52e0880909301657xd1632c9rd12771d9adf65f0f@mail.gmail.com> On Wed, Sep 30, 2009 at 7:42 PM, Peter Alexander wrote: > On Wed, Sep 30, 2009 at 1:52 PM, Dag Sverre Seljebotn > wrote: >> Christopher Barker wrote: >>> Dag Sverre Seljebotn wrote: >>>> ?- Numerical computations in Cython (a copy of the corresponding paper) >>> >>>> 4) I think the current Cython/NumPy tutorial should be removed in favour >>>> of the above generic tutorial + numerical Cython paper; opinions on that? >>> >>> Well, one good intro to numpy+cython is better than two that both need >>> to be maintained. >> >> Thanks for your feedback. My thoughts: >> >> Yes, but the existing intro on numpy+cython: >> a) Lacks quite a bit in several areas >> b) Is outdated >> >> While the tutorial + paper is already written now. >> >>> However, maybe it's my personal use-case bias, but I think that numpy is >>> almost a standard part of Cython use -- I can't think of what I'd like >>> to optimize that I wouldn't want to use numpy for! And numpy is why I >>> skipped past pyrex and straight to Cython. >> >> Well, take Stefan Behnel, who doesn't use NumPy at all, but rather works >> with XML documents. >> >> Even within science, the whole Sage project (a very important Cython >> user) don't use that much NumPy either, and in particular not the >> Cython/NumPy features, as they need exact math which isn't covered by >> NumPy's dtypes (and also tend to operate on thousands rather than >> billions of numbers I think?). >> >> Then you have any kind of wrappers around native libraries. >> >> There's enough usecases for Cython without NumPy to make our primary >> Cython tutorial generic and not targeted for numerical users IMO. >> >> And then you have the question of whether one should have *two* >> tutorials. Perhaps a very small intro document for numerical users which >> links heavily into the other documents... >> >> >> -- >> Dag Sverre >> _______________________________________________ >> Cython-dev mailing list >> Cython-dev at codespeak.net >> http://codespeak.net/mailman/listinfo/cython-dev >> > > 1) Minh, I have a now repo[1] at bitbucket where I will push to often. > 2) I agree that Numpy should be a seperate TOC entry, because it > deserves special, detailed attention. > 3) After some thought and review, the current abstract structure of > the docs are good. > 4) We need to: a) incorporate all the possible new information, b) add > lots of (cross)-references c) and lots of integrated (flowing) > examples. 4) Refactor and minimize verbosity. 4) Consider the > possiblity of a "Quick Ref" section which are essentially an index of > "HowTos" for fast look-up (Its nice to immediately put your fingers on > something your looking for, without having to have to read half a page > of paragraphs). These could simply be an index of links in to the main > doc sections.. maybe.. > 5) Consider how to incorporate what Python syntax Cython currently > optimizes and what it does not. We need to elliminate this frustrating > enigma for un-informed users. Also, whats on the near term agenda for > new, further optimizations of syntax magic, etc.. > > [1] http://bitbucket.org/travlr/cython-docs > [...] 6) Provide simple (up-front) information to users about bug reporting/querying, enhancement proposals, utilizing the wiki as documentation appendage for users.. From Chris.Barker at noaa.gov Thu Oct 1 02:07:36 2009 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Wed, 30 Sep 2009 17:07:36 -0700 Subject: [Cython] Updating Documentation In-Reply-To: <4AC39AF8.9010906@student.matnat.uio.no> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <4AC32A6D.7080000@student.matnat.uio.no> <4AC39271.3080300@noaa.gov> <4AC39AF8.9010906@student.matnat.uio.no> Message-ID: <4AC3F2C8.70006@noaa.gov> Dag Sverre Seljebotn wrote: > Christopher Barker wrote: > Yes, but the existing intro on numpy+cython: > a) Lacks quite a bit in several areas > b) Is outdated > > While the tutorial + paper is already written now. right -- my pint was that we really should have only one -- if the tutorial+paper is the better/more up-to-date one, then by all means let's make that the one people find. >> However, maybe it's my personal use-case bias, but I think that numpy is >> almost a standard part of Cython use -- I can't think of what I'd like >> to optimize that I wouldn't want to use numpy for! And numpy is why I >> skipped past pyrex and straight to Cython. > > Well, take Stefan Behnel, who doesn't use NumPy at all, but rather works > with XML documents. > > Even within science, the whole Sage project (a very important Cython > user) don't use that much NumPy either, and in particular not the > Cython/NumPy features, as they need exact math which isn't covered by > NumPy's dtypes OK -- lot's of non-numpy use. > Then you have any kind of wrappers around native libraries. yes, but if those native libraries are working with arrays of data, numpy may well be a good idea there, too. > There's enough usecases for Cython without NumPy to make our primary > Cython tutorial generic and not targeted for numerical users IMO. agreed, though I may never use the stuff used to process XML docs, but it gets first class treatment... > And then you have the question of whether one should have *two* > tutorials. Perhaps a very small intro document for numerical users which > links heavily into the other documents... Sure -- in fact, it often makes lots of sense for there to be different tutorial focused on different user groups -- either because they have different use-cases, or because they have different backgrounds. I can tell you that I went straight to the numpy+Cython tutorial, because I knew I'd want to work primarily with numpy arrays. We may some day want tutorials for: - how to use Cython to wrap C libs - how to use Cython to wrap C++ libs (maybe targeted for folks that are used to using SWIG, ctypes, etc.) Anyway. I love to see this documentation effort! -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From bpederse at gmail.com Thu Oct 1 02:07:58 2009 From: bpederse at gmail.com (Brent Pedersen) Date: Wed, 30 Sep 2009 17:07:58 -0700 Subject: [Cython] Appending... In-Reply-To: <4AC3C575.5010607@noaa.gov> References: <4AC38C4B.5040903@student.matnat.uio.no> <4AC3B001.3060508@behnel.de> <4AC3C575.5010607@noaa.gov> Message-ID: On Wed, Sep 30, 2009 at 1:54 PM, Christopher Barker wrote: > > > Brent Pedersen wrote: >>>> timing on my machine, that gives: >>>> >>>> vector append 1.19197511673 >>>> python append 6.57795596123 >>>> vector get 0.080246925354 >>>> python get 2.01052689552 > > While you're at it, why not give an array.array implementation a try -- > it might be closer to the C++ version -- it should be! > > -Chris looks like it could actually be faster. http://gist.github.com/198576 gives: method: append/get python: 3.5361 / 1.8621 vector: 1.8887 / 0.5865 array : 0.3319 / 0.1467 think that's a reasonably fair test except i cheated for array.array on the inserts by doing a resize() and then inserting, not appending. otherwise, it's _very_ slow to do the array.append() -- over 30 seconds instead of .33 for array.array, i used the stuff attached to this ticket: http://trac.cython.org/cython_trac/ticket/314 > > > > > > -- > Christopher Barker, Ph.D. > Oceanographer > > Emergency Response Division > NOAA/NOS/OR&R ? ? ? ? ? ?(206) 526-6959 ? voice > 7600 Sand Point Way NE ? (206) 526-6329 ? fax > Seattle, WA ?98115 ? ? ? (206) 526-6317 ? main reception > > Chris.Barker at noaa.gov > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > From Chris.Barker at noaa.gov Thu Oct 1 03:12:36 2009 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Wed, 30 Sep 2009 18:12:36 -0700 Subject: [Cython] Appending... In-Reply-To: References: <4AC38C4B.5040903@student.matnat.uio.no> <4AC3B001.3060508@behnel.de> <4AC3C575.5010607@noaa.gov> Message-ID: <4AC40204.9030808@noaa.gov> Brent Pedersen wrote: > http://gist.github.com/198576 > > gives: > > method: append/get > python: 3.5361 / 1.8621 > vector: 1.8887 / 0.5865 > array : 0.3319 / 0.1467 > > think that's a reasonably fair test except I cheated for array.array > on the inserts by doing a resize() and then inserting, not appending. Actually, that is a total cheat, and not testing the right thing at all. (IIUC what teh OP was looking for). You've pre-allocated, so of course accumulating is going to be blazingly fast. I think the point of this was for a situation where you don't know how big it's going to get, so you can't pre-allocate. > otherwise, it's _very_ slow to do the array.append() -- over 30 > seconds instead of .33 wow! that is really, really bad. Something has got to be wrong. I've been poking into the array.array over-allocations scheme (thanks Robert), and it is more conservative than lists, so it may be slower, but that seems like too much. > for array.array, i used the stuff attached to this ticket: > http://trac.cython.org/cython_trac/ticket/314 That should make it speedy indeed. Have you looked at the generated C? cdef array.array array_append(N): cdef int i pyaa = array.array('i') array.array_resize(pyaa, N) cdef array.array aa = pyaa for i in range(N): aa._i[i] = i return aa I haven't poked into the code in that ticket, but something is odd. Maybe you need to tell Cython that aa is not only an array.array, but also what type it is? -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From robert.kern at gmail.com Thu Oct 1 04:57:26 2009 From: robert.kern at gmail.com (Robert Kern) Date: Wed, 30 Sep 2009 21:57:26 -0500 Subject: [Cython] Updating Documentation In-Reply-To: <4AC3F2C8.70006@noaa.gov> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <4AC32A6D.7080000@student.matnat.uio.no> <4AC39271.3080300@noaa.gov> <4AC39AF8.9010906@student.matnat.uio.no> <4AC3F2C8.70006@noaa.gov> Message-ID: Christopher Barker wrote: > Dag Sverre Seljebotn wrote: >> There's enough usecases for Cython without NumPy to make our primary >> Cython tutorial generic and not targeted for numerical users IMO. > > agreed, though I may never use the stuff used to process XML docs, but > it gets first class treatment... There really isn't any special "stuff used to process XML docs" in Cython. There is special stuff in Cython to interact with numpy arrays. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From honnibal at gmail.com Thu Oct 1 07:40:59 2009 From: honnibal at gmail.com (Matthew Honnibal) Date: Thu, 1 Oct 2009 15:40:59 +1000 Subject: [Cython] Question about buffer interface for Python2.6 Message-ID: Hi, I've only just started using Cython today, and I'm having trouble with the buffer interface indexing described here: http://wiki.cython.org/enhancements/buffer . I want to iterate over a unicode string getting contiguous subsequences. My Cython function has the following declaration: def parseDoc(object[object] string): I've tried various Python types, but I always get a runtime error like: TypeError: 'unicode' does not have the buffer interface TypeError: 'array.array' does not have the buffer interface TypeError: 'buffer' does not have the buffer interface The last one was obtained by calling the built-in buffer() function on the string. I can get a step further by doing cimport numpy and using a numpy array, but then unicode is not one of the supported types, and that doesn't seem like it was the intention --- the docs suggest at Python 2.6+, I shouldn't need the numpy work-around. What am I doing wrong? Matthew. P.S. I tried to post this yesterday but it didn't seem to come up. Apologies if this double-posts. From robertwb at math.washington.edu Thu Oct 1 08:53:19 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 30 Sep 2009 23:53:19 -0700 Subject: [Cython] Updating Documentation In-Reply-To: <4AC338AE.1010404@student.matnat.uio.no> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880909300253s44949a0al5d987c03c2ba503d@mail.gmail.com> <4AC32BB5.7050604@student.matnat.uio.no> <1e52e0880909300306u1940255ara37e321bc8634b88@mail.gmail.com> <1e52e0880909300327p63bc1fccjf78b58f643454085@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> Message-ID: On Sep 30, 2009, at 3:53 AM, Dag Sverre Seljebotn wrote: > Peter Alexander wrote: >> One thing I'd like to have an idea of atm is if you'd like the entire >> site to be more homogenous. A nice template/theme could run through >> out the website. Maybe using Sphinx's index.html as the portal page >> and then linking to tutorial, manual, howto's, wiki, trac, etc.. from >> there. I not much of a web-site developer but I'm sure I could handle >> a template and css well enough. >> > As far as *system* goes, I personally think the current system is > great. > It's more about *content*. > > Brain dump: > > I like the current system of: > > - cython.org: A *short*, single, static HTML page. It should be as > short > as possible, only providing the essential links ("what is Cython", > docs, > download, mailing list, authors & financial contributions). Everything > else is either relevant to users and should go into docs, or community > stuff/dynamic lists which should go into wiki. > > - docs.cython.org: Served by Sphinx (which can then also build static > Windows help files, documentation we can ship etc. etc). Sphinx can > contain tutorials, howtos etc. in addition to reference manual. > http://docs.python.org is great; many parts, all of which are > searchable > together immedeately. (I like that better than docs.scipy.org). > > - wiki.cython.org: We need a wiki for day-to-day work, but it > should be > used as a place for documentation to a lesser degree than today. > > - trac.cython.org: Perhaps get the logo back up but I don't see any > need > to integrate it nicely into anything else myself. > > Most users will only see docs.cython.org and so layout *will* be > uniform > without us thinking about it. The documentation on the wiki should IMO > be removed from there and replaced with links to docs.cython.org (once > the contents is moved). The Cython Enhancement Proposals should > have the > relevant link to docs.cython.org prominently placed on top of them, > but > stay in the wiki. > > The way I see it, the wiki and trac are ideally (but not today) mostly > for developers and active mailing list participants, and so a nice > experience is less important. Everything that we want people to read > should find their way into http://docs.cython.org. +1 to all of the above. We should be more aggressive about making tickets to moving content on the wiki to actual documentation when things get stable. > Part of the problem is that it was never documented how to change > docs.cython.org (I can change the hg repo but how to publish the > changes?), and so to get documentation for e.g. NumPy stuff out I > needed > to put it on the wiki (Gabriel did a single pull of the tutorial but > it's outdated now). > > BTW the SciPy project can edit their Sphinx documentation through a > web > interface (but I don't think that's the end to start for us; a simple > automatic generation when a push is made to hg.cython.org/cython-docs > will get us far). Currently, there's an .hg repo in docs.cython.org that I pull from and build right there. I'm not sure how to set up the hooks to fire on push (it can probably be done) or even if it's a good idea, but a single script one can run to refresh all docs would be very useful. http://trac.cython.org/cython_trac/ticket/383 - Robert From robertwb at math.washington.edu Thu Oct 1 09:07:02 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 1 Oct 2009 00:07:02 -0700 Subject: [Cython] Updating Documentation In-Reply-To: <4AC3F2C8.70006@noaa.gov> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <4AC32A6D.7080000@student.matnat.uio.no> <4AC39271.3080300@noaa.gov> <4AC39AF8.9010906@student.matnat.uio.no> <4AC3F2C8.70006@noaa.gov> Message-ID: <71236E99-6956-4143-BA53-678A8D66B21E@math.washington.edu> On Sep 30, 2009, at 5:07 PM, Christopher Barker wrote: > Dag Sverre Seljebotn wrote: >> Christopher Barker wrote: >> Yes, but the existing intro on numpy+cython: >> a) Lacks quite a bit in several areas >> b) Is outdated >> >> While the tutorial + paper is already written now. > > right -- my pint was that we really should have only one -- if the > tutorial+paper is the better/more up-to-date one, then by all means > let's make that the one people find. > > >>> However, maybe it's my personal use-case bias, but I think that >>> numpy is >>> almost a standard part of Cython use -- I can't think of what I'd >>> like >>> to optimize that I wouldn't want to use numpy for! And numpy is >>> why I >>> skipped past pyrex and straight to Cython. >> >> Well, take Stefan Behnel, who doesn't use NumPy at all, but rather >> works >> with XML documents. >> >> Even within science, the whole Sage project (a very important Cython >> user) don't use that much NumPy either, and in particular not the >> Cython/NumPy features, as they need exact math which isn't covered by >> NumPy's dtypes > > OK -- lot's of non-numpy use. Yep. Sage ships SciPy, and we defer lots of the numerical stuff to that. We could probably use NumPy more than we do, but for most stuff fixed-size fixed-precision arrays SIMD operations just doesn't describe what we do. >> Then you have any kind of wrappers around native libraries. > > yes, but if those native libraries are working with arrays of data, > numpy may well be a good idea there, too. I would say that most (non-scientific) libraries don't work with arrays of data. >> There's enough usecases for Cython without NumPy to make our primary >> Cython tutorial generic and not targeted for numerical users IMO. > > agreed, though I may never use the stuff used to process XML docs, but > it gets first class treatment... I think the main point here is string processing, which is much more broadly applicable than parsing XML. >> And then you have the question of whether one should have *two* >> tutorials. Perhaps a very small intro document for numerical users >> which >> links heavily into the other documents... > > Sure -- in fact, it often makes lots of sense for there to be > different > tutorial focused on different user groups -- either because they have > different use-cases, or because they have different backgrounds. > > I can tell you that I went straight to the numpy+Cython tutorial, > because I knew I'd want to work primarily with numpy arrays. > > We may some day want tutorials for: > - how to use Cython to wrap C libs > - how to use Cython to wrap C++ libs > (maybe targeted for folks that are used to using SWIG, ctypes, > etc.) Maybe something like Intro - Brief overview of what Cython is (and is not) - Building (very simple example, setup.py) -- note that this can be skipped if using the sage notebook. (Eventually it might be good to have a link right to the sage notebook for people to try all the examples out--the setup can be a hurdle, and this gives people a chance to see how easy and powerful it is to have motivation to actually set it up on their machines). - Basics cdef variables, methods(?), and types. cython -a All of the above is essential to any use of Cython. We could then dive into topic-specific tutorials, specifically: - NumPy -- this would be the SciPy paper, minus intro stuff - Calling and wrapping external libraries - Creating extension classes - String processing - Advanced topics (for...from, include, .pxd files) - Common pitfalls - Pure mode - ??? All of the above would assume only the background of the (shortish) intro chapter(s), and be relatively self-contained. There should also be a reference. This would contain things like specific optimizations, directives, language details, and would be heavily linked to from the above. - Robert From robertwb at math.washington.edu Thu Oct 1 09:09:07 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 1 Oct 2009 00:09:07 -0700 Subject: [Cython] Updating Documentation In-Reply-To: References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880909300253s44949a0al5d987c03c2ba503d@mail.gmail.com> <4AC32BB5.7050604@student.matnat.uio.no> <1e52e0880909300306u1940255ara37e321bc8634b88@mail.gmail.com> <1e52e0880909300327p63bc1fccjf78b58f643454085@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> Message-ID: BTW, who wants/needs push access to hg.cython.org/cython-docs? (Though you can set up your own repos as well.) - Robert From robertwb at math.washington.edu Thu Oct 1 09:18:13 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 1 Oct 2009 00:18:13 -0700 Subject: [Cython] Appending... In-Reply-To: <4AC39696.2070605@noaa.gov> References: <4AC38C4B.5040903@student.matnat.uio.no> <4AC39696.2070605@noaa.gov> Message-ID: <0763C7DF-8AFE-4E7E-B494-6CFE5DA6E0EA@math.washington.edu> On Sep 30, 2009, at 10:34 AM, Christopher Barker wrote: > Magnus Lie Hetland wrote: >> Yeah, one-dimensional data -- simply a list of ints. >> >> I'll just go for a Python list for now, then, and look into it if >> performance becomes a problem. (It's not going to be a long list, but >> it may be traversed hundreds of thousands of times, so who >> knows... :->) > > Funny you should write this. I was just composing a note in my head > about a proposal for a numpy "accumulating array". This idea was > inspired by a discussion at SciPY, in which we spent a LOT of time > during the numpy tutorial talking about how to accumulate values in an > array when you don't know how big the array needs to be when you > start. > > The "standard practice" is to accumulate in a python list, then > convert > the final result into an array. This is a good idea because Python > lists > are standard, well tested, efficient, etc. > > However, as was pointed out in that lengthy discussion, if what you > are > doing is accumulating is a whole bunch of numbers (ints, floats, > whatever), or particularly if you need to accumulate a data type that > plain python doesn't support, there is a lot of overhead involved: a > python float type is pretty heavyweight. If performance or memory > use is > important, it might create issues. > > What I have in mind is very simple. It would be: > - Only 1-d > - Support append() and extend() methods > - Support any valid numpy dtype > - which could even get you pseudo n-d arrays... > - maybe it would act like an array in other ways, I'm not so sure.. > > > It could be written in pure python, using np.resize()(or concatenate, > or,...), and certainly written efficiently in Cython or even (no!) C. Sounds useful. One thing that would be missing from a pure Python implementation is the ability to append and get raw c types, rather than just their wrapped counterparts, which would probably be the bulk of the overhead. (In Cython one would have to write a separate class for each type, oh if only we have templates already...) - Robert From dagss at student.matnat.uio.no Thu Oct 1 09:21:28 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 01 Oct 2009 09:21:28 +0200 Subject: [Cython] Updating Documentation In-Reply-To: <71236E99-6956-4143-BA53-678A8D66B21E@math.washington.edu> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <4AC32A6D.7080000@student.matnat.uio.no> <4AC39271.3080300@noaa.gov> <4AC39AF8.9010906@student.matnat.uio.no> <4AC3F2C8.70006@noaa.gov> <71236E99-6956-4143-BA53-678A8D66B21E@math.washington.edu> Message-ID: <4AC45878.6020107@student.matnat.uio.no> Robert Bradshaw wrote: > On Sep 30, 2009, at 5:07 PM, Christopher Barker wrote: > > >> Dag Sverre Seljebotn wrote: >> >>> Christopher Barker wrote: >>> Yes, but the existing intro on numpy+cython: >>> a) Lacks quite a bit in several areas >>> b) Is outdated >>> >>> While the tutorial + paper is already written now. >>> >> right -- my pint was that we really should have only one -- if the >> tutorial+paper is the better/more up-to-date one, then by all means >> let's make that the one people find. >> >> >> >>>> However, maybe it's my personal use-case bias, but I think that >>>> numpy is >>>> almost a standard part of Cython use -- I can't think of what I'd >>>> like >>>> to optimize that I wouldn't want to use numpy for! And numpy is >>>> why I >>>> skipped past pyrex and straight to Cython. >>>> >>> Well, take Stefan Behnel, who doesn't use NumPy at all, but rather >>> works >>> with XML documents. >>> >>> Even within science, the whole Sage project (a very important Cython >>> user) don't use that much NumPy either, and in particular not the >>> Cython/NumPy features, as they need exact math which isn't covered by >>> NumPy's dtypes >>> >> OK -- lot's of non-numpy use. >> > > Yep. Sage ships SciPy, and we defer lots of the numerical stuff to > that. We could probably use NumPy more than we do, but for most stuff > fixed-size fixed-precision arrays SIMD operations just doesn't > describe what we do. > > >>> Then you have any kind of wrappers around native libraries. >>> >> yes, but if those native libraries are working with arrays of data, >> numpy may well be a good idea there, too. >> > > I would say that most (non-scientific) libraries don't work with > arrays of data. > > >>> There's enough usecases for Cython without NumPy to make our primary >>> Cython tutorial generic and not targeted for numerical users IMO. >>> >> agreed, though I may never use the stuff used to process XML docs, but >> it gets first class treatment... >> > > I think the main point here is string processing, which is much more > broadly applicable than parsing XML. > > >>> And then you have the question of whether one should have *two* >>> tutorials. Perhaps a very small intro document for numerical users >>> which >>> links heavily into the other documents... >>> >> Sure -- in fact, it often makes lots of sense for there to be >> different >> tutorial focused on different user groups -- either because they have >> different use-cases, or because they have different backgrounds. >> >> I can tell you that I went straight to the numpy+Cython tutorial, >> because I knew I'd want to work primarily with numpy arrays. >> >> We may some day want tutorials for: >> - how to use Cython to wrap C libs >> - how to use Cython to wrap C++ libs >> (maybe targeted for folks that are used to using SWIG, ctypes, >> etc.) >> > > Maybe something like > > Intro > - Brief overview of what Cython is (and is not) > - Building (very simple example, setup.py) -- note that this can be > skipped if using the sage notebook. (Eventually it might be good to > have a link right to the sage notebook for people to try all the > examples out--the setup can be a hurdle, and this gives people a > chance to see how easy and powerful it is to have motivation to > actually set it up on their machines). > - Basics cdef variables, methods(?), and types. cython -a > > All of the above is essential to any use of Cython. We could then > dive into topic-specific tutorials, specifically: > > - NumPy -- this would be the SciPy paper, minus intro stuff > - Calling and wrapping external libraries > - Creating extension classes > - String processing > - Advanced topics (for...from, include, .pxd files) > - Common pitfalls > - Pure mode > - ??? > That's a great idea. Basically just putting the last half of our SciPy tutorial into seperate chapters and link to them (so that they don't have to be read in a particular order) gets us very far. I was thinking about this when writing the tutorial -- which section to put first of: a) NumPy b) string processing c) wrapping external lib? As they don't build on one another. Dag Sverre From vel.accel at gmail.com Thu Oct 1 09:21:47 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Thu, 1 Oct 2009 03:21:47 -0400 Subject: [Cython] Updating Documentation In-Reply-To: References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880909300253s44949a0al5d987c03c2ba503d@mail.gmail.com> <4AC32BB5.7050604@student.matnat.uio.no> <1e52e0880909300306u1940255ara37e321bc8634b88@mail.gmail.com> <1e52e0880909300327p63bc1fccjf78b58f643454085@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> Message-ID: <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> On Thu, Oct 1, 2009 at 3:09 AM, Robert Bradshaw wrote: > BTW, who wants/needs push access to hg.cython.org/cython-docs? > (Though you can set up your own repos as well.) > > - Robert > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > Hi Robert. I have a branch repo at http://bitbucket.org/travlr/cython-docs . That should suffice for now, I'd think. Unless you all want it differently. At this point I've redone the super-structure and am iterating inward. Conciseness is my goal. Let me know, at any time, your thoughts or vision do not coincide with what I do.. From robertwb at math.washington.edu Thu Oct 1 09:28:23 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 1 Oct 2009 00:28:23 -0700 Subject: [Cython] Buffer interface in Python2.6 In-Reply-To: References: Message-ID: On Sep 30, 2009, at 10:08 AM, Matthew Honnibal wrote: > Hi, > I've only just started using Cython today, and I'm having trouble with > the buffer interface indexing described here: > http://wiki.cython.org/enhancements/buffer . I want to iterate over a > unicode string getting contiguous subsequences. I'm not sure what the intended behavior is, given that unicode objects can be stored with various encodings, and, in particular, the default (UTF-8) is a variable-length encoding. > My Cython function has the following declaration: > > def parseDoc(object[object] string): If you really want a 1D list of objects, I'd just use a list. > I've tried various Python types, but I always get a runtime error > like: > > TypeError: 'unicode' does not have the buffer interface > TypeError: 'array.array' does not have the buffer interface > TypeError: 'buffer' does not have the buffer interface > > The last one was obtained by calling the built-in buffer() function on > the string. > > I can get a step further by doing cimport numpy and using a numpy > array, but then unicode is not one of the supported types, and that > doesn't seem like it was the intention --- the docs suggest at Python > 2.6+, I shouldn't need the numpy work-around. > > What am I doing wrong? I'm not sure. I can't even get def foo(object[double] a): return a[0] foo(numpy.ndarrray(5)) to work. Dag, any ideas? Is this supposed to work for Py < 3.0? - Robert From dagss at student.matnat.uio.no Thu Oct 1 09:32:08 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 01 Oct 2009 09:32:08 +0200 Subject: [Cython] Buffer interface in Python2.6 In-Reply-To: References: Message-ID: <4AC45AF8.8050807@student.matnat.uio.no> Robert Bradshaw wrote: > On Sep 30, 2009, at 10:08 AM, Matthew Honnibal wrote: > > >> Hi, >> I've only just started using Cython today, and I'm having trouble with >> the buffer interface indexing described here: >> http://wiki.cython.org/enhancements/buffer . I want to iterate over a >> unicode string getting contiguous subsequences. >> > > I'm not sure what the intended behavior is, given that unicode > objects can be stored with various encodings, and, in particular, the > default (UTF-8) is a variable-length encoding. > > >> My Cython function has the following declaration: >> >> def parseDoc(object[object] string): >> > > If you really want a 1D list of objects, I'd just use a list. > > >> I've tried various Python types, but I always get a runtime error >> like: >> >> TypeError: 'unicode' does not have the buffer interface >> TypeError: 'array.array' does not have the buffer interface >> TypeError: 'buffer' does not have the buffer interface >> >> The last one was obtained by calling the built-in buffer() function on >> the string. >> >> I can get a step further by doing cimport numpy and using a numpy >> array, but then unicode is not one of the supported types, and that >> doesn't seem like it was the intention --- the docs suggest at Python >> 2.6+, I shouldn't need the numpy work-around. >> >> What am I doing wrong? >> > > I'm not sure. > > I can't even get > > def foo(object[double] a): > return a[0] > > foo(numpy.ndarrray(5)) > > to work. Dag, any ideas? Is this supposed to work for Py < 3.0? > Try foo(numpy.array([5]).astype(np.double)) ... I'll answer the rest seperately. Dag Sverre From dagss at student.matnat.uio.no Thu Oct 1 09:45:06 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 01 Oct 2009 09:45:06 +0200 Subject: [Cython] Question about buffer interface for Python2.6 In-Reply-To: References: Message-ID: <4AC45E02.6070408@student.matnat.uio.no> Matthew Honnibal wrote: > Hi, > I've only just started using Cython today, and I'm having trouble with > the buffer interface indexing described here: > http://wiki.cython.org/enhancements/buffer . I want to iterate over a > unicode string getting contiguous subsequences. > The buffer PEP is *available* in Python 2.6, however I don't think objects in the Python standard library exports its buffers using it. Unfortunately. What you can try to do is use the backwards-compatability mechanisms of implementing __getbuffer__ in Cython, something like (untested): from python_unicode cimport Py_UNICODE cdef extern from "Python.h": # Or Python's unicodeobject.h ctypedef class unicode [object PyUnicodeObject]: Py_ssize_t length Py_UNICODE *str def __getbuffer__(self, Py_buffer* buf, int flags): ... fill in buf struct with PEP 3118 information to export self.str/self.length ... Notes: a) If you only want to deal with unicodes, you can probably just as well drop __getbuffer__. With the declaration above, you can still do cdef unicode u = myunicode cdef Py_UNICODE *buf = u.str print buf[3] # gets 4th unicode character without any buffer support. b) If you do write up a decent unicode declaration, make sure to contribute it to Cython's Cython/Includes/python_unicode. c) If you go the __getbuffer__ route for more convenient syntax, be aware that unicode types are not supported; you need to export it as "=I", "=H", "=B" (int, short, byte) depending on sizeof(Py_UNICODE), see struct module, and then acquire a buffer through cdef unicode[Py_UNICODE] u = myunicode cdef Py_UNICODE onechar = u[3] Dag Sverre From stefan_ml at behnel.de Thu Oct 1 10:27:40 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 01 Oct 2009 10:27:40 +0200 Subject: [Cython] Buffer interface in Python2.6 In-Reply-To: References: Message-ID: <4AC467FC.5000002@behnel.de> Robert Bradshaw wrote: > On Sep 30, 2009, at 10:08 AM, Matthew Honnibal wrote: >> I've only just started using Cython today, and I'm having trouble with >> the buffer interface indexing described here: >> http://wiki.cython.org/enhancements/buffer . I want to iterate over a >> unicode string getting contiguous subsequences. > > I'm not sure what the intended behavior is, given that unicode > objects can be stored with various encodings, and, in particular, the > default (UTF-8) is a variable-length encoding. UTF-8 is not used here. However, the real encoding of the underlying byte buffer is platform specific and one of UCS-4 or UCS-2 as little endian or big endian, i.e. four possible encodings. I never tried, but I'd expect the buffer view of unicode objects to point to that internal buffer. Anyway, the fastest way to get to the data content of a unicode object are the C-API functions PyUnicode_AS_DATA() and PyUnicode_GET_DATA_SIZE(), or if you prefer character chunked data instead of byte data, PyUnicode_AS_UNICODE() and PyUnicode_GET_SIZE(). Also see the definition of the Py_UNICODE character type, which can be a 2-byte or 4-byte integer type, or a wchar_t type, depending on the platform. http://docs.python.org/c-api/unicode.html#Py_UNICODE Stefan From robertwb at math.washington.edu Thu Oct 1 11:22:43 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 1 Oct 2009 02:22:43 -0700 Subject: [Cython] Cython in language shootout? In-Reply-To: <85e81ba30909301439t9aa5e5ex2d426077d8fd61@mail.gmail.com> References: <5B3508FD-AE97-4904-91B1-C74EB449E276@hetland.org> <85e81ba30909301143t7d746dc7o577376dca9490205@mail.gmail.com> <85e81ba30909301439t9aa5e5ex2d426077d8fd61@mail.gmail.com> Message-ID: <6F871507-E4FA-49D3-A146-E3991269BEB8@math.washington.edu> On Sep 30, 2009, at 2:39 PM, William Stein wrote: > On Wed, Sep 30, 2009 at 2:04 PM, Lisandro Dalcin > wrote: >> On Wed, Sep 30, 2009 at 3:43 PM, William Stein >> wrote: >>> On Wed, Sep 30, 2009 at 5:05 AM, Magnus Lie Hetland >>> wrote: >>>> One of my PhD students suggested adding Cython to the Computer >>>> Language Benchmark Game: >>>> >>>> http://shootout.alioth.debian.org/ >>>> >>>> Seems like it would be fun -- after all, there are already Python >>>> implementations there (for 11 problems), so as a start, one could >>>> simply wrap up a proper compilation script for Cython, and >>>> submit it. >>>> Fiddling with declarations etc. would be a natural next step, of >>>> course. >>>> >>>> I'm thinking about doing something here myself, but I'm a bit busy >>>> with another project at the moment, so I thought I'd mention it >>>> here, >>>> in case someone else felt inspired. >>>> >>>> I think this is a shootout many people refer to when discussing >>>> relative performance of languages; getting Cython in there might >>>> peak >>>> the interest of people who might actually need it, but who don't >>>> know >>>> it exists... >>>> >>>> (Sorry for cross-posting -- I guess this might be relevant for both >>>> lists.) >>>> >>> >>> I've always wanted somebody to add Cython to that page, since I >>> think >>> Cython should do as well as C in every benchmark... which would >>> be fun >>> because C wins every benchmark. Yes, we should do that for sure. The --embed mode makes things much easier. I also think we should have two implementations--a Pythonic one (perhaps with types, but still natural), and a maximum performance (essentially C). >> Though IMHO Cython should be tested in two "modes": plain compilation >> of py sources, and cdef-typed implementations... >> > > I just did the pidigits one in about 5-10 minutes... and Robert > Bradshaw just walked into my office and said he's already done some of > them (they are sitting on his laptop somewhere). Now they're up at http://hg.cython.org/shootout/file/tip Please feel free to expand/improve. > http://sage.math.washington.edu/home/wstein/tmp/pidigits.pyx > > The timing for that one is basically the same as C. Robert remarks > that in some cases Python's "print/rawinput" is a serious bottleneck > compared to C if we want to stick with idiomatic Cython. Yep, and several of them are IO intensive. We can use printf and friends if we need. - Robert From dagss at student.matnat.uio.no Thu Oct 1 13:54:25 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 01 Oct 2009 13:54:25 +0200 Subject: [Cython] doctesthack directive Message-ID: <4AC49871.9070400@student.matnat.uio.no> I now have code sitting on my drive for a doctesthack directive. What it does is work around the limitations of the doctest module by automatically creating a global __test__ dictionary mapping descriptive names to function and method docstrings. 1) Can I push it? 2) Can I make it the default? It never does anything if a __test__ already exists, so it should be fully backwards compatible. The only downside I can see is a little bit of extra memory used. Line numbers are embedded into the test names (the keys in __dict__). Note: This does not solve the problem of doctest being unable to print line numbers for class docstrings. Also the test procedure ends up flowing a little bit different from the Python module (as each function is a seperate testcase, and not simply part of the module test). As the name says, it is a hack. Dag Sverre From stefan_ml at behnel.de Thu Oct 1 13:58:58 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 01 Oct 2009 13:58:58 +0200 Subject: [Cython] doctesthack directive In-Reply-To: <4AC49871.9070400@student.matnat.uio.no> References: <4AC49871.9070400@student.matnat.uio.no> Message-ID: <4AC49982.1080806@behnel.de> Dag Sverre Seljebotn wrote: > I now have code sitting on my drive for a doctesthack directive. What it > does is work around the limitations of the doctest module by > automatically creating a global __test__ dictionary mapping descriptive > names to function and method docstrings. > > 1) Can I push it? > 2) Can I make it the default? It never does anything if a __test__ > already exists, so it should be fully backwards compatible. The only > downside I can see is a little bit of extra memory used. > > Line numbers are embedded into the test names (the keys in __dict__). > > Note: This does not solve the problem of doctest being unable to print > line numbers for class docstrings. Also the test procedure ends up > flowing a little bit different from the Python module (as each function > is a seperate testcase, and not simply part of the module test). As the > name says, it is a hack. Now that I know what kind of problems this does *not* fix and what new problems it introduces, what about some more detail what kind of problem this actually fixes? Stefan From dagss at student.matnat.uio.no Thu Oct 1 14:06:14 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 01 Oct 2009 14:06:14 +0200 Subject: [Cython] doctesthack directive In-Reply-To: <4AC49982.1080806@behnel.de> References: <4AC49871.9070400@student.matnat.uio.no> <4AC49982.1080806@behnel.de> Message-ID: <4AC49B36.4070607@student.matnat.uio.no> Stefan Behnel wrote: > Dag Sverre Seljebotn wrote: > >> I now have code sitting on my drive for a doctesthack directive. What it >> does is work around the limitations of the doctest module by >> automatically creating a global __test__ dictionary mapping descriptive >> names to function and method docstrings. >> >> 1) Can I push it? >> 2) Can I make it the default? It never does anything if a __test__ >> already exists, so it should be fully backwards compatible. The only >> downside I can see is a little bit of extra memory used. >> >> Line numbers are embedded into the test names (the keys in __dict__). >> >> Note: This does not solve the problem of doctest being unable to print >> line numbers for class docstrings. Also the test procedure ends up >> flowing a little bit different from the Python module (as each function >> is a seperate testcase, and not simply part of the module test). As the >> name says, it is a hack. >> > > Now that I know what kind of problems this does *not* fix and what new > problems it introduces, what about some more detail what kind of problem > this actually fixes? > What it fixes is that I can take a simple pyx file like this: def func(x): """ >>> func(3) """ ... and then test it like I would a Python module: python -c 'import doctest; import mymod; doctest.testmod(mymod)' doctest does not pick up the function docstring automatically as it reports negative to inspect.isfunction, however putting those functions in the __test__ dict works around it. Arguments in favor: - Lowers the barrier. It is the kind of thing which took me by surprise when I first met it; letting this be the default could save half an hour for every new Cython user. - This also allows very easily writing function-wise doctests in the Cython test suite An approach which requires a custom script for doctesting Cython files is here: http://wiki.cython.org/FAQ#HowcanIrundoctestsinCythoncode.28pyxfiles.29.3F But I happen to like this approach better as it lower the barriers and makes peoples test scripts simpler without Cython-specific logic. Dag Sverre From ndbecker2 at gmail.com Thu Oct 1 16:17:27 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 01 Oct 2009 10:17:27 -0400 Subject: [Cython] generic types? Message-ID: I need to code some cython functions which will be instantiated for several different data types. Very much like what c++ templates are used for. What approaches can be used to do this? (I'm guessing some kind of macro text processing. Does cython use cpp?) Now suppose in general I need a little more intelligence. For example, suppose I have a function that is templated on a single datatype. Suppose some types internal to that function depend in a (possibly nontrivial way) on that datatype. Same approach? How about a function templated on multiple datatypes? From Chris.Barker at noaa.gov Thu Oct 1 18:22:29 2009 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Thu, 01 Oct 2009 09:22:29 -0700 Subject: [Cython] Updating Documentation In-Reply-To: References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <4AC32A6D.7080000@student.matnat.uio.no> <4AC39271.3080300@noaa.gov> <4AC39AF8.9010906@student.matnat.uio.no> <4AC3F2C8.70006@noaa.gov> Message-ID: <4AC4D745.4020301@noaa.gov> Robert Kern wrote: > Christopher Barker wrote: >> agreed, though I may never use the stuff used to process XML docs, but >> it gets first class treatment... > > There really isn't any special "stuff used to process XML docs" in Cython. There > is special stuff in Cython to interact with numpy arrays. I never used the term "special". My point was that for many users, working with numpy arrays may be just as or more important that python strings (or even lists, etc.) As I see it, the only thing "special" about numpy arrays is that they are not part of the standard library (which I think they should be) -- but they are part of the standard Cython distro. Robert Bradshaw wrote: >>> Then you have any kind of wrappers around native libraries. >> yes, but if those native libraries are working with arrays of data, >> numpy may well be a good idea there, too. > > I would say that most (non-scientific) libraries don't work with > arrays of data. It might be interesting to do a survey, but I can, off the top of my head, think of a couple broad categories that I've worked with: - text-oriented : not numpy - image processing: numpy could/should play a role here - scientific/numerical: duh! - GUI: numpy could/should play a role here, too. mainly for graphics, etc. - GIS: numpy does/could/should play a role here, too. As an example, if pyOpenGL didn't work with numpy arrays, it would be crippled -- or it would have to provide its own data types for storing/manipulating big blocks of data. Any C library is going to work with one or both of two things: text and numbers -- what fraction of libs only work with text? Of course, what I'm really doing here is advocating for an nd-array in the standard lib... > Maybe something like > > Intro > - Brief overview of what Cython is (and is not) > - Building (very simple example, setup.py) -- note that this can be > skipped if using the sage notebook. (Eventually it might be good to > have a link right to the sage notebook for people to try all the > examples out--the setup can be a hurdle, and this gives people a > chance to see how easy and powerful it is to have motivation to > actually set it up on their machines). Sage is wonderful, but I'd not like to see it get too tied into Cython... > - Basics cdef variables, methods(?), and types. cython -a > > All of the above is essential to any use of Cython. We could then > dive into topic-specific tutorials, specifically: > > - NumPy -- this would be the SciPy paper, minus intro stuff > - Calling and wrapping external libraries > - Creating extension classes > - String processing > - Advanced topics (for...from, include, .pxd files) > - Common pitfalls > - Pure mode > - ??? > > All of the above would assume only the background of the (shortish) > intro chapter(s), and be relatively self-contained. Yes, this is a great outline! I think it accomplished what I was getting at -- a short path from newbie to working with numpy arrays, but also an equally short path to working with strings, etc. A new user is likely to come to Cython with a particular problem to solve, and this looks like a good structure to get them there quickly. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From Chris.Barker at noaa.gov Thu Oct 1 18:31:00 2009 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Thu, 01 Oct 2009 09:31:00 -0700 Subject: [Cython] Updating Documentation In-Reply-To: <4AC45878.6020107@student.matnat.uio.no> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <4AC32A6D.7080000@student.matnat.uio.no> <4AC39271.3080300@noaa.gov> <4AC39AF8.9010906@student.matnat.uio.no> <4AC3F2C8.70006@noaa.gov> <71236E99-6956-4143-BA53-678A8D66B21E@math.washington.edu> <4AC45878.6020107@student.matnat.uio.no> Message-ID: <4AC4D944.7040805@noaa.gov> Dag Sverre Seljebotn wrote: > which section to put first of: > > a) NumPy > b) string processing > c) wrapping external lib? > > As they don't build on one another. Then it doesn't much matter, but I can't imagine how you could wrap an external lib without using numpy and/or string processing, so maybe that should go last. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From robertwb at math.washington.edu Thu Oct 1 20:00:08 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 1 Oct 2009 11:00:08 -0700 Subject: [Cython] Updating Documentation In-Reply-To: <4AC4D745.4020301@noaa.gov> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <4AC32A6D.7080000@student.matnat.uio.no> <4AC39271.3080300@noaa.gov> <4AC39AF8.9010906@student.matnat.uio.no> <4AC3F2C8.70006@noaa.gov> <4AC4D745.4020301@noaa.gov> Message-ID: <0741A875-6A6E-452D-8B9D-B54FF6BE207E@math.washington.edu> On Oct 1, 2009, at 9:22 AM, Christopher Barker wrote: > Robert Bradshaw wrote: >>>> Then you have any kind of wrappers around native libraries. >>> yes, but if those native libraries are working with arrays of data, >>> numpy may well be a good idea there, too. >> >> I would say that most (non-scientific) libraries don't work with >> arrays of data. > > It might be interesting to do a survey, but I can, off the top of my > head, think of a couple broad categories that I've worked with: > - text-oriented : not numpy > - image processing: numpy could/should play a role here > - scientific/numerical: duh! > - GUI: numpy could/should play a role here, too. mainly for > graphics, > etc. > - GIS: numpy does/could/should play a role here, too. > > As an example, if pyOpenGL didn't work with numpy arrays, it would be > crippled -- or it would have to provide its own data types for > storing/manipulating big blocks of data. > > Any C library is going to work with one or both of two things: text > and > numbers -- what fraction of libs only work with text? Just for fun I did a quick survey of the libraries we access from Cython in Sage (which is probably not typical, but at least is a large set I can say something about): - Neither string processing nor obvious application of NumPy arrays: cliquer, cvxopt, ecl (soon?), ecm, elliptic_curves, flint, gaplib (soon?), givaro, gmp/mpir, iml, lcalc, fplll, libgcrypt, linbox, m4ri, mpfi, mpfr, ntl, palp, pari, polybori, polytopes, pynac (ginac), quaddouble, qs, ratpoints, singular, symmetrica, sympow, zn_poly. - Could potentially use NumPy arrays: ghmm, gd, gsl, lapak. - Non-trivial string processing: Nothing we wrap with Cython (that I know of off the top of my head). Of course there's stdlib, stdio, math, etc. as well. Often we wrap things as (semi-)opaque objects, call methods on them, etc. That being said, I think the scientific/numerical audience is (currently at least) one of the largest audiences for Cython, and it's important to cater to them. > Of course, what I'm really doing here is advocating for an nd-array in > the standard lib... Yeah. The buffer interface is a nice step in that direction though. >> Maybe something like >> >> Intro >> - Brief overview of what Cython is (and is not) >> - Building (very simple example, setup.py) -- note that this can be >> skipped if using the sage notebook. (Eventually it might be good to >> have a link right to the sage notebook for people to try all the >> examples out--the setup can be a hurdle, and this gives people a >> chance to see how easy and powerful it is to have motivation to >> actually set it up on their machines). > > Sage is wonderful, but I'd not like to see it get too tied into > Cython... Well, at least we don't call it SageX anymore ;). I'm thinking more of a "try it now" kind of link. - Robert > From robertwb at math.washington.edu Thu Oct 1 20:09:08 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 1 Oct 2009 11:09:08 -0700 Subject: [Cython] generic types? In-Reply-To: References: Message-ID: <5E1EE29A-FBD0-435B-9D86-A0D7A7846684@math.washington.edu> On Oct 1, 2009, at 7:17 AM, Neal Becker wrote: > I need to code some cython functions which will be instantiated for > several > different data types. Very much like what c++ templates are used for. > > What approaches can be used to do this? > > (I'm guessing some kind of macro text processing. Does cython use > cpp?) > > Now suppose in general I need a little more intelligence. For > example, > suppose I have a function that is templated on a single datatype. > Suppose > some types internal to that function depend in a (possibly > nontrivial way) > on that datatype. Same approach? > > How about a function templated on multiple datatypes? Somewhat hackish is to do this with a pxi. Define a pxi using a dummy type, e.g. cdef class Wrapper: cdef TYPE value cdef set(self, TYPE value): self.value = value cdef TYPE get(self): return self.value ... Then make several pyx/pxd files that do ctypedef TYPE double include "wrapper.pxi" And voila, "templates." Of course, eventually we'll want to have a much nicer way of doing this, e.g. being able to template cdef classes like you can in C++ (though I don't think we want to go with the full template metaprograming model they have). - Robert From robertwb at math.washington.edu Thu Oct 1 20:19:31 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 1 Oct 2009 11:19:31 -0700 Subject: [Cython] doctesthack directive In-Reply-To: <4AC49B36.4070607@student.matnat.uio.no> References: <4AC49871.9070400@student.matnat.uio.no> <4AC49982.1080806@behnel.de> <4AC49B36.4070607@student.matnat.uio.no> Message-ID: <78D599DD-8F8F-478C-B325-0B352A6C2452@math.washington.edu> On Oct 1, 2009, at 5:06 AM, Dag Sverre Seljebotn wrote: > Stefan Behnel wrote: >> Dag Sverre Seljebotn wrote: >> >>> I now have code sitting on my drive for a doctesthack directive. >>> What it >>> does is work around the limitations of the doctest module by >>> automatically creating a global __test__ dictionary mapping >>> descriptive >>> names to function and method docstrings. >>> >>> 1) Can I push it? >>> 2) Can I make it the default? It never does anything if a __test__ >>> already exists, so it should be fully backwards compatible. The only >>> downside I can see is a little bit of extra memory used. >>> >>> Line numbers are embedded into the test names (the keys in >>> __dict__). >>> >>> Note: This does not solve the problem of doctest being unable to >>> print >>> line numbers for class docstrings. Also the test procedure ends up >>> flowing a little bit different from the Python module (as each >>> function >>> is a seperate testcase, and not simply part of the module test). >>> As the >>> name says, it is a hack. >>> >> >> Now that I know what kind of problems this does *not* fix and what >> new >> problems it introduces, what about some more detail what kind of >> problem >> this actually fixes? >> > What it fixes is that I can take a simple pyx file like this: > > def func(x): > """ >>>> func(3) > """ > ... > > and then test it like I would a Python module: > > python -c 'import doctest; import mymod; doctest.testmod(mymod)' > > doctest does not pick up the function docstring automatically as it > reports negative to inspect.isfunction, however putting those > functions > in the __test__ dict works around it. > > Arguments in favor: > - Lowers the barrier. It is the kind of thing which took me by > surprise > when I first met it; letting this be the default could save half an > hour > for every new Cython user. > - This also allows very easily writing function-wise doctests in the > Cython test suite > > An approach which requires a custom script for doctesting Cython files > is here: > > http://wiki.cython.org/FAQ#HowcanIrundoctestsinCythoncode. > 28pyxfiles.29.3F > > But I happen to like this approach better as it lower the barriers and > makes peoples test scripts simpler without Cython-specific logic. I actually wasn't aware that this was such an issue, as Sage has its own doctesting framework (e.g. it need to take care of preprocessing, optional doctests, etc.) I think the right thing to do is convince them to fix the doctest module. Of course, that won't help past and current version of Python. That being said, this looks like a sound solution, and I'm in favor of it going in, and probably even being on by default. - Robert From dagss at student.matnat.uio.no Thu Oct 1 20:44:46 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 01 Oct 2009 20:44:46 +0200 Subject: [Cython] doctesthack directive In-Reply-To: <78D599DD-8F8F-478C-B325-0B352A6C2452@math.washington.edu> References: <4AC49871.9070400@student.matnat.uio.no> <4AC49982.1080806@behnel.de> <4AC49B36.4070607@student.matnat.uio.no> <78D599DD-8F8F-478C-B325-0B352A6C2452@math.washington.edu> Message-ID: <4AC4F89E.7050308@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 1, 2009, at 5:06 AM, Dag Sverre Seljebotn wrote: > >> Stefan Behnel wrote: >>> Dag Sverre Seljebotn wrote: >>> >>>> I now have code sitting on my drive for a doctesthack directive. >>>> What it >>>> does is work around the limitations of the doctest module by >>>> automatically creating a global __test__ dictionary mapping >>>> descriptive >>>> names to function and method docstrings. >>>> >>>> 1) Can I push it? >>>> 2) Can I make it the default? It never does anything if a __test__ >>>> already exists, so it should be fully backwards compatible. The only >>>> downside I can see is a little bit of extra memory used. >>>> >>>> Line numbers are embedded into the test names (the keys in >>>> __dict__). >>>> >>>> Note: This does not solve the problem of doctest being unable to >>>> print >>>> line numbers for class docstrings. Also the test procedure ends up >>>> flowing a little bit different from the Python module (as each >>>> function >>>> is a seperate testcase, and not simply part of the module test). >>>> As the >>>> name says, it is a hack. >>>> >>> Now that I know what kind of problems this does *not* fix and what >>> new >>> problems it introduces, what about some more detail what kind of >>> problem >>> this actually fixes? >>> >> What it fixes is that I can take a simple pyx file like this: >> >> def func(x): >> """ >>>>> func(3) >> """ >> ... >> >> and then test it like I would a Python module: >> >> python -c 'import doctest; import mymod; doctest.testmod(mymod)' >> >> doctest does not pick up the function docstring automatically as it >> reports negative to inspect.isfunction, however putting those >> functions >> in the __test__ dict works around it. >> >> Arguments in favor: >> - Lowers the barrier. It is the kind of thing which took me by >> surprise >> when I first met it; letting this be the default could save half an >> hour >> for every new Cython user. >> - This also allows very easily writing function-wise doctests in the >> Cython test suite >> >> An approach which requires a custom script for doctesting Cython files >> is here: >> >> http://wiki.cython.org/FAQ#HowcanIrundoctestsinCythoncode. >> 28pyxfiles.29.3F >> >> But I happen to like this approach better as it lower the barriers and >> makes peoples test scripts simpler without Cython-specific logic. > > I actually wasn't aware that this was such an issue, as Sage has its > own doctesting framework (e.g. it need to take care of preprocessing, > optional doctests, etc.) I think the right thing to do is convince > them to fix the doctest module. Of course, that won't help past and > current version of Python. That being said, this looks like a sound > solution, and I'm in favor of it going in, and probably even being on > by default. It's possible to rather easily fix doctest to pick up the functions, but to my knowledge there's no way for doctest to retrieve the line numbers -- which has made me reluctant to submit anything. My hack works around it by embedding that information in the test name, so it says something like: Doctest failed at line ?: somemodule.__tests__.somefunction (line 35) I guess we could try to agree with them on a new convention though -- something like: Any module can optionally provide the dict __testlinenumbers__, mapping functions and classes to integers. This dict, if present, is checked before any of the conventional methods for retrieving line numbers. -- Dag Sverre From dagss at student.matnat.uio.no Thu Oct 1 21:02:16 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 01 Oct 2009 21:02:16 +0200 Subject: [Cython] Can't push to repos Message-ID: <4AC4FCB8.9040402@student.matnat.uio.no> I get 500 Internal server error on pushes to hg.cython.org. I tried running "hg verify" in the cython-unstable folder (by SSHing into the server) but it didn't show anything. Any other ideas? -- Dag Sverre From stefan_ml at behnel.de Thu Oct 1 21:07:59 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 01 Oct 2009 21:07:59 +0200 Subject: [Cython] PyBench results compared to Py2.6.2 Message-ID: <4AC4FE0F.1060704@behnel.de> Hi all, for a talk I'm about to give, I ran the pybench benchmark with cython-unstable. I had to fix up the sources a tiny bit (nothing that impacts the results) and select the benchmarks that actually compile (mostly due to inner classes being used). It's run like this: PYTHONPATH=. python2.6 -c 'import pybench; pybench.PyBenchCmdline()' \ --debug -w 1 -n 5 -f results-cython.pybench -t \ 'Arithmetic|IfThen|Loops|Dict|Try.*Except|Import|List|Compare|String|Tuple|Unicode' FWIW, both the Python 2.6.2 interpreter and the Cython generated C modules were built on the same machine with the same CFLAGS. The sources I used are here: http://codespeak.net/lxml/pybench.tar.gz I attached the results. I left out the CompareIntegers/Floats/etc. benchmarks as they only compare numeric literals, which ends up in the C code as, well, a comparison of literals, so that the C compiler finds a lot of dead code to discard. The resulting 100% speedup isn't really that informative. Note that the numbers are for plain Python code without any type annotations, so a lot of possible optimisations are not even used. However, the remaining total improvement of almost 33%, and the huge speedups for control structures (especially loops) and builtin types is clearly worth a look. Have fun, Stefan -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: results-compared.txt Url: http://codespeak.net/pipermail/cython-dev/attachments/20091001/444742ad/attachment-0001.txt From ndbecker2 at gmail.com Thu Oct 1 21:45:24 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 01 Oct 2009 15:45:24 -0400 Subject: [Cython] generic types? References: <5E1EE29A-FBD0-435B-9D86-A0D7A7846684@math.washington.edu> Message-ID: Robert Bradshaw wrote: > On Oct 1, 2009, at 7:17 AM, Neal Becker wrote: > >> I need to code some cython functions which will be instantiated for >> several >> different data types. Very much like what c++ templates are used for. >> >> What approaches can be used to do this? >> >> (I'm guessing some kind of macro text processing. Does cython use >> cpp?) >> >> Now suppose in general I need a little more intelligence. For >> example, >> suppose I have a function that is templated on a single datatype. >> Suppose >> some types internal to that function depend in a (possibly >> nontrivial way) >> on that datatype. Same approach? >> >> How about a function templated on multiple datatypes? > > Somewhat hackish is to do this with a pxi. > > Define a pxi using a dummy type, e.g. > > cdef class Wrapper: > cdef TYPE value > cdef set(self, TYPE value): > self.value = value > cdef TYPE get(self): > return self.value > ... > > Then make several pyx/pxd files that do > > ctypedef TYPE double > include "wrapper.pxi" > > And voila, "templates." > > Of course, eventually we'll want to have a much nicer way of doing > this, e.g. being able to template cdef classes like you can in C++ > (though I don't think we want to go with the full template > metaprograming model they have). > > - Robert Would that work where a type used within a class or function is 'computed'? Could ctypedef TYPE double be made conditional, for example? From dagss at student.matnat.uio.no Thu Oct 1 21:52:27 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 01 Oct 2009 21:52:27 +0200 Subject: [Cython] generic types? In-Reply-To: References: <5E1EE29A-FBD0-435B-9D86-A0D7A7846684@math.washington.edu> Message-ID: <4AC5087B.8050901@student.matnat.uio.no> Neal Becker wrote: > Robert Bradshaw wrote: > >> On Oct 1, 2009, at 7:17 AM, Neal Becker wrote: >> >>> I need to code some cython functions which will be instantiated for >>> several >>> different data types. Very much like what c++ templates are used for. >>> >>> What approaches can be used to do this? >>> >>> (I'm guessing some kind of macro text processing. Does cython use >>> cpp?) >>> >>> Now suppose in general I need a little more intelligence. For >>> example, >>> suppose I have a function that is templated on a single datatype. >>> Suppose >>> some types internal to that function depend in a (possibly >>> nontrivial way) >>> on that datatype. Same approach? >>> >>> How about a function templated on multiple datatypes? >> Somewhat hackish is to do this with a pxi. >> >> Define a pxi using a dummy type, e.g. >> >> cdef class Wrapper: >> cdef TYPE value >> cdef set(self, TYPE value): >> self.value = value >> cdef TYPE get(self): >> return self.value >> ... >> >> Then make several pyx/pxd files that do >> >> ctypedef TYPE double >> include "wrapper.pxi" >> >> And voila, "templates." >> >> Of course, eventually we'll want to have a much nicer way of doing >> this, e.g. being able to template cdef classes like you can in C++ >> (though I don't think we want to go with the full template >> metaprograming model they have). >> >> - Robert > > Would that work where a type used within a class or function is 'computed'? > Could > ctypedef TYPE double > be made conditional, for example? Personally I'd save myself the trouble and use a good templating engine to generate my Cython sources. I know people use http://www.cheetahtemplate.org/ to generate GPU code (with PyCUDA) for instance, so it is probably usable for your purpose. -- Dag Sverre From robert.kern at gmail.com Thu Oct 1 22:50:35 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 01 Oct 2009 15:50:35 -0500 Subject: [Cython] Updating Documentation In-Reply-To: <4AC4D745.4020301@noaa.gov> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <4AC32A6D.7080000@student.matnat.uio.no> <4AC39271.3080300@noaa.gov> <4AC39AF8.9010906@student.matnat.uio.no> <4AC3F2C8.70006@noaa.gov> <4AC4D745.4020301@noaa.gov> Message-ID: Christopher Barker wrote: > Robert Kern wrote: >> Christopher Barker wrote: > >>> agreed, though I may never use the stuff used to process XML docs, but >>> it gets first class treatment... >> There really isn't any special "stuff used to process XML docs" in Cython. There >> is special stuff in Cython to interact with numpy arrays. > > I never used the term "special". My point was that for many users, > working with numpy arrays may be just as or more important that python > strings (or even lists, etc.) As I see it, the only thing "special" > about numpy arrays is that they are not part of the standard library > (which I think they should be) -- but they are part of the standard > Cython distro. My point in adding the "special" is to note that you probably *are* using the Cython features that are used in lxml whereas most people not using numpy will never touch the buffer syntax. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From robertwb at math.washington.edu Fri Oct 2 03:39:16 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 1 Oct 2009 18:39:16 -0700 Subject: [Cython] Updating Documentation In-Reply-To: <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880909300253s44949a0al5d987c03c2ba503d@mail.gmail.com> <4AC32BB5.7050604@student.matnat.uio.no> <1e52e0880909300306u1940255ara37e321bc8634b88@mail.gmail.com> <1e52e0880909300327p63bc1fccjf78b58f643454085@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> Message-ID: <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> On Oct 1, 2009, at 12:21 AM, Peter Alexander wrote: > Hi Robert. I have a branch repo at > http://bitbucket.org/travlr/cython-docs . That should suffice for now, > I'd think. Unless you all want it differently. Yes, that's totally fine. Distributed revision control is nice :) > At this point I've redone the super-structure and am iterating inward. > Conciseness is my goal. Let me know, at any time, your thoughts or > vision do not coincide with what I do.. Looks good. I think most of the language basics could be put later, with the exception of typing. So the first three sections could be overview, data typing, and compilation. After those three, we could move on to the topic-specific tutorials. - Robert From vel.accel at gmail.com Fri Oct 2 04:13:44 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Thu, 1 Oct 2009 22:13:44 -0400 Subject: [Cython] Updating Documentation In-Reply-To: <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880909300253s44949a0al5d987c03c2ba503d@mail.gmail.com> <4AC32BB5.7050604@student.matnat.uio.no> <1e52e0880909300306u1940255ara37e321bc8634b88@mail.gmail.com> <1e52e0880909300327p63bc1fccjf78b58f643454085@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> Message-ID: <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> On Thu, Oct 1, 2009 at 9:39 PM, Robert Bradshaw wrote: > On Oct 1, 2009, at 12:21 AM, Peter Alexander wrote: > >> Hi Robert. I have a branch repo at >> http://bitbucket.org/travlr/cython-docs . That should suffice for now, >> I'd think. Unless you all want it differently. > > Yes, that's totally fine. Distributed revision control is nice :) > >> At this point I've redone the super-structure and am iterating inward. >> Conciseness is my goal. Let me know, at any time, your thoughts or >> vision do not coincide with what I do.. > > Looks good. I think most of the language basics could be put later, > with the exception of typing. So the first three sections could be > overview, data typing, and compilation. After those three, we could > move on to the topic-specific tutorials. > > - Robert > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > I look at what I'm working on now as a "reference guide" should be solely considered as a "get your fingers on the answer, quickly", guide. Basically, what I'm thinking of for this, is a very complete outline stating the language rules, particulars, etc., with cross-references galore, indexing, and lots of examples, etc., I believe that a multiplicity of documentation sources is a good thing.. Tutorial, reference, and "papers".. etc, etc. Tutorials as introductory "dive-in, and get you hair wet" type, and acomplete, very well thought out, no-nonsense reference material for those engaged in their project that "just want the answer that second" (like me) kind a guy/gal. So.. personally I am invested in the reference type, but I totally think that domain specific tutorials would be great for Cython to support. And a necessity, you might say. But, for now I'd like to concentrate on making the ref guide succinct, accessible, and most of all... complete. I also very much appreciate input from others. So please speak up when you want to... so we can get this right. ~Peter From vel.accel at gmail.com Fri Oct 2 05:27:34 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Thu, 1 Oct 2009 23:27:34 -0400 Subject: [Cython] Updating Documentation In-Reply-To: <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <4AC32BB5.7050604@student.matnat.uio.no> <1e52e0880909300306u1940255ara37e321bc8634b88@mail.gmail.com> <1e52e0880909300327p63bc1fccjf78b58f643454085@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> Message-ID: <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> On Thu, Oct 1, 2009 at 10:13 PM, Peter Alexander wrote: > On Thu, Oct 1, 2009 at 9:39 PM, Robert Bradshaw > wrote: >> On Oct 1, 2009, at 12:21 AM, Peter Alexander wrote: >> >>> Hi Robert. I have a branch repo at >>> http://bitbucket.org/travlr/cython-docs . That should suffice for now, >>> I'd think. Unless you all want it differently. >> >> Yes, that's totally fine. Distributed revision control is nice :) >> >>> At this point I've redone the super-structure and am iterating inward. >>> Conciseness is my goal. Let me know, at any time, your thoughts or >>> vision do not coincide with what I do.. >> >> Looks good. I think most of the language basics could be put later, >> with the exception of typing. So the first three sections could be >> overview, data typing, and compilation. After those three, we could >> move on to the topic-specific tutorials. >> >> - Robert >> >> _______________________________________________ >> Cython-dev mailing list >> Cython-dev at codespeak.net >> http://codespeak.net/mailman/listinfo/cython-dev >> > > I look at what I'm working on now as a "reference guide" should be > solely considered as a "get your fingers on the answer, quickly", > guide. > > Basically, what I'm thinking of for this, is a very complete outline > stating the language rules, particulars, etc., with cross-references > galore, indexing, and lots of examples, etc., > > I believe that a multiplicity of documentation sources is a good > thing.. Tutorial, reference, and "papers".. etc, etc. > > Tutorials as introductory "dive-in, and get you hair wet" type, and > acomplete, very well thought out, no-nonsense reference material for > those engaged in their project that "just want the answer that second" > (like me) kind a guy/gal. > > So.. personally I am invested in the reference type, but I totally > think that domain specific tutorials would be great for Cython to > support. And a necessity, you might say. > > But, for now I'd like to concentrate on making the ref guide succinct, > accessible, and most of all... complete. > > I also very much appreciate input from others. So please speak up when > you want to... so we can get this right. > > ~Peter > Now, that I'm thinking about it.. the "overview" could itself be a seperate document. Kind of a like "Getting Started..." or "Welcome..." documentation. I also think that cross-documentation linking is essential, so as to not duplicate information all over the place. So for instance in the "ref" guide, link to the overview... link to general and domain specific material in the tutorials. Link, link, link.. index.. etc.. blah blah blah In other words.. The thought process of "structure" should be inter-documentary. Ok, lets hear comments, ideas, etc... please :) From vel.accel at gmail.com Fri Oct 2 06:46:51 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Fri, 2 Oct 2009 00:46:51 -0400 Subject: [Cython] Updating Documentation In-Reply-To: <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880909300306u1940255ara37e321bc8634b88@mail.gmail.com> <1e52e0880909300327p63bc1fccjf78b58f643454085@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> Message-ID: <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> On Thu, Oct 1, 2009 at 11:27 PM, Peter Alexander wrote: > On Thu, Oct 1, 2009 at 10:13 PM, Peter Alexander wrote: >> On Thu, Oct 1, 2009 at 9:39 PM, Robert Bradshaw >> wrote: >>> On Oct 1, 2009, at 12:21 AM, Peter Alexander wrote: >>> >>>> Hi Robert. I have a branch repo at >>>> http://bitbucket.org/travlr/cython-docs . That should suffice for now, >>>> I'd think. Unless you all want it differently. >>> >>> Yes, that's totally fine. Distributed revision control is nice :) >>> >>>> At this point I've redone the super-structure and am iterating inward. >>>> Conciseness is my goal. Let me know, at any time, your thoughts or >>>> vision do not coincide with what I do.. >>> >>> Looks good. I think most of the language basics could be put later, >>> with the exception of typing. So the first three sections could be >>> overview, data typing, and compilation. After those three, we could >>> move on to the topic-specific tutorials. >>> >>> - Robert >>> >>> _______________________________________________ >>> Cython-dev mailing list >>> Cython-dev at codespeak.net >>> http://codespeak.net/mailman/listinfo/cython-dev >>> >> >> I look at what I'm working on now as a "reference guide" should be >> solely considered as a "get your fingers on the answer, quickly", >> guide. >> >> Basically, what I'm thinking of for this, is a very complete outline >> stating the language rules, particulars, etc., with cross-references >> galore, indexing, and lots of examples, etc., >> >> I believe that a multiplicity of documentation sources is a good >> thing.. Tutorial, reference, and "papers".. etc, etc. >> >> Tutorials as introductory "dive-in, and get you hair wet" type, and >> acomplete, very well thought out, no-nonsense reference material for >> those engaged in their project that "just want the answer that second" >> (like me) kind a guy/gal. >> >> So.. personally I am invested in the reference type, but I totally >> think that domain specific tutorials would be great for Cython to >> support. And a necessity, you might say. >> >> But, for now I'd like to concentrate on making the ref guide succinct, >> accessible, and most of all... complete. >> >> I also very much appreciate input from others. So please speak up when >> you want to... so we can get this right. >> >> ~Peter >> > > Now, that I'm thinking about it.. the "overview" could itself be a > seperate document. Kind of a like "Getting Started..." or "Welcome..." > documentation. > > I also think that cross-documentation linking is essential, so as to > not duplicate information all over the place. So for instance in the > "ref" guide, link to the overview... link to general and domain > specific material in the tutorials. Link, link, link.. index.. etc.. > blah blah blah > > In other words.. The thought process of "structure" should be inter-documentary. > > Ok, lets hear comments, ideas, etc... please :) > I gonna expand on my thoughts here. I think that there should possibly be something like this posted on the documentation section of the static Cython portal page: "Introduction To Cython", "Tutorials", "Reference Guide", "User Guide", "Videos and WebCasts", "White Papers", etc... "Introduction To Cython" would be the overview and introduction including all sorts of introductory topics and links. "Tutorials" would be a self contained sphinx doc with a TOC that includes tutorials of general, topic and domain specific "dive-in and get your hair wet" material. Here we "hold the reader's hand" and walk them through usage. "Reference Guide" would be an elaborate "outline" of facts. Used for fast access to succinct information. "User Guide" would essentially be the reference guide outline but in paragraph form which includes more detailed info, caveats, gotchas. This would help keep the ref guide succinct in that "detail" can be linked to from that document to this document (as well as tutorial sections, etc..) "Videos and Webcasts" would be.. well this is self-explanatory... "White Papers" would be any pdf like documents available.. etc. ..Now, All examples/snippets should be global, in its own directory, so each documentation can "embed" the example it needs. Hell.. if we were sophisticated one day.. video snippets might also be "embedded" or at least linked to. Lastly, of my thoughts for now is, the subject of "search portals". Common, current search technology is one of my pet-peeves in that a search lead you to a page and not to the item context within the page itself. To mitigate this hindrance, I think each topic should reside each within in its own page. Also, to accommodate my vision of inter-documentary documentation a global search engine will be needed. Xapian, could be considered.. it is exceptional with python bindings. Or google or what ever.. I defer. What's your opinion... enquiring minds want to know. :-) From robertwb at math.washington.edu Fri Oct 2 08:16:18 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 1 Oct 2009 23:16:18 -0700 Subject: [Cython] Can't push to repos In-Reply-To: <4AC4FCB8.9040402@student.matnat.uio.no> References: <4AC4FCB8.9040402@student.matnat.uio.no> Message-ID: <95BD00DE-0C2B-437A-968A-B884404ED251@math.washington.edu> On Oct 1, 2009, at 12:02 PM, Dag Sverre Seljebotn wrote: > I get 500 Internal server error on pushes to hg.cython.org. > > I tried running "hg verify" in the cython-unstable folder (by SSHing > into the server) but it didn't show anything. Any other ideas? Looks like everything hosted on sagemath is down right now. Looking into it... - Robert From robertwb at math.washington.edu Fri Oct 2 09:00:25 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Fri, 2 Oct 2009 00:00:25 -0700 Subject: [Cython] Updating Documentation In-Reply-To: <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880909300306u1940255ara37e321bc8634b88@mail.gmail.com> <1e52e0880909300327p63bc1fccjf78b58f643454085@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> Message-ID: <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> On Oct 1, 2009, at 9:46 PM, Peter Alexander wrote: > I look at what I'm working on now as a "reference guide" should be > solely considered as a "get your fingers on the answer, quickly", > guide. > > Basically, what I'm thinking of for this, is a very complete outline > stating the language rules, particulars, etc., with cross-references > galore, indexing, and lots of examples, etc., OK, that helps me see more where you're coming from. I think the two papers we have are more of the tutorial style, but have a lot of good material in them. > So.. personally I am invested in the reference type, but I totally > think that domain specific tutorials would be great for Cython to > support. And a necessity, you might say. > > But, for now I'd like to concentrate on making the ref guide succinct, > accessible, and most of all... complete. Completeness, especially of a moving target, is an ambitious but important goal. [...] > I think that there should possibly be something like this posted on > the documentation section of the static Cython portal page: > "Introduction To Cython", "Tutorials", "Reference Guide", "User > Guide", "Videos and WebCasts", "White Papers", etc... Though I think coming at things from a different angle is good, I worry about having too many different overlapping components (from both a maintenance and generation viewpoint). > "Introduction To Cython" would be the overview and introduction > including all sorts of introductory topics and links. Are you thinking more than a pageful of content, or would this essentially be the front page of the documentation? (I'm leaning towards the latter.) > "Tutorials" would be a self contained sphinx doc with a TOC that > includes tutorials of general, topic and domain specific "dive-in and > get your hair wet" material. Here we "hold the reader's hand" and walk > them through usage. I could see this expanding into the bulk of the documentation, with 2-4 "getting started" sections, and then numerous independent chapters after that as previously mentioned in this thread. Another option is making tutorials like short "quick starts" with the bulk of the meat in the reference manual. I'm leaning against this, but would like feedback. > "Reference Guide" would be an elaborate "outline" of facts. Used for > fast access to succinct information. I could see this containing things such as the list of all compiler directives, syntax particulars, list of builtin types and optimizations, differences between Python and Cython and other stuff that does not fit into a tutorial-like nature. Stuff like buffers should have an entry here, with syntax and a brief overview of how they work and what they're for, with a link to the tutorial section for more. How to use them to accomplish different things doesn't seem to belong in a reference manual. Perhaps gotchas and caviats could go here too. > "User Guide" would essentially be the reference guide outline but in > paragraph form which includes more detailed info, caveats, gotchas. > This would help keep the ref guide succinct in that "detail" can be > linked to from that document to this document (as well as tutorial > sections, etc..) This section seems redundant with tutorial + reference guide. > "Videos and Webcasts" would be.. well this is self-explanatory... > > "White Papers" would be any pdf like documents available.. etc. These two would basically be aggregations of whatever comes up (like the two recent SciPy proceedings submissions). We could probably put a list of slides/talks there as well. > ..Now, All examples/snippets should be global, in its own directory, > so each documentation can "embed" the example it needs. Hell.. if we > were sophisticated one day.. video snippets might also be "embedded" > or at least linked to. Does sphinx have the ability to embed external code snippets? I think it's important to have actual snippets in the documentation itself, ideally with links to 1. entire working program directories (complete with build scripts) 2. Annotated (-a html output) versions and 3. Sage notebooks (to make it easy to try out and play with while you're reading the documentation) and 4. somewhere that we can run regression tests on. > Lastly, of my thoughts for now is, the subject of "search portals". > Common, current search technology is one of my pet-peeves in that a > search lead you to a page and not to the item context within the page > itself. To mitigate this hindrance, I think each topic should reside > each within in its own page. Also, to accommodate my vision of > inter-documentary documentation a global search engine will be needed. > Xapian, could be considered.. it is exceptional with python bindings. > Or google or what ever.. I defer. I personally hate tutorials where I have to keep clicking "next" instead of scrolling down, but we could experiment with both. Another note on this--the table of contents in the header of the page and each section is quite bulky--it'd be nice to only have it in the sidebar. - Robert From vel.accel at gmail.com Fri Oct 2 09:51:03 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Fri, 2 Oct 2009 03:51:03 -0400 Subject: [Cython] Updating Documentation In-Reply-To: <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> Message-ID: <1e52e0880910020051k2cfe14ebw875c752e344d705b@mail.gmail.com> On Fri, Oct 2, 2009 at 3:00 AM, Robert Bradshaw wrote: > On Oct 1, 2009, at 9:46 PM, Peter Alexander wrote: > >> I look at what I'm working on now as a "reference guide" should be >> solely considered as a "get your fingers on the answer, quickly", >> guide. >> >> Basically, what I'm thinking of for this, is a very complete outline >> stating the language rules, particulars, etc., with cross-references >> galore, indexing, and lots of examples, etc., > > OK, that helps me see more where you're coming from. I think the two > papers we have are more of the tutorial style, but have a lot of good > material in them. I think there is excellent material in them. I'm just the kind of guy who only likes to read through verbosity when I want to, not that I should have to.. in order to get to the vital piece of information I'm striving to find at that moment. This is personal peeve that is general to all information retrieval and should not be considered specific to anything here. > >> So.. personally I am invested in the reference type, but I totally >> think that domain specific tutorials would be great for Cython to >> support. And a necessity, you might say. >> >> But, for now I'd like to concentrate on making the ref guide succinct, >> accessible, and most of all... complete. > > Completeness, especially of a moving target, is an ambitious but > important goal. Eventually we might consider Numpy's documentation approach and guidelines. Although Cython is not a library where an API is dominant, but instead a language, I think we might still glean an approach from them as to easy documentation updating... for constant completeness. > > [...] > >> I think that there should possibly be something like this posted on >> the documentation section of the static Cython portal page: >> "Introduction To Cython", "Tutorials", "Reference Guide", "User >> Guide", "Videos and WebCasts", "White Papers", etc... > > Though I think coming at things from a different angle is good, I > worry about having too many different overlapping components (from > both a maintenance and generation viewpoint). Oh yeah, +1, me too. Maybe an MVC type approach can be utilized. Let me investigate and think about this a little bit. Considering the api is not dominant to Cython users, reST inlined with the code source is not the right approach. > >> "Introduction To Cython" would be the overview and introduction >> including all sorts of introductory topics and links. > > Are you thinking more than a pageful of content, or would this > essentially be the front page of the documentation? (I'm leaning > towards the latter.) Yes, front page is certainly adequate. In fact I have no theoretical objection to an entire, single document structure either... I'm just rambling thoughts as I go. > >> "Tutorials" would be a self contained sphinx doc with a TOC that >> includes tutorials of general, topic and domain specific "dive-in and >> get your hair wet" material. Here we "hold the reader's hand" and walk >> them through usage. > > I could see this expanding into the bulk of the documentation, with > 2-4 "getting started" sections, and then numerous independent > chapters after that as previously mentioned in this thread. > > Another option is making tutorials like short "quick starts" with the > bulk of the meat in the reference manual. I'm leaning against this, > but would like feedback. My attitude is whatever works best gets my support. My view point is from "the guy who wants an answer to a question NOW", and doesn't want to have to search forever to find it. However that is accomplished suits me greatly. Beyond that, I want what will be considered to work best for the subjective user. > >> "Reference Guide" would be an elaborate "outline" of facts. Used for >> fast access to succinct information. > > I could see this containing things such as the list of all compiler > directives, syntax particulars, list of builtin types and > optimizations, differences between Python and Cython and other stuff > that does not fit into a tutorial-like nature. Stuff like buffers > should have an entry here, with syntax and a brief overview of how > they work and what they're for, with a link to the tutorial section > for more. How to use them to accomplish different things doesn't seem > to belong in a reference manual. Perhaps gotchas and caviats could go > here too. +1. Succinct, navigable, and complete... are the necessary requirements, imho. However that is best achieved is great. > >> "User Guide" would essentially be the reference guide outline but in >> paragraph form which includes more detailed info, caveats, gotchas. >> This would help keep the ref guide succinct in that "detail" can be >> linked to from that document to this document (as well as tutorial >> sections, etc..) > > This section seems redundant with tutorial + reference guide. Agreed. I was just trying to solve a way to keep verbosity out of the ref guide. > >> "Videos and Webcasts" would be.. well this is self-explanatory... >> >> "White Papers" would be any pdf like documents available.. etc. > > These two would basically be aggregations of whatever comes up (like > the two recent SciPy proceedings submissions). We could probably put > a list of slides/talks there as well. > >> ..Now, All examples/snippets should be global, in its own directory, >> so each documentation can "embed" the example it needs. Hell.. if we >> were sophisticated one day.. video snippets might also be "embedded" >> or at least linked to. > > Does sphinx have the ability to embed external code snippets? I think > it's important to have actual snippets in the documentation itself, > ideally with links to 1. entire working program directories (complete > with build scripts) 2. Annotated (-a html output) versions and 3. > Sage notebooks (to make it easy to try out and play with while you're > reading the documentation) and 4. somewhere that we can run > regression tests on. Yes, absolute embedding is crucial and +1 on the rest. > >> Lastly, of my thoughts for now is, the subject of "search portals". >> Common, current search technology is one of my pet-peeves in that a >> search lead you to a page and not to the item context within the page >> itself. To mitigate this hindrance, I think each topic should reside >> each within in its own page. Also, to accommodate my vision of >> inter-documentary documentation a global search engine will be needed. >> Xapian, could be considered.. it is exceptional with python bindings. >> Or google or what ever.. I defer. > > I personally hate tutorials where I have to keep clicking "next" > instead of scrolling down, but we could experiment with both. Another > note on this--the table of contents in the header of the page and > each section is quite bulky--it'd be nice to only have it in the > sidebar. Yes, I agree with "next-itus" too. I just want to figure out a way to eliminate the valuable time it takes to obtain a particular piece of information. How we get there should be our focus. So, thank you very much for all your input. ..As sort of an ironic side note... My model for decent navigable documentation has always been Trolltech/Nokia's Qt framework, which I just noticed will be re-designing their doc structure [1] . [1] http://labs.trolltech.com/blogs/2009/09/28/giving-the-doc-a-facelift/ ~Pete > > - Robert > > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > From dagss at student.matnat.uio.no Fri Oct 2 09:59:12 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 02 Oct 2009 09:59:12 +0200 Subject: [Cython] Updating Documentation In-Reply-To: <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880909300306u1940255ara37e321bc8634b88@mail.gmail.com> <1e52e0880909300327p63bc1fccjf78b58f643454085@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> Message-ID: <4AC5B2D0.7070705@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 1, 2009, at 9:46 PM, Peter Alexander wrote: > > >> "Tutorials" would be a self contained sphinx doc with a TOC that >> includes tutorials of general, topic and domain specific "dive-in and >> get your hair wet" material. Here we "hold the reader's hand" and walk >> them through usage. >> > > I could see this expanding into the bulk of the documentation, with > 2-4 "getting started" sections, and then numerous independent > chapters after that as previously mentioned in this thread. > > Another option is making tutorials like short "quick starts" with the > bulk of the meat in the reference manual. I'm leaning against this, > but would like feedback. > > >> "Reference Guide" would be an elaborate "outline" of facts. Used for >> fast access to succinct information. >> > > I could see this containing things such as the list of all compiler > directives, syntax particulars, list of builtin types and > optimizations, differences between Python and Cython and other stuff > that does not fit into a tutorial-like nature. Stuff like buffers > should have an entry here, with syntax and a brief overview of how > they work and what they're for, with a link to the tutorial section > for more. How to use them to accomplish different things doesn't seem > to belong in a reference manual. Perhaps gotchas and caviats could go > here too. > > >> "User Guide" would essentially be the reference guide outline but in >> paragraph form which includes more detailed info, caveats, gotchas. >> This would help keep the ref guide succinct in that "detail" can be >> linked to from that document to this document (as well as tutorial >> sections, etc..) >> > > This section seems redundant with tutorial + reference guide. > I think that it would not be entirely redundant; some other projects have user guides and it tends to work well. However it is a question of how much we are able to do -- even creating it is a lot of work, but (much worse) then it has to be maintained for years to come too. So I agree that we should avoid this one, at least until the other points on the list are done. I think everything else proposed by Peter looks great. >> ..Now, All examples/snippets should be global, in its own directory, >> so each documentation can "embed" the example it needs. Hell.. if we >> were sophisticated one day.. video snippets might also be "embedded" >> or at least linked to. >> > > Does sphinx have the ability to embed external code snippets? I think > it's important to have actual snippets in the documentation itself, > ideally with links to 1. entire working program directories (complete > with build scripts) 2. Annotated (-a html output) versions and 3. > Sage notebooks (to make it easy to try out and play with while you're > reading the documentation) and 4. somewhere that we can run > regression tests on. > The matplotlib project has very good experience with some exciting stuff that's kind of related (their entire web page is made with Sphinx). They wrote a plugin to sphinx for a new code block tag (in the rst file in the documentation). When encountered, Sphinx a) presents the code as syntax-highlighted Python, b) executes the code and retrieves the generated plot and present it. By adapting such a plugin for our needs, a special tag can be used to embed Cython code, which at least syntax-highlights and makes "cython -a" easily available; perhaps also presents a link to a Sage worksheet with the code. Automatically benchmarking Cython examples comes to mind too and would make it easier to write tutorials etc (although that means documentation must be rebuilt under benchmark conditions (no other load, always rebuild everything on the same machine) which is a serious drawback). The great thing is that everything stays in the ReST documents and is easily rebuildable. An idea for Peter or Minh for now is to at least look into making :cython:: available as a ReST tag and start using it -- even if it has no effect currently, that will make it easier to introduce features like that later on. I'll try to dig up the sources for the matplotlib Sphinx extension. Dag Sverre From stefan_ml at behnel.de Fri Oct 2 10:03:51 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 02 Oct 2009 10:03:51 +0200 Subject: [Cython] Updating Documentation In-Reply-To: <1e52e0880910020051k2cfe14ebw875c752e344d705b@mail.gmail.com> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> <1e52e0880910020051k2cfe14ebw875c752e344d705b@mail.gmail.com> Message-ID: <4AC5B3E7.3090201@behnel.de> Peter Alexander wrote: > Considering the api is not dominant to Cython users, reST inlined with > the code source is not the right approach. Well, the examples are there to present Cython code. I don't see how this makes inlined code the wrong approach. It even has the advantage of allowing to split the code around explanatory text sections. The only problem I see is that it's harder to test as doctest doesn't currently work for Cython code. But that could be helped by extracting the code from the document into a module first. The problem I see with an MVC approach (I assume you considered writing the example code with text injection hooks) is that they'd loose the context. The examples don't make much sense without the surrounding text that explains what's interesting about them. And if they do, they may not be good examples in the first place, as they're likely too broad. Stefan From dagss at student.matnat.uio.no Fri Oct 2 10:16:06 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 02 Oct 2009 10:16:06 +0200 Subject: [Cython] Updating Documentation In-Reply-To: <4AC5B2D0.7070705@student.matnat.uio.no> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880909300306u1940255ara37e321bc8634b88@mail.gmail.com> <1e52e0880909300327p63bc1fccjf78b58f643454085@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> <4AC5B2D0.7070705@student.matnat.uio.no> Message-ID: <4AC5B6C6.9050706@student.matnat.uio.no> Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: > >> On Oct 1, 2009, at 9:46 PM, Peter Alexander wrote: >> >> >>> ..Now, All examples/snippets should be global, in its own directory, >>> so each documentation can "embed" the example it needs. Hell.. if we >>> were sophisticated one day.. video snippets might also be "embedded" >>> or at least linked to. >>> >>> >> Does sphinx have the ability to embed external code snippets? I think >> it's important to have actual snippets in the documentation itself, >> ideally with links to 1. entire working program directories (complete >> with build scripts) 2. Annotated (-a html output) versions and 3. >> Sage notebooks (to make it easy to try out and play with while you're >> reading the documentation) and 4. somewhere that we can run >> regression tests on. >> >> > The matplotlib project has very good experience with some exciting stuff > that's kind of related (their entire web page is made with Sphinx). They > wrote a plugin to sphinx for a new code block tag (in the rst file in > the documentation). When encountered, Sphinx a) presents the code as > syntax-highlighted Python, b) executes the code and retrieves the > generated plot and present it. > > By adapting such a plugin for our needs, a special tag can be used to > embed Cython code, which at least syntax-highlights and makes "cython > -a" easily available; perhaps also presents a link to a Sage worksheet > with the code. Automatically benchmarking Cython examples comes to mind > too and would make it easier to write tutorials etc (although that means > documentation must be rebuilt under benchmark conditions (no other load, > always rebuild everything on the same machine) which is a serious drawback). > > The great thing is that everything stays in the ReST documents and is > easily rebuildable. > > An idea for Peter or Minh for now is to at least look into making > :cython:: available as a ReST tag and start using it -- even if it has > no effect currently, that will make it easier to introduce features like > that later on. > > I'll try to dig up the sources for the matplotlib Sphinx extension. > I must say I'm really keen on having code snippets embedded into ReST text (and rather automatically exported as files), rather than the other way around. A link to matplotlib's Sphinx extensions: http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py?view=markup http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/sphinxext/ Longwinded example of what could be done. """ Simple demo ========= .. cython:: :name: example2 :hidden: True # This stuff is not shown in docs as people's got used to them being there by # this point in the tutorial. However it ends up in the generated "example2.pyx". cimport cython # Other blocks with the same name are appended later. We start with making a function: .. cython:: :name: example 2 def myfunc(x): return x * 2 This is now available from Python: .. pythonshell:: >>> import example2 >>> example2.myfunc(2) .. Note that above we don't need to enter output, that is generated by Sphinx. However, a cdef function is not available: .. cython:: :name: example2 cdef mycdef(x): return x * 2 .. pythonshell:: :continue: True >>> example2.mycdef(3) """ In the end, example2.pyx and setup.py is generated by concatenating the chunks and offered for download. From vel.accel at gmail.com Fri Oct 2 10:32:32 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Fri, 2 Oct 2009 04:32:32 -0400 Subject: [Cython] Updating Documentation In-Reply-To: <4AC5B6C6.9050706@student.matnat.uio.no> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> <4AC5B2D0.7070705@student.matnat.uio.no> <4AC5B6C6.9050706@student.matnat.uio.no> Message-ID: <1e52e0880910020132y70c075fet7e93dd62f63931a9@mail.gmail.com> On Fri, Oct 2, 2009 at 4:16 AM, Dag Sverre Seljebotn wrote: > Dag Sverre Seljebotn wrote: >> Robert Bradshaw wrote: >> >>> On Oct 1, 2009, at 9:46 PM, Peter Alexander wrote: >>> >>> >>>> ..Now, All examples/snippets should be global, in its own directory, >>>> so each documentation can "embed" the example it needs. Hell.. if we >>>> were sophisticated one day.. video snippets might also be "embedded" >>>> or at least linked to. >>>> >>>> >>> Does sphinx have the ability to embed external code snippets? I think >>> it's important to have actual snippets in the documentation itself, >>> ideally with links to 1. entire working program directories (complete >>> with build scripts) 2. Annotated (-a html output) versions and 3. >>> Sage notebooks (to make it easy to try out and play with while you're >>> reading the documentation) and 4. somewhere that we can run >>> regression tests on. >>> >>> >> The matplotlib project has very good experience with some exciting stuff >> that's kind of related (their entire web page is made with Sphinx). They >> wrote a plugin to sphinx for a new code block tag (in the rst file in >> the documentation). When encountered, Sphinx a) presents the code as >> syntax-highlighted Python, b) executes the code and retrieves the >> generated plot and present it. >> >> By adapting such a plugin for our needs, a special tag can be used to >> embed Cython code, which at least syntax-highlights and makes "cython >> -a" easily available; perhaps also presents a link to a Sage worksheet >> with the code. Automatically benchmarking Cython examples comes to mind >> too and would make it easier to write tutorials etc (although that means >> documentation must be rebuilt under benchmark conditions (no other load, >> always rebuild everything on the same machine) which is a serious drawback). >> >> The great thing is that everything stays in the ReST documents and is >> easily rebuildable. >> >> An idea for Peter or Minh for now is to at least look into making >> :cython:: available as a ReST tag and start using it -- even if it has >> no effect currently, that will make it easier to introduce features like >> that later on. >> >> I'll try to dig up the sources for the matplotlib Sphinx extension. >> > I must say I'm really keen on having code snippets embedded into ReST > text (and rather automatically exported as files), rather than the other > way around. A link to matplotlib's Sphinx extensions: > > http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py?view=markup > http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/sphinxext/ > > > Longwinded example of what could be done. > > """ > Simple demo > ========= > > .. cython:: > ? ?:name: example2 > ? ?:hidden: True > > ? ?# This stuff is not shown in docs as people's got used to them being > there by > ? ?# this point in the tutorial. However it ends up in the generated > "example2.pyx". > ? ?cimport cython > ? ?# Other blocks with the same name are appended later. > > We start with making a function: > > .. cython:: > ? ?:name: example 2 > > ? ?def myfunc(x): > ? ? ? ?return x * 2 > > This is now available from Python: > > .. pythonshell:: > ? ?>>> import example2 > ? ?>>> example2.myfunc(2) > > .. Note that above we don't need to enter output, that is generated by > Sphinx. > > However, a cdef function is not available: > > .. cython:: > ? ?:name: example2 > > ? ?cdef mycdef(x): > ? ? ? ?return x * 2 > > .. pythonshell:: > ? ?:continue: True > > ? ?>>> example2.mycdef(3) > > """ > > In the end, example2.pyx and setup.py is generated by concatenating the > chunks and offered for download. > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > Putting my creative hat on... Would be nice to just be able to toss "chunks" of information into a directory pool, that can be automatically structured to a view, by a "documentation structure model"? That way upkeep could be made more simple because all you'd have to worry about is tossing in the "chunk". That's kind of what I mean by an MVC model. From dagss at student.matnat.uio.no Fri Oct 2 10:46:10 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 02 Oct 2009 10:46:10 +0200 Subject: [Cython] Updating Documentation In-Reply-To: <1e52e0880910020132y70c075fet7e93dd62f63931a9@mail.gmail.com> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> <4AC5B2D0.7070705@student.matnat.uio.no> <4AC5B6C6.9050706@student.matnat.uio.no> <1e52e0880910020132y70c075fet7e93dd62f63931a9@mail.gmail.com> Message-ID: <4AC5BDD2.90704@student.matnat.uio.no> Peter Alexander wrote: > On Fri, Oct 2, 2009 at 4:16 AM, Dag Sverre Seljebotn > wrote: > >> Dag Sverre Seljebotn wrote: >> >>> Robert Bradshaw wrote: >>> >>> >>>> On Oct 1, 2009, at 9:46 PM, Peter Alexander wrote: >>>> >>>> >>>> >>>>> ..Now, All examples/snippets should be global, in its own directory, >>>>> so each documentation can "embed" the example it needs. Hell.. if we >>>>> were sophisticated one day.. video snippets might also be "embedded" >>>>> or at least linked to. >>>>> >>>>> >>>>> >>>> Does sphinx have the ability to embed external code snippets? I think >>>> it's important to have actual snippets in the documentation itself, >>>> ideally with links to 1. entire working program directories (complete >>>> with build scripts) 2. Annotated (-a html output) versions and 3. >>>> Sage notebooks (to make it easy to try out and play with while you're >>>> reading the documentation) and 4. somewhere that we can run >>>> regression tests on. >>>> >>>> >>>> >>> The matplotlib project has very good experience with some exciting stuff >>> that's kind of related (their entire web page is made with Sphinx). They >>> wrote a plugin to sphinx for a new code block tag (in the rst file in >>> the documentation). When encountered, Sphinx a) presents the code as >>> syntax-highlighted Python, b) executes the code and retrieves the >>> generated plot and present it. >>> >>> By adapting such a plugin for our needs, a special tag can be used to >>> embed Cython code, which at least syntax-highlights and makes "cython >>> -a" easily available; perhaps also presents a link to a Sage worksheet >>> with the code. Automatically benchmarking Cython examples comes to mind >>> too and would make it easier to write tutorials etc (although that means >>> documentation must be rebuilt under benchmark conditions (no other load, >>> always rebuild everything on the same machine) which is a serious drawback). >>> >>> The great thing is that everything stays in the ReST documents and is >>> easily rebuildable. >>> >>> An idea for Peter or Minh for now is to at least look into making >>> :cython:: available as a ReST tag and start using it -- even if it has >>> no effect currently, that will make it easier to introduce features like >>> that later on. >>> >>> I'll try to dig up the sources for the matplotlib Sphinx extension. >>> >>> >> I must say I'm really keen on having code snippets embedded into ReST >> text (and rather automatically exported as files), rather than the other >> way around. A link to matplotlib's Sphinx extensions: >> >> http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py?view=markup >> http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/sphinxext/ >> >> >> Longwinded example of what could be done. >> >> """ >> Simple demo >> ========= >> >> .. cython:: >> :name: example2 >> :hidden: True >> >> # This stuff is not shown in docs as people's got used to them being >> there by >> # this point in the tutorial. However it ends up in the generated >> "example2.pyx". >> cimport cython >> # Other blocks with the same name are appended later. >> >> We start with making a function: >> >> .. cython:: >> :name: example 2 >> >> def myfunc(x): >> return x * 2 >> >> This is now available from Python: >> >> .. pythonshell:: >> >>> import example2 >> >>> example2.myfunc(2) >> >> .. Note that above we don't need to enter output, that is generated by >> Sphinx. >> >> However, a cdef function is not available: >> >> .. cython:: >> :name: example2 >> >> cdef mycdef(x): >> return x * 2 >> >> .. pythonshell:: >> :continue: True >> >> >>> example2.mycdef(3) >> >> """ >> >> In the end, example2.pyx and setup.py is generated by concatenating the >> chunks and offered for download. >> _______________________________________________ >> Cython-dev mailing list >> Cython-dev at codespeak.net >> http://codespeak.net/mailman/listinfo/cython-dev >> >> > > Putting my creative hat on... > > Would be nice to just be able to toss "chunks" of information into a > directory pool, that can be automatically structured to a view, by a > "documentation structure model"? > > That way upkeep could be made more simple because all you'd have to > worry about is tossing in the "chunk". > > That's kind of what I mean by an MVC model. > OK, I see where you are coming from. As usual my suggestions are mostly with tutorials in mind. Other projects can do this in a great way by making the docstrings in the codebase their chunks. That doesn't *quite* all the time with Cython, but I think it could work great in some types of situations. Experiment: class WraparoundDirective(CompilerDirective): # in Options.py """ wraparound information about the wraparound compiler directive """ class ForInStatNode(Node): # In Nodes.py """ Python-style for-loop more info TAGS: pythoncompatible, loops """ Some transforms would fit for documenting language features as well: class ForloopOptimizations(CythonTransform): """ Optimizations done to for-loops: - for in range is ... """ Then, a pragmatic, non-pure "documentation structure model" could simply be ReST documentation with some codes for grabbing the chunks from the codebase: .. docstring:: ForInStatNode or perhaps .. docstring-table:: :subclassesof: CompilerDirective .. docstring-table:: :tag: pythoncompatible Dag Sverre From vel.accel at gmail.com Fri Oct 2 10:55:44 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Fri, 2 Oct 2009 04:55:44 -0400 Subject: [Cython] Updating Documentation In-Reply-To: <4AC5BDD2.90704@student.matnat.uio.no> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> <4AC5B2D0.7070705@student.matnat.uio.no> <4AC5B6C6.9050706@student.matnat.uio.no> <1e52e0880910020132y70c075fet7e93dd62f63931a9@mail.gmail.com> <4AC5BDD2.90704@student.matnat.uio.no> Message-ID: <1e52e0880910020155h1853fdd6w124b825f9b524745@mail.gmail.com> On Fri, Oct 2, 2009 at 4:46 AM, Dag Sverre Seljebotn wrote: > Peter Alexander wrote: >> On Fri, Oct 2, 2009 at 4:16 AM, Dag Sverre Seljebotn >> wrote: >> >>> Dag Sverre Seljebotn wrote: >>> >>>> Robert Bradshaw wrote: >>>> >>>> >>>>> On Oct 1, 2009, at 9:46 PM, Peter Alexander wrote: >>>>> >>>>> >>>>> >>>>>> ..Now, All examples/snippets should be global, in its own directory, >>>>>> so each documentation can "embed" the example it needs. Hell.. if we >>>>>> were sophisticated one day.. video snippets might also be "embedded" >>>>>> or at least linked to. >>>>>> >>>>>> >>>>>> >>>>> Does sphinx have the ability to embed external code snippets? I think >>>>> it's important to have actual snippets in the documentation itself, >>>>> ideally with links to 1. entire working program directories (complete >>>>> with build scripts) 2. Annotated (-a html output) versions and 3. >>>>> Sage notebooks (to make it easy to try out and play with while you're >>>>> reading the documentation) and 4. somewhere that we can run >>>>> regression tests on. >>>>> >>>>> >>>>> >>>> The matplotlib project has very good experience with some exciting stuff >>>> that's kind of related (their entire web page is made with Sphinx). They >>>> wrote a plugin to sphinx for a new code block tag (in the rst file in >>>> the documentation). When encountered, Sphinx a) presents the code as >>>> syntax-highlighted Python, b) executes the code and retrieves the >>>> generated plot and present it. >>>> >>>> By adapting such a plugin for our needs, a special tag can be used to >>>> embed Cython code, which at least syntax-highlights and makes "cython >>>> -a" easily available; perhaps also presents a link to a Sage worksheet >>>> with the code. Automatically benchmarking Cython examples comes to mind >>>> too and would make it easier to write tutorials etc (although that means >>>> documentation must be rebuilt under benchmark conditions (no other load, >>>> always rebuild everything on the same machine) which is a serious drawback). >>>> >>>> The great thing is that everything stays in the ReST documents and is >>>> easily rebuildable. >>>> >>>> An idea for Peter or Minh for now is to at least look into making >>>> :cython:: available as a ReST tag and start using it -- even if it has >>>> no effect currently, that will make it easier to introduce features like >>>> that later on. >>>> >>>> I'll try to dig up the sources for the matplotlib Sphinx extension. >>>> >>>> >>> I must say I'm really keen on having code snippets embedded into ReST >>> text (and rather automatically exported as files), rather than the other >>> way around. A link to matplotlib's Sphinx extensions: >>> >>> http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/sphinxext/plot_directive.py?view=markup >>> http://matplotlib.svn.sourceforge.net/viewvc/matplotlib/trunk/matplotlib/lib/matplotlib/sphinxext/ >>> >>> >>> Longwinded example of what could be done. >>> >>> """ >>> Simple demo >>> ========= >>> >>> .. cython:: >>> ? ?:name: example2 >>> ? ?:hidden: True >>> >>> ? ?# This stuff is not shown in docs as people's got used to them being >>> there by >>> ? ?# this point in the tutorial. However it ends up in the generated >>> "example2.pyx". >>> ? ?cimport cython >>> ? ?# Other blocks with the same name are appended later. >>> >>> We start with making a function: >>> >>> .. cython:: >>> ? ?:name: example 2 >>> >>> ? ?def myfunc(x): >>> ? ? ? ?return x * 2 >>> >>> This is now available from Python: >>> >>> .. pythonshell:: >>> ? ?>>> import example2 >>> ? ?>>> example2.myfunc(2) >>> >>> .. Note that above we don't need to enter output, that is generated by >>> Sphinx. >>> >>> However, a cdef function is not available: >>> >>> .. cython:: >>> ? ?:name: example2 >>> >>> ? ?cdef mycdef(x): >>> ? ? ? ?return x * 2 >>> >>> .. pythonshell:: >>> ? ?:continue: True >>> >>> ? ?>>> example2.mycdef(3) >>> >>> """ >>> >>> In the end, example2.pyx and setup.py is generated by concatenating the >>> chunks and offered for download. >>> _______________________________________________ >>> Cython-dev mailing list >>> Cython-dev at codespeak.net >>> http://codespeak.net/mailman/listinfo/cython-dev >>> >>> >> >> Putting my creative hat on... >> >> Would be nice to just be able to toss "chunks" of information into a >> directory pool, that can be automatically structured to a view, by a >> "documentation structure model"? >> >> That way upkeep could be made more simple because all you'd have to >> worry about is tossing in the "chunk". >> >> That's kind of what I mean by an MVC model. >> > OK, I see where you are coming from. As usual my suggestions are mostly > with tutorials in mind. > > Other projects can do this in a great way by making the docstrings in > the codebase their chunks. That doesn't *quite* all the time with > Cython, but I think it could work great in some types of situations. > > Experiment: > > class WraparoundDirective(CompilerDirective): # in Options.py > ? ?""" > ? ?wraparound > > ? ?information about the wraparound compiler directive > ? ?""" > > class ForInStatNode(Node): # In Nodes.py > ? """ > ? Python-style for-loop > > ? more info > > ? TAGS: pythoncompatible, loops > ? """ > > > Some transforms would fit for documenting language features as well: > > class ForloopOptimizations(CythonTransform): > ? ?""" > ? ?Optimizations done to for-loops: > > ? ? ? - for in range is ... > ? ?""" > > > Then, a pragmatic, non-pure "documentation structure model" could simply > be ReST documentation with some codes for grabbing the chunks from the > codebase: > > .. docstring:: ForInStatNode > > or perhaps > > .. docstring-table:: > ? ?:subclassesof: CompilerDirective > > .. docstring-table:: > ? ?:tag: pythoncompatible > > Dag Sverre > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > Is this a practical and like-able idea? should we investigate going along this route? I'm gonna look into making custom sphinx directives, which I haven't done before.. look at what numpy, matplotlib and others are doing with custom directives. I feel we should seriously consider it over a pita to upkeep, one-off doc creation scenario. More comments most welcome.. :) From robertwb at math.washington.edu Fri Oct 2 10:56:06 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Fri, 2 Oct 2009 01:56:06 -0700 Subject: [Cython] Updating Documentation In-Reply-To: <4AC5B2D0.7070705@student.matnat.uio.no> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880909300306u1940255ara37e321bc8634b88@mail.gmail.com> <1e52e0880909300327p63bc1fccjf78b58f643454085@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> <4AC5B2D0.7070705@student.matnat.uio.no> Message-ID: <3CA75457-B053-4657-A282-B760F62B921F@math.washington.edu> On Oct 2, 2009, at 12:59 AM, Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: >> On Oct 1, 2009, at 9:46 PM, Peter Alexander wrote: >> >>> "User Guide" would essentially be the reference guide outline but in >>> paragraph form which includes more detailed info, caveats, gotchas. >>> This would help keep the ref guide succinct in that "detail" can be >>> linked to from that document to this document (as well as tutorial >>> sections, etc..) >> >> This section seems redundant with tutorial + reference guide. >> > I think that it would not be entirely redundant; some other projects > have user guides and it tends to work well. However it is a > question of > how much we are able to do -- even creating it is a lot of work, but > (much worse) then it has to be maintained for years to come too. > > So I agree that we should avoid this one, at least until the other > points on the list are done. I should clarify--I imagine our "tutorials" to have somewhat of a users guide feel (as opposed to a task solving feel). > The matplotlib project has very good experience with some exciting > stuff > that's kind of related (their entire web page is made with Sphinx). > They > wrote a plugin to sphinx for a new code block tag (in the rst file in > the documentation). When encountered, Sphinx a) presents the code as > syntax-highlighted Python, b) executes the code and retrieves the > generated plot and present it. > > By adapting such a plugin for our needs, a special tag can be used to > embed Cython code, which at least syntax-highlights and makes "cython > -a" easily available; perhaps also presents a link to a Sage worksheet > with the code. Automatically benchmarking Cython examples comes to > mind > too and would make it easier to write tutorials etc (although that > means > documentation must be rebuilt under benchmark conditions (no other > load, > always rebuild everything on the same machine) which is a serious > drawback). > > The great thing is that everything stays in the ReST documents and is > easily rebuildable. That sounds nice. > I must say I'm really keen on having code snippets embedded into ReST > text (and rather automatically exported as files), rather than the > other > way around. Me too. I like your example of using :hidden and constructing whole files--I didn't know you could do that. Sounds perfect (for the tutorials at least). - Robert From robertwb at math.washington.edu Fri Oct 2 11:06:00 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Fri, 2 Oct 2009 02:06:00 -0700 Subject: [Cython] Updating Documentation In-Reply-To: <4AC5BDD2.90704@student.matnat.uio.no> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> <4AC5B2D0.7070705@student.matnat.uio.no> <4AC5B6C6.9050706@student.matnat.uio.no> <1e52e0880910020132y70c075fet7e93dd62f63931a9@mail.gmail.com> <4AC5BDD2.90704@student.matnat.uio.no> Message-ID: On Oct 2, 2009, at 1:46 AM, Dag Sverre Seljebotn wrote: > Peter Alexander wrote: >> >> Putting my creative hat on... >> >> Would be nice to just be able to toss "chunks" of information into a >> directory pool, that can be automatically structured to a view, by a >> "documentation structure model"? >> >> That way upkeep could be made more simple because all you'd have to >> worry about is tossing in the "chunk". >> >> That's kind of what I mean by an MVC model. It almost sounds like you want a big glorified index. (I'm not saying that's a bad thing, and it certainly would fit your bill of being able to look stuff up fast.) > OK, I see where you are coming from. As usual my suggestions are > mostly > with tutorials in mind. > > Other projects can do this in a great way by making the docstrings in > the codebase their chunks. We do that in Sage and it works very well--the reference manual is thousands of pages long, nearly all from function docstrings. > That doesn't *quite* all the time with > Cython, but I think it could work great in some types of situations. > > Experiment: > > class WraparoundDirective(CompilerDirective): # in Options.py > """ > wraparound > > information about the wraparound compiler directive > """ > > class ForInStatNode(Node): # In Nodes.py > """ > Python-style for-loop > > more info > > TAGS: pythoncompatible, loops > """ > > > Some transforms would fit for documenting language features as well: > > class ForloopOptimizations(CythonTransform): > """ > Optimizations done to for-loops: > > - for in range is ... > """ No offense intended (as this was clearly marked as an experiment) but I have to admit this feels rather contrived, especially if we end up making classes/structuring code just to hold the docstrings of user- level abstractions. I think it would lead to a sparse scattering of documentation throughout the codebase (most of the code does *not* need to be exposed to the user documentation, e.g. all the Nodes that represent Python nodes, and most transforms). The comments/doctests in the code should probably be about the code itself (useful to a cython developer, but probably not to a cython user). - Robert From dagss at student.matnat.uio.no Fri Oct 2 11:06:56 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 02 Oct 2009 11:06:56 +0200 Subject: [Cython] Updating Documentation In-Reply-To: <3CA75457-B053-4657-A282-B760F62B921F@math.washington.edu> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880909300306u1940255ara37e321bc8634b88@mail.gmail.com> <1e52e0880909300327p63bc1fccjf78b58f643454085@mail.gmail.com> <4AC338AE.1010404@student.matnat.uio.no> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> <4AC5B2D0.7070705@student.matnat.uio.no> <3CA75457-B053-4657-A282-B760F62B921F@math.washington.edu> Message-ID: <4AC5C2B0.5090005@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 2, 2009, at 12:59 AM, Dag Sverre Seljebotn wrote: > > > > >> I must say I'm really keen on having code snippets embedded into ReST >> text (and rather automatically exported as files), rather than the >> other >> way around. >> > > > Me too. I like your example of using :hidden and constructing whole > files--I didn't know you could do that. Sounds perfect (for the > tutorials at least). > Basically I think you are just fed everything (arguments + body) of a ReST tag, and are expected to supply a replacement ReST string. So you can do anything. Worst-case sceneario, two passes through the docs would be needed, one to create the whole file...I don't know, but that's not too horrible. So I just invented something. Come to think of it, I'd like #SHOW, #HIDE and #SNIP instructions in Cython source instead so that the number of ReST tags can be reduced. Dag Sverre From robertwb at math.washington.edu Fri Oct 2 11:09:27 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Fri, 2 Oct 2009 02:09:27 -0700 Subject: [Cython] Updating Documentation In-Reply-To: References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> <4AC5B2D0.7070705@student.matnat.uio.no> <4AC5B6C6.9050706@student.matnat.uio.no> <1e52e0880910020132y70c075fet7e93dd62f63931a9@mail.gmail.com> <4AC5BDD2.90704@student.matnat.uio.no> Message-ID: <978905F9-B728-4E2B-824F-2FEED13DB33B@math.washington.edu> > > > We do that in Sage and it works very well--the reference manual is > thousands of pages long, nearly all from function docstrings. > >> That doesn't *quite* all the time with >> Cython, but I think it could work great in some types of situations. >> >> Experiment: >> >> class WraparoundDirective(CompilerDirective): # in Options.py >> """ >> wraparound >> >> information about the wraparound compiler directive >> """ >> >> class ForInStatNode(Node): # In Nodes.py >> """ >> Python-style for-loop >> >> more info >> >> TAGS: pythoncompatible, loops >> """ >> >> >> Some transforms would fit for documenting language features as well: >> >> class ForloopOptimizations(CythonTransform): >> """ >> Optimizations done to for-loops: >> >> - for in range is ... >> """ > > No offense intended (as this was clearly marked as an experiment) but > I have to admit this feels rather contrived, especially if we end up > making classes/structuring code just to hold the docstrings of user- > level abstractions. I think it would lead to a sparse scattering of > documentation throughout the codebase (most of the code does *not* > need to be exposed to the user documentation, e.g. all the Nodes that > represent Python nodes, and most transforms). The comments/doctests > in the code should probably be about the code itself (useful to a > cython developer, but probably not to a cython user). [I hit send too soon] It feels a bit as if one put the documentation for the Python language into the source of the CPython interpreter. - Robert From dagss at student.matnat.uio.no Fri Oct 2 11:13:41 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 02 Oct 2009 11:13:41 +0200 Subject: [Cython] Updating Documentation In-Reply-To: References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880910010021w1295bf4gdfba2ff0555768b0@mail.gmail.com> <880EDD51-6ED7-410F-BFD3-4C290D006D65@math.washington.edu> <1e52e0880910011913w4e6c6b04q69b02f3ad61c7d85@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> <4AC5B2D0.7070705@student.matnat.uio.no> <4AC5B6C6.9050706@student.matnat.uio.no> <1e52e0880910020132y70c075fet7e93dd62f63931a9@mail.gmail.com> <4AC5BDD2.90704@student.matnat.uio.no> Message-ID: <4AC5C445.8050706@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 2, 2009, at 1:46 AM, Dag Sverre Seljebotn wrote: > > >> Peter Alexander wrote: >> >>> Putting my creative hat on... >>> >>> Would be nice to just be able to toss "chunks" of information into a >>> directory pool, that can be automatically structured to a view, by a >>> "documentation structure model"? >>> >>> That way upkeep could be made more simple because all you'd have to >>> worry about is tossing in the "chunk". >>> >>> That's kind of what I mean by an MVC model. >>> > > It almost sounds like you want a big glorified index. (I'm not saying > that's a bad thing, and it certainly would fit your bill of being > able to look stuff up fast.) > > >> OK, I see where you are coming from. As usual my suggestions are >> mostly >> with tutorials in mind. >> >> Other projects can do this in a great way by making the docstrings in >> the codebase their chunks. >> > > We do that in Sage and it works very well--the reference manual is > thousands of pages long, nearly all from function docstrings. > > >> That doesn't *quite* all the time with >> Cython, but I think it could work great in some types of situations. >> >> Experiment: >> >> class WraparoundDirective(CompilerDirective): # in Options.py >> """ >> wraparound >> >> information about the wraparound compiler directive >> """ >> >> class ForInStatNode(Node): # In Nodes.py >> """ >> Python-style for-loop >> >> more info >> >> TAGS: pythoncompatible, loops >> """ >> >> >> Some transforms would fit for documenting language features as well: >> >> class ForloopOptimizations(CythonTransform): >> """ >> Optimizations done to for-loops: >> >> - for in range is ... >> """ >> > > No offense intended (as this was clearly marked as an experiment) but > I have to admit this feels rather contrived, especially if we end up > making classes/structuring code just to hold the docstrings of user- > level abstractions. I think it would lead to a sparse scattering of > documentation throughout the codebase (most of the code does *not* > need to be exposed to the user documentation, e.g. all the Nodes that > represent Python nodes, and most transforms). The comments/doctests > in the code should probably be about the code itself (useful to a > cython developer, but probably not to a cython user). > > You may be right. (The one advantage is that it makes it easy to have documentation for different versions of Cython.). Thing is I need to have some "way of entry" into writing documentation -- I must either think about the code that implements the feature, or how I'd "tell people about it" directly in the docs. A pure MVC doesn't give me that I think -- it would tend to just be another hierarchy to remember just for the sake of it, when the hierarchy present in the docs (the view) is the one I'm likely to know by heart. So I'm not sure I'd like to just dump a chunk somewhere if it is not in the code, as I wouldn't get into the right "mood" by just dumping a fragment somewhere (how do I find the fragment again later? At least with the codebase I'd know where to look.) So I think I'm not a big supporter of MVC with chunks as seperate files in a seperate directory. However, if all I have to do is submit trac tickets containing documentation for a feature I just wrote, then I don't care much either way. Dag Sverre From vel.accel at gmail.com Fri Oct 2 11:25:27 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Fri, 2 Oct 2009 05:25:27 -0400 Subject: [Cython] Updating Documentation In-Reply-To: <4AC5C445.8050706@student.matnat.uio.no> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880910012027u2580dc9co79e48fd84920c40f@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> <4AC5B2D0.7070705@student.matnat.uio.no> <4AC5B6C6.9050706@student.matnat.uio.no> <1e52e0880910020132y70c075fet7e93dd62f63931a9@mail.gmail.com> <4AC5BDD2.90704@student.matnat.uio.no> <4AC5C445.8050706@student.matnat.uio.no> Message-ID: <1e52e0880910020225p5d2eb9d4vb82bd9f0a11ed036@mail.gmail.com> On Fri, Oct 2, 2009 at 5:13 AM, Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: >> On Oct 2, 2009, at 1:46 AM, Dag Sverre Seljebotn wrote: >> >> >>> Peter Alexander wrote: >>> >>>> Putting my creative hat on... >>>> >>>> Would be nice to just be able to toss "chunks" of information into a >>>> directory pool, that can be automatically structured to a view, by a >>>> "documentation structure model"? >>>> >>>> That way upkeep could be made more simple because all you'd have to >>>> worry about is tossing in the "chunk". >>>> >>>> That's kind of what I mean by an MVC model. >>>> >> >> It almost sounds like you want a big glorified index. (I'm not saying >> that's a bad thing, and it certainly would fit your bill of being >> able to look stuff up fast.) >> >> >>> OK, I see where you are coming from. As usual my suggestions are >>> mostly >>> with tutorials in mind. >>> >>> Other projects can do this in a great way by making the docstrings in >>> the codebase their chunks. >>> >> >> We do that in Sage and it works very well--the reference manual is >> thousands of pages long, nearly all from function docstrings. >> >> >>> That doesn't *quite* all the time with >>> Cython, but I think it could work great in some types of situations. >>> >>> Experiment: >>> >>> class WraparoundDirective(CompilerDirective): # in Options.py >>> ? ? """ >>> ? ? wraparound >>> >>> ? ? information about the wraparound compiler directive >>> ? ? """ >>> >>> class ForInStatNode(Node): # In Nodes.py >>> ? ?""" >>> ? ?Python-style for-loop >>> >>> ? ?more info >>> >>> ? ?TAGS: pythoncompatible, loops >>> ? ?""" >>> >>> >>> Some transforms would fit for documenting language features as well: >>> >>> class ForloopOptimizations(CythonTransform): >>> ? ? """ >>> ? ? Optimizations done to for-loops: >>> >>> ? ? ? ?- for in range is ... >>> ? ? """ >>> >> >> No offense intended (as this was clearly marked as an experiment) but >> I have to admit this feels rather contrived, especially if we end up >> making classes/structuring code just to hold the docstrings of user- >> level abstractions. I think it would lead to a sparse scattering of >> documentation throughout the codebase (most of the code does *not* >> need to be exposed to the user documentation, e.g. all the Nodes that >> represent Python nodes, and most transforms). The comments/doctests >> in the code should probably be about the code itself (useful to a >> cython developer, but probably not to a cython user). >> >> > You may be right. (The one advantage is that it makes it easy to have > documentation for different versions of Cython.). > > Thing is I need to have some "way of entry" into writing documentation > -- I must either think about the code that implements the feature, or > how I'd "tell people about it" directly in the docs. A pure MVC doesn't > give me that I think -- it would tend to just be another hierarchy to > remember just for the sake of it, when the hierarchy present in the docs > (the view) is the one I'm likely to know by heart. > > So I'm not sure I'd like to just dump a chunk somewhere if it is not in > the code, as I wouldn't get into the right "mood" by just dumping a > fragment somewhere (how do I find the fragment again later? At least > with the codebase I'd know where to look.) So I think I'm not a big > supporter of MVC with chunks as seperate files in a seperate directory. > > However, if all I have to do is submit trac tickets containing > documentation for a feature I just wrote, then I don't care much either way. > > Dag Sverre > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > The thing that's different about Cython from the others, is that it's not a library which is API centric.. where extracting doc strings from the code source itself makes perfect sense. But, I don't feel that it's necessarily impractical in Cython's case either. It all depends on preference, I think. From vel.accel at gmail.com Fri Oct 2 11:29:19 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Fri, 2 Oct 2009 05:29:19 -0400 Subject: [Cython] Updating Documentation In-Reply-To: <1e52e0880910020225p5d2eb9d4vb82bd9f0a11ed036@mail.gmail.com> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> <4AC5B2D0.7070705@student.matnat.uio.no> <4AC5B6C6.9050706@student.matnat.uio.no> <1e52e0880910020132y70c075fet7e93dd62f63931a9@mail.gmail.com> <4AC5BDD2.90704@student.matnat.uio.no> <4AC5C445.8050706@student.matnat.uio.no> <1e52e0880910020225p5d2eb9d4vb82bd9f0a11ed036@mail.gmail.com> Message-ID: <1e52e0880910020229s254fc667gd6cf6e40ba7bdca@mail.gmail.com> On Fri, Oct 2, 2009 at 5:25 AM, Peter Alexander wrote: > On Fri, Oct 2, 2009 at 5:13 AM, Dag Sverre Seljebotn > wrote: >> Robert Bradshaw wrote: >>> On Oct 2, 2009, at 1:46 AM, Dag Sverre Seljebotn wrote: >>> >>> >>>> Peter Alexander wrote: >>>> >>>>> Putting my creative hat on... >>>>> >>>>> Would be nice to just be able to toss "chunks" of information into a >>>>> directory pool, that can be automatically structured to a view, by a >>>>> "documentation structure model"? >>>>> >>>>> That way upkeep could be made more simple because all you'd have to >>>>> worry about is tossing in the "chunk". >>>>> >>>>> That's kind of what I mean by an MVC model. >>>>> >>> >>> It almost sounds like you want a big glorified index. (I'm not saying >>> that's a bad thing, and it certainly would fit your bill of being >>> able to look stuff up fast.) >>> >>> >>>> OK, I see where you are coming from. As usual my suggestions are >>>> mostly >>>> with tutorials in mind. >>>> >>>> Other projects can do this in a great way by making the docstrings in >>>> the codebase their chunks. >>>> >>> >>> We do that in Sage and it works very well--the reference manual is >>> thousands of pages long, nearly all from function docstrings. >>> >>> >>>> That doesn't *quite* all the time with >>>> Cython, but I think it could work great in some types of situations. >>>> >>>> Experiment: >>>> >>>> class WraparoundDirective(CompilerDirective): # in Options.py >>>> ? ? """ >>>> ? ? wraparound >>>> >>>> ? ? information about the wraparound compiler directive >>>> ? ? """ >>>> >>>> class ForInStatNode(Node): # In Nodes.py >>>> ? ?""" >>>> ? ?Python-style for-loop >>>> >>>> ? ?more info >>>> >>>> ? ?TAGS: pythoncompatible, loops >>>> ? ?""" >>>> >>>> >>>> Some transforms would fit for documenting language features as well: >>>> >>>> class ForloopOptimizations(CythonTransform): >>>> ? ? """ >>>> ? ? Optimizations done to for-loops: >>>> >>>> ? ? ? ?- for in range is ... >>>> ? ? """ >>>> >>> >>> No offense intended (as this was clearly marked as an experiment) but >>> I have to admit this feels rather contrived, especially if we end up >>> making classes/structuring code just to hold the docstrings of user- >>> level abstractions. I think it would lead to a sparse scattering of >>> documentation throughout the codebase (most of the code does *not* >>> need to be exposed to the user documentation, e.g. all the Nodes that >>> represent Python nodes, and most transforms). The comments/doctests >>> in the code should probably be about the code itself (useful to a >>> cython developer, but probably not to a cython user). >>> >>> >> You may be right. (The one advantage is that it makes it easy to have >> documentation for different versions of Cython.). >> >> Thing is I need to have some "way of entry" into writing documentation >> -- I must either think about the code that implements the feature, or >> how I'd "tell people about it" directly in the docs. A pure MVC doesn't >> give me that I think -- it would tend to just be another hierarchy to >> remember just for the sake of it, when the hierarchy present in the docs >> (the view) is the one I'm likely to know by heart. >> >> So I'm not sure I'd like to just dump a chunk somewhere if it is not in >> the code, as I wouldn't get into the right "mood" by just dumping a >> fragment somewhere (how do I find the fragment again later? At least >> with the codebase I'd know where to look.) So I think I'm not a big >> supporter of MVC with chunks as seperate files in a seperate directory. >> >> However, if all I have to do is submit trac tickets containing >> documentation for a feature I just wrote, then I don't care much either way. >> >> Dag Sverre >> _______________________________________________ >> Cython-dev mailing list >> Cython-dev at codespeak.net >> http://codespeak.net/mailman/listinfo/cython-dev >> > > The thing that's different about Cython from the others, is that it's > not a library which is API centric.. where extracting doc strings from > the code source itself makes perfect sense. > > But, I don't feel that it's necessarily impractical in Cython's case > either. It all depends on preference, I think. > More... come to think of it.. all of Qt's documenation (including technology elaborations, exaples and demos) reside within the source code itself. They use "qdoc" to extract it to a view. This is what DOxygen is modelled after which all though is primarily for API extraction, is not solely for that purpose either. From stefan_ml at behnel.de Fri Oct 2 12:06:28 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 02 Oct 2009 12:06:28 +0200 Subject: [Cython] Updating Documentation In-Reply-To: <1e52e0880910020229s254fc667gd6cf6e40ba7bdca@mail.gmail.com> References: <1e52e0880909300141l146ec811k40a90a439ee73a3a@mail.gmail.com> <1e52e0880910012146r7ed37d78r9dfdbc43d37400f7@mail.gmail.com> <6BA4BC4F-66D0-4167-B65E-31FE32504376@math.washington.edu> <4AC5B2D0.7070705@student.matnat.uio.no> <4AC5B6C6.9050706@student.matnat.uio.no> <1e52e0880910020132y70c075fet7e93dd62f63931a9@mail.gmail.com> <4AC5BDD2.90704@student.matnat.uio.no> <4AC5C445.8050706@student.matnat.uio.no> <1e52e0880910020225p5d2eb9d4vb82bd9f0a11ed036@mail.gmail.com> <1e52e0880910020229s254fc667gd6cf6e40ba7bdca@mail.gmail.com> Message-ID: <4AC5D0A4.9060300@behnel.de> Peter Alexander wrote: > On Fri, Oct 2, 2009 at 5:25 AM, Peter Alexander wrote: >> On Fri, Oct 2, 2009 at 5:13 AM, Dag Sverre Seljebotn wrote: >>> Robert Bradshaw wrote: >>>> No offense intended (as this was clearly marked as an experiment) but >>>> I have to admit this feels rather contrived, especially if we end up >>>> making classes/structuring code just to hold the docstrings of user- >>>> level abstractions. +1 >>>> I think it would lead to a sparse scattering of >>>> documentation throughout the codebase (most of the code does *not* >>>> need to be exposed to the user documentation, e.g. all the Nodes that >>>> represent Python nodes, and most transforms). The comments/doctests >>>> in the code should probably be about the code itself (useful to a >>>> cython developer, but probably not to a cython user). >>>> >>> You may be right. (The one advantage is that it makes it easy to have >>> documentation for different versions of Cython.). That's an orthogonal problem and I find it unlikely that we will ever have to manage so many different Cython versions that the documentation becomes a bottleneck. >>> Thing is I need to have some "way of entry" into writing documentation >>> -- I must either think about the code that implements the feature, or >>> how I'd "tell people about it" directly in the docs. A pure MVC doesn't >>> give me that I think -- it would tend to just be another hierarchy to >>> remember just for the sake of it, when the hierarchy present in the docs >>> (the view) is the one I'm likely to know by heart. >>> >>> So I'm not sure I'd like to just dump a chunk somewhere if it is not in >>> the code, as I wouldn't get into the right "mood" by just dumping a >>> fragment somewhere (how do I find the fragment again later? At least >>> with the codebase I'd know where to look.) So I think I'm not a big >>> supporter of MVC with chunks as seperate files in a seperate directory. +1 >>> However, if all I have to do is submit trac tickets containing >>> documentation for a feature I just wrote, then I don't care much either way. I don't think that can be sufficient. If it's only about a set of examples, there's the Demos directory. If it's anything that needs more commentary and presentation, you'll have to make it fit into the docs somewhere and make sure people a) find it at the right place(s) when they look for it and/or read along, and b) understand what you want to bring across with the example in this specific context. The problem with MVC here is that the model isn't complete. The context (i.e. the view) is just as important. The same line of code can tell very different things depending on the text section you put it into. It'll be hard to write examples that are reused in multiple documents without impacting clarity and conciseness in any of them. The only niche I can think of where a simplified approach might make sense is optimisations. Something like "Since version x.y.z, Cython will recognise /this/ code pattern and translate it into efficient C code like /this/" might work well when put into an index. Everything else is best expressed in flowing text IMO. >> The thing that's different about Cython from the others, is that it's >> not a library which is API centric.. where extracting doc strings from >> the code source itself makes perfect sense. >> >> But, I don't feel that it's necessarily impractical in Cython's case >> either. It all depends on preference, I think. > > More... come to think of it.. all of Qt's documenation (including > technology elaborations, exaples and demos) reside within the source > code itself. They use "qdoc" to extract it to a view. This is what > DOxygen is modelled after which all though is primarily for API > extraction, is not solely for that purpose either. That certainly doesn't apply to Cython. A language needs a very different way of presentation than a simple mapping from an API implementation/spec to a doc index. Stefan From wstein at gmail.com Fri Oct 2 17:59:23 2009 From: wstein at gmail.com (William Stein) Date: Fri, 2 Oct 2009 08:59:23 -0700 Subject: [Cython] sagemath.org, etc. Message-ID: <85e81ba30910020859o71309ccate0c970dad5424a14@mail.gmail.com> Hi, After being rock solid for 9 months, the VMware server crashed badly on boxen.math.washington.edu, and we absolutely could not get it to work despite repeated clean reinstalls, reboots, etc. Repeatedly tempted by things appearing to work, I tried to migrate the virtual infrastructure to VirtualBox, but after many hours of work major performance issues made this impossible for now (though I hold out hope) -- something about my hardware setup or VirtualBox makes it completely unusable. Fortunately, I was able to get VMware server installed on mod.math.washington.edu, and get the virtual servers back online. I had to change the DNS entries for everything to point to mod.math.washington.edu (128.208.160.198) instead of boxen.math.washington.edu (128.208.160.197). As the DNS propagates, you should see all relevant web pages come back and work exactly as before the crash (no data was lost). If you are one of the people that works on sagemath (e.g., to maintain the cython, sagemath, mpir, etc.) webpage, the main change for now is that you login to mod.math.washington.edu instead of boxen.math.washington.edu before connecting to sagemath. (This is temporary.) William -- William Stein Associate Professor of Mathematics University of Washington http://wstein.org From dagss at student.matnat.uio.no Fri Oct 2 18:33:05 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 02 Oct 2009 18:33:05 +0200 Subject: [Cython] Can't push to repos In-Reply-To: <95BD00DE-0C2B-437A-968A-B884404ED251@math.washington.edu> References: <4AC4FCB8.9040402@student.matnat.uio.no> <95BD00DE-0C2B-437A-968A-B884404ED251@math.washington.edu> Message-ID: <4AC62B41.6030401@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 1, 2009, at 12:02 PM, Dag Sverre Seljebotn wrote: > >> I get 500 Internal server error on pushes to hg.cython.org. >> >> I tried running "hg verify" in the cython-unstable folder (by SSHing >> into the server) but it didn't show anything. Any other ideas? > > Looks like everything hosted on sagemath is down right now. Looking > into it... This happened before VMWare went down, and now that the server is up again the issue is still there. 500 server error on push, otherwise seems to work OK... -- Dag Sverre From dalcinl at gmail.com Fri Oct 2 19:34:40 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 2 Oct 2009 14:34:40 -0300 Subject: [Cython] cimport behaviour: "from package cimport module" ... bug o feature? Message-ID: See this: I install mpi4py C-API headers, SWIG typemaps, and of course Cython pxd's here: $ tree $HOME/lib/python/mpi4py/include/ /u/dalcinl/lib/python/mpi4py/include/ `-- mpi4py |-- MPI.pxd |-- __init__.pyx |-- mpi.pxi |-- mpi4py.MPI.h |-- mpi4py.MPI_api.h |-- mpi4py.h |-- mpi4py.i `-- mpi_c.pxd As you can see, I have a (empty) __init__.pyx alonside MPI.pxd Now suppose I have Cython code wanting to cimport MPI.pxd like this: $ cat tmp.pyx from mpi4py cimport MPI Now I try to cythonize the source, passing -I (AFAIK) appropriately : $ cython -I$HOME/lib/python/mpi4py/include tmp.pyx Error converting Pyrex file to C: ------------------------------------------------------------ ... from mpi4py cimport MPI ^ ------------------------------------------------------------ /u/dalcinl/Devel/mpi4py-dev/demo/wrap-cython/tmp.pyx:1:0: 'mpi4py.pxd' not found Now if I add an empty mpi4py.pxd $ touch $HOME/lib/python/mpi4py/include/mpi4py.pxd And try to cythonize again... SUCCESS!!. Why should I add a "mpi4py.pxd" alongside the "mpi4py/" directory to make Cython understand that "mpi4py" is a package, provided that "mpi4py/__init__.pyx" file is there? Am I missing something? Is this a bug or a feature? Please note that if I code the cimport like this: cimport mpi4py.MPI as MPI ... then I DO NOT need to add the mpi4py.pxd stub file... This makes me think that the behaviour I'm describing is actually a bug... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From stefan_ml at behnel.de Fri Oct 2 22:23:50 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 02 Oct 2009 22:23:50 +0200 Subject: [Cython] benchmarking input In-Reply-To: <200909211527.n8LFR4xQ028739@theraft.openend.se> References: <200909211527.n8LFR4xQ028739@theraft.openend.se> Message-ID: <4AC66156.1050400@behnel.de> Hi, I just sent this mail to the PyPy list. Given that there is some interest in getting Cython into the Alioth shootout, and the move towards an nightly benchmarking run for PyPy, I thought it would be nice to have not only CPython as comparison. Stefan Stefan Behnel wrote: > Anders Hammarquist wrote: >> Anyway, what I was thinking about, and need input on, is how to get >> at the interpreters to run the benchmark. > [...] > > I wonder, would it be possible to add Cython to the benchmark loop? I would > love to see it compared to PyPy, simply because both projects aim to > compile Python code to C code (amongst other things, obviously). > > I know that Cython can't currently compete with PyPy in terms of feature > completeness - it clearly lacks some very important features of the Python > language, so it won't be able to run all benchmarks for a while, and the > comparison would easily show where the black spots are that need fixing. > > Just out of curiosity (and to wet your appetite :), I ran PyPy's richards > benchmark unmodified in Cython (latest cython-unstable) and got this: > > python2.6 -c 'import richards; richards.main()' > Richards benchmark (Python) starting... [...] > finished. > Total time for 10 iterations: 3.98 secs > Average time per iteration: 398.44 ms > > compared to CPython 2.6.2: > > python2.6 -c 'import richards; richards.main()' > Richards benchmark (Python) starting... [...] > finished. > Total time for 10 iterations: 4.86 secs > Average time per iteration: 485.97 ms > > That's almost 20% faster IMO and not bad at all, given that Cython's main > performance feature (C typing) wasn't used. When I use an external .pxd > file (attached) to redeclare the classes as extension types and to add a C > nature to their methods (still without any benchmark code modifications), I > get this: > > python2.6 -c 'import richards; richards.main(iterations=10)' > Richards benchmark (Python) starting... [...] > finished. > Total time for 10 iterations: 0.99 secs > Average time per iteration: 99.28 ms > > That's almost a factor of five compared to CPython. > > If possible, I would like to add both a normal Cython compiler run and a > pxd enabled run to the benchmark comparison with PyPy and CPython. Any > chance this could be integrated? > > I'm asking now, because I imagine that the benchmarking framework will have > to integrate the Cython compiler somehow, maybe using distutils or > on-the-fly compilation with pyximport. > > Stefan From ndbecker2 at gmail.com Fri Oct 2 23:41:30 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 02 Oct 2009 17:41:30 -0400 Subject: [Cython] Cannot assign type ... Message-ID: How do I fix this? cython doesn't seem to like my use of functions as parameters. /home/nbecker/raysat/mod/test1.pyx:27:110: Cannot assign type 'numpy.int64_t (numpy.int64_t, int, numpy.int64_t, int __pyx_skip_dispatch)' to 'test1.rnd_policy_t' -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: test1.pyx Url: http://codespeak.net/pipermail/cython-dev/attachments/20091002/2f4d2aa8/attachment.diff From ndbecker2 at gmail.com Sat Oct 3 01:51:44 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 02 Oct 2009 19:51:44 -0400 Subject: [Cython] numpy generic iteration Message-ID: I need to write functions that apply element-wise numpy arrays, and should be independent of the number of dimensions. numpy has a mechanism for generic (dimension-independent) iteration over elements of the array, but is there any way to use this (or implement something similar) in cython? From vel.accel at gmail.com Sat Oct 3 04:20:43 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Fri, 2 Oct 2009 22:20:43 -0400 Subject: [Cython] numpy generic iteration In-Reply-To: References: Message-ID: <1e52e0880910021920g75eb5675rc8bc85db40108650@mail.gmail.com> On Fri, Oct 2, 2009 at 7:51 PM, Neal Becker wrote: > I need to write functions that apply element-wise numpy arrays, and should > be independent of the number of dimensions. > > numpy has a mechanism for generic (dimension-independent) iteration over > elements of the array, but is there any way to use this (or implement > something similar) in cython? > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > Hi Neal. I don't know exactly where Dag is right now on his great work with "numpy under cython's covers" but you can simply use pointer arithmetic.. right. Numpy has a set of macros it uses and if I remember correctly there is documentation of a their simple algorithm somewhere... maybe it was in Travis's numpy book.. I don't exactly remember the doc right now. If I come across it I'll come back and post it. From dagss at student.matnat.uio.no Sat Oct 3 09:14:29 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 03 Oct 2009 09:14:29 +0200 Subject: [Cython] numpy generic iteration In-Reply-To: References: Message-ID: <4AC6F9D5.7030502@student.matnat.uio.no> Neal Becker wrote: > I need to write functions that apply element-wise numpy arrays, and should > be independent of the number of dimensions. > > numpy has a mechanism for generic (dimension-independent) iteration over > elements of the array, but is there any way to use this (or implement > something similar) in cython? There's two methods: ufuncs and multi-iterators. ufuncs is the most common one -- search for ufunc on the Cython wiki, there should be an example somewhere. I just did this using multi-iterators (which I had to do because I needed some context -- a temporary buffer -- during the calculation). Attaching my code for calculating a Wigner 3j symbol elementwise with full broadcasting. (It is not as fast as it could be -- it is possible to extract out the inner loop and have it as a C loop rather than rely on the iterator, which is faster. I didn't bother yet though, mainly because each Wigner symbol calculation is rather heavy.) The NumPy docs is rather good in this area, check there next! (search for the multiiterator functions I use + ufuncs) Also you need a newer numpy.pxd than the one shipped with Cython for both ufuncs and multiiterators. Just replace the one in Cython/Includes with the attachment. I will include it in the next Cython release. [Edit: The attachments were too large, but they're up at sage.math.washington.edu/home/dagss as numpy.pxd and wigner.pyx. The main idea is: cdef np.broadcast it = np.broadcast(l1, l2, l3, m1, m2, m3) shape = (it).shape if out is None: out = np.empty(shape, dtype) else: if out.shape != shape: raise ValueError(u"out argument has incorrect shape") if out.dtype != dtype: raise ValueError(u"out argument has incorrect dtype") it = np.broadcast(l1, l2, l3, m1, m2, m3, out) with nogil: while np.PyArray_MultiIter_NOTDONE(it): l1val = (np.PyArray_MultiIter_DATA(it, 0))[0] l2val = (np.PyArray_MultiIter_DATA(it, 1))[0] l3val = (np.PyArray_MultiIter_DATA(it, 2))[0] m1val = (np.PyArray_MultiIter_DATA(it, 3))[0] m2val = (np.PyArray_MultiIter_DATA(it, 4))[0] m3val = (np.PyArray_MultiIter_DATA(it, 4))[0] ...make outval... (np.PyArray_MultiIter_DATA(it, 6))[0] = outval np.PyArray_MultiIter_NEXT(it) ] -- Dag Sverre From dagss at student.matnat.uio.no Sat Oct 3 10:08:46 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 03 Oct 2009 10:08:46 +0200 Subject: [Cython] Can't push to repos In-Reply-To: <4AC62B41.6030401@student.matnat.uio.no> References: <4AC4FCB8.9040402@student.matnat.uio.no> <95BD00DE-0C2B-437A-968A-B884404ED251@math.washington.edu> <4AC62B41.6030401@student.matnat.uio.no> Message-ID: <4AC7068E.5070902@student.matnat.uio.no> Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: >> On Oct 1, 2009, at 12:02 PM, Dag Sverre Seljebotn wrote: >> >>> I get 500 Internal server error on pushes to hg.cython.org. >>> >>> I tried running "hg verify" in the cython-unstable folder (by SSHing >>> into the server) but it didn't show anything. Any other ideas? >> Looks like everything hosted on sagemath is down right now. Looking >> into it... > > This happened before VMWare went down, and now that the server is up > again the issue is still there. 500 server error on push, otherwise > seems to work OK... > And now it worked. -- Dag Sverre From dagss at student.matnat.uio.no Sat Oct 3 10:46:45 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 03 Oct 2009 10:46:45 +0200 Subject: [Cython] Huh? Thread vars faster than global vars? (#281) Message-ID: <4AC70F75.60308@student.matnat.uio.no> In the interest of fixing http://trac.cython.org/cython_trac/ticket/281 I'm doing some benchmarks which are rather surprising to me. Explanations? Unless something is wrong it seems I can safely replace __pyx_lineno and friends with thread variables (on Python versions which support it, haven't checked that yet). In [12]: %timeit dagss.globalvar(1e3) 100 loops, best of 3: 6.18 ms per loop In [13]: %timeit dagss.threadvar(1e3) 10000 loops, best of 3: 553 micros per loop In [14]: %timeit dagss.threadvar(1e6) 10 loops, best of 3: 153 ms per loop cdef extern from "pythread.h": int PyThread_create_key() void PyThread_delete_key(int) int PyThread_set_key_value(int, void *) void* PyThread_get_key_value(int) void PyThread_delete_key_value(int key) cdef int v cdef void setvar(int x): global v v = x cdef int getvar(): return v def threadvar(N): cdef int key = PyThread_create_key() cdef int i cdef void* j for i in range(N): PyThread_set_key_value(key, i) j = PyThread_get_key_value(key) def globalvar(N): cdef int i cdef int j for i in range(N): setvar(i) j = getvar() -- Dag Sverre From ndbecker2 at gmail.com Sat Oct 3 15:48:14 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 03 Oct 2009 09:48:14 -0400 Subject: [Cython] numpy generic iteration References: <4AC6F9D5.7030502@student.matnat.uio.no> Message-ID: I don't think I can use ufunc, because these functions will need access to some additional data. The ufunc mechanism seems poorly suited here. I'm trying the iterator interface. I just need iteration over a single array ATM. I'm trying to follow wigner example, but it looks like ITER macros are missing from numpy.pxd. I tried this: bint PyArray_ITER_NOTDONE (flatiter x) nogil No familiar with the syntax here, just guessing. Is this correct? Compiles and executes, but looks like it did not execute correctly. From ndbecker2 at gmail.com Sat Oct 3 16:17:56 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 03 Oct 2009 10:17:56 -0400 Subject: [Cython] numpy generic iteration References: <4AC6F9D5.7030502@student.matnat.uio.no> Message-ID: Made some more progress. Need: Added to numpy.pyd: bint PyArray_ITER_NOTDONE (flatiter x) nogil void PyArray_ITER_NEXT (flatiter x) nogil void* PyArray_ITER_DATA (flatiter x) nogil -------------- Test module sum.pyx: import numpy as np cimport numpy as np dtype = np.double ctypedef double dtype_t np.import_array() def sum (in1): cdef: np.flatiter it dtype_t out = 0 in1 = np.asarray (in1, dtype) shape = in1.shape it = np.flatiter (in1) <<< problem here cdef dtype_t val while not np.PyArray_ITER_NOTDONE (it): val = (np.PyArray_ITER_DATA (it))[0] print val out += val np.PyArray_ITER_NEXT (it) return out -------------- test_sum.py: import sum import numpy as np arr = np.arange (10) print sum.sum (arr) -------------- result: TypeError: cannot create 'numpy.flatiter' instances From dagss at student.matnat.uio.no Sat Oct 3 18:00:06 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 03 Oct 2009 18:00:06 +0200 Subject: [Cython] numpy generic iteration In-Reply-To: References: <4AC6F9D5.7030502@student.matnat.uio.no> Message-ID: <4AC77506.9030008@student.matnat.uio.no> Neal Becker wrote: > Made some more progress. Need: > > Added to numpy.pyd: > bint PyArray_ITER_NOTDONE (flatiter x) nogil > void PyArray_ITER_NEXT (flatiter x) nogil > void* PyArray_ITER_DATA (flatiter x) nogil > > -------------- > Test module sum.pyx: > import numpy as np > cimport numpy as np > > dtype = np.double > ctypedef double dtype_t > > np.import_array() > > def sum (in1): > cdef: > np.flatiter it > dtype_t out = 0 > > in1 = np.asarray (in1, dtype) > shape = in1.shape > it = np.flatiter (in1) <<< problem here Declare and use PyArray_IterNew, see "Iterators" in http://docs.scipy.org/doc/numpy/reference/c-api.array.html I'm not sure whether this call really returns a "flatiter" instance (in which case you can keep the others as is). If it returns something else than "flatiter", you can just use "object" everywhere you now use "flatiter" and it should work (though perhaps not be safe, i.e. if you pass a Python tuple to ITER_NOTDONE you get to keep the pieces. So use flatiter as the type if possible.). -- Dag Sverre From dalcinl at gmail.com Sat Oct 3 19:20:43 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sat, 3 Oct 2009 14:20:43 -0300 Subject: [Cython] Huh? Thread vars faster than global vars? (#281) In-Reply-To: <4AC70F75.60308@student.matnat.uio.no> References: <4AC70F75.60308@student.matnat.uio.no> Message-ID: On Sat, Oct 3, 2009 at 5:46 AM, Dag Sverre Seljebotn wrote: > In the interest of fixing > > http://trac.cython.org/cython_trac/ticket/281 > I was thinking on this a couple of days ago. Why the filename is not just passed to Pyx_AddTracebak... and further, why the lineno is not just stored the C function stack? > > I'm doing some benchmarks which are rather surprising to me. > You should not be surprised, your results are a total nonsense :-) > Explanations? One thing that is suspicious is this line PyThread_set_key_value(key, i) I think it should read: PyThread_set_key_value(key, &i) go to the actual implementation of that call, you will see assert(value != NULL); > Unless something is wrong it seems I can safely replace > __pyx_lineno and friends with thread variables (on Python versions which > support it, haven't checked that yet). > > In [12]: %timeit dagss.globalvar(1e3) > 100 loops, best of 3: 6.18 ms per loop > > In [13]: %timeit dagss.threadvar(1e3) > 10000 loops, best of 3: 553 micros per loop > > In [14]: %timeit dagss.threadvar(1e6) > 10 loops, best of 3: 153 ms per loop > > cdef extern from "pythread.h": > ? ? int PyThread_create_key() > ? ? void PyThread_delete_key(int) > ? ? int PyThread_set_key_value(int, void *) > ? ? void* PyThread_get_key_value(int) > ? ? void PyThread_delete_key_value(int key) > > cdef int v > > cdef void setvar(int x): > ? ? global v > ? ? v = x > > cdef int getvar(): > ? ? return v > > def threadvar(N): > ? ? cdef int key = PyThread_create_key() > ? ? cdef int i > ? ? cdef void* j > ? ? for i in range(N): > ? ? ? ? PyThread_set_key_value(key, i) > ? ? ? ? j = PyThread_get_key_value(key) > > def globalvar(N): > ? ? cdef int i > ? ? cdef int j > ? ? for i in range(N): > ? ? ? ? setvar(i) > ? ? ? ? j = getvar() > > > > > -- > Dag Sverre > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From robertwb at math.washington.edu Sat Oct 3 20:40:22 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 3 Oct 2009 11:40:22 -0700 Subject: [Cython] Huh? Thread vars faster than global vars? (#281) In-Reply-To: References: <4AC70F75.60308@student.matnat.uio.no> Message-ID: On Oct 3, 2009, at 10:20 AM, Lisandro Dalcin wrote: > On Sat, Oct 3, 2009 at 5:46 AM, Dag Sverre Seljebotn > wrote: >> In the interest of fixing >> >> http://trac.cython.org/cython_trac/ticket/281 >> > > I was thinking on this a couple of days ago. Why the filename is not > just passed to Pyx_AddTracebak... and further, why the lineno is not > just stored the C function stack? Yes, this has bothered me too. There's no reason for these to be globals, they should just be stack vars and passed directly into the Pyx_AddTraceback. - Robert From robertwb at math.washington.edu Sat Oct 3 20:42:15 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 3 Oct 2009 11:42:15 -0700 Subject: [Cython] PyBench results compared to Py2.6.2 In-Reply-To: <4AC4FE0F.1060704@behnel.de> References: <4AC4FE0F.1060704@behnel.de> Message-ID: <88CC9A8D-4052-4983-B9F7-001CAF427489@math.washington.edu> On Oct 1, 2009, at 12:07 PM, Stefan Behnel wrote: > Hi all, > > for a talk I'm about to give, I ran the pybench benchmark with > cython-unstable. I had to fix up the sources a tiny bit (nothing that > impacts the results) and select the benchmarks that actually compile > (mostly due to inner classes being used). It's run like this: > > PYTHONPATH=. python2.6 -c 'import pybench; pybench.PyBenchCmdline()' \ > --debug -w 1 -n 5 -f results-cython.pybench -t \ > 'Arithmetic|IfThen|Loops|Dict|Try.*Except|Import|List|Compare| > String|Tuple|Unicode' > > FWIW, both the Python 2.6.2 interpreter and the Cython generated C > modules > were built on the same machine with the same CFLAGS. > > The sources I used are here: > > http://codespeak.net/lxml/pybench.tar.gz > > I attached the results. > > I left out the CompareIntegers/Floats/etc. benchmarks as they only > compare > numeric literals, which ends up in the C code as, well, a > comparison of > literals, so that the C compiler finds a lot of dead code to > discard. The > resulting 100% speedup isn't really that informative. > > Note that the numbers are for plain Python code without any type > annotations, so a lot of possible optimisations are not even used. > > However, the remaining total improvement of almost 33%, and the huge > speedups for control structures (especially loops) and builtin > types is > clearly worth a look. Cool. - Robert From stefan_ml at behnel.de Sat Oct 3 20:46:56 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 03 Oct 2009 20:46:56 +0200 Subject: [Cython] Huh? Thread vars faster than global vars? (#281) In-Reply-To: References: <4AC70F75.60308@student.matnat.uio.no> Message-ID: <4AC79C20.4060005@behnel.de> Lisandro Dalcin wrote: > On Sat, Oct 3, 2009 at 5:46 AM, Dag Sverre Seljebotn > wrote: >> In the interest of fixing >> >> http://trac.cython.org/cython_trac/ticket/281 > > I was thinking on this a couple of days ago. Same here, though ages ago. > Why the filename is not > just passed to Pyx_AddTracebak... Didn't we allow includes inside of blocks by now? > and further, why the lineno is not > just stored the C function stack? Yes, that should change. Stefan From lodatom at gmail.com Sat Oct 3 21:13:21 2009 From: lodatom at gmail.com (Mark Lodato) Date: Sat, 3 Oct 2009 15:13:21 -0400 Subject: [Cython] Huh? Thread vars faster than global vars? (#281) In-Reply-To: <4AC70F75.60308@student.matnat.uio.no> References: <4AC70F75.60308@student.matnat.uio.no> Message-ID: On Sat, Oct 3, 2009 at 4:46 AM, Dag Sverre Seljebotn wrote: > In the interest of fixing > > http://trac.cython.org/cython_trac/ticket/281 > > I'm doing some benchmarks which are rather surprising to me. > Explanations? Unless something is wrong it seems I can safely replace > __pyx_lineno and friends with thread variables (on Python versions which > support it, haven't checked that yet). > > In [12]: %timeit dagss.globalvar(1e3) > 100 loops, best of 3: 6.18 ms per loop > > In [13]: %timeit dagss.threadvar(1e3) > 10000 loops, best of 3: 553 micros per loop > > In [14]: %timeit dagss.threadvar(1e6) > 10 loops, best of 3: 153 ms per loop I don't get the same result at all: $ gcc -O0 -shared -I/usr/include/python2.6 -g -fPIC dagss.c -o dagss.so In [2]: %timeit dagss.globalvar(1e3) 100000 loops, best of 3: 10.6 ?s per loop In [3]: %timeit dagss.threadvar(1e3) 10000 loops, best of 3: 446 ?s per loop In [4]: %timeit dagss.globalvar(1e6) 100 loops, best of 3: 10.3 ms per loop In [5]: %timeit dagss.threadvar(1e6) 10 loops, best of 3: 147 ms per loop $ gcc -O1 -shared -I/usr/include/python2.6 -g -fPIC dagss.c -o dagss.so In [2]: %timeit dagss.globalvar(1e3) 1000000 loops, best of 3: 1.67 ?s per loop In [3]: %timeit dagss.threadvar(1e3) 10000 loops, best of 3: 451 ?s per loop In [4]: %timeit dagss.globalvar(1e6) 1000 loops, best of 3: 1.41 ms per loop In [5]: %timeit dagss.threadvar(1e6) 10 loops, best of 3: 145 ms per loop * -O2 or -O3: With these optimization levels, the compiler optimizes out the loop. * Setup: The only change I made was to change i from an 'int' to a 'long' to remove a compiler warning. Cython: version 0.11.3 gcc: version 4.3.3 OS: Ubuntu 9.04 Processor: Intel Core 2 Duo E6300 Compile line: gcc -shared -I/usr/include/python2.6 -g -fPIC -O0 dagss.c -o dagss.so -- Mark Lodato From dagss at student.matnat.uio.no Sat Oct 3 21:17:21 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 03 Oct 2009 21:17:21 +0200 Subject: [Cython] Huh? Thread vars faster than global vars? (#281) In-Reply-To: References: <4AC70F75.60308@student.matnat.uio.no> Message-ID: <4AC7A341.9030706@student.matnat.uio.no> Lisandro Dalcin wrote: > On Sat, Oct 3, 2009 at 5:46 AM, Dag Sverre Seljebotn > wrote: >> In the interest of fixing >> >> http://trac.cython.org/cython_trac/ticket/281 >> > > I was thinking on this a couple of days ago. Why the filename is not > just passed to Pyx_AddTracebak... and further, why the lineno is not > just stored the C function stack? Since these are only used in exceptional circumstances, one reason to make them globals though might be to help the compiler by making sure the variables doesn't occupy registers (because unless the compiler is smart enough to take into account the unlikely(), perhaps it will think that the except branch will be taken and take a register from some other variable that could have better need of it?). Just wildly guessing here though. Actually I blindly assumed it had a reason and should stay that way, that's why I started with thread variables. Judging by your responses using thread vars isn't the way to go then. >> I'm doing some benchmarks which are rather surprising to me. >> > > You should not be surprised, your results are a total nonsense :-) You sure? As long as i != 0 one would be OK (I only store and retrieve a pointer that's opaque to the thread var storage...). Anyway I tried your suggestion (which would make the value always != 0) and the timings are still the same. I'm assuming it is nonsense though, even if I can't see why. If not, there's a lot of stuff we should better move into thread-local storage :-) > >> Explanations? > > One thing that is suspicious is this line > > PyThread_set_key_value(key, i) > > I think it should read: > > PyThread_set_key_value(key, &i) > > go to the actual implementation of that call, you will see > assert(value != NULL); -- Dag Sverre From dagss at student.matnat.uio.no Sat Oct 3 21:25:20 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 03 Oct 2009 21:25:20 +0200 Subject: [Cython] Huh? Thread vars faster than global vars? (#281) In-Reply-To: References: <4AC70F75.60308@student.matnat.uio.no> Message-ID: <4AC7A520.501@student.matnat.uio.no> Mark Lodato wrote: > On Sat, Oct 3, 2009 at 4:46 AM, Dag Sverre Seljebotn > wrote: >> In the interest of fixing >> >> http://trac.cython.org/cython_trac/ticket/281 >> >> I'm doing some benchmarks which are rather surprising to me. >> Explanations? Unless something is wrong it seems I can safely replace >> __pyx_lineno and friends with thread variables (on Python versions which >> support it, haven't checked that yet). >> >> In [12]: %timeit dagss.globalvar(1e3) >> 100 loops, best of 3: 6.18 ms per loop >> >> In [13]: %timeit dagss.threadvar(1e3) >> 10000 loops, best of 3: 553 micros per loop >> >> In [14]: %timeit dagss.threadvar(1e6) >> 10 loops, best of 3: 153 ms per loop > > > I don't get the same result at all: > > $ gcc -O0 -shared -I/usr/include/python2.6 -g -fPIC dagss.c -o dagss.so > > In [2]: %timeit dagss.globalvar(1e3) > 100000 loops, best of 3: 10.6 ?s per loop > > In [3]: %timeit dagss.threadvar(1e3) > 10000 loops, best of 3: 446 ?s per loop > > In [4]: %timeit dagss.globalvar(1e6) > 100 loops, best of 3: 10.3 ms per loop > > In [5]: %timeit dagss.threadvar(1e6) > 10 loops, best of 3: 147 ms per loop > > $ gcc -O1 -shared -I/usr/include/python2.6 -g -fPIC dagss.c -o dagss.so > > In [2]: %timeit dagss.globalvar(1e3) > 1000000 loops, best of 3: 1.67 ?s per loop > > In [3]: %timeit dagss.threadvar(1e3) > 10000 loops, best of 3: 451 ?s per loop > > In [4]: %timeit dagss.globalvar(1e6) > 1000 loops, best of 3: 1.41 ms per loop > > In [5]: %timeit dagss.threadvar(1e6) > 10 loops, best of 3: 145 ms per loop > > * -O2 or -O3: > > With these optimization levels, the compiler optimizes out the loop. > > * Setup: > > The only change I made was to change i from an 'int' to a 'long' to > remove a compiler warning. > > Cython: version 0.11.3 > gcc: version 4.3.3 > OS: Ubuntu 9.04 > Processor: Intel Core 2 Duo E6300 > Compile line: gcc -shared -I/usr/include/python2.6 -g -fPIC -O0 > dagss.c -o dagss.so Now I feel stupid ;-) I used runtests.py to compile, which turned on the refnanny, which meant the getter/setter functions had a much larger overhead than the function calls to the CPython lib. Thanks for doing this, I'll just trust your numbers. IMO this is not too horrible, and I think thread local variables are cheap enough that we can safely use them to propagate exceptions -- *if* we for some reason don't want __pyx_lineno and __pyx_clineno as function-local variables. (Which we shouldn't IMO if there's any chance at all that it can decrease normal running performance.) -- Dag Sverre From dagss at student.matnat.uio.no Sat Oct 3 21:28:50 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 03 Oct 2009 21:28:50 +0200 Subject: [Cython] Bug day? Message-ID: <4AC7A5F2.6000503@student.matnat.uio.no> Robert was talking about a bug day -- I can do a bug day any day during next week (09-16 CEST only). Also, before a bug-day I think we should tag all bugs which are "newbie-friendly" so that newcomers can join if they want to. -- Dag Sverre From stefan_ml at behnel.de Sat Oct 3 21:27:06 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 03 Oct 2009 21:27:06 +0200 Subject: [Cython] Huh? Thread vars faster than global vars? (#281) In-Reply-To: <4AC7A341.9030706@student.matnat.uio.no> References: <4AC70F75.60308@student.matnat.uio.no> <4AC7A341.9030706@student.matnat.uio.no> Message-ID: <4AC7A58A.8080504@behnel.de> Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: >> On Sat, Oct 3, 2009 at 5:46 AM, Dag Sverre Seljebotn wrote: >>> In the interest of fixing >>> >>> http://trac.cython.org/cython_trac/ticket/281 >>> >> I was thinking on this a couple of days ago. Why the filename is not >> just passed to Pyx_AddTracebak... and further, why the lineno is not >> just stored the C function stack? > > Since these are only used in exceptional circumstances, one reason to > make them globals though might be to help the compiler by making sure > the variables doesn't occupy registers (because unless the compiler is > smart enough to take into account the unlikely(), perhaps it will think > that the except branch will be taken and take a register from some other > variable that could have better need of it?). But that would still only apply to the exception case, which is always followed by a "goto", i.e. it jumps to a different section of the function (or module code) which likely uses different variables. I doubt that this has any performance impact, even if the C compiler decides to put the values into registers before the jump. For non trivial functions, I expect register allocation to be almost never function wide, especially on the limited x86 architecture. You also shouldn't assume a 1:1 mapping between a variable and a register. C compilers can alias variables between subsequent assignments, for example. Stefan From robertwb at math.washington.edu Sat Oct 3 20:37:41 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 3 Oct 2009 11:37:41 -0700 Subject: [Cython] Can't push to repos In-Reply-To: <4AC7068E.5070902@student.matnat.uio.no> References: <4AC4FCB8.9040402@student.matnat.uio.no> <95BD00DE-0C2B-437A-968A-B884404ED251@math.washington.edu> <4AC62B41.6030401@student.matnat.uio.no> <4AC7068E.5070902@student.matnat.uio.no> Message-ID: <5BCC6947-A6B8-49B2-BE79-50A01BCEC832@math.washington.edu> On Oct 3, 2009, at 1:08 AM, Dag Sverre Seljebotn wrote: > Dag Sverre Seljebotn wrote: >> Robert Bradshaw wrote: >>> On Oct 1, 2009, at 12:02 PM, Dag Sverre Seljebotn wrote: >>> >>>> I get 500 Internal server error on pushes to hg.cython.org. >>>> >>>> I tried running "hg verify" in the cython-unstable folder (by >>>> SSHing >>>> into the server) but it didn't show anything. Any other ideas? >>> Looks like everything hosted on sagemath is down right now. Looking >>> into it... >> >> This happened before VMWare went down, and now that the server is up >> again the issue is still there. 500 server error on push, otherwise >> seems to work OK... >> > > And now it worked. I think it was just a permissions issue (I fixed some of the permissions in the cython account). - Robert From dalcinl at gmail.com Sat Oct 3 22:49:14 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sat, 3 Oct 2009 17:49:14 -0300 Subject: [Cython] Huh? Thread vars faster than global vars? (#281) In-Reply-To: <4AC7A520.501@student.matnat.uio.no> References: <4AC70F75.60308@student.matnat.uio.no> <4AC7A520.501@student.matnat.uio.no> Message-ID: On Sat, Oct 3, 2009 at 4:25 PM, Dag Sverre Seljebotn wrote: > > IMO this is not too > horrible, and I think thread local variables are cheap enough that we > can safely use them to propagate exceptions -- *if* we for some reason > don't want __pyx_lineno and __pyx_clineno as function-local variables. > (Which we shouldn't IMO if there's any chance at all that it can > decrease normal running performance.) > I would not be so sure without more testing... these thread local vars are actually implemented with linked lists, then the key lookup is linear... Your test created just a single key, so the lookup was cheap. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From lodatom at gmail.com Sun Oct 4 05:39:12 2009 From: lodatom at gmail.com (Mark Lodato) Date: Sat, 3 Oct 2009 23:39:12 -0400 Subject: [Cython] --embed and cython_freeze no longer work Message-ID: It appears that changeset c951607190c2 broke --embed and cython_freeze. http://hg.cython.org/cython-devel/rev/c951607190c2 You can see this problem in Demos/freeze. Just run make and then run ./nCr. Or, you can boil it down to this simple example: $ echo "print __name__" > simple.pyx $ cython --embed simple.pyx $ gcc -I/usr/include/python2.6 simple.c -o simple -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions /usr/lib/python2.6/config/libpython2.6.a -lm -ldl -pthread -lutil -lz $ ./simple Traceback (most recent call last): File "simple.pyx", line 1, in init simple (simple.c:454) print __name__ NameError: __name__ I think the problem is that __Pyx_InitGlobals() is now being called after __Pyx_SetAttrString(__pyx_m, "__name__", __pyx_kp___main__), but I don't know enough about Cython or the Python API to know how to fix this. On an unrelated note, cython_freeze.py should be executable, and perhaps installed with "python setup.py install". -- Mark From robertwb at math.washington.edu Sun Oct 4 06:12:19 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 3 Oct 2009 21:12:19 -0700 Subject: [Cython] --embed and cython_freeze no longer work In-Reply-To: References: Message-ID: <2F34C111-D81E-436B-94F2-FC476680D119@math.washington.edu> On Oct 3, 2009, at 8:39 PM, Mark Lodato wrote: > It appears that changeset c951607190c2 broke --embed and > cython_freeze. > > http://hg.cython.org/cython-devel/rev/c951607190c2 > > You can see this problem in Demos/freeze. Just run make and then run > ./nCr. Or, you can boil it down to this simple example: > > $ echo "print __name__" > simple.pyx > > $ cython --embed simple.pyx > > $ gcc -I/usr/include/python2.6 simple.c -o simple -Xlinker > -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions > /usr/lib/python2.6/config/libpython2.6.a -lm -ldl -pthread -lutil -lz > > $ ./simple > Traceback (most recent call last): > File "simple.pyx", line 1, in init simple (simple.c:454) > print __name__ > NameError: __name__ > > > I think the problem is that __Pyx_InitGlobals() is now being called > after __Pyx_SetAttrString(__pyx_m, "__name__", __pyx_kp___main__), but > I don't know enough about Cython or the Python API to know how to fix > this. Yep, that is the problem. Fix at http://hg.cython.org/cython-devel/ rev/55e5ddc03e3b Still needs a regression test. > On an unrelated note, cython_freeze.py should be executable, and > perhaps installed with "python setup.py install". Yes, that makes sense. - Robert From lodatom at gmail.com Sun Oct 4 07:48:53 2009 From: lodatom at gmail.com (Mark Lodato) Date: Sun, 4 Oct 2009 01:48:53 -0400 Subject: [Cython] --embed and cython_freeze no longer work In-Reply-To: <2F34C111-D81E-436B-94F2-FC476680D119@math.washington.edu> References: <2F34C111-D81E-436B-94F2-FC476680D119@math.washington.edu> Message-ID: On Sun, Oct 4, 2009 at 12:12 AM, Robert Bradshaw wrote: > Yep, that is the problem. Fix at http://hg.cython.org/cython-devel/ > rev/55e5ddc03e3b Still needs a regression test. Great. Thanks for the fix. >> On an unrelated note, cython_freeze.py should be executable, and >> perhaps installed with "python setup.py install". > > Yes, that makes sense. I also made some changes to cython_freeze. You can see the git repository here: http://github.com/MarkLodato/cython_freeze What is the best way to get these changes into Cython? I'm used to the git model, where I would just post patches to the mailing list, but I'm not too familiar with Hg. The main changes are: * Remove ".py" from filename. * Add --output=FILE option to specify the output file. * Add --pymain option to build a regular python interpreter. * Expand the README and example. * Fix a mistaken semicolon in generated code. -- Mark From robertwb at math.washington.edu Sun Oct 4 09:52:49 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sun, 4 Oct 2009 00:52:49 -0700 Subject: [Cython] --embed and cython_freeze no longer work In-Reply-To: References: <2F34C111-D81E-436B-94F2-FC476680D119@math.washington.edu> Message-ID: On Oct 3, 2009, at 10:48 PM, Mark Lodato wrote: > On Sun, Oct 4, 2009 at 12:12 AM, Robert Bradshaw > wrote: >> Yep, that is the problem. Fix at http://hg.cython.org/cython-devel/ >> rev/55e5ddc03e3b Still needs a regression test. > > Great. Thanks for the fix. Just wish we had found it in one of the release candidates... >>> On an unrelated note, cython_freeze.py should be executable, and >>> perhaps installed with "python setup.py install". >> >> Yes, that makes sense. > > I also made some changes to cython_freeze. You can see the git > repository here: > > http://github.com/MarkLodato/cython_freeze > > What is the best way to get these changes into Cython? I'm used to > the git model, where I would just post patches to the mailing list, > but I'm not too familiar with Hg. That model works with hg as well, though we typically don't send a lot of patches back and forth via email as it clutters the mailing list. Another thing you can do is post the patch to a ticket in trac. (Don't close the ticket though, or it might not get noticed and merged...) - Robert From stefan_ml at behnel.de Sun Oct 4 17:34:38 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Oct 2009 17:34:38 +0200 Subject: [Cython] Parse tree assertions for doctests Message-ID: <4AC8C08E.3060508@behnel.de> Hi all, I implemented the test support for parse tree assertions and put some docs into the Wiki. http://wiki.cython.org/HackerGuide#Parsetreeassertions The main idea is that you add decorators to your doctest functions: @cython.test_fail_if_path_exists("//...") @cython.test_assert_path_exists("//...") def some_test(): ... They will be evaluated in the compiler pipeline, activated by a compiler option that the test runner uses. For example, the for-range transformation can be tested like this: @cython.test_fail_if_path_exists("//ForInStatNode") @cython.test_assert_path_exists("//ForFromStatNode") def test(): cdef int i for i in range(100): pass Simple enough. Note that this isn't currently exported to pure mode as I didn't see a reason to make it 'public' (i.e. export it in Shadow.py). Have fun, Stefan From dagss at student.matnat.uio.no Sun Oct 4 17:55:57 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sun, 04 Oct 2009 17:55:57 +0200 Subject: [Cython] Parse tree assertions for doctests In-Reply-To: <4AC8C08E.3060508@behnel.de> References: <4AC8C08E.3060508@behnel.de> Message-ID: <4AC8C58D.40904@student.matnat.uio.no> Stefan Behnel wrote: > Hi all, > > I implemented the test support for parse tree assertions and put some docs > into the Wiki. > > http://wiki.cython.org/HackerGuide#Parsetreeassertions > > The main idea is that you add decorators to your doctest functions: > > @cython.test_fail_if_path_exists("//...") > @cython.test_assert_path_exists("//...") > def some_test(): > ... > > They will be evaluated in the compiler pipeline, activated by a compiler > option that the test runner uses. > > For example, the for-range transformation can be tested like this: > > @cython.test_fail_if_path_exists("//ForInStatNode") > @cython.test_assert_path_exists("//ForFromStatNode") > def test(): > cdef int i > for i in range(100): > pass > > Simple enough. Wonderful! Thanks a lot! How much of XPath is supported? It says that only string comparisons are allowed in the [] predicates, but what about for node selection -- is there "/" to only match direct children? What about X/predecing-siblings::Y? (Not that I need anything more complicated than the examples, just curious.) Thanks again! -- Dag Sverre From stefan_ml at behnel.de Sun Oct 4 18:42:33 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Oct 2009 18:42:33 +0200 Subject: [Cython] Parse tree assertions for doctests In-Reply-To: <4AC8C58D.40904@student.matnat.uio.no> References: <4AC8C08E.3060508@behnel.de> <4AC8C58D.40904@student.matnat.uio.no> Message-ID: <4AC8D079.9030103@behnel.de> Dag Sverre Seljebotn wrote: > Stefan Behnel wrote: >> I implemented the test support for parse tree assertions and put some docs >> into the Wiki. >> >> http://wiki.cython.org/HackerGuide#Parsetreeassertions > > How much of XPath is supported? It says that only string comparisons are > allowed in the [] predicates, but what about for node selection -- is > there "/" to only match direct children? Yep, I'll have to extend that a little, I guess. For example, this also works: //ReturnStatNode[./NameNode] and you can use '*' to match any node. But be aware that the current test suite isn't really that big, so some more advanced conditions may fail. > What about X/predecing-siblings::Y? Siblings don't work. Since this involves some tricky tree traversal, I'd prefer waiting for a use case here. Stefan From stefan_ml at behnel.de Sun Oct 4 18:58:32 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 04 Oct 2009 18:58:32 +0200 Subject: [Cython] Parse tree assertions for doctests In-Reply-To: <4AC8D079.9030103@behnel.de> References: <4AC8C08E.3060508@behnel.de> <4AC8C58D.40904@student.matnat.uio.no> <4AC8D079.9030103@behnel.de> Message-ID: <4AC8D438.6070304@behnel.de> Stefan Behnel wrote: > Dag Sverre Seljebotn wrote: >> Stefan Behnel wrote: >>> I implemented the test support for parse tree assertions and put some docs >>> into the Wiki. >>> >>> http://wiki.cython.org/HackerGuide#Parsetreeassertions >> How much of XPath is supported? It says that only string comparisons are >> allowed in the [] predicates, but what about for node selection -- is >> there "/" to only match direct children? > > Yep, I'll have to extend that a little, I guess. For example, this also works: > > //ReturnStatNode[./NameNode] ... or this: //DefNode[.//ReturnStatNode[./NameNode[@name = 'fun']]/NameNode] :) Stefan From dagss at student.matnat.uio.no Mon Oct 5 15:25:54 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Mon, 05 Oct 2009 15:25:54 +0200 Subject: [Cython] doctesthack directive In-Reply-To: <78D599DD-8F8F-478C-B325-0B352A6C2452@math.washington.edu> References: <4AC49871.9070400@student.matnat.uio.no> <4AC49982.1080806@behnel.de> <4AC49B36.4070607@student.matnat.uio.no> <78D599DD-8F8F-478C-B325-0B352A6C2452@math.washington.edu> Message-ID: <4AC9F3E2.5050002@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 1, 2009, at 5:06 AM, Dag Sverre Seljebotn wrote: > >> Stefan Behnel wrote: >>> Dag Sverre Seljebotn wrote: >>> >>>> I now have code sitting on my drive for a doctesthack directive. >>>> What it >>>> does is work around the limitations of the doctest module by >>>> automatically creating a global __test__ dictionary mapping >>>> descriptive >>>> names to function and method docstrings. >>>> >>>> 1) Can I push it? >>>> 2) Can I make it the default? It never does anything if a __test__ >>>> already exists, so it should be fully backwards compatible. The only >>>> downside I can see is a little bit of extra memory used. >>>> >>>> Line numbers are embedded into the test names (the keys in >>>> __dict__). >>>> >>>> Note: This does not solve the problem of doctest being unable to >>>> print >>>> line numbers for class docstrings. Also the test procedure ends up >>>> flowing a little bit different from the Python module (as each >>>> function >>>> is a seperate testcase, and not simply part of the module test). >>>> As the >>>> name says, it is a hack. >>>> >>> Now that I know what kind of problems this does *not* fix and what >>> new >>> problems it introduces, what about some more detail what kind of >>> problem >>> this actually fixes? >>> >> What it fixes is that I can take a simple pyx file like this: >> >> def func(x): >> """ >>>>> func(3) >> """ >> ... >> >> and then test it like I would a Python module: >> >> python -c 'import doctest; import mymod; doctest.testmod(mymod)' >> >> doctest does not pick up the function docstring automatically as it >> reports negative to inspect.isfunction, however putting those >> functions >> in the __test__ dict works around it. >> >> Arguments in favor: >> - Lowers the barrier. It is the kind of thing which took me by >> surprise >> when I first met it; letting this be the default could save half an >> hour >> for every new Cython user. >> - This also allows very easily writing function-wise doctests in the >> Cython test suite >> >> An approach which requires a custom script for doctesting Cython files >> is here: >> >> http://wiki.cython.org/FAQ#HowcanIrundoctestsinCythoncode. >> 28pyxfiles.29.3F >> >> But I happen to like this approach better as it lower the barriers and >> makes peoples test scripts simpler without Cython-specific logic. > > I actually wasn't aware that this was such an issue, as Sage has its > own doctesting framework (e.g. it need to take care of preprocessing, > optional doctests, etc.) I think the right thing to do is convince > them to fix the doctest module. Of course, that won't help past and > current version of Python. That being said, this looks like a sound > solution, and I'm in favor of it going in, and probably even being on > by default. OK, since there's no more comments, I've now pushed it, made it the default, and renamed it to: autotestdict -- Dag Sverre From ndbecker2 at gmail.com Mon Oct 5 15:49:28 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 05 Oct 2009 09:49:28 -0400 Subject: [Cython] status of complex? Message-ID: I noticed the announcement http://codespeak.net/pipermail/cython-dev/2009-May/005548.html Is complex considered usable at this point? Is complex available by grabbing the current devel, or is this a branch? Now the hard part. I really need complex, and I really need c++. But, IIRC gcc-4.4.1 will not allow c99 complex in c++ mode. Not sure what to do about that. From dagss at student.matnat.uio.no Mon Oct 5 16:25:54 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Mon, 05 Oct 2009 16:25:54 +0200 Subject: [Cython] status of complex? In-Reply-To: References: Message-ID: <4ACA01F2.4030104@student.matnat.uio.no> Neal Becker wrote: > I noticed the announcement > http://codespeak.net/pipermail/cython-dev/2009-May/005548.html > > Is complex considered usable at this point? It's usable. conjugate() is not supported, and "x += 1" doesn't work (you need to type x = x + 1). > > Is complex available by grabbing the current devel, or is this a branch? It's been in Cython since release 0.11.2. cdef double complex x = 1 + 3j > Now the hard part. I really need complex, and I really need c++. But, IIRC > gcc-4.4.1 will not allow c99 complex in c++ mode. Not sure what to do about > that. If you do not need to pass complex numbers back and forth between Cython code and C, just make sure that "complex.h" is never included through your header files (which would be disallowed by the compiler anyways), and C99 complex will not be used. Cython "by default" (when complex.h is not included) uses its own implementation based on a struct of two reals. If you need to pass complex numbers back and forth, you could write a manual converter function in Cython. Or, we can help you towards contributing a patch to allow Cython to use C++ complex numbers directly (as a third backend in addition to C structs and C99 complex) when in C++ mode. -- Dag Sverre From dalcinl at gmail.com Mon Oct 5 17:19:34 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Mon, 5 Oct 2009 12:19:34 -0300 Subject: [Cython] status of complex? In-Reply-To: <4ACA01F2.4030104@student.matnat.uio.no> References: <4ACA01F2.4030104@student.matnat.uio.no> Message-ID: On Mon, Oct 5, 2009 at 11:25 AM, Dag Sverre Seljebotn wrote: > >> Now the hard part. ?I really need complex, and I really need c++. ?But, IIRC >> gcc-4.4.1 will not allow c99 complex in c++ mode. ?Not sure what to do about >> that. > > > Or, we can help you towards > contributing a patch to allow Cython to use C++ complex numbers directly > (as a third backend in addition to C structs and C99 complex) when in > C++ mode. > I could help here... Dag, which repo should be target of this? cython-devel? Neal, can you contribute a bit of your time to help me? -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From ndbecker2 at gmail.com Mon Oct 5 17:35:31 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 05 Oct 2009 11:35:31 -0400 Subject: [Cython] status of complex? References: <4ACA01F2.4030104@student.matnat.uio.no> Message-ID: Lisandro Dalcin wrote: > On Mon, Oct 5, 2009 at 11:25 AM, Dag Sverre Seljebotn > wrote: >> >>> Now the hard part. I really need complex, and I really need c++. But, >>> IIRC gcc-4.4.1 will not allow c99 complex in c++ mode. Not sure what to >>> do about that. >> >> >> Or, we can help you towards >> contributing a patch to allow Cython to use C++ complex numbers directly >> (as a third backend in addition to C structs and C99 complex) when in >> C++ mode. >> > > I could help here... > > Dag, which repo should be target of this? cython-devel? > > Neal, can you contribute a bit of your time to help me? > > Yes, what type of help would be needed? (I currently know nothing about cython internals). From ndbecker2 at gmail.com Mon Oct 5 17:42:18 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 05 Oct 2009 11:42:18 -0400 Subject: [Cython] status of complex? References: <4ACA01F2.4030104@student.matnat.uio.no> Message-ID: Dag Sverre Seljebotn wrote: [...] > >> Now the hard part. I really need complex, and I really need c++. But, >> IIRC >> gcc-4.4.1 will not allow c99 complex in c++ mode. Not sure what to do >> about that. > > If you do not need to pass complex numbers back and forth between Cython > code and C, just make sure that "complex.h" is never included through > your header files (which would be disallowed by the compiler anyways), > and C99 complex will not be used. Mostly what I want to do is wrap c++ code with cython. Inputs/outputs on python/cython side are numpy complex arrays. I have a simple wrapper to allow numpy array to be passed to c++ algorithms expecting generic array inputs. Normally c++ algorithms are written with a generic interface using boost::range. I can adapt numpy array to boost::range. From ndbecker2 at gmail.com Mon Oct 5 17:58:57 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 05 Oct 2009 11:58:57 -0400 Subject: [Cython] status of complex? References: <4ACA01F2.4030104@student.matnat.uio.no> Message-ID: def sum_cmplx (in1): in1 = np.asarray (in1, np.complex128) shape = in1.shape it = in1.flat cdef double complex val while np.PyArray_ITER_NOTDONE (it): val = (np.PyArray_ITER_DATA (it))[0] out += val np.PyArray_ITER_NEXT (it) return val Error converting Pyrex file to C: ------------------------------------------------------------ ... shape = in1.shape it = in1.flat cdef double complex val while np.PyArray_ITER_NOTDONE (it): val = (np.PyArray_ITER_DATA (it))[0] ^ ------------------------------------------------------------ /home/nbecker/raysat/mod/sum.pyx:34:16: 'complex' is not a type identifier Any hints? From dalcinl at gmail.com Mon Oct 5 18:17:47 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Mon, 5 Oct 2009 13:17:47 -0300 Subject: [Cython] status of complex? In-Reply-To: References: <4ACA01F2.4030104@student.matnat.uio.no> Message-ID: On Mon, Oct 5, 2009 at 12:35 PM, Neal Becker wrote: > Lisandro Dalcin wrote: > >> On Mon, Oct 5, 2009 at 11:25 AM, Dag Sverre Seljebotn >> wrote: >>> >>>> Now the hard part. ?I really need complex, and I really need c++. ?But, >>>> IIRC gcc-4.4.1 will not allow c99 complex in c++ mode. ?Not sure what to >>>> do about that. >>> >>> >>> Or, we can help you towards >>> contributing a patch to allow Cython to use C++ complex numbers directly >>> (as a third backend in addition to C structs and C99 complex) when in >>> C++ mode. >>> >> >> I could help here... >> >> Dag, which repo should be target of this? cython-devel? >> >> Neal, can you contribute a bit of your time to help me? >> >> > Yes, what type of help would be needed? ?(I currently know nothing about > cython internals). > Basically, the most time consuming part for me is to write good testcases and exercise Cython into corner cases to make sure all works 100%... So I could manage to write the support, and you could manage to the beast, and even more: try to make my patch fail ;-) -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dagss at student.matnat.uio.no Mon Oct 5 18:38:28 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Mon, 05 Oct 2009 18:38:28 +0200 Subject: [Cython] status of complex? In-Reply-To: References: <4ACA01F2.4030104@student.matnat.uio.no> Message-ID: <4ACA2104.7030900@student.matnat.uio.no> Neal Becker wrote: > > def sum_cmplx (in1): > in1 = np.asarray (in1, np.complex128) > shape = in1.shape > it = in1.flat > > cdef double complex val > while np.PyArray_ITER_NOTDONE (it): > val = (np.PyArray_ITER_DATA (it))[0] > out += val > np.PyArray_ITER_NEXT (it) > > return val > > Error converting Pyrex file to C: > ------------------------------------------------------------ > ... > shape = in1.shape > it = in1.flat > > cdef double complex val > while np.PyArray_ITER_NOTDONE (it): > val = (np.PyArray_ITER_DATA (it))[0] > ^ > ------------------------------------------------------------ > > /home/nbecker/raysat/mod/sum.pyx:34:16: 'complex' is not a type identifier > You need to use a pointer type. Dag Sverre From dagss at student.matnat.uio.no Mon Oct 5 18:42:27 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Mon, 05 Oct 2009 18:42:27 +0200 Subject: [Cython] status of complex? In-Reply-To: References: <4ACA01F2.4030104@student.matnat.uio.no> Message-ID: <4ACA21F3.70100@student.matnat.uio.no> Neal Becker wrote: > Lisandro Dalcin wrote: > > >> On Mon, Oct 5, 2009 at 11:25 AM, Dag Sverre Seljebotn >> wrote: >> >>>> Now the hard part. I really need complex, and I really need c++. But, >>>> IIRC gcc-4.4.1 will not allow c99 complex in c++ mode. Not sure what to >>>> do about that. >>>> >>> Or, we can help you towards >>> contributing a patch to allow Cython to use C++ complex numbers directly >>> (as a third backend in addition to C structs and C99 complex) when in >>> C++ mode. >>> >>> >> I could help here... >> >> Dag, which repo should be target of this? cython-devel? >> I think pretty much everything now goes on in cython-unstable as 0.12 is the next planned release. (We should really push all changes from -unstable to -devel...) PyrexTypes.py is where the action is at. >> Neal, can you contribute a bit of your time to help me? >> >> >> > Yes, what type of help would be needed? (I currently know nothing about > cython internals). > What is needed, help where you can: a) Explain/dig up references about the C++ complex type. b) Figure out how Boost++ does conversion of complex floating point (is it using the same type as in a)?) c) Figure out if it is guaranteed that it has the same memory layout as struct { floattype real, imag; } so that one can cast pointers as well as converting values. d) Help writing testcases Dag Sverre From ndbecker2 at gmail.com Mon Oct 5 18:53:41 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 05 Oct 2009 12:53:41 -0400 Subject: [Cython] status of complex? References: <4ACA01F2.4030104@student.matnat.uio.no> <4ACA2104.7030900@student.matnat.uio.no> Message-ID: Dag Sverre Seljebotn wrote: > Neal Becker wrote: >> >> def sum_cmplx (in1): >> in1 = np.asarray (in1, np.complex128) >> shape = in1.shape >> it = in1.flat >> >> cdef double complex val >> while np.PyArray_ITER_NOTDONE (it): >> val = (np.PyArray_ITER_DATA (it))[0] >> out += val >> np.PyArray_ITER_NEXT (it) >> >> return val >> >> Error converting Pyrex file to C: >> ------------------------------------------------------------ >> ... >> shape = in1.shape >> it = in1.flat >> >> cdef double complex val >> while np.PyArray_ITER_NOTDONE (it): >> val = (np.PyArray_ITER_DATA (it))[0] >> ^ >> ------------------------------------------------------------ >> >> /home/nbecker/raysat/mod/sum.pyx:34:16: 'complex' is not a type >> identifier >> > You need to use a pointer type. > > Dag Sverre Sorry for the obvious mistake. Changing to complex* gives the same: shape = in1.shape it = in1.flat cdef double complex val while np.PyArray_ITER_NOTDONE (it): val = (np.PyArray_ITER_DATA (it))[0] ^ ------------------------------------------------------------ /home/nbecker/raysat/mod/sum.pyx:34:16: 'complex' is not a type identifier From dagss at student.matnat.uio.no Mon Oct 5 19:01:24 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Mon, 05 Oct 2009 19:01:24 +0200 Subject: [Cython] status of complex? In-Reply-To: References: <4ACA01F2.4030104@student.matnat.uio.no> <4ACA2104.7030900@student.matnat.uio.no> Message-ID: <4ACA2664.30507@student.matnat.uio.no> Neal Becker wrote: > Dag Sverre Seljebotn wrote: > > >> Neal Becker wrote: >> >>> >>> def sum_cmplx (in1): >>> in1 = np.asarray (in1, np.complex128) >>> shape = in1.shape >>> it = in1.flat >>> >>> cdef double complex val >>> while np.PyArray_ITER_NOTDONE (it): >>> val = (np.PyArray_ITER_DATA (it))[0] >>> out += val >>> np.PyArray_ITER_NEXT (it) >>> >>> return val >>> >>> Error converting Pyrex file to C: >>> ------------------------------------------------------------ >>> ... >>> shape = in1.shape >>> it = in1.flat >>> >>> cdef double complex val >>> while np.PyArray_ITER_NOTDONE (it): >>> val = (np.PyArray_ITER_DATA (it))[0] >>> ^ >>> ------------------------------------------------------------ >>> >>> /home/nbecker/raysat/mod/sum.pyx:34:16: 'complex' is not a type >>> identifier >>> >>> >> You need to use a pointer type. >> >> Dag Sverre >> > Sorry for the obvious mistake. Changing to complex* gives the same: > shape = in1.shape > it = in1.flat > > cdef double complex val > while np.PyArray_ITER_NOTDONE (it): > val = (np.PyArray_ITER_DATA (it))[0] > ^ > ------------------------------------------------------------ > > /home/nbecker/raysat/mod/sum.pyx:34:16: 'complex' is not a type identifier > At any rate, it should have been here. But it is a bug (please file?). Try to work around it with ctypedef double complex dcomplex ... ... At any rate, you should rather be using np.complex128_t with Cython 0.11.3 and newer, when talking to NumPy arrays. Dag Sverre From ndbecker2 at gmail.com Mon Oct 5 19:09:56 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 05 Oct 2009 13:09:56 -0400 Subject: [Cython] status of complex? References: <4ACA01F2.4030104@student.matnat.uio.no> <4ACA21F3.70100@student.matnat.uio.no> Message-ID: Dag Sverre Seljebotn wrote: > > a) Explain/dig up references about the C++ complex type. > > b) Figure out how Boost++ does conversion of complex floating point (is > it using the same type as in a)?) Boost++? What's that? > > c) Figure out if it is guaranteed that it has the same memory layout as > > struct { floattype real, imag; } > > so that one can cast pointers as well as converting values. > I am almost certain of this, although it would take time to dig up the standards. I'm thinking this is guaranteed in c++0x? > d) Help writing testcases > > Dag Sverre From dalcinl at gmail.com Mon Oct 5 19:18:04 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Mon, 5 Oct 2009 14:18:04 -0300 Subject: [Cython] status of complex? In-Reply-To: References: <4ACA01F2.4030104@student.matnat.uio.no> <4ACA21F3.70100@student.matnat.uio.no> Message-ID: On Mon, Oct 5, 2009 at 2:09 PM, Neal Becker wrote: > Dag Sverre Seljebotn wrote: > > >> >> a) Explain/dig up references about the C++ complex type. >> >> b) Figure out how Boost++ does conversion of complex floating point (is >> it using the same type as in a)?) > > Boost++? ?What's that? > Never mind :-) .. Though FYI, I think Dag was pointing here: http://www.boost.org/doc/libs/1_40_0/libs/python/doc/index.html BTW, SWIG could be another source of inspiration about C++ complex <-> PyComplex conversion... >> >> c) Figure out if it is guaranteed that it has the same memory layout as >> >> struct { floattype real, imag; } >> >> so that one can cast pointers as well as converting values. >> > > I am almost certain of this, although it would take time to dig up the > standards. ?I'm thinking this is guaranteed in c++0x? > Mmm... I think you are right.. I remember I've read about this somewhere, C++ complex cannot be internally stored in polar form, for example... But a check from you side -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From robertwb at math.washington.edu Mon Oct 5 19:24:31 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 5 Oct 2009 10:24:31 -0700 Subject: [Cython] Parse tree assertions for doctests In-Reply-To: <4AC8C08E.3060508@behnel.de> References: <4AC8C08E.3060508@behnel.de> Message-ID: <050ECB57-8EAD-460B-A2C6-B3BC1D774D33@math.washington.edu> On Oct 4, 2009, at 8:34 AM, Stefan Behnel wrote: > Hi all, > > I implemented the test support for parse tree assertions and put > some docs > into the Wiki. > > http://wiki.cython.org/HackerGuide#Parsetreeassertions > > The main idea is that you add decorators to your doctest functions: > > @cython.test_fail_if_path_exists("//...") > @cython.test_assert_path_exists("//...") > def some_test(): > ... > > They will be evaluated in the compiler pipeline, activated by a > compiler > option that the test runner uses. > > For example, the for-range transformation can be tested like this: > > @cython.test_fail_if_path_exists("//ForInStatNode") > @cython.test_assert_path_exists("//ForFromStatNode") > def test(): > cdef int i > for i in range(100): > pass > > Simple enough. +1 That's great. The only comment I have is the names seem a bit verbose, but that's not too important. > Note that this isn't currently exported to pure mode as I didn't see a > reason to make it 'public' (i.e. export it in Shadow.py). I agree. - Robert From robertwb at math.washington.edu Mon Oct 5 19:35:33 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 5 Oct 2009 10:35:33 -0700 Subject: [Cython] -unstable and -devel branch Message-ID: <4012D449-E725-4614-9FB5-A8FD07D7BF80@math.washington.edu> Does anyone have any objections to merging -unstable into -devel in preparation for the next release? - Robert From ndbecker2 at gmail.com Mon Oct 5 19:37:51 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 05 Oct 2009 13:37:51 -0400 Subject: [Cython] status of complex? References: <4ACA01F2.4030104@student.matnat.uio.no> <4ACA21F3.70100@student.matnat.uio.no> Message-ID: Dag Sverre Seljebotn wrote: > What is needed, help where you can: > > a) Explain/dig up references about the C++ complex type. I think this is the most up-to-date reference, but not yet adopted: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2960.pdf One tricky area. How to get/put the real/imag values? This seems to have evolved. First there are both member and non-member functions for real() and imag(). Second, seems to have evolved as to whether these return lvalues. Meaning, on gcc-4.4.1 today this should work: real(z) = 2 But reading the above standard, I think the way to put real, imag values would be: z.real (2) I believe the non-member versions in c++0x only allow getting the value -------------------- #include void foo () { typedef std::complex complex_t; complex_t z; z.real(2); real (z) = 2; } ---------------------- gcc-4.4.1 normal mode: OK gcc-4.4.1 -std=c++0x: test_complex.cc:10: error: lvalue required as left operand of assignment So: typedef std::complex complex_t 1) create complex: complex_t z (x, y); or complex_t z = complex_t (x, y) 2) get real/imag part: double x = z.real() or double x = real(z) 3) put real/imag parg: z.real(x) Note: z.real()=x used to work but not going forward z.real is a member function, not the data! From stefan_ml at behnel.de Mon Oct 5 19:46:29 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 05 Oct 2009 19:46:29 +0200 Subject: [Cython] -unstable and -devel branch In-Reply-To: <4012D449-E725-4614-9FB5-A8FD07D7BF80@math.washington.edu> References: <4012D449-E725-4614-9FB5-A8FD07D7BF80@math.washington.edu> Message-ID: <4ACA30F5.4000502@behnel.de> Robert Bradshaw wrote: > Does anyone have any objections to merging -unstable into -devel in > preparation for the next release? I bet you meant that anyway, but I'd prefer replacing cython-devel with cython-unstable, and (maybe) keeping the current cython-devel as a legacy 0.11.x branch. We kept cython-unstable updated from cython-devel, so there shouldn't be anything missing. Stefan From robertwb at math.washington.edu Mon Oct 5 20:03:46 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 5 Oct 2009 11:03:46 -0700 Subject: [Cython] -unstable and -devel branch In-Reply-To: <4ACA30F5.4000502@behnel.de> References: <4012D449-E725-4614-9FB5-A8FD07D7BF80@math.washington.edu> <4ACA30F5.4000502@behnel.de> Message-ID: <7FAF8C93-DF4C-4251-9A00-E7969C051893@math.washington.edu> On Oct 5, 2009, at 10:46 AM, Stefan Behnel wrote: > Robert Bradshaw wrote: >> Does anyone have any objections to merging -unstable into -devel in >> preparation for the next release? > > I bet you meant that anyway, but I'd prefer replacing cython-devel > with > cython-unstable, and (maybe) keeping the current cython-devel as a > legacy > 0.11.x branch. > > We kept cython-unstable updated from cython-devel, so there > shouldn't be > anything missing. Yes, that's what I meant, -unstable would become the new -devel up on hg.cython.org - Robert From dalcinl at gmail.com Mon Oct 5 21:12:59 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Mon, 5 Oct 2009 16:12:59 -0300 Subject: [Cython] -unstable and -devel branch In-Reply-To: <7FAF8C93-DF4C-4251-9A00-E7969C051893@math.washington.edu> References: <4012D449-E725-4614-9FB5-A8FD07D7BF80@math.washington.edu> <4ACA30F5.4000502@behnel.de> <7FAF8C93-DF4C-4251-9A00-E7969C051893@math.washington.edu> Message-ID: Sorry, I'm lost ... Can any of you explicitly explain what the new repo names are going to be? BTW, if we are going to leave a legacy 0.11.3 branch, it would be clear to rename it to cython-release-0.11 or something like that... On Mon, Oct 5, 2009 at 3:03 PM, Robert Bradshaw wrote: > On Oct 5, 2009, at 10:46 AM, Stefan Behnel wrote: > >> Robert Bradshaw wrote: >>> Does anyone have any objections to merging -unstable into -devel in >>> preparation for the next release? >> >> I bet you meant that anyway, but I'd prefer replacing cython-devel >> with >> cython-unstable, and (maybe) keeping the current cython-devel as a >> legacy >> 0.11.x branch. >> >> We kept cython-unstable updated from cython-devel, so there >> shouldn't be >> anything missing. > > Yes, that's what I meant, -unstable would become the new -devel up on > hg.cython.org > > - Robert > > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From stefan_ml at behnel.de Mon Oct 5 21:19:38 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 05 Oct 2009 21:19:38 +0200 Subject: [Cython] -unstable and -devel branch In-Reply-To: References: <4012D449-E725-4614-9FB5-A8FD07D7BF80@math.washington.edu> <4ACA30F5.4000502@behnel.de> <7FAF8C93-DF4C-4251-9A00-E7969C051893@math.washington.edu> Message-ID: <4ACA46CA.50502@behnel.de> Lisandro Dalcin wrote: > Sorry, I'm lost ... Can any of you explicitly explain what the new > repo names are going to be? BTW, if we are going to leave a legacy > 0.11.3 branch, it would be clear to rename it to cython-release-0.11 > or something like that... Ah, now that you mention it: Cython 0.11.3 didn't make it to the "cython" branch. We should make Cython 0.11.3 "cython" now and "cython-0.11" when Cython 0.12 gets released, and Cython 0.12 "cython-devel" now and "cython" when it gets released (with continued development in "cython-devel"). Let's see when we start needing a new "cython-unstable" then. Stefan From dalcinl at gmail.com Mon Oct 5 21:27:18 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Mon, 5 Oct 2009 16:27:18 -0300 Subject: [Cython] -unstable and -devel branch In-Reply-To: <4ACA46CA.50502@behnel.de> References: <4012D449-E725-4614-9FB5-A8FD07D7BF80@math.washington.edu> <4ACA30F5.4000502@behnel.de> <7FAF8C93-DF4C-4251-9A00-E7969C051893@math.washington.edu> <4ACA46CA.50502@behnel.de> Message-ID: On Mon, Oct 5, 2009 at 4:19 PM, Stefan Behnel wrote: > > Let's see when we start needing a new "cython-unstable" then. > OK, that's the reason I asked... Let's use cython-unstable only if required and for wild experimental stuf. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From stefan_ml at behnel.de Mon Oct 5 21:48:28 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 05 Oct 2009 21:48:28 +0200 Subject: [Cython] -unstable and -devel branch In-Reply-To: <7FAF8C93-DF4C-4251-9A00-E7969C051893@math.washington.edu> References: <4012D449-E725-4614-9FB5-A8FD07D7BF80@math.washington.edu> <4ACA30F5.4000502@behnel.de> <7FAF8C93-DF4C-4251-9A00-E7969C051893@math.washington.edu> Message-ID: <4ACA4D8C.2090501@behnel.de> Robert Bradshaw wrote: > -unstable would become the new -devel up on hg.cython.org BTW, do you think we're close enough to a release to just put out a 0.12 alpha when that's done? I really hope that users will jump on the new features soon and come up with more bug reports even before the beta phase. The only real thing I still see missing is the cython-closures merge. If we merge that before 0.12, it should go into the first alpha, too. Stefan From dagss at student.matnat.uio.no Mon Oct 5 21:53:34 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Mon, 05 Oct 2009 21:53:34 +0200 Subject: [Cython] -unstable and -devel branch In-Reply-To: <4ACA46CA.50502@behnel.de> References: <4012D449-E725-4614-9FB5-A8FD07D7BF80@math.washington.edu> <4ACA30F5.4000502@behnel.de> <7FAF8C93-DF4C-4251-9A00-E7969C051893@math.washington.edu> <4ACA46CA.50502@behnel.de> Message-ID: <4ACA4EBE.3070904@student.matnat.uio.no> Stefan Behnel wrote: > Lisandro Dalcin wrote: >> Sorry, I'm lost ... Can any of you explicitly explain what the new >> repo names are going to be? BTW, if we are going to leave a legacy >> 0.11.3 branch, it would be clear to rename it to cython-release-0.11 >> or something like that... > > Ah, now that you mention it: Cython 0.11.3 didn't make it to the "cython" > branch. > > We should make Cython 0.11.3 "cython" now and "cython-0.11" when Cython > 0.12 gets released, and Cython 0.12 "cython-devel" now and "cython" when it > gets released (with continued development in "cython-devel"). > > Let's see when we start needing a new "cython-unstable" then. IMO cython-closures should be our new cython-unstable, to make sure it is tested and merged and keep the number of (cooperative) branches down. And I think that if there's possibilities of a bug day, it would be good to take it before 0.12 to knock off all those small irritating "Cython crashes" bugs. But I guess that shouldn't hold off 0.12 for too long, we can do a 0.12.1 a month later anyway. -- Dag Sverre From dalcinl at gmail.com Mon Oct 5 22:18:59 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Mon, 5 Oct 2009 17:18:59 -0300 Subject: [Cython] C++ complex support Message-ID: Well, I'm hacking on supporting C++ complex, but have some questions Robert: why did you bothered about using 'infix' operators instead of using macros when c99 complex is on? Just to generate more readable C code? Could this be changed to always use the macros? I'm facing some trouble... I'm adding a 'cxx_complex' directive, but I'm not sure what to do in these situations (I'm thinking in a C++ compiler supporting C99 complex) 1) What to do here? Use struct-based complex? compiler: C c99_complex=0 cxx_complex=1 2) What to do here? Use struct-based complex? compiler: C++ c99_complex=1 cxx_complex=0 3) What to do here? Use C99 complex? compiler: C c99_complex=1 cxx_complex=1 4) What to do here? Use C++ complex? compiler: C c99_complex=1 cxx_complex=1 -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From stefan_ml at behnel.de Mon Oct 5 22:33:14 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 05 Oct 2009 22:33:14 +0200 Subject: [Cython] -unstable and -devel branch In-Reply-To: <4ACA4EBE.3070904@student.matnat.uio.no> References: <4012D449-E725-4614-9FB5-A8FD07D7BF80@math.washington.edu> <4ACA30F5.4000502@behnel.de> <7FAF8C93-DF4C-4251-9A00-E7969C051893@math.washington.edu> <4ACA46CA.50502@behnel.de> <4ACA4EBE.3070904@student.matnat.uio.no> Message-ID: <4ACA580A.8090307@behnel.de> Dag Sverre Seljebotn wrote: > IMO cython-closures should be our new cython-unstable, to make sure it > is tested and merged and keep the number of (cooperative) branches down. I don't mind either way. I agree that cython-closures can really use some more testing and shouldn't delay 0.12. > And I think that if there's possibilities of a bug day, it would be good > to take it before 0.12 to knock off all those small irritating "Cython > crashes" bugs. But I guess that shouldn't hold off 0.12 for too long, we > can do a 0.12.1 a month later anyway. Fine with me. Regarding a bug day, I have no idea when I'll be available for a whole day, though. Stefan From harald.schilly at gmail.com Mon Oct 5 23:17:46 2009 From: harald.schilly at gmail.com (Harald Schilly) Date: Mon, 5 Oct 2009 23:17:46 +0200 Subject: [Cython] howto call and build cython definitions from C Message-ID: <20548feb0910051417q281661d8o43385f92fad783a3@mail.gmail.com> hi, i want to call cython definitions from C and I know about http://docs.cython.org/docs/external_C_code.html#using-cython-declarations-from-c which looks exactly what i want, but i have no idea how to build and link everything together so that it works. Is there somewhere some kind of blueprint example? h From ondrej at certik.cz Mon Oct 5 23:36:23 2009 From: ondrej at certik.cz (Ondrej Certik) Date: Mon, 5 Oct 2009 14:36:23 -0700 Subject: [Cython] [pyamg-user] Re: Calling pyamg from an external Fortran90 application In-Reply-To: References: <8749999d-12c7-4172-b78e-16b8fb89bb91@g1g2000vbr.googlegroups.com> <85b5c3130910050954p100aa72ah3d89b58faa5136d8@mail.gmail.com> Message-ID: <85b5c3130910051436r270b17fag84cc7fb875217ea8@mail.gmail.com> On Mon, Oct 5, 2009 at 1:37 PM, Luke Olson wrote: > > > On Mon, Oct 5, 2009 at 11:54 AM, Ondrej Certik wrote: >> >> On Mon, Oct 5, 2009 at 5:03 AM, Luke wrote: >> > >> > AS, >> > >> > Thanks for you comments. ?Glad you've liked the package so far. >> > >> > As for your Fortran code, we're working on a pure C-branch >> > specifically for this reason. ?It's a ways off, however. ?I've tried >> > both of your solutions: >> > >> > Solution1: >> > For me this worked very well. ?I was impressed with F2Py. ?I had to do >> > very little coding to interface Python with Fortran and did not notice >> > a performance drop. ?This is an easy first pass that's worth trying. >> > >> > Solution 2: >> > I've never been able to do this :) ?Embedding the interpreter works >> > (for me) for very small python examples, but nothing with SciPy/NumPy/ >> > PyAMG. ?You may be a little more savvy, however; I didn't spend too >> > much time investigating. >> >> The example how to do embed python (and numpy+scipy works!) into a C >> (resp. C++) app is here: >> >> http://hpfem.org/hermes1d/ >> >> e.g. do: >> >> git clone http://hpfem.math.unr.edu/git/hermes1d.git >> cd hermes1d >> python -c 'print "set(WITH_PYTHON yes)\n"' > CMake.vars >> cmake . >> make >> cd examples/schroedinger >> ./schroedinger >> >> >> and a matplotlib window will popup, I use numpy for solving the >> eigenproblem an this is all done from *within* a C++ app, see the >> main.cpp (see the line 86). Here is an example of how it looks like if >> you run it: >> >> >> http://groups.google.com/group/hermes1d/browse_thread/thread/3f73e5bde7ebe527 >> >> the hermes2d is a very young code, so you will almost surely discover >> some bugs, but the python <-> C interface works great and without any >> problems, I use it in other projects too. >> >> Ondrej >> > > Ondrej, > > Nice example.? One difficulty, however, is that the data is passed by > writing to a file and then rereading in the python script. ? In the other That is just a quick hack. You can ignore that. > example, a full copy is performed. The real challenge for PyAMG would be to > pass a reference to the data as data to a numpy object.? If you have any > example of this, that would be helpful. It's super easy to pass a reference to the data, *without* copying anything. See below how to do it. In the other example, this Cython code is responsible for converting C++ array into a numpy array: cdef ndarray array_double_c2numpy(double *A, int len): from numpy import empty cdef ndarray vec = empty([len], dtype="double") cdef double *pvec = vec.data memcpy(pvec, A, len*sizeof(double)) return vec (see python/hermes1d/_hermes1d.pyx, line 94), so currently the data is copied, because that is the safest approach (you never know if the C++/Python code doesn't free the memory if the other one needs it). In my case the memcopy is really fast and not the bottleneck. If however, you know that you can safely use the exact same memory from both C++ and Python, or the memcpy is really killing you, just use this patch: diff --git a/python/hermes1d/_hermes1d.pyx b/python/hermes1d/_hermes1d.pyx index c1d8cdd..3586069 100644 --- a/python/hermes1d/_hermes1d.pyx +++ b/python/hermes1d/_hermes1d.pyx @@ -94,8 +94,9 @@ cdef ndarray array_int_c2numpy(int *A, int len): cdef ndarray array_double_c2numpy(double *A, int len): from numpy import empty cdef ndarray vec = empty([len], dtype="double") - cdef double *pvec = vec.data - memcpy(pvec, A, len*sizeof(double)) + vec.data = A + #cdef double *pvec = vec.data + #memcpy(pvec, A, len*sizeof(double)) return vec This doesn't copy any memory and I just tested that it works for me. To get data from Python into C++ without copying, just use this code (see the line 101) to convert from python to C++: cdef api void array_double_numpy2c_inplace(object A_n, double **A_c, int *n): cdef ndarray A = A_n if not (A.nd == 1 and A.strides[0] == sizeof(double)): from numpy import array A = array(A.flat, dtype="double") n[0] = len(A) A_c[0] = (A.data) you can see that no memory is copied, except if the numpy array is not contiguous. I tested that and it works for me. Note that this inplace creating of numpy arrays doesn't usually work for me, since I use a code like this: insert_int("len", len); double _mat[len*len]; for(int i=0; iget(i, j); insert_double_array("mat", _mat, len*len); the insert_double_array() calls the array_double_c2numpy() above and as you can see, the _mat memory gets destroyed after the insert_double_array(), so one has to be really careful and think about this all the time. To fix the above, I would have to do: diff --git a/examples/schroedinger/main.cpp b/examples/schroedinger/main.cpp index 50c35bf..6bfd107 100644 --- a/examples/schroedinger/main.cpp +++ b/examples/schroedinger/main.cpp @@ -37,7 +37,7 @@ double rhs(int num, double *x, double *weights, void insert_matrix(DenseMatrix *mat, int len) { insert_int("len", len); - double _mat[len*len]; + double *_mat = new double[len*len]; for(int i=0; iget(i, j); then it works. But as I said, it's a major pain to handle this memory by hand. Ondrej P.S. CCing cython-dev, maybe someone there could offer a better advise. From ondrej at certik.cz Mon Oct 5 23:41:27 2009 From: ondrej at certik.cz (Ondrej Certik) Date: Mon, 5 Oct 2009 14:41:27 -0700 Subject: [Cython] [pyamg-user] Re: Calling pyamg from an external Fortran90 application In-Reply-To: <85b5c3130910051436r270b17fag84cc7fb875217ea8@mail.gmail.com> References: <8749999d-12c7-4172-b78e-16b8fb89bb91@g1g2000vbr.googlegroups.com> <85b5c3130910050954p100aa72ah3d89b58faa5136d8@mail.gmail.com> <85b5c3130910051436r270b17fag84cc7fb875217ea8@mail.gmail.com> Message-ID: <85b5c3130910051441o722b9018j9d7c1735144aa553@mail.gmail.com> On Mon, Oct 5, 2009 at 2:36 PM, Ondrej Certik wrote: > On Mon, Oct 5, 2009 at 1:37 PM, Luke Olson wrote: >> >> >> On Mon, Oct 5, 2009 at 11:54 AM, Ondrej Certik wrote: >>> >>> On Mon, Oct 5, 2009 at 5:03 AM, Luke wrote: >>> > >>> > AS, >>> > >>> > Thanks for you comments. ?Glad you've liked the package so far. >>> > >>> > As for your Fortran code, we're working on a pure C-branch >>> > specifically for this reason. ?It's a ways off, however. ?I've tried >>> > both of your solutions: >>> > >>> > Solution1: >>> > For me this worked very well. ?I was impressed with F2Py. ?I had to do >>> > very little coding to interface Python with Fortran and did not notice >>> > a performance drop. ?This is an easy first pass that's worth trying. >>> > >>> > Solution 2: >>> > I've never been able to do this :) ?Embedding the interpreter works >>> > (for me) for very small python examples, but nothing with SciPy/NumPy/ >>> > PyAMG. ?You may be a little more savvy, however; I didn't spend too >>> > much time investigating. >>> >>> The example how to do embed python (and numpy+scipy works!) into a C >>> (resp. C++) app is here: >>> >>> http://hpfem.org/hermes1d/ >>> >>> e.g. do: >>> >>> git clone http://hpfem.math.unr.edu/git/hermes1d.git >>> cd hermes1d >>> python -c 'print "set(WITH_PYTHON yes)\n"' > CMake.vars >>> cmake . >>> make >>> cd examples/schroedinger >>> ./schroedinger >>> >>> >>> and a matplotlib window will popup, I use numpy for solving the >>> eigenproblem an this is all done from *within* a C++ app, see the >>> main.cpp (see the line 86). Here is an example of how it looks like if >>> you run it: >>> >>> >>> http://groups.google.com/group/hermes1d/browse_thread/thread/3f73e5bde7ebe527 >>> >>> the hermes2d is a very young code, so you will almost surely discover >>> some bugs, but the python <-> C interface works great and without any >>> problems, I use it in other projects too. >>> >>> Ondrej >>> >> >> Ondrej, >> >> Nice example.? One difficulty, however, is that the data is passed by >> writing to a file and then rereading in the python script. ? In the other > > That is just a quick hack. You can ignore that. > >> example, a full copy is performed. The real challenge for PyAMG would be to >> pass a reference to the data as data to a numpy object.? If you have any >> example of this, that would be helpful. > > It's super easy to pass a reference to the data, *without* copying > anything. See below how to do it. > > In the other example, this Cython code is responsible for converting > C++ array into a numpy array: > > cdef ndarray array_double_c2numpy(double *A, int len): > ? ?from numpy import empty > ? ?cdef ndarray vec = empty([len], dtype="double") > ? ?cdef double *pvec = vec.data > ? ?memcpy(pvec, A, len*sizeof(double)) > ? ?return vec > > (see python/hermes1d/_hermes1d.pyx, line 94), so currently the data is > copied, because that is the safest approach (you never know if the > C++/Python code doesn't free the memory if the other one needs it). In > my case the memcopy is really fast and not the bottleneck. > > If however, you know that you can safely use the exact same memory > from both C++ and Python, or the memcpy is really killing you, just > use this patch: > > diff --git a/python/hermes1d/_hermes1d.pyx b/python/hermes1d/_hermes1d.pyx > index c1d8cdd..3586069 100644 > --- a/python/hermes1d/_hermes1d.pyx > +++ b/python/hermes1d/_hermes1d.pyx > @@ -94,8 +94,9 @@ cdef ndarray array_int_c2numpy(int *A, int len): > ?cdef ndarray array_double_c2numpy(double *A, int len): > ? ? from numpy import empty > ? ? cdef ndarray vec = empty([len], dtype="double") > - ? ?cdef double *pvec = vec.data > - ? ?memcpy(pvec, A, len*sizeof(double)) > + ? ?vec.data = A > + ? ?#cdef double *pvec = vec.data > + ? ?#memcpy(pvec, A, len*sizeof(double)) > ? ? return vec One problem that I can see with this is that the "vec.data" is first allocated, and then I should free it myself in the above function, and then numpy will free the new "vec.data". This also takes care of: > then it works. But as I said, it's a major pain to handle this memory by hand. ^^^ numpy actually frees it for me I think. The remaining problem is how to make numpy not to allocate the memory at all. But in any case, that imho is a minor problem, it should not slow things down and if you free it yourself in the above function, it should get you started. Please ping me if you figure out how to force numpy not to allocate the "vec.data" in the first place. Ondrej From vel.accel at gmail.com Mon Oct 5 23:43:44 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Mon, 5 Oct 2009 17:43:44 -0400 Subject: [Cython] howto call and build cython definitions from C In-Reply-To: <20548feb0910051417q281661d8o43385f92fad783a3@mail.gmail.com> References: <20548feb0910051417q281661d8o43385f92fad783a3@mail.gmail.com> Message-ID: <1e52e0880910051443p61e02fdem23e68f93de3abfa3@mail.gmail.com> On Mon, Oct 5, 2009 at 5:17 PM, Harald Schilly wrote: > hi, i want to call cython definitions from C and I know about > http://docs.cython.org/docs/external_C_code.html#using-cython-declarations-from-c > which looks exactly what i want, but i have no idea how to build and > link everything together so that it works. Is there somewhere some > kind of blueprint example? > > h > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > Better documentation is being worked on atm. In the mean time on the wiki [1], several articles show how to build. Also are there are two new tutorials [2][3]in pdf that we will be migrating over soon as well. [1] http://wiki.cython.org/ [2] http://sage.math.washington.edu/home/dagss/cython-tutorial-preprint.pdf [3] http://sage.math.washington.edu/home/dagss/numerical-cython-preprint.pdf From craigcitro at gmail.com Tue Oct 6 01:56:35 2009 From: craigcitro at gmail.com (Craig Citro) Date: Mon, 5 Oct 2009 16:56:35 -0700 Subject: [Cython] -unstable and -devel branch In-Reply-To: <4ACA580A.8090307@behnel.de> References: <4012D449-E725-4614-9FB5-A8FD07D7BF80@math.washington.edu> <4ACA30F5.4000502@behnel.de> <7FAF8C93-DF4C-4251-9A00-E7969C051893@math.washington.edu> <4ACA46CA.50502@behnel.de> <4ACA4EBE.3070904@student.matnat.uio.no> <4ACA580A.8090307@behnel.de> Message-ID: >> IMO cython-closures should be our new cython-unstable, to make sure it >> is tested and merged and keep the number of (cooperative) branches down. > > I don't mind either way. I agree that cython-closures can really use some > more testing and shouldn't delay 0.12. > I actually just posted a patch (actually, two patches, because I forgot to run tests before I pushed) to that branch. This is the bug that Robert ran into during our SD15 talk ... it should work now. I'm going to try and run a bunch more tests tonight, but I'm also +1 on cython-closures becoming the new cython-unstable. -cc From robertwb at math.washington.edu Tue Oct 6 02:34:08 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 5 Oct 2009 17:34:08 -0700 Subject: [Cython] -unstable and -devel branch In-Reply-To: <4ACA4EBE.3070904@student.matnat.uio.no> References: <4012D449-E725-4614-9FB5-A8FD07D7BF80@math.washington.edu> <4ACA30F5.4000502@behnel.de> <7FAF8C93-DF4C-4251-9A00-E7969C051893@math.washington.edu> <4ACA46CA.50502@behnel.de> <4ACA4EBE.3070904@student.matnat.uio.no> Message-ID: <2F5359FA-9D35-4C4B-9244-8B272E4EAD59@math.washington.edu> On Oct 5, 2009, at 12:53 PM, Dag Sverre Seljebotn wrote: > Stefan Behnel wrote: >> Lisandro Dalcin wrote: >>> Sorry, I'm lost ... Can any of you explicitly explain what the new >>> repo names are going to be? BTW, if we are going to leave a legacy >>> 0.11.3 branch, it would be clear to rename it to cython-release-0.11 >>> or something like that... >> >> Ah, now that you mention it: Cython 0.11.3 didn't make it to the >> "cython" >> branch. >> >> We should make Cython 0.11.3 "cython" now and "cython-0.11" when >> Cython >> 0.12 gets released, and Cython 0.12 "cython-devel" now and >> "cython" when it >> gets released (with continued development in "cython-devel"). >> >> Let's see when we start needing a new "cython-unstable" then. > > IMO cython-closures should be our new cython-unstable, to make sure it > is tested and merged and keep the number of (cooperative) branches > down. Lets leave cython-closures as cython-closures, until we feel it is stable enough to merge (and, with the latest patch, hopefully soon :), and only go to using -unstable when we really need it for something wildly crazy and potentially (but temporarily) very broken (like the temp refactoring). > And I think that if there's possibilities of a bug day, it would be > good > to take it before 0.12 to knock off all those small irritating "Cython > crashes" bugs. But I guess that shouldn't hold off 0.12 for too > long, we > can do a 0.12.1 a month later anyway. Yes, how about the 10th or 17th of this month (next Saturday, or the next) for a Cython bugs day? We could cut a beta right after that. - Robert From robertwb at math.washington.edu Tue Oct 6 02:38:07 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 5 Oct 2009 17:38:07 -0700 Subject: [Cython] howto call and build cython definitions from C In-Reply-To: <1e52e0880910051443p61e02fdem23e68f93de3abfa3@mail.gmail.com> References: <20548feb0910051417q281661d8o43385f92fad783a3@mail.gmail.com> <1e52e0880910051443p61e02fdem23e68f93de3abfa3@mail.gmail.com> Message-ID: On Oct 5, 2009, at 2:43 PM, Peter Alexander wrote: > On Mon, Oct 5, 2009 at 5:17 PM, Harald Schilly > wrote: >> hi, i want to call cython definitions from C and I know about >> http://docs.cython.org/docs/external_C_code.html#using-cython- >> declarations-from-c >> which looks exactly what i want, but i have no idea how to build and >> link everything together so that it works. Is there somewhere some >> kind of blueprint example? >> >> h >> _______________________________________________ >> Cython-dev mailing list >> Cython-dev at codespeak.net >> http://codespeak.net/mailman/listinfo/cython-dev >> > > Better documentation is being worked on atm. > > In the mean time on the wiki [1], several articles show how to build. > > Also are there are two new tutorials [2][3]in pdf that we will be > migrating over soon as well. > > [1] http://wiki.cython.org/ > [2] http://sage.math.washington.edu/home/dagss/cython-tutorial- > preprint.pdf > [3] http://sage.math.washington.edu/home/dagss/numerical-cython- > preprint.pdf At the moment, for a specific example, I would look at the many examples in Sage. - Robert From lodatom at gmail.com Tue Oct 6 03:56:41 2009 From: lodatom at gmail.com (Mark Lodato) Date: Mon, 5 Oct 2009 21:56:41 -0400 Subject: [Cython] --embed and cython_freeze no longer work In-Reply-To: References: <2F34C111-D81E-436B-94F2-FC476680D119@math.washington.edu> Message-ID: On Sun, Oct 4, 2009 at 3:52 AM, Robert Bradshaw wrote: > Just wish we had found it in one of the release candidates... Me too. To be honest, I didn't even know that you included cython_freeze until I saw the release announcement. >> What is the best way to get these changes into Cython? ?I'm used to >> the git model, where I would just post patches to the mailing list, >> but I'm not too familiar with Hg. > > That model works with hg as well, though we typically don't send a > lot of patches back and forth via email as it clutters the mailing > list. Another thing you can do is post the patch to a ticket in trac. > (Don't close the ticket though, or it might not get noticed and > merged...) I created a git clone of the cython-devel repository and posted it to GitHub: http://github.com/MarkLodato/cython/tree/freeze The main line is branch "master" and my changes are in branch "freeze". As far as I can tell, "hg import" accepts git patches - is this correct? I hope so, because I much prefer git to hg. If that's case, I'll post these patches to trac to make it easier for you to import (or whatever would be best for you). By the way, it might be nice to have an automatic, read-only mirror on GitHub. If you're interested in hosting the script to do this, I would be happy to put something together for you. -- Mark From ondrej at certik.cz Tue Oct 6 08:04:22 2009 From: ondrej at certik.cz (Ondrej Certik) Date: Mon, 5 Oct 2009 23:04:22 -0700 Subject: [Cython] [pyamg-user] Re: Calling pyamg from an external Fortran90 application In-Reply-To: <85b5c3130910051441o722b9018j9d7c1735144aa553@mail.gmail.com> References: <8749999d-12c7-4172-b78e-16b8fb89bb91@g1g2000vbr.googlegroups.com> <85b5c3130910050954p100aa72ah3d89b58faa5136d8@mail.gmail.com> <85b5c3130910051436r270b17fag84cc7fb875217ea8@mail.gmail.com> <85b5c3130910051441o722b9018j9d7c1735144aa553@mail.gmail.com> Message-ID: <85b5c3130910052304g1048cf04md99fd42686a2c62e@mail.gmail.com> On Mon, Oct 5, 2009 at 2:41 PM, Ondrej Certik wrote: > On Mon, Oct 5, 2009 at 2:36 PM, Ondrej Certik wrote: >> On Mon, Oct 5, 2009 at 1:37 PM, Luke Olson wrote: >>> >>> >>> On Mon, Oct 5, 2009 at 11:54 AM, Ondrej Certik wrote: >>>> >>>> On Mon, Oct 5, 2009 at 5:03 AM, Luke wrote: >>>> > >>>> > AS, >>>> > >>>> > Thanks for you comments. ?Glad you've liked the package so far. >>>> > >>>> > As for your Fortran code, we're working on a pure C-branch >>>> > specifically for this reason. ?It's a ways off, however. ?I've tried >>>> > both of your solutions: >>>> > >>>> > Solution1: >>>> > For me this worked very well. ?I was impressed with F2Py. ?I had to do >>>> > very little coding to interface Python with Fortran and did not notice >>>> > a performance drop. ?This is an easy first pass that's worth trying. >>>> > >>>> > Solution 2: >>>> > I've never been able to do this :) ?Embedding the interpreter works >>>> > (for me) for very small python examples, but nothing with SciPy/NumPy/ >>>> > PyAMG. ?You may be a little more savvy, however; I didn't spend too >>>> > much time investigating. >>>> >>>> The example how to do embed python (and numpy+scipy works!) into a C >>>> (resp. C++) app is here: >>>> >>>> http://hpfem.org/hermes1d/ >>>> >>>> e.g. do: >>>> >>>> git clone http://hpfem.math.unr.edu/git/hermes1d.git >>>> cd hermes1d >>>> python -c 'print "set(WITH_PYTHON yes)\n"' > CMake.vars >>>> cmake . >>>> make >>>> cd examples/schroedinger >>>> ./schroedinger >>>> >>>> >>>> and a matplotlib window will popup, I use numpy for solving the >>>> eigenproblem an this is all done from *within* a C++ app, see the >>>> main.cpp (see the line 86). Here is an example of how it looks like if >>>> you run it: >>>> >>>> >>>> http://groups.google.com/group/hermes1d/browse_thread/thread/3f73e5bde7ebe527 >>>> >>>> the hermes2d is a very young code, so you will almost surely discover >>>> some bugs, but the python <-> C interface works great and without any >>>> problems, I use it in other projects too. >>>> >>>> Ondrej >>>> >>> >>> Ondrej, >>> >>> Nice example.? One difficulty, however, is that the data is passed by >>> writing to a file and then rereading in the python script. ? In the other >> >> That is just a quick hack. You can ignore that. >> >>> example, a full copy is performed. The real challenge for PyAMG would be to >>> pass a reference to the data as data to a numpy object.? If you have any >>> example of this, that would be helpful. >> >> It's super easy to pass a reference to the data, *without* copying >> anything. See below how to do it. >> >> In the other example, this Cython code is responsible for converting >> C++ array into a numpy array: >> >> cdef ndarray array_double_c2numpy(double *A, int len): >> ? ?from numpy import empty >> ? ?cdef ndarray vec = empty([len], dtype="double") >> ? ?cdef double *pvec = vec.data >> ? ?memcpy(pvec, A, len*sizeof(double)) >> ? ?return vec >> >> (see python/hermes1d/_hermes1d.pyx, line 94), so currently the data is >> copied, because that is the safest approach (you never know if the >> C++/Python code doesn't free the memory if the other one needs it). In >> my case the memcopy is really fast and not the bottleneck. >> >> If however, you know that you can safely use the exact same memory >> from both C++ and Python, or the memcpy is really killing you, just >> use this patch: >> >> diff --git a/python/hermes1d/_hermes1d.pyx b/python/hermes1d/_hermes1d.pyx >> index c1d8cdd..3586069 100644 >> --- a/python/hermes1d/_hermes1d.pyx >> +++ b/python/hermes1d/_hermes1d.pyx >> @@ -94,8 +94,9 @@ cdef ndarray array_int_c2numpy(int *A, int len): >> ?cdef ndarray array_double_c2numpy(double *A, int len): >> ? ? from numpy import empty >> ? ? cdef ndarray vec = empty([len], dtype="double") >> - ? ?cdef double *pvec = vec.data >> - ? ?memcpy(pvec, A, len*sizeof(double)) >> + ? ?vec.data = A >> + ? ?#cdef double *pvec = vec.data >> + ? ?#memcpy(pvec, A, len*sizeof(double)) >> ? ? return vec > > One problem that I can see with this is that the "vec.data" is first > allocated, and then I should free it myself in the above function, and > then numpy will free the new "vec.data". This also takes care of: > >> then it works. But as I said, it's a major pain to handle this memory by hand. > > ^^^ numpy actually frees it for me I think. > > The remaining problem is how to make numpy not to allocate the memory > at all. But in any case, that imho is a minor problem, it should not > slow things down and if you free it yourself in the above function, it > should get you started. > > Please ping me if you figure out how to force numpy not to allocate > the "vec.data" in the first place. Ok, I have fixed that now, the solution is to use the numpy C/API. So if you do now: git clone http://hpfem.math.unr.edu/git/hermes1d.git cd hermes1d python -c 'print "set(WITH_PYTHON yes)\n"' > CMake.vars cmake . make cd examples/schroedinger ./schroedinger it will be copying the data using memcpy. If you apply this patch: diff --git a/examples/schroedinger/main.cpp b/examples/schroedinger/main.cpp index 4800440..5d3be6e 100644 --- a/examples/schroedinger/main.cpp +++ b/examples/schroedinger/main.cpp @@ -36,12 +36,12 @@ double rhs(int num, double *x, double *weights, void insert_matrix(DenseMatrix *mat, int len) { - double _mat[len*len]; + double *_mat = new double[len*len]; for(int i=0; iget(i, j); insert_object("len", c2py_int(len)); - insert_object("mat", c2numpy_double(_mat, len*len)); + insert_object("mat", c2numpy_double_inplace(_mat, len*len)); cmd("_ = mat.reshape((len, len))"); cmd("del len"); cmd("del mat"); it will not be copying anything, nor allocating any memory in vain during the conversion. Ondrej From dagss at student.matnat.uio.no Sat Oct 3 09:08:32 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 03 Oct 2009 09:08:32 +0200 Subject: [Cython] numpy generic iteration In-Reply-To: References: Message-ID: <4AC6F870.50603@student.matnat.uio.no> Neal Becker wrote: > I need to write functions that apply element-wise numpy arrays, and should > be independent of the number of dimensions. > > numpy has a mechanism for generic (dimension-independent) iteration over > elements of the array, but is there any way to use this (or implement > something similar) in cython? > There's two methods: ufuncs and multi-iterators. ufuncs is the most common one -- search for ufunc on the Cython wiki, there should be an example somewhere. I just did this using multi-iterators (which I had to do because I needed some context -- a temporary buffer -- during the calculation). Attaching my code for calculating a Wigner 3j symbol elementwise with full broadcasting. (It is not as fast as it could be -- it is possible to extract out the inner loop and have it as a C loop rather than rely on the iterator, which is faster. I didn't bother yet though, mainly because each Wigner symbol calculation is rather heavy.) The NumPy docs is rather good in this area, check there next! (search for the multiiterator functions I use + ufuncs) Also you need a newer numpy.pxd than the one shipped with Cython for both ufuncs and multiiterators. Just replace the one in Cython/Includes with the attachment. I will include it in the next Cython release. -- Dag Sverre -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: numpy.pxd Url: http://codespeak.net/pipermail/cython-dev/attachments/20091003/494b951f/attachment.diff -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: wigner.pyx Url: http://codespeak.net/pipermail/cython-dev/attachments/20091003/494b951f/attachment-0001.diff From robertwb at math.washington.edu Tue Oct 6 10:26:56 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Tue, 6 Oct 2009 01:26:56 -0700 Subject: [Cython] --embed and cython_freeze no longer work In-Reply-To: References: <2F34C111-D81E-436B-94F2-FC476680D119@math.washington.edu> Message-ID: <75BA7DE6-995A-4A90-98DB-24758E80E118@math.washington.edu> On Oct 5, 2009, at 6:56 PM, Mark Lodato wrote: > On Sun, Oct 4, 2009 at 3:52 AM, Robert Bradshaw > wrote: >> Just wish we had found it in one of the release candidates... > > Me too. To be honest, I didn't even know that you included > cython_freeze until I saw the release announcement. I remember you were encouraging about including it when this first came up--we just haven't done a release since then. (Well, maybe 0.11.2, but that didn't have much new stuff.) >>> What is the best way to get these changes into Cython? I'm used to >>> the git model, where I would just post patches to the mailing list, >>> but I'm not too familiar with Hg. >> >> That model works with hg as well, though we typically don't send a >> lot of patches back and forth via email as it clutters the mailing >> list. Another thing you can do is post the patch to a ticket in trac. >> (Don't close the ticket though, or it might not get noticed and >> merged...) > > I created a git clone of the cython-devel repository and posted it > to GitHub: > > http://github.com/MarkLodato/cython/tree/freeze > > The main line is branch "master" and my changes are in branch > "freeze". As far as I can tell, "hg import" accepts git patches - is > this correct? I hope so, because I much prefer git to hg. Just out of complete curiosity, why the strong preference? (I like both for different reasons.) > If that's case, I'll post these patches to trac to make it easier > for you to > import (or whatever would be best for you). Yes, please do that. > By the way, it might be nice to have an automatic, read-only mirror on > GitHub. If you're interested in hosting the script to do this, I > would be happy to put something together for you. Sure. - Robert From robertwb at math.washington.edu Tue Oct 6 10:45:37 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Tue, 6 Oct 2009 01:45:37 -0700 Subject: [Cython] C++ complex support In-Reply-To: References: Message-ID: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> On Oct 5, 2009, at 1:18 PM, Lisandro Dalcin wrote: > Well, I'm hacking on supporting C++ complex, but have some questions > > Robert: why did you bothered about using 'infix' operators instead of > using macros when c99 complex is on? Just to generate more readable C > code? Could this be changed to always use the macros? Yep, that's probably why. Is there an advantage to always using the macros. > I'm facing some trouble... I'm adding a 'cxx_complex' directive, but > I'm not sure what to do in these situations (I'm thinking in a C++ > compiler supporting C99 complex) > > 1) What to do here? Use struct-based complex? > compiler: C > c99_complex=0 > cxx_complex=1 > > 2) What to do here? Use struct-based complex? > compiler: C++ > c99_complex=1 > cxx_complex=0 > > 3) What to do here? Use C99 complex? > compiler: C > c99_complex=1 > cxx_complex=1 > > 4) What to do here? Use C++ complex? > compiler: C > c99_complex=1 > cxx_complex=1 So, there's really three types of complex numbers: - Native (struct-based) - c99 (valid for C) - c++ (valid for C++) Is there any case where the latter can both be used? Rather than two boolean directives, I think this calls for a single directive that takes three values. Also, if complex.h is imported, we want compatible complex numbers (whether that's c99 or c++ type). - Robert From dagss at student.matnat.uio.no Tue Oct 6 10:48:26 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Tue, 06 Oct 2009 10:48:26 +0200 Subject: [Cython] -unstable and -devel branch In-Reply-To: <2F5359FA-9D35-4C4B-9244-8B272E4EAD59@math.washington.edu> References: <4012D449-E725-4614-9FB5-A8FD07D7BF80@math.washington.edu> <4ACA30F5.4000502@behnel.de> <7FAF8C93-DF4C-4251-9A00-E7969C051893@math.washington.edu> <4ACA46CA.50502@behnel.de> <4ACA4EBE.3070904@student.matnat.uio.no> <2F5359FA-9D35-4C4B-9244-8B272E4EAD59@math.washington.edu> Message-ID: <4ACB045A.10402@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 5, 2009, at 12:53 PM, Dag Sverre Seljebotn wrote: > > >> And I think that if there's possibilities of a bug day, it would be >> good >> to take it before 0.12 to knock off all those small irritating "Cython >> crashes" bugs. But I guess that shouldn't hold off 0.12 for too >> long, we >> can do a 0.12.1 a month later anyway. >> > > Yes, how about the 10th or 17th of this month (next Saturday, or the > next) for a Cython bugs day? We could cut a beta right after that. > Hmm. Saturdays are taken for me the rest of the month. And since Stefan can't make it and we're on different timezones I'm starting to doubt that it will be practical. Perhaps a few hours early in my morning on some weekday. (In November I'll spend a couple of weeks in the same time zone as you (Pasadena) so perhaps it's better to save it for then though.) Dag Sverre From stefan_ml at behnel.de Tue Oct 6 11:14:05 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 06 Oct 2009 11:14:05 +0200 Subject: [Cython] howto call and build cython definitions from C In-Reply-To: <20548feb0910051417q281661d8o43385f92fad783a3@mail.gmail.com> References: <20548feb0910051417q281661d8o43385f92fad783a3@mail.gmail.com> Message-ID: <4ACB0A5D.9030005@behnel.de> Harald Schilly wrote: > hi, i want to call cython definitions from C and I know about > http://docs.cython.org/docs/external_C_code.html#using-cython-declarations-from-c > which looks exactly what i want, but i have no idea how to build and > link everything together so that it works. Is there somewhere some > kind of blueprint example? Cython generates a header file for functions declared "api" and/or "public". You need to include that in your C source and - the rest depends on what you want to do. Do you want to link your C code into a Python module, or rather embed the CPython Interpreter in a C program and use your Cython module there? Stefan From harald.schilly at gmail.com Tue Oct 6 11:27:19 2009 From: harald.schilly at gmail.com (Harald Schilly) Date: Tue, 6 Oct 2009 11:27:19 +0200 Subject: [Cython] howto call and build cython definitions from C In-Reply-To: <4ACB0A5D.9030005@behnel.de> References: <20548feb0910051417q281661d8o43385f92fad783a3@mail.gmail.com> <4ACB0A5D.9030005@behnel.de> Message-ID: <20548feb0910060227u200695b5u423acda1a7fed099@mail.gmail.com> On Tue, Oct 6, 2009 at 11:14, Stefan Behnel wrote: > Do you want to link your C code into a Python module, or rather embed the > CPython Interpreter in a C program and use your Cython module there? hello, thanks for the answers so far. What I want to do is to call a Python program from an existing C program. I think I know what should be done (compile the cython code with the public keyword, include the header, link to the .so library object) but since I don't know much about building C programs it doesn't do what I want. Cython makes many things easy, but you are still stuck to this gcc compiler and well, sorry for my lack of knowledge, but that's a bit of a mystery to me ;) That's why a working minimal example would be helpful for me and I could look at the build commands. However, if this would be added to the documentation I and probably many others would be happy! Harald From stefan_ml at behnel.de Tue Oct 6 11:35:34 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 06 Oct 2009 11:35:34 +0200 Subject: [Cython] howto call and build cython definitions from C In-Reply-To: <20548feb0910060227u200695b5u423acda1a7fed099@mail.gmail.com> References: <20548feb0910051417q281661d8o43385f92fad783a3@mail.gmail.com> <4ACB0A5D.9030005@behnel.de> <20548feb0910060227u200695b5u423acda1a7fed099@mail.gmail.com> Message-ID: <4ACB0F66.90806@behnel.de> Harald Schilly wrote: > On Tue, Oct 6, 2009 at 11:14, Stefan Behnel wrote: >> Do you want to link your C code into a Python module, or rather embed the >> CPython Interpreter in a C program and use your Cython module there? > > hello, thanks for the answers so far. What I want to do is to call a > Python program from an existing C program. Look at the Demos/embed directory in the Cython source distribution. Stefan From stefan_ml at behnel.de Tue Oct 6 11:40:45 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 06 Oct 2009 11:40:45 +0200 Subject: [Cython] howto call and build cython definitions from C In-Reply-To: <4ACB0F66.90806@behnel.de> References: <20548feb0910051417q281661d8o43385f92fad783a3@mail.gmail.com> <4ACB0A5D.9030005@behnel.de> <20548feb0910060227u200695b5u423acda1a7fed099@mail.gmail.com> <4ACB0F66.90806@behnel.de> Message-ID: <4ACB109D.9070908@behnel.de> Stefan Behnel wrote: > Harald Schilly wrote: >> On Tue, Oct 6, 2009 at 11:14, Stefan Behnel wrote: >>> Do you want to link your C code into a Python module, or rather embed the >>> CPython Interpreter in a C program and use your Cython module there? >> hello, thanks for the answers so far. What I want to do is to call a >> Python program from an existing C program. > > Look at the Demos/embed directory in the Cython source distribution. ... although that won't tell you how to access the public C-API of a module from C code when the module is imported by an embedded CPython runtime. I've never done something like that before. I guess it's not hard, but I don't have any shrink-wrapped example code either. Anyone? Stefan From stefan_ml at behnel.de Tue Oct 6 11:45:18 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 06 Oct 2009 11:45:18 +0200 Subject: [Cython] howto call and build cython definitions from C In-Reply-To: <4ACB109D.9070908@behnel.de> References: <20548feb0910051417q281661d8o43385f92fad783a3@mail.gmail.com> <4ACB0A5D.9030005@behnel.de> <20548feb0910060227u200695b5u423acda1a7fed099@mail.gmail.com> <4ACB0F66.90806@behnel.de> <4ACB109D.9070908@behnel.de> Message-ID: <4ACB11AE.7010804@behnel.de> Stefan Behnel wrote: > Stefan Behnel wrote: >> Harald Schilly wrote: >>> On Tue, Oct 6, 2009 at 11:14, Stefan Behnel wrote: >>>> Do you want to link your C code into a Python module, or rather embed the >>>> CPython Interpreter in a C program and use your Cython module there? >>> hello, thanks for the answers so far. What I want to do is to call a >>> Python program from an existing C program. >> Look at the Demos/embed directory in the Cython source distribution. > > ... although that won't tell you how to access the public C-API of a module > from C code when the module is imported by an embedded CPython runtime. ... think twice before you post. I guess you don't even have to use a public C-API here. It should be enough to use the embedding code and link the Python module directly into your C binary. Then, after initialising the interpreter and calling the module init function, you should be able to call the exported "public" functions of your Cython module directly. But as I said, I never tested that. Would make a nice extension to the Demos/embed example, though. Stefan From dalcinl at gmail.com Tue Oct 6 16:40:39 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Tue, 6 Oct 2009 11:40:39 -0300 Subject: [Cython] C++ complex support In-Reply-To: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> Message-ID: On Tue, Oct 6, 2009 at 5:45 AM, Robert Bradshaw wrote: > On Oct 5, 2009, at 1:18 PM, Lisandro Dalcin wrote: > >> Well, I'm hacking on supporting C++ complex, but have some questions >> >> Robert: why did you bothered about using 'infix' operators instead of >> using macros when c99 complex is on? Just to generate more readable C >> code? Could this be changed to always use the macros? > > Yep, that's probably why. Is there an advantage to always using the > macros. > Was that a question? Then I think yes, we could potentially select at C compile type the kind of complex numbers to use. For this to be possible, the rest of the code has to be identical...Well, this would require to always promote int/float to complexes, but for C99/C++ that can also be done with a macro (no need at all of using a inline function as currently) > > So, there's really three types of complex numbers: > > - Native (struct-based) > - c99 (valid for C) > - c++ (valid for C++) > Yes, but C99 complexes could be used in C++ (for example, IBM compilers seems to let you use C99 complexes in C++, look at the very end of: http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=/com.ibm.vacpp7a.doc/language/ref/clrc03complex_types.htm) > Is there any case where the latter can both be used? Well, you can always compile your C code with C++... And I do think that we should support C compile time selection of the kind of complex to use.. Is this a nonsense? If we can support that, why not? > Rather than two > boolean directives, I think this calls for a single directive that > takes three values. OK, makes sense, of course, so they values should be a string in 'c99', 'c++', 'xxx' (please choose 'xxx', you are our BDLF, the position comes with responsibilities) > Also, if complex.h is imported, we want > compatible complex numbers (whether that's c99 or c++ type). > Well, that's going to be hard in the C++ case... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From cournape at gmail.com Tue Oct 6 16:44:01 2009 From: cournape at gmail.com (David Cournapeau) Date: Tue, 6 Oct 2009 23:44:01 +0900 Subject: [Cython] C++ complex support In-Reply-To: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> Message-ID: <5b8d13220910060744g2d17ddb9t74439669c2feab05@mail.gmail.com> On Tue, Oct 6, 2009 at 5:45 PM, Robert Bradshaw wrote: > On Oct 5, 2009, at 1:18 PM, Lisandro Dalcin wrote: > >> Well, I'm hacking on supporting C++ complex, but have some questions >> >> Robert: why did you bothered about using 'infix' operators instead of >> using macros when c99 complex is on? Just to generate more readable C >> code? Could this be changed to always use the macros? > > Yep, that's probably why. Is there an advantage to always using the > macros. > >> ?I'm facing some trouble... I'm adding a 'cxx_complex' directive, but >> I'm not sure what to do in these situations (I'm thinking in a C++ >> compiler supporting C99 complex) >> >> 1) What to do here? Use struct-based complex? >> compiler: C >> c99_complex=0 >> cxx_complex=1 >> >> 2) What to do here? Use struct-based complex? >> compiler: C++ >> c99_complex=1 >> cxx_complex=0 >> >> 3) What to do here? Use C99 complex? >> compiler: C >> c99_complex=1 >> cxx_complex=1 >> >> 4) What to do here? Use C++ complex? >> compiler: C >> c99_complex=1 >> cxx_complex=1 > > So, there's really three types of complex numbers: > > - Native (struct-based) > - c99 (valid for C) > - c++ (valid for C++) > > Is there any case where the latter can both be used? Rather than two > boolean directives, I think this calls for a single directive that > takes three values. Also, if complex.h is imported, we want > compatible complex numbers (whether that's c99 or c++ type). I am not sure I understand the problem, but C99 complex are explicitly designed to be binary compatible with c++ complex. cheers, David From ndbecker2 at gmail.com Tue Oct 6 16:47:42 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 06 Oct 2009 10:47:42 -0400 Subject: [Cython] C++ complex support References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> Message-ID: Lisandro Dalcin wrote: > On Tue, Oct 6, 2009 at 5:45 AM, Robert Bradshaw > wrote: >> On Oct 5, 2009, at 1:18 PM, Lisandro Dalcin wrote: >> >>> Well, I'm hacking on supporting C++ complex, but have some questions >>> >>> Robert: why did you bothered about using 'infix' operators instead of >>> using macros when c99 complex is on? Just to generate more readable C >>> code? Could this be changed to always use the macros? >> >> Yep, that's probably why. Is there an advantage to always using the >> macros. >> > > Was that a question? Then I think yes, we could potentially select at > C compile type the kind of complex numbers to use. For this to be > possible, the rest of the code has to be identical...Well, this would > require to always promote int/float to complexes, but for C99/C++ that > can also be done with a macro (no need at all of using a inline > function as currently) > >> >> So, there's really three types of complex numbers: >> >> - Native (struct-based) >> - c99 (valid for C) >> - c++ (valid for C++) >> > > Yes, but C99 complexes could be used in C++ (for example, IBM > compilers seems to let you use C99 complexes in C++, look at the very > end of: > http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=/com.ibm.vacpp7a.doc/language/ref/clrc03complex_types.htm) > I'm pretty sure gcc won't allow this. From dalcinl at gmail.com Tue Oct 6 16:50:02 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Tue, 6 Oct 2009 11:50:02 -0300 Subject: [Cython] C++ complex support In-Reply-To: <5b8d13220910060744g2d17ddb9t74439669c2feab05@mail.gmail.com> References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> <5b8d13220910060744g2d17ddb9t74439669c2feab05@mail.gmail.com> Message-ID: On Tue, Oct 6, 2009 at 11:44 AM, David Cournapeau wrote: > > I am not sure I understand the problem, but C99 complex are explicitly > designed to be binary compatible with c++ complex. > Fortunately! The problem is just what 'kind' of complex to use at C/C++ compile time -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Tue Oct 6 17:04:25 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Tue, 6 Oct 2009 12:04:25 -0300 Subject: [Cython] C++ complex support In-Reply-To: References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> Message-ID: On Tue, Oct 6, 2009 at 11:47 AM, Neal Becker wrote: >> >> Yes, but C99 complexes could be used in C++ (for example, IBM >> compilers seems to let you use C99 complexes in C++, look at the very >> end of: >> > http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=/com.ibm.vacpp7a.doc/language/ref/clrc03complex_types.htm) >> > I'm pretty sure gcc won't allow this. > OK. Now I've actually read the C++0x draft, and it seems that the C99 complexes will not be supported (am I right here)? In such case, now it is pretty clear what to do: by default, Cython uses the struct-based complex, and with an appropriate directive (we should rename c99_complex to something more language-agnostic, right?) Cython switches to use C99 complexes in case of C compilation, and C++ complexes in case of C++ compilation. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From ndbecker2 at gmail.com Tue Oct 6 17:07:41 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Tue, 06 Oct 2009 11:07:41 -0400 Subject: [Cython] C++ complex support References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> Message-ID: Lisandro Dalcin wrote: > On Tue, Oct 6, 2009 at 11:47 AM, Neal Becker > wrote: >>> >>> Yes, but C99 complexes could be used in C++ (for example, IBM >>> compilers seems to let you use C99 complexes in C++, look at the very >>> end of: >>> >> http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=/com.ibm.vacpp7a.doc/language/ref/clrc03complex_types.htm) >>> >> I'm pretty sure gcc won't allow this. >> > > OK. Now I've actually read the C++0x draft, and it seems that the C99 > complexes will not be supported (am I right here)? In such case, now > it is pretty clear what to do: by default, Cython uses the > struct-based complex, and with an appropriate directive (we should > rename c99_complex to something more language-agnostic, right?) Cython > switches to use C99 complexes in case of C compilation, and C++ > complexes in case of C++ compilation. > Keep in mind that c++ complex != c99 complex. Specifically, you cannot just get/put values using: double y = z.imag That code got refactored, and the I got a bit lost... can the guilty parties take a look? The generated ClenupGlobals() is opened, but the closing brace is not written. Do we still need to generate CleanupGlobals() ? -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dagss at student.matnat.uio.no Tue Oct 6 19:35:08 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Tue, 06 Oct 2009 19:35:08 +0200 Subject: [Cython] C++ complex support In-Reply-To: References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> Message-ID: <4ACB7FCC.9020901@student.matnat.uio.no> Lisandro Dalcin wrote: > On Tue, Oct 6, 2009 at 11:47 AM, Neal Becker wrote: > >>> Yes, but C99 complexes could be used in C++ (for example, IBM >>> compilers seems to let you use C99 complexes in C++, look at the very >>> end of: >>> >>> >> http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=/com.ibm.vacpp7a.doc/language/ref/clrc03complex_types.htm) >> >> I'm pretty sure gcc won't allow this. >> >> > > OK. Now I've actually read the C++0x draft, and it seems that the C99 > complexes will not be supported (am I right here)? In such case, now > it is pretty clear what to do: by default, Cython uses the > struct-based complex, and with an appropriate directive (we should > rename c99_complex to something more language-agnostic, right?) Cython > switches to use C99 complexes in case of C compilation, and C++ > complexes in case of C++ compilation. > The current behaviour is that Cython figures out at _C compilation time_ whether to use structs or C99 complex. I've forgotten what the directive does but at least if it stays as default, it's figured out automatically. There's already a flag for C++ mode, so most users won't need to touch directives regarding complex support. Dag Sverre From dagss at student.matnat.uio.no Tue Oct 6 19:36:51 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Tue, 06 Oct 2009 19:36:51 +0200 Subject: [Cython] module cleanup broken in cython-unstable In-Reply-To: References: Message-ID: <4ACB8033.1060605@student.matnat.uio.no> Lisandro Dalcin wrote: > That code got refactored, and the I got a bit lost... can the guilty > parties take a look? The generated ClenupGlobals() is opened, but the > closing brace is not written. Do we still need to generate > CleanupGlobals() ? > > It's probably my fault. Can you remind me how to turn on cleanup of globals? Is it possible to do it in the test runner? Why isn't this always turned on? Dag Sverre From robertwb at math.washington.edu Tue Oct 6 20:44:43 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Tue, 6 Oct 2009 11:44:43 -0700 Subject: [Cython] module cleanup broken in cython-unstable In-Reply-To: <4ACB8033.1060605@student.matnat.uio.no> References: <4ACB8033.1060605@student.matnat.uio.no> Message-ID: On Oct 6, 2009, at 10:36 AM, Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: >> That code got refactored, and the I got a bit lost... can the guilty >> parties take a look? The generated ClenupGlobals() is opened, but the >> closing brace is not written. Do we still need to generate >> CleanupGlobals() ? >> >> > It's probably my fault. Can you remind me how to turn on cleanup of > globals? Is it possible to do it in the test runner? Why isn't this > always turned on? Because it is inherently unsafe and can cause segfaults. Perhaps in our tests it'd be OK as modules don't invoke each other. - Robert From robertwb at math.washington.edu Tue Oct 6 21:03:56 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Tue, 6 Oct 2009 12:03:56 -0700 Subject: [Cython] C++ complex support In-Reply-To: <4ACB7FCC.9020901@student.matnat.uio.no> References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> <4ACB7FCC.9020901@student.matnat.uio.no> Message-ID: On Oct 6, 2009, at 10:35 AM, Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: >> On Tue, Oct 6, 2009 at 11:47 AM, Neal Becker >> wrote: >> >>>> Yes, but C99 complexes could be used in C++ (for example, IBM >>>> compilers seems to let you use C99 complexes in C++, look at the >>>> very >>>> end of: >>>> >>>> >>> http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp? >>> topic=/com.ibm.vacpp7a.doc/language/ref/clrc03complex_types.htm) >>> >>> I'm pretty sure gcc won't allow this. >>> >>> >> >> OK. Now I've actually read the C++0x draft, and it seems that the C99 >> complexes will not be supported (am I right here)? In such case, now >> it is pretty clear what to do: by default, Cython uses the >> struct-based complex, and with an appropriate directive (we should >> rename c99_complex to something more language-agnostic, right?) >> Cython >> switches to use C99 complexes in case of C compilation, and C++ >> complexes in case of C++ compilation. >> > The current behaviour is that Cython figures out at _C compilation > time_ > whether to use structs or C99 complex. I've forgotten what the > directive > does but at least if it stays as default, it's figured out > automatically. There's already a flag for C++ mode, so most users > won't > need to touch directives regarding complex support. c99_complex is an internal directive (and I (intentionally) didn't add it to the list of directives because I wasn't sure if that's the final interface we wanted), so I think we're safe to change it. I'm starting to wonder if we even need it at all. Rather, we could use struct-based complexes by default, but if complex.h is included (detected by looking for the specific macros it defines) either c99 or C++ complexes would be used. All arithmetic (including getting/ setting the real/imag parts) would be done via macros. This is essentially the current default behavior, except we'd add support for C++ complexes in place of c99 complexes if, at C compile time, the language is determined to be C++. - Robert From dagss at student.matnat.uio.no Tue Oct 6 22:01:22 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Tue, 06 Oct 2009 22:01:22 +0200 Subject: [Cython] C++ complex support In-Reply-To: References: Message-ID: <4ACBA212.2030006@student.matnat.uio.no> Lisandro Dalcin wrote: > Well, I'm hacking on supporting C++ complex, but have some questions I'm in a situation where the lack of .conjugate() is getting rather out of hand in my code -- I'd really like to have .conjugate() in Cython within the next week or so. If I step in now it might be a lot of unnecesarry merges though. When do you think you'll be done (or start)? (Also something to keep in mind while working on the C++ support, i.e. there should probably be a macro for conjugate.) -- Dag Sverre From dalcinl at gmail.com Tue Oct 6 23:45:10 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Tue, 6 Oct 2009 18:45:10 -0300 Subject: [Cython] module cleanup broken in cython-unstable In-Reply-To: References: <4ACB8033.1060605@student.matnat.uio.no> Message-ID: On Tue, Oct 6, 2009 at 3:44 PM, Robert Bradshaw wrote: > On Oct 6, 2009, at 10:36 AM, Dag Sverre Seljebotn wrote: > >> Lisandro Dalcin wrote: >>> That code got refactored, and the I got a bit lost... can the guilty >>> parties take a look? The generated ClenupGlobals() is opened, but the >>> closing brace is not written. Do we still need to generate >>> CleanupGlobals() ? >>> >>> >> It's probably my fault. Can you remind me how to turn on cleanup of >> globals? Is it possible to do it in the test runner? Why isn't this >> always turned on? > > Because it is inherently unsafe and can cause segfaults. Perhaps in > our tests it'd be OK as modules don't invoke each other. > Anyway, the right way would be to hack on this and make the cleanup code run immediately after the doctests... then we would likely need do have some support for run the cleanup code from Python code and not registering with atexit, ... I mean, having all the module cleanup functions to run at Python exit is a bit disappointing... > - Robert > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Tue Oct 6 23:48:18 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Tue, 6 Oct 2009 18:48:18 -0300 Subject: [Cython] module cleanup broken in cython-unstable In-Reply-To: <4ACB8033.1060605@student.matnat.uio.no> References: <4ACB8033.1060605@student.matnat.uio.no> Message-ID: On Tue, Oct 6, 2009 at 2:36 PM, Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: >> That code got refactored, and the I got a bit lost... can the guilty >> parties take a look? The generated ClenupGlobals() is opened, but the >> closing brace is not written. Do we still need to generate >> CleanupGlobals() ? >> >> > It's probably my fault. Can you remind me how to turn on cleanup of > globals? Not sure how to do that in runtests.py, but in the cmd line you use "cython --clenup 3 ..." ... You can also hack things with this: from Cython.Compiler import Options Options.generate_cleanup_code = 3 > Is it possible to do it in the test runner? Why isn't this > always turned on? > > Dag Sverre > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Wed Oct 7 00:13:02 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Tue, 6 Oct 2009 19:13:02 -0300 Subject: [Cython] C++ complex support In-Reply-To: <4ACBA212.2030006@student.matnat.uio.no> References: <4ACBA212.2030006@student.matnat.uio.no> Message-ID: On Tue, Oct 6, 2009 at 5:01 PM, Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: >> Well, I'm hacking on supporting C++ complex, but have some questions > > I'm in a situation where the lack of .conjugate() is getting rather out > of hand in my code -- I'd really like to have .conjugate() in Cython > within the next week or so. > > If I step in now it might be a lot of unnecesarry merges though. When do > you think you'll be done (or start)? > It is mostly working on my box at work (at home right now)... I could have something working by tomorrow > > (Also something to keep in mind while working on the C++ support, i.e. > there should probably be a macro for conjugate.) > And also for abs(), in case it is not currently handled... > -- > Dag Sverre > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Wed Oct 7 00:32:30 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Tue, 6 Oct 2009 19:32:30 -0300 Subject: [Cython] C++ complex support In-Reply-To: References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> <4ACB7FCC.9020901@student.matnat.uio.no> Message-ID: On Tue, Oct 6, 2009 at 4:03 PM, Robert Bradshaw wrote: > > c99_complex is an internal directive (and I (intentionally) didn't > add it to the list of directives because I wasn't sure if that's the > final interface we wanted), so I think we're safe to change it. I'm > starting to wonder if we even need it at all. I think we need it... you know how much I hate second guessing... I've never liked that of c99 complex being on depending of "complex.h" being included... Moreover, going C++, I do not know how to detect if was #include's ... > Rather, we could use > struct-based complexes by default, but if complex.h is included > (detected by looking for the specific macros it defines) either c99 > or C++ complexes would be used. I have an alternative proposal: Let's call the directive 'ccomplex' (in the spirit of cdivision, which applies both to C and C++)... Cython generates code to support struct-based complexes, C99 _Complex in C, and std::complex<> in C++... there is a C macro PYX_USE_CCOMPLEX that let choose the struct based implementation or the C99/C++ (depending on defined(__cplusplus))... Then the ONLY effect of the directive 'ccomplex=True' would be to make the macro PYX_USE_CCOMPLEX be 1 be default... BUT if at C compile time PYX_USE_CCOMPLEX is set to 0, then the struct-based impl is used.... Similarly, if 'ccomplex=False' (the default), then PYX_USE_CCOMPLEX defaults to 0, BUT again if at C compile time PYX_USE_CCOMPLEX is defined to 1, then the C99 or C++ versions are used depending on __cplusplus... What do you think? I really like this.. > All arithmetic (including getting/ > setting the real/imag parts) would be done via macros. > Of course. Though I anticipate problems the setter/getter for real/imag ... I do think we should have {SET|GET}_{REAL|IMAG} part, if not we will not be able to support C++0x ... Also, currently the C99 support is using __real__/__imag__ > This is essentially the current default behavior, except we'd add > support for C++ complexes in place of c99 complexes if, at C compile > time, the language is determined to be C++. > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From robertwb at math.washington.edu Wed Oct 7 02:11:23 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Tue, 6 Oct 2009 17:11:23 -0700 Subject: [Cython] C++ complex support In-Reply-To: References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> <4ACB7FCC.9020901@student.matnat.uio.no> Message-ID: On Oct 6, 2009, at 3:32 PM, Lisandro Dalcin wrote: > On Tue, Oct 6, 2009 at 4:03 PM, Robert Bradshaw > wrote: >> >> c99_complex is an internal directive (and I (intentionally) didn't >> add it to the list of directives because I wasn't sure if that's the >> final interface we wanted), so I think we're safe to change it. I'm >> starting to wonder if we even need it at all. > > I think we need it... you know how much I hate second guessing... I've > never liked that of c99 complex being on depending of "complex.h" > being included... Moreover, going C++, I do not know how to detect if > was #include's ... #ifdef __STD_COMPLEX ? >> Rather, we could use >> struct-based complexes by default, but if complex.h is included >> (detected by looking for the specific macros it defines) either c99 >> or C++ complexes would be used. > > I have an alternative proposal: Let's call the directive 'ccomplex' > (in the spirit of cdivision, which applies both to C and C++)... > Cython generates code to support struct-based complexes, C99 _Complex > in C, and std::complex<> in C++... there is a C macro PYX_USE_CCOMPLEX > that let choose the struct based implementation or the C99/C++ > (depending on defined(__cplusplus))... > > Then the ONLY effect of the directive 'ccomplex=True' would be to make > the macro PYX_USE_CCOMPLEX be 1 be default... BUT if at C compile time > PYX_USE_CCOMPLEX is set to 0, then the struct-based impl is used.... > > Similarly, if 'ccomplex=False' (the default), then PYX_USE_CCOMPLEX > defaults to 0, BUT again if at C compile time PYX_USE_CCOMPLEX is > defined to 1, then the C99 or C++ versions are used depending on > __cplusplus... > > What do you think? I really like this.. I like ccomplex which forces C99 _Complex or std::complex depending on __cplusplus, but perhaps I have not adequately justified why the auto-setting of PYX_USE_CCOMPLEX is desirable. If complex values are only used internally, then our native implementation works fine and there is no need for c99 or c++ compiler support. If, however, one wants to call some of the math functions in complex.h, or interact with some other library that uses C99/std::complex complex numbers, then our native implementation will create values of the wrong type. What I'd like to avoid is having complex numbers that work great until you decide you want to use something from complex.h, at which point they break. Then one would have to go to the mailing list and/ or FAQ to see that "to use the functions in complex.h, you must set this directive." Since the compiler can figure it out, much better to not bother the user with it at all, and have Cython complex numbers just work in every scenario. To get this, ccomplex=True would set PYX_USE_CCOMPLEX to 1, ccomplex=False would set PYX_USE_CCOMPLEX to something like (defined (_Complex_I) || defined(__STD_COMPLEX)) rather than 0. >> All arithmetic (including getting/ >> setting the real/imag parts) would be done via macros. >> > > Of course. Though I anticipate problems the setter/getter for > real/imag ... I do think we should have {SET|GET}_{REAL|IMAG} part, if > not we will not be able to support C++0x ... Also, currently the C99 > support is using __real__/__imag__ That's because we need something that gives us an lvalue. I bet AttributeNode could be given a special case for complex types that would generate the appropriate macros for assignment. - Robert From lodatom at gmail.com Wed Oct 7 05:07:50 2009 From: lodatom at gmail.com (Mark Lodato) Date: Tue, 6 Oct 2009 23:07:50 -0400 Subject: [Cython] --embed and cython_freeze no longer work In-Reply-To: <75BA7DE6-995A-4A90-98DB-24758E80E118@math.washington.edu> References: <2F34C111-D81E-436B-94F2-FC476680D119@math.washington.edu> <75BA7DE6-995A-4A90-98DB-24758E80E118@math.washington.edu> Message-ID: On Tue, Oct 6, 2009 at 4:26 AM, Robert Bradshaw wrote: > On Oct 5, 2009, at 6:56 PM, Mark Lodato wrote: >> [...] I much prefer git to hg. > > Just out of complete curiosity, why the strong preference? (I like > both for different reasons.) The main reasons why I like git over any other SCM are the index and history rewriting / navigation. In git, I can work quickly without worrying about mistakes, because if I make any, I can easily go back and fix them. The index (along with rebase -i) allows me to make nice history that is readable and useful. The in-place branching is really nice, and it allows me to cheaply try things while saving my complete history. If I decide I don't like the path I've gone down, I can easily back up and go down a different path, saving the history off to the side in case I come back to it in the future. For example, when I developed the cython freeze patches that I posted, I created a topic branch so that my changes would not be mixed up with the official history, and used rebase -i extensively to make sure that my patch series made sense. The supplemental reason is that all of the commands I use on a daily basis seem to be nicer in git than in Hg. Many of the Hg extensions seem like poor imitations of git. In particular, I find the following nicer in git: (By no equivalent, I mean nothing that ships with hg.) * git's index (especially `git add -p`) - no equivalent * git rebase (especially `git rebase -i`) - no equivalent to -i, haven't tried transplant or rebase * git branch - no equivalent * git tag - combination of hg tag and bookmarks seems more awkward * git commit --amend - hg rollback is more work * git stash - no equivalent * git format-patch - no equivalent * gitk - hg view is not as nice * git log - hg is slower, less detailed, and not in color * git grep - hg is much slower * git diff (especially `git diff --color-words`) - hg is slower and has less options To be fair, I really don't know Mercurial, and I imagine once I got used to it some of my problems would go away, and I may even find things I like better about it. But so far, I have found nothing but frustration. >> By the way, it might be nice to have an automatic, read-only mirror on >> GitHub. ?If you're interested in hosting the script to do this, I >> would be happy to put something together for you. > > Sure. Great! This shouldn't be complicated. Just hg-fast-export.sh and git push. I'll put something together when I get a chance. Mark From dalcinl at gmail.com Wed Oct 7 06:08:46 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 7 Oct 2009 01:08:46 -0300 Subject: [Cython] C++ complex support In-Reply-To: References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> <4ACB7FCC.9020901@student.matnat.uio.no> Message-ID: On Tue, Oct 6, 2009 at 9:11 PM, Robert Bradshaw wrote: > On Oct 6, 2009, at 3:32 PM, Lisandro Dalcin wrote: > >> On Tue, Oct 6, 2009 at 4:03 PM, Robert Bradshaw >> wrote: >>> >>> c99_complex is an internal directive (and I (intentionally) didn't >>> add it to the list of directives because I wasn't sure if that's the >>> final interface we wanted), so I think we're safe to change it. I'm >>> starting to wonder if we even need it at all. >> >> I think we need it... you know how much I hate second guessing... I've >> never liked that of c99 complex being on depending of "complex.h" >> being included... Moreover, going C++, I do not know how to detect if >> was #include's ... > > #ifdef __STD_COMPLEX ? > That is not portable at all. GCC (4.4.1) does #define _GLIBCXX_COMPLEX_H, but not __STD_COMPLEX ... This macro is available from IBM's XL C++ compiler and MS VC++, though. Do you have any reference that such macro definition is standard? > > I like ccomplex which forces C99 _Complex or std::complex depending > on __cplusplus, but perhaps I have not adequately justified why the > auto-setting of PYX_USE_CCOMPLEX is desirable. If complex values are > only used internally, then our native implementation works fine and > there is no need for c99 or c++ compiler support. If, however, one > wants to call some of the math functions in complex.h, or interact > with some other library that uses C99/std::complex complex numbers, > then our native implementation will create values of the wrong type. > Well, what worries my is that "complex.h" could end-up being included indirectly... It could certainly happens that some project with many .pyx files end-up using different complex, just because some of then #include some third-party header that in turn #include complex.h ... > What I'd like to avoid is having complex numbers that work great > until you decide you want to use something from complex.h, at which > point they break. Then one would have to go to the mailing list and/ > or FAQ to see that "to use the functions in complex.h, you must set > this directive." I see your point, it really makes sense, but... > Since the compiler can figure it out, much better to > not bother the user with it at all, and have Cython complex numbers > just work in every scenario. That's the problem... can the compiler figure out it? For the C++ case, I still do not know a (standard, portable) way to do that. For C99, it is supposed that _Complex_I is a macro, but are you 100% sure that such macro is guaranteed to be defined, or it is just a consequence of the implementation? > > To get this, ccomplex=True would set PYX_USE_CCOMPLEX to 1, > ccomplex=False would set PYX_USE_CCOMPLEX to something like (defined > (_Complex_I) || defined(__STD_COMPLEX)) rather than 0. > I could live with that, provided that this can be changed at C compile time pasing -DPYX_USE_CCOMPLEX=0/1 ... And provided that up-to now (unless you can point a reference) there is no (portable) way to figure out on C++ that was #include'd , perhaps we should default to use std::complex<> in C++ (what would be the point of using structs in that case) ? >>> All arithmetic (including getting/ >>> setting the real/imag parts) would be done via macros. >>> >> >> Of course. Though I anticipate problems the setter/getter for >> real/imag ... I do think we should have {SET|GET}_{REAL|IMAG} part, if >> not we will not be able to support C++0x ... Also, currently the C99 >> support is using __real__/__imag__ > > > That's because we need something that gives us an lvalue. I bet > AttributeNode could be given a special case for complex types that > would generate the appropriate macros for assignment. > I'll likely require some help with this part... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dagss at student.matnat.uio.no Wed Oct 7 09:35:16 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 07 Oct 2009 09:35:16 +0200 Subject: [Cython] C++ complex support In-Reply-To: References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> <4ACB7FCC.9020901@student.matnat.uio.no> Message-ID: <4ACC44B4.50707@student.matnat.uio.no> Lisandro Dalcin wrote: > On Tue, Oct 6, 2009 at 9:11 PM, Robert Bradshaw > wrote: > >> On Oct 6, 2009, at 3:32 PM, Lisandro Dalcin wrote: >> >> >>> On Tue, Oct 6, 2009 at 4:03 PM, Robert Bradshaw >>> wrote: >>> >>>> c99_complex is an internal directive (and I (intentionally) didn't >>>> add it to the list of directives because I wasn't sure if that's the >>>> final interface we wanted), so I think we're safe to change it. I'm >>>> starting to wonder if we even need it at all. >>>> >>> I think we need it... you know how much I hate second guessing... I've >>> never liked that of c99 complex being on depending of "complex.h" >>> being included... Moreover, going C++, I do not know how to detect if >>> was #include's ... >>> >> #ifdef __STD_COMPLEX ? >> >> > > That is not portable at all. GCC (4.4.1) does #define > _GLIBCXX_COMPLEX_H, but not __STD_COMPLEX ... This macro is available > from IBM's XL C++ compiler and MS VC++, though. > Is there any targeted version of C++ which does not bundle ? Otherwise I'd say we *always* enable C++ complex when C++ is the target, and include ourself if we need to. There's nothing about struct complex which would should make you choose them if compiler support complex, they're there for backwards compatability. (If it's about the possibility of doing our own arithmetic implementation, we can always have a seperate directive "slow_and_safe_complex_arithmetic" which just gets and sets real and imag parts -- this isn't linked to storage type). >> I like ccomplex which forces C99 _Complex or std::complex depending >> on __cplusplus, but perhaps I have not adequately justified why the >> auto-setting of PYX_USE_CCOMPLEX is desirable. If complex values are >> only used internally, then our native implementation works fine and >> there is no need for c99 or c++ compiler support. If, however, one >> wants to call some of the math functions in complex.h, or interact >> with some other library that uses C99/std::complex complex numbers, >> then our native implementation will create values of the wrong type. >> >> > > Well, what worries my is that "complex.h" could end-up being included > indirectly... It could certainly happens that some project with many > .pyx files end-up using different complex, just because some of then > #include some third-party header that in turn #include complex.h ... > If complex.h is somehow included indirectly, then it follows that the compiler supports C99 complex types. If the compiler supports C99 complex, there should never be a version to use the backwards-compatability structs. To make it all more predictable, perhaps we should just include "complex.h" explicitly if we know we are in C99 mode? So basically: - structs for pre-C99 - C complex for C99 - C++ complex for C++ Seems much simpler to explain. (I don't mind overriding the chosen implementation with a CYTHON_COMPLEX_IMPL or similar to the C compiler, but I don't see a need for a directive.) >> Since the compiler can figure it out, much better to >> not bother the user with it at all, and have Cython complex numbers >> just work in every scenario. >> > > That's the problem... can the compiler figure out it? For the C++ > case, I still do not know a (standard, portable) way to do that. For > C99, it is supposed that _Complex_I is a macro, but are you 100% sure > that such macro is guaranteed to be defined, or it is just a > consequence of the implementation? > I remember reading that such a macro is part of the C99 standard, at least. > >> To get this, ccomplex=True would set PYX_USE_CCOMPLEX to 1, >> ccomplex=False would set PYX_USE_CCOMPLEX to something like (defined >> (_Complex_I) || defined(__STD_COMPLEX)) rather than 0. >> >> > > I could live with that, provided that this can be changed at C compile > time pasing -DPYX_USE_CCOMPLEX=0/1 ... > > And provided that up-to now (unless you can point a reference) there > is no (portable) way to figure out on C++ that was > #include'd , perhaps we should default to use std::complex<> in C++ > (what would be the point of using structs in that case) ? > Yep, let's just include ourself. Dag SVerre From dagss at student.matnat.uio.no Wed Oct 7 09:41:19 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 07 Oct 2009 09:41:19 +0200 Subject: [Cython] --embed and cython_freeze no longer work In-Reply-To: References: <2F34C111-D81E-436B-94F2-FC476680D119@math.washington.edu> <75BA7DE6-995A-4A90-98DB-24758E80E118@math.washington.edu> Message-ID: <4ACC461F.6020003@student.matnat.uio.no> Mark Lodato wrote: > On Tue, Oct 6, 2009 at 4:26 AM, Robert Bradshaw > wrote: > >> On Oct 5, 2009, at 6:56 PM, Mark Lodato wrote: >> >>> [...] I much prefer git to hg. >>> >> Just out of complete curiosity, why the strong preference? (I like >> both for different reasons.) >> You didn't ask me, but I'll go anyway :-), because I've considered switching to git for my own work and would like to see if my opinions hold water. I don't really know git that well. But I wind up in situations that irritate me a lot with hg all the time: - The need to sometimes use patch queues. From what I understand of git, such situations would be tackled as part of normal git workflow rather than having to switch to, essentially, a different version control system within a version control system. - When I figure out "oh, I need to do this first in a seperate patch", I have to make a new clone and shut down and open emacs again (lest I accidentally edit files in the wrong clone), and so on. With in-place branching I haven't really learned about hg branches though. I kind of consider clones and patch queues more than enough tools for the same job, without there being branches as well -- so many tools for creating a diff/patch seems like an indication that something's been designed wrong. With git, all of this seems to just be one nicely integrated system of patches. Only one system to learn (although with a higher learning curve for svn users). I'm sure that if I started reaelly using git I'd find things wrong with it though :-) Dag Sverre From dagss at student.matnat.uio.no Wed Oct 7 09:43:38 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 07 Oct 2009 09:43:38 +0200 Subject: [Cython] --embed and cython_freeze no longer work In-Reply-To: <4ACC461F.6020003@student.matnat.uio.no> References: <2F34C111-D81E-436B-94F2-FC476680D119@math.washington.edu> <75BA7DE6-995A-4A90-98DB-24758E80E118@math.washington.edu> <4ACC461F.6020003@student.matnat.uio.no> Message-ID: <4ACC46AA.80804@student.matnat.uio.no> Dag Sverre Seljebotn wrote: > Mark Lodato wrote: > >> On Tue, Oct 6, 2009 at 4:26 AM, Robert Bradshaw >> wrote: >> >> >>> On Oct 5, 2009, at 6:56 PM, Mark Lodato wrote: >>> >>> >>>> [...] I much prefer git to hg. >>>> >>>> >>> Just out of complete curiosity, why the strong preference? (I like >>> both for different reasons.) >>> >>> > You didn't ask me, but I'll go anyway :-), because I've considered > switching to git for my own work and would like to see if my opinions > hold water. > > I don't really know git that well. But I wind up in situations that > irritate me a lot with hg all the time: > > - The need to sometimes use patch queues. From what I understand of > git, such situations would be tackled as part of normal git workflow > rather than having to switch to, essentially, a different version > control system within a version control system. > - When I figure out "oh, I need to do this first in a seperate patch", > I have to make a new clone and shut down and open emacs again (lest I > accidentally edit files in the wrong clone), and so on. With in-place > branching > ... I'd get a better workflow; simply commit (can always rebase later), switch branch, and reload buffers in emacs. > I haven't really learned about hg branches though. I kind of consider > clones and patch queues more than enough tools for the same job, without > there being branches as well -- so many tools for creating a diff/patch > seems like an indication that something's been designed wrong. > > With git, all of this seems to just be one nicely integrated system of > patches. Only one system to learn (although with a higher learning curve > for svn users). > > I'm sure that if I started reaelly using git I'd find things wrong with > it though :-) > > Dag Sverre > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > From dagss at student.matnat.uio.no Wed Oct 7 09:48:07 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 07 Oct 2009 09:48:07 +0200 Subject: [Cython] C++ complex support In-Reply-To: <4ACC44B4.50707@student.matnat.uio.no> References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> <4ACB7FCC.9020901@student.matnat.uio.no> <4ACC44B4.50707@student.matnat.uio.no> Message-ID: <4ACC47B7.80101@student.matnat.uio.no> Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: > >> On Tue, Oct 6, 2009 at 9:11 PM, Robert Bradshaw >> wrote: >> >> >>> On Oct 6, 2009, at 3:32 PM, Lisandro Dalcin wrote: >>> >>> >>> >>>> On Tue, Oct 6, 2009 at 4:03 PM, Robert Bradshaw >>>> wrote: >>>> >>>> >>>>> c99_complex is an internal directive (and I (intentionally) didn't >>>>> add it to the list of directives because I wasn't sure if that's the >>>>> final interface we wanted), so I think we're safe to change it. I'm >>>>> starting to wonder if we even need it at all. >>>>> >>>>> >>>> I think we need it... you know how much I hate second guessing... I've >>>> never liked that of c99 complex being on depending of "complex.h" >>>> being included... Moreover, going C++, I do not know how to detect if >>>> was #include's ... >>>> >>>> >>> #ifdef __STD_COMPLEX ? >>> >>> >>> >> That is not portable at all. GCC (4.4.1) does #define >> _GLIBCXX_COMPLEX_H, but not __STD_COMPLEX ... This macro is available >> from IBM's XL C++ compiler and MS VC++, though. >> >> > Is there any targeted version of C++ which does not bundle ? > Otherwise I'd say we *always* enable C++ complex when C++ is the target, > and include ourself if we need to. > Also note that a header file can relatively easily be written from scratch in C++, there's no compiler support needed, it's all templates and operator overloading. So even if somebody has a compiler without , it's probably easy enough to find one one the net to drop in. So I don't see a need for struct complex on C++ at all. Dag Sverre From stefan_ml at behnel.de Wed Oct 7 09:57:12 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 07 Oct 2009 09:57:12 +0200 Subject: [Cython] module cleanup broken in cython-unstable In-Reply-To: References: <4ACB8033.1060605@student.matnat.uio.no> Message-ID: <4ACC49D8.80102@behnel.de> Lisandro Dalcin wrote: > On Tue, Oct 6, 2009 at 3:44 PM, Robert Bradshaw > wrote: >> On Oct 6, 2009, at 10:36 AM, Dag Sverre Seljebotn wrote: >> >>> Lisandro Dalcin wrote: >>>> That code got refactored, and the I got a bit lost... can the guilty >>>> parties take a look? The generated ClenupGlobals() is opened, but the >>>> closing brace is not written. Do we still need to generate >>>> CleanupGlobals() ? >>>> >>>> >>> It's probably my fault. Can you remind me how to turn on cleanup of >>> globals? Is it possible to do it in the test runner? Why isn't this >>> always turned on? >> Because it is inherently unsafe and can cause segfaults. Perhaps in >> our tests it'd be OK as modules don't invoke each other. >> > > Anyway, the right way would be to hack on this and make the cleanup > code run immediately after the doctests... then we would likely need > do have some support for run the cleanup code from Python code and not > registering with atexit, ... I mean, having all the module cleanup > functions to run at Python exit is a bit disappointing... May I remind you that Py3 has a mechanism for this: http://trac.cython.org/cython_trac/ticket/218 We currently have the problem anyway that we do not unload the tested modules in runtests.py, so 1) the C++ built modules are never doctested as they have the same name as the C module, and 2) the cleanup code is never tested as 3) the modules are never unloaded and just fill up sys.modules. Stefan From stefan_ml at behnel.de Wed Oct 7 10:11:50 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 07 Oct 2009 10:11:50 +0200 Subject: [Cython] Can't push: "ssl required" Message-ID: <4ACC4D46.9020001@behnel.de> Hi, I can't currently push to cython-unstable (I guess that's the case for all repos), as I get an "ssl required" error. However, using SSL doesn't work either. Were there any setup changes since yesterday? Stefan From stefan_ml at behnel.de Wed Oct 7 10:12:29 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 07 Oct 2009 10:12:29 +0200 Subject: [Cython] module cleanup broken in cython-unstable In-Reply-To: References: <4ACB8033.1060605@student.matnat.uio.no> Message-ID: <4ACC4D6D.2050100@behnel.de> Lisandro Dalcin wrote: > from Cython.Compiler import Options > Options.generate_cleanup_code = 3 Yes, those lines should be added to the test runner. Stefan From dagss at student.matnat.uio.no Wed Oct 7 10:24:15 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 07 Oct 2009 10:24:15 +0200 Subject: [Cython] C++ complex support In-Reply-To: References: <4ACBA212.2030006@student.matnat.uio.no> Message-ID: <4ACC502F.6000305@student.matnat.uio.no> Lisandro Dalcin wrote: > On Tue, Oct 6, 2009 at 5:01 PM, Dag Sverre Seljebotn > wrote: > >> Lisandro Dalcin wrote: >> >>> Well, I'm hacking on supporting C++ complex, but have some questions >>> >> I'm in a situation where the lack of .conjugate() is getting rather out >> of hand in my code -- I'd really like to have .conjugate() in Cython >> within the next week or so. >> >> If I step in now it might be a lot of unnecesarry merges though. When do >> you think you'll be done (or start)? >> >> > > It is mostly working on my box at work (at home right now)... I could > have something working by tomorrow > >> (Also something to keep in mind while working on the C++ support, i.e. >> there should probably be a macro for conjugate.) >> >> > > And also for abs(), in case it is not currently handled... > Hmm. Yes. However the argument is a bit harder: import cmath z = 1 + 3j magnitude = abs(z) argument = cmath.phase(z) One could argue that we should not implement such a special case for cmath.phase yet but wait for function overloading in pxd files. Still it feels strange to provide an efficient way of getting the magnitude only and not the argument. Dag Sverre From robertwb at math.washington.edu Wed Oct 7 10:25:15 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 7 Oct 2009 01:25:15 -0700 Subject: [Cython] module cleanup broken in cython-unstable In-Reply-To: <4ACC49D8.80102@behnel.de> References: <4ACB8033.1060605@student.matnat.uio.no> <4ACC49D8.80102@behnel.de> Message-ID: <1CB119E4-7D7C-4EEC-8458-990D190036EB@math.washington.edu> On Oct 7, 2009, at 12:57 AM, Stefan Behnel wrote: > Lisandro Dalcin wrote: >> On Tue, Oct 6, 2009 at 3:44 PM, Robert Bradshaw >> wrote: >>> On Oct 6, 2009, at 10:36 AM, Dag Sverre Seljebotn wrote: >>> >>>> Lisandro Dalcin wrote: >>>>> That code got refactored, and the I got a bit lost... can the >>>>> guilty >>>>> parties take a look? The generated ClenupGlobals() is opened, >>>>> but the >>>>> closing brace is not written. Do we still need to generate >>>>> CleanupGlobals() ? >>>>> >>>>> >>>> It's probably my fault. Can you remind me how to turn on cleanup of >>>> globals? Is it possible to do it in the test runner? Why isn't this >>>> always turned on? >>> Because it is inherently unsafe and can cause segfaults. Perhaps in >>> our tests it'd be OK as modules don't invoke each other. >>> >> >> Anyway, the right way would be to hack on this and make the cleanup >> code run immediately after the doctests... then we would likely need >> do have some support for run the cleanup code from Python code and >> not >> registering with atexit, ... I mean, having all the module cleanup >> functions to run at Python exit is a bit disappointing... > > May I remind you that Py3 has a mechanism for this: > > http://trac.cython.org/cython_trac/ticket/218 > > We currently have the problem anyway that we do not unload the tested > modules in runtests.py, so 1) the C++ built modules are never > doctested as > they have the same name as the C module, and 2) the cleanup code is > never > tested as 3) the modules are never unloaded and just fill up > sys.modules. Ouch, good point. Is there even a way to unload modules in Python 2? I guess we could be spawning a new python for every test (which would make the tests slower). - Robert From robertwb at math.washington.edu Wed Oct 7 10:26:36 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 7 Oct 2009 01:26:36 -0700 Subject: [Cython] Can't push: "ssl required" In-Reply-To: <4ACC4D46.9020001@behnel.de> References: <4ACC4D46.9020001@behnel.de> Message-ID: On Oct 7, 2009, at 1:11 AM, Stefan Behnel wrote: > Hi, > > I can't currently push to cython-unstable (I guess that's the case > for all > repos), as I get an "ssl required" error. However, using SSL > doesn't work > either. > > Were there any setup changes since yesterday? Yes, I went ahead nd merged cython-devel and cython-unstable, so cython-unstable is just up there read-only so URLs pointing to it don't break. - Robert From robertwb at math.washington.edu Wed Oct 7 10:43:39 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 7 Oct 2009 01:43:39 -0700 Subject: [Cython] C++ complex support In-Reply-To: <4ACC44B4.50707@student.matnat.uio.no> References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> <4ACB7FCC.9020901@student.matnat.uio.no> <4ACC44B4.50707@student.matnat.uio.no> Message-ID: <1AF56280-A480-450D-9165-D025F7CF7AE1@math.washington.edu> On Oct 7, 2009, at 12:35 AM, Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: >> On Tue, Oct 6, 2009 at 9:11 PM, Robert Bradshaw >> wrote: >> >>> On Oct 6, 2009, at 3:32 PM, Lisandro Dalcin wrote: >>> >>> >>>> On Tue, Oct 6, 2009 at 4:03 PM, Robert Bradshaw >>>> wrote: >>>> >>>>> c99_complex is an internal directive (and I (intentionally) didn't >>>>> add it to the list of directives because I wasn't sure if >>>>> that's the >>>>> final interface we wanted), so I think we're safe to change it. >>>>> I'm >>>>> starting to wonder if we even need it at all. >>>>> >>>> I think we need it... you know how much I hate second >>>> guessing... I've >>>> never liked that of c99 complex being on depending of "complex.h" >>>> being included... Moreover, going C++, I do not know how to >>>> detect if >>>> was #include's ... >>>> >>> #ifdef __STD_COMPLEX ? >>> >>> >> >> That is not portable at all. GCC (4.4.1) does #define >> _GLIBCXX_COMPLEX_H, but not __STD_COMPLEX ... This macro is available >> from IBM's XL C++ compiler and MS VC++, though. I'm really not sure if there's something standard to look at... > Is there any targeted version of C++ which does not bundle ? > Otherwise I'd say we *always* enable C++ complex when C++ is the > target, > and include ourself if we need to. If that's the case, makes sense to me. >>> I like ccomplex which forces C99 _Complex or std::complex depending >>> on __cplusplus, but perhaps I have not adequately justified why the >>> auto-setting of PYX_USE_CCOMPLEX is desirable. If complex values are >>> only used internally, then our native implementation works fine and >>> there is no need for c99 or c++ compiler support. If, however, one >>> wants to call some of the math functions in complex.h, or interact >>> with some other library that uses C99/std::complex complex numbers, >>> then our native implementation will create values of the wrong type. >>> >>> >> >> Well, what worries my is that "complex.h" could end-up being included >> indirectly... It could certainly happens that some project with many >> .pyx files end-up using different complex, just because some of then >> #include some third-party header that in turn #include complex.h ... >> > If complex.h is somehow included indirectly, then it follows that the > compiler supports C99 complex types. Yep, and that we need to be using them. > If the compiler supports C99 complex, there should never be a > version to > use the backwards-compatability structs. > > To make it all more predictable, perhaps we should just include > "complex.h" explicitly if we know we are in C99 mode? So basically: > - structs for pre-C99 > - C complex for C99 > - C++ complex for C++ > > Seems much simpler to explain. Personally, detecting the complex.h seems more direct and obvious than having a switch on the a standard compliance macro. Also, IIRC, most compilers (e.g. including many versions of gcc) that support complex arithmetic did so (do so?) before being totally C99 compliant. > (I don't mind overriding the chosen > implementation with a CYTHON_COMPLEX_IMPL or similar to the C > compiler, > but I don't see a need for a directive.) > >>> Since the compiler can figure it out, much better to >>> not bother the user with it at all, and have Cython complex numbers >>> just work in every scenario. >>> >> >> That's the problem... can the compiler figure out it? For the C++ >> case, I still do not know a (standard, portable) way to do that. For >> C99, it is supposed that _Complex_I is a macro, but are you 100% sure >> that such macro is guaranteed to be defined, or it is just a >> consequence of the implementation? >> > I remember reading that such a macro is part of the C99 standard, > at least. Yep. >> >>> To get this, ccomplex=True would set PYX_USE_CCOMPLEX to 1, >>> ccomplex=False would set PYX_USE_CCOMPLEX to something like (defined >>> (_Complex_I) || defined(__STD_COMPLEX)) rather than 0. >>> >>> >> >> I could live with that, provided that this can be changed at C >> compile >> time pasing -DPYX_USE_CCOMPLEX=0/1 ... >> >> And provided that up-to now (unless you can point a reference) there >> is no (portable) way to figure out on C++ that was >> #include'd , perhaps we should default to use std::complex<> in C++ >> (what would be the point of using structs in that case) ? >> > Yep, let's just include ourself. If that's always available, lets do that. - Robert From stefan_ml at behnel.de Wed Oct 7 11:14:11 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 07 Oct 2009 11:14:11 +0200 Subject: [Cython] module cleanup broken in cython-unstable In-Reply-To: <1CB119E4-7D7C-4EEC-8458-990D190036EB@math.washington.edu> References: <4ACB8033.1060605@student.matnat.uio.no> <4ACC49D8.80102@behnel.de> <1CB119E4-7D7C-4EEC-8458-990D190036EB@math.washington.edu> Message-ID: <4ACC5BE3.9060008@behnel.de> Robert Bradshaw wrote: > Is there even a way to unload modules in Python 2? You could remove them from sys.modules, which sort-of worked for Python modules and sometimes seemed to work for C modules but didn't. So the answer is pretty much a "no", which is why PEP 3121 was written up in the first place. > I guess we could be spawning a new python for every test (which would > make the tests slower). Well, there's fork() under Unix systems, which won't impact the test performance in any noticeable way. Since all main developers use Linux or MacOS, I'm fine with a solution that falls back to sequential testing and no unloading under Windows, until we get PEP 3121 properly implemented and can run portable unloading tests under Py3. Actually, the only reason why I still didn't add a fork() to parallelise the test runs is that I don't see a way to capture the GCC output. Stefan From magnus at hetland.org Wed Oct 7 11:45:12 2009 From: magnus at hetland.org (Magnus Lie Hetland) Date: Wed, 7 Oct 2009 11:45:12 +0200 Subject: [Cython] --embed and cython_freeze no longer work In-Reply-To: References: <2F34C111-D81E-436B-94F2-FC476680D119@math.washington.edu> <75BA7DE6-995A-4A90-98DB-24758E80E118@math.washington.edu> Message-ID: <233EC79F-F237-4790-83FA-DEF8E01460F6@hetland.org> On Oct 7, 2009, at 05:07, Mark Lodato wrote: > On Tue, Oct 6, 2009 at 4:26 AM, Robert Bradshaw > wrote: >> On Oct 5, 2009, at 6:56 PM, Mark Lodato wrote: >>> [...] I much prefer git to hg. >> >> Just out of complete curiosity, why the strong preference? (I like >> both for different reasons.) > > The main reasons why I like git over any other SCM are the index and > history rewriting / navigation. [snip] Interesting points. > * git branch - no equivalent I don't know git, really ... is it possible to sum up the main differences between this and "hg branch" briefly? - M -- Magnus Lie Hetland http://hetland.org From magnus at hetland.org Wed Oct 7 14:33:15 2009 From: magnus at hetland.org (Magnus Lie Hetland) Date: Wed, 7 Oct 2009 14:33:15 +0200 Subject: [Cython] Are min/max ever optimized? Message-ID: <7E426F06-A1C0-449A-B500-414BD0AD1204@hetland.org> Just wondered -- are the min/max function ever optimized (like range)? I find myself importing fminf/fmaxf (for example) or using if statements etc. when it would be much nicer, IMO, to just use min/max. I'm not talking over sequences or the like -- just a simple min/max over a constant number of values of equal (C) type. For example, when I *do* want to find the maximum over a range of things, calculated on the fly, I'll usually want something like: cdef double res = 0 for foo in bar: # ... res = max(res, somethingelse()) As it is, I'll use val = somethingelse() if val > res: res = val ... or import the proper min functions from C. Is this kind of optimization available (seems like the builtin min() is used in the C code, if I try to use that)? Could/should it be? -- Magnus Lie Hetland http://hetland.org From dagss at student.matnat.uio.no Wed Oct 7 14:48:00 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: 07 Oct 2009 14:48:00 +0200 Subject: [Cython] Are min/max ever optimized? Message-ID: <3337771725.1253831@smtp.netcom.no> No, they are not optimized (unless there's been a recent change). IMO they should be, and I miss this too. It would not be hard to implement (ask for details :-)). Dag Sverre Seljebotn -----Original Message----- From: Magnus Lie Hetland Date: Wednesday, Oct 7, 2009 2:33 pm Subject: [Cython] Are min/max ever optimized? To: cython-dev at codespeak.netReply-To: cython-dev at codespeak.net Just wondered -- are the min/max function ever optimized (like range)? > >I find myself importing fminf/fmaxf (for example) or using if >statements etc. when it would be much nicer, IMO, to just use min/max. >I'm not talking over sequences or the like -- just a simple min/max >over a constant number of values of equal (C) type. > >For example, when I *do* want to find the maximum over a range of >things, calculated on the fly, I'll usually want something like: > > cdef double res = 0 > for foo in bar: > # ... > res = max(res, somethingelse()) > >As it is, I'll use > > val = somethingelse() > if val > res: res = val > >... or import the proper min functions from C. > >Is this kind of optimization available (seems like the builtin min() >is used in the C code, if I try to use that)? Could/should it be? > >-- >Magnus Lie Hetland >http://hetland.org > > >_______________________________________________ >Cython-dev mailing list >Cython-dev at codespeak.net >http://codespeak.net/mailman/listinfo/cython-dev > From stefan_ml at behnel.de Wed Oct 7 15:04:22 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 07 Oct 2009 15:04:22 +0200 Subject: [Cython] Are min/max ever optimized? In-Reply-To: <7E426F06-A1C0-449A-B500-414BD0AD1204@hetland.org> References: <7E426F06-A1C0-449A-B500-414BD0AD1204@hetland.org> Message-ID: <4ACC91D6.7040703@behnel.de> Magnus Lie Hetland wrote: > Just wondered -- are the min/max function ever optimized (like range)? "are"? No. "will"? Sure, why not? You can implement new methods "_handle_simple_function_min"/"_max" in Optimize.py -> OptimizeBuiltinCalls that special cases the use cases you need and builds a new subtree for them. Note that you may have to unwrap parse tree nodes that have already been coerced to a Python type. There are already tons of examples in that class that do similar things. Stefan From magnus at hetland.org Wed Oct 7 15:17:56 2009 From: magnus at hetland.org (Magnus Lie Hetland) Date: Wed, 7 Oct 2009 15:17:56 +0200 Subject: [Cython] Are min/max ever optimized? In-Reply-To: <4ACC91D6.7040703@behnel.de> References: <7E426F06-A1C0-449A-B500-414BD0AD1204@hetland.org> <4ACC91D6.7040703@behnel.de> Message-ID: <83BF77BE-7B74-412F-84F1-7891790D7D31@hetland.org> On Oct 7, 2009, at 15:04 , Stefan Behnel wrote: > > Magnus Lie Hetland wrote: >> Just wondered -- are the min/max function ever optimized (like >> range)? > > "are"? No. "will"? Sure, why not? > > You can implement new methods "_handle_simple_function_min"/"_max" in > Optimize.py -> OptimizeBuiltinCalls that special cases the use cases > you > need and builds a new subtree for them. Note that you may have to > unwrap > parse tree nodes that have already been coerced to a Python type. > There are > already tons of examples in that class that do similar things. Cool, thanks. This is mainly an aesthetic thing for me at the moment -- not critical functionality -- so I might not get around to it Real Soon, but it sounds like a nice little project :) - M -- Magnus Lie Hetland http://hetland.org From magnus at hetland.org Wed Oct 7 15:24:34 2009 From: magnus at hetland.org (Magnus Lie Hetland) Date: Wed, 7 Oct 2009 15:24:34 +0200 Subject: [Cython] A (small) sunshine story Message-ID: <3ADAE2D6-4837-436A-9308-08F7D1924966@hetland.org> I'm currently working on stuff related to various metric distance functions, with the code written in Cython. Most of the data I'm working are sets of float-vectors (represented as two-dimensional NumPy arrays -- with each row being a vector). Works well. However, I had also implemented a string edit distance (plain Levenshtein, for now), where the strings could have different lengths. My first hunch was that using a full len(strings) by max(len(s) for s in strings) NumPy array would be wasteful space-wise. So -- as a quick hack, I simply used a list of strings. And since I was already disregarding any Cython cleverness here, I simply used the plain strings directly in the distance calculation as well. And it was sloooow. I thought the quadratic nature of the distance function had much of the blame for the slowness. However, I sat down now to see if I could speed it up. I made some assumptions (used uint8 for the characters and uint16 in a separate array of string lengths) and basically declared all variables (storing map(ord, string) in the rows of the NumPy array). The whole thing (which wasn't all *that* focused) took me roughly an hour (including some fiddling with writing a timing script, to measure the speedup properly). And from this moderate investment of time/energy, I got a speedup factor of over 200! :-D - M (very happy with Cython right now :-) -- Magnus Lie Hetland http://hetland.org From sccolbert at gmail.com Wed Oct 7 18:45:49 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Wed, 7 Oct 2009 18:45:49 +0200 Subject: [Cython] Is it possible to link to libraries at runtime with Cython Message-ID: <7f014ea60910070945x783853bbja741c983877c11d1@mail.gmail.com> using something similar to ctypes dlopen? I would like to be able to create a wrapper for a library that can built on the client machine without the necessity of the target libraries being present. Then, upon import of the library, the library would check for the presence of the .so's and raise an exception if they are not found. This way, once the user installs the libraries, the functionality automagically works. I've searched around, but not really found anything on the topic. Is it as easy as just using "cdef extern from dlfcn.h" and declaring the appropriate dlopen machinery and using as normal? Cheers! Chris From dagss at student.matnat.uio.no Wed Oct 7 19:58:57 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 07 Oct 2009 19:58:57 +0200 Subject: [Cython] Is it possible to link to libraries at runtime with Cython In-Reply-To: <7f014ea60910070945x783853bbja741c983877c11d1@mail.gmail.com> References: <7f014ea60910070945x783853bbja741c983877c11d1@mail.gmail.com> Message-ID: <4ACCD6E1.7060703@student.matnat.uio.no> Chris Colbert wrote: > using something similar to ctypes dlopen? > > I would like to be able to create a wrapper for a library that can > built on the client machine without the necessity of the target > libraries being present. Consider having multiple modules -- say, mylib and mylib.withsolib. a) Have the build fail gracefully for withsolib b) In mylib, import withsolib with a try/except. This is by far the most cross-platform, robust etc. etc. way of doing it -- it basically pushes everything to the build system. > > Then, upon import of the library, the library would check for the > presence of the .so's and raise an exception if they are not found. > > This way, once the user installs the libraries, the functionality > automagically works. > > I've searched around, but not really found anything on the topic. > > Is it as easy as just using "cdef extern from dlfcn.h" and declaring > the appropriate dlopen machinery and using as normal? Yes, should be. That is, you need to declare function pointers and use the functions through these: cdef double (*cosine)(double) And then assign and call them. The example from "man dlopen" can probably be ported almost verbatim to Cython. -- Dag Sverre From sccolbert at gmail.com Wed Oct 7 20:16:53 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Wed, 7 Oct 2009 20:16:53 +0200 Subject: [Cython] Is it possible to link to libraries at runtime with Cython In-Reply-To: <4ACCD6E1.7060703@student.matnat.uio.no> References: <7f014ea60910070945x783853bbja741c983877c11d1@mail.gmail.com> <4ACCD6E1.7060703@student.matnat.uio.no> Message-ID: <7f014ea60910071116q21625b44oa08e727e97c20a6c@mail.gmail.com> More particularly, i'm going to be working on some opencv compatibility for scikits.image. The idea is the user can build scikits.image once, regardless of whether or not OpenCV is currently on their system. If and when the user does put OpenCV on their system, then scikits.image.opencv automagically works... Perhaps, that's what you meant in point a)... I was thinking more along the lines of point b).... if the user tries to import scikits.image.opencv and opencv .so's are not present, then i would raise an exception when dlopen returned None. Chris On Wed, Oct 7, 2009 at 7:58 PM, Dag Sverre Seljebotn wrote: > Chris Colbert wrote: >> using something similar to ctypes dlopen? >> >> I would like to be able to create a wrapper for a library that can >> built on the client machine without the necessity of the target >> libraries being present. > > Consider having multiple modules -- say, mylib and mylib.withsolib. > > a) Have the build fail gracefully for withsolib > b) In mylib, import withsolib with a try/except. > > This is by far the most cross-platform, robust etc. etc. way of doing it > -- it basically pushes everything to the build system. > >> >> Then, upon import of the library, the library would check for the >> presence of the .so's and raise an exception if they are not found. >> >> This way, once the user installs the libraries, the functionality >> automagically works. >> >> I've searched around, but not really found anything on the topic. >> >> Is it as easy as just using "cdef extern from dlfcn.h" and declaring >> the appropriate dlopen machinery and using as normal? > > Yes, should be. That is, you need to declare function pointers and use > the functions through these: > > cdef double (*cosine)(double) > > And then assign and call them. The example from "man dlopen" can > probably be ported almost verbatim to Cython. > > -- > Dag Sverre > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > From dagss at student.matnat.uio.no Wed Oct 7 21:31:45 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 07 Oct 2009 21:31:45 +0200 Subject: [Cython] Is it possible to link to libraries at runtime with Cython In-Reply-To: <7f014ea60910071116q21625b44oa08e727e97c20a6c@mail.gmail.com> References: <7f014ea60910070945x783853bbja741c983877c11d1@mail.gmail.com> <4ACCD6E1.7060703@student.matnat.uio.no> <7f014ea60910071116q21625b44oa08e727e97c20a6c@mail.gmail.com> Message-ID: <4ACCECA1.7030301@student.matnat.uio.no> Chris Colbert wrote: > More particularly, i'm going to be working on some opencv > compatibility for scikits.image. The idea is the user can build > scikits.image once, regardless of whether or not OpenCV is currently > on their system. If and when the user does put OpenCV on their system, > then scikits.image.opencv automagically works... Ah ok. a) won't work then, you might want to go for b). However: It's going to be hard to write cross-platform code that way. A cross-platform alternative would be to actually use ctypes to load the functions (which works on both Windows and Unix, contains code to search for the right library in the manner standard on the platform, etc.). It doesn't look like ctypes has a good enough C API, but once you have a function pointer in ctypes I suppose you can extract the pointer value as an integer *somehow*, at the very worst use ctypes to pass the pointer to a C function which converts the pointer to an integer. -- Dag Sverre From robertwb at math.washington.edu Wed Oct 7 22:49:37 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 7 Oct 2009 13:49:37 -0700 Subject: [Cython] C++ complex support In-Reply-To: <1AF56280-A480-450D-9165-D025F7CF7AE1@math.washington.edu> References: <222BA8F6-BC29-4CFB-9D7F-142E63A1A5AA@math.washington.edu> <4ACB7FCC.9020901@student.matnat.uio.no> <4ACC44B4.50707@student.matnat.uio.no> <1AF56280-A480-450D-9165-D025F7CF7AE1@math.washington.edu> Message-ID: <18B3556C-0EEE-4341-8BC4-C2598A9B96A9@math.washington.edu> On Oct 7, 2009, at 1:43 AM, Robert Bradshaw wrote: > On Oct 7, 2009, at 12:35 AM, Dag Sverre Seljebotn wrote: > >> Lisandro Dalcin wrote: >>> On Tue, Oct 6, 2009 at 9:11 PM, Robert Bradshaw >>> wrote: >>> >>>> On Oct 6, 2009, at 3:32 PM, Lisandro Dalcin wrote: >>>> >>>> >>>>> On Tue, Oct 6, 2009 at 4:03 PM, Robert Bradshaw >>>>> wrote: >>>>> >>>>>> c99_complex is an internal directive (and I (intentionally) >>>>>> didn't >>>>>> add it to the list of directives because I wasn't sure if >>>>>> that's the >>>>>> final interface we wanted), so I think we're safe to change it. >>>>>> I'm >>>>>> starting to wonder if we even need it at all. >>>>>> >>>>> I think we need it... you know how much I hate second >>>>> guessing... I've >>>>> never liked that of c99 complex being on depending of "complex.h" >>>>> being included... Moreover, going C++, I do not know how to >>>>> detect if >>>>> was #include's ... >>>>> >>>> #ifdef __STD_COMPLEX ? >>>> >>>> >>> >>> That is not portable at all. GCC (4.4.1) does #define >>> _GLIBCXX_COMPLEX_H, but not __STD_COMPLEX ... This macro is >>> available >>> from IBM's XL C++ compiler and MS VC++, though. > > I'm really not sure if there's something standard to look at... Actually, would defined(std::complex) work? Really, I don't have a strong preference of how it works as long as it just works for the user, in both C and C++, whether or not the compiler supports it, and without having to specify extra directives. - Robert From robertwb at math.washington.edu Wed Oct 7 22:51:20 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 7 Oct 2009 13:51:20 -0700 Subject: [Cython] Are min/max ever optimized? In-Reply-To: <83BF77BE-7B74-412F-84F1-7891790D7D31@hetland.org> References: <7E426F06-A1C0-449A-B500-414BD0AD1204@hetland.org> <4ACC91D6.7040703@behnel.de> <83BF77BE-7B74-412F-84F1-7891790D7D31@hetland.org> Message-ID: On Oct 7, 2009, at 6:17 AM, Magnus Lie Hetland wrote: > On Oct 7, 2009, at 15:04 , Stefan Behnel wrote: > >> >> Magnus Lie Hetland wrote: >>> Just wondered -- are the min/max function ever optimized (like >>> range)? >> >> "are"? No. "will"? Sure, why not? >> >> You can implement new methods "_handle_simple_function_min"/"_max" in >> Optimize.py -> OptimizeBuiltinCalls that special cases the use cases >> you >> need and builds a new subtree for them. Note that you may have to >> unwrap >> parse tree nodes that have already been coerced to a Python type. >> There are >> already tons of examples in that class that do similar things. > > Cool, thanks. > > This is mainly an aesthetic thing for me at the moment -- not critical > functionality -- so I might not get around to it Real Soon, but it > sounds like a nice little project :) Note also that Danilo did some work on overloaded functions which could be useful here too. - Robert From robertwb at math.washington.edu Wed Oct 7 22:54:23 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 7 Oct 2009 13:54:23 -0700 Subject: [Cython] Is it possible to link to libraries at runtime with Cython In-Reply-To: <4ACCECA1.7030301@student.matnat.uio.no> References: <7f014ea60910070945x783853bbja741c983877c11d1@mail.gmail.com> <4ACCD6E1.7060703@student.matnat.uio.no> <7f014ea60910071116q21625b44oa08e727e97c20a6c@mail.gmail.com> <4ACCECA1.7030301@student.matnat.uio.no> Message-ID: <44AC141D-75CA-423F-AA2B-AF9D8C7A1A30@math.washington.edu> On Oct 7, 2009, at 12:31 PM, Dag Sverre Seljebotn wrote: > Chris Colbert wrote: >> More particularly, i'm going to be working on some opencv >> compatibility for scikits.image. The idea is the user can build >> scikits.image once, regardless of whether or not OpenCV is currently >> on their system. If and when the user does put OpenCV on their >> system, >> then scikits.image.opencv automagically works... > > Ah ok. a) won't work then, you might want to go for b). > > However: It's going to be hard to write cross-platform code that > way. A > cross-platform alternative would be to actually use ctypes to load the > functions (which works on both Windows and Unix, contains code to > search > for the right library in the manner standard on the platform, etc.). > > It doesn't look like ctypes has a good enough C API, but once you > have a > function pointer in ctypes I suppose you can extract the pointer value > as an integer *somehow*, at the very worst use ctypes to pass the > pointer to a C function which converts the pointer to an integer. Also, note that you can just use ctypes directly in Cython the same as from Python, but of course it'll be going through the Python interface. Ideally ctypes would expose an nice C API we could wrap, but I don't think that's at all the case. - Robert From robertwb at math.washington.edu Wed Oct 7 22:54:23 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 7 Oct 2009 13:54:23 -0700 Subject: [Cython] Is it possible to link to libraries at runtime with Cython In-Reply-To: <4ACCECA1.7030301@student.matnat.uio.no> References: <7f014ea60910070945x783853bbja741c983877c11d1@mail.gmail.com> <4ACCD6E1.7060703@student.matnat.uio.no> <7f014ea60910071116q21625b44oa08e727e97c20a6c@mail.gmail.com> <4ACCECA1.7030301@student.matnat.uio.no> Message-ID: <44AC141D-75CA-423F-AA2B-AF9D8C7A1A30@math.washington.edu> On Oct 7, 2009, at 12:31 PM, Dag Sverre Seljebotn wrote: > Chris Colbert wrote: >> More particularly, i'm going to be working on some opencv >> compatibility for scikits.image. The idea is the user can build >> scikits.image once, regardless of whether or not OpenCV is currently >> on their system. If and when the user does put OpenCV on their >> system, >> then scikits.image.opencv automagically works... > > Ah ok. a) won't work then, you might want to go for b). > > However: It's going to be hard to write cross-platform code that > way. A > cross-platform alternative would be to actually use ctypes to load the > functions (which works on both Windows and Unix, contains code to > search > for the right library in the manner standard on the platform, etc.). > > It doesn't look like ctypes has a good enough C API, but once you > have a > function pointer in ctypes I suppose you can extract the pointer value > as an integer *somehow*, at the very worst use ctypes to pass the > pointer to a C function which converts the pointer to an integer. Also, note that you can just use ctypes directly in Cython the same as from Python, but of course it'll be going through the Python interface. Ideally ctypes would expose an nice C API we could wrap, but I don't think that's at all the case. - Robert From dalcinl at gmail.com Wed Oct 7 23:43:52 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 7 Oct 2009 18:43:52 -0300 Subject: [Cython] C++ complex support In-Reply-To: <18B3556C-0EEE-4341-8BC4-C2598A9B96A9@math.washington.edu> References: <4ACB7FCC.9020901@student.matnat.uio.no> <4ACC44B4.50707@student.matnat.uio.no> <1AF56280-A480-450D-9165-D025F7CF7AE1@math.washington.edu> <18B3556C-0EEE-4341-8BC4-C2598A9B96A9@math.washington.edu> Message-ID: On Wed, Oct 7, 2009 at 5:49 PM, Robert Bradshaw wrote: > > Actually, would defined(std::complex) work? > Of course not ... The preprocessor knows nothing about C/C++ types ... > Really, I don't have a > strong preference of how it works as long as it just works for the > user, in both C and C++, whether or not the compiler supports it, and > without having to specify extra directives. > Well, I'm almost there... The patch is attached. Should I upload it to Trac, and reopen ticket #305? For the case of C, C99 complexes will be automatically used ONLY if _Complex_I is defined... of if the user explicitly pass "-DPYX_CCOMPLEX=1" at C-compile time (or a Cython-included C header #define PYX_CCOMPLEX=1), or if the directive "ccomplex=True". I'm still in doubt about how to handle 'ccomplex=True'... Should it just enable by default using "#define PYX_CCOMPLEX=1", or actually impact in code generation (as currently does)... Ah! I forgot... I do not know how to implement z.conjugate(); the C/C99/C++ support is there though... BTW, GCC seems to accept "~z" for complex conjugation (no idea if it is C99-standard or a GCC-extension)... Perhaps Cython should accept this (non-Python) syntax? I think it is nice. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 -------------- next part -------------- A non-text attachment was scrubbed... Name: ccomplex.diff Type: text/x-patch Size: 21542 bytes Desc: not available Url : http://codespeak.net/pipermail/cython-dev/attachments/20091007/da76d4fd/attachment-0001.bin From robertwb at math.washington.edu Wed Oct 7 23:59:07 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 7 Oct 2009 14:59:07 -0700 Subject: [Cython] C++ complex support In-Reply-To: References: <4ACB7FCC.9020901@student.matnat.uio.no> <4ACC44B4.50707@student.matnat.uio.no> <1AF56280-A480-450D-9165-D025F7CF7AE1@math.washington.edu> <18B3556C-0EEE-4341-8BC4-C2598A9B96A9@math.washington.edu> Message-ID: <1FB090B0-0F2B-4741-99EC-1CDB98FC5F8F@math.washington.edu> On Oct 7, 2009, at 2:43 PM, Lisandro Dalcin wrote: > On Wed, Oct 7, 2009 at 5:49 PM, Robert Bradshaw > wrote: >> Really, I don't have a >> strong preference of how it works as long as it just works for the >> user, in both C and C++, whether or not the compiler supports it, and >> without having to specify extra directives. >> > > Well, I'm almost there... The patch is attached. Should I upload it to > Trac, and reopen ticket #305? Don't reopen the ticket, make a new one for C++ complex support. > For the case of C, C99 complexes will be automatically used ONLY if > _Complex_I is defined... of if the user explicitly pass > "-DPYX_CCOMPLEX=1" at C-compile time (or a Cython-included C header > #define PYX_CCOMPLEX=1), or if the directive "ccomplex=True". > > I'm still in doubt about how to handle 'ccomplex=True'... Should it > just enable by default using "#define PYX_CCOMPLEX=1", or actually > impact in code generation (as currently does)... I would be OK with it just changing the flag, with the code generation remaining unchanged. > Ah! I forgot... I do not know how to implement z.conjugate(); the > C/C99/C++ support is there though... BTW, GCC seems to accept "~z" for > complex conjugation (no idea if it is C99-standard or a > GCC-extension)... Perhaps Cython should accept this (non-Python) > syntax? I think it is nice. I know is sage we map ~z to 1/z (it is the __invert__ operator after all). Python doesn't define an __invert__ for their native complex type. I could go either way. - Robert From dalcinl at gmail.com Thu Oct 8 01:03:38 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 7 Oct 2009 20:03:38 -0300 Subject: [Cython] cannot access trac.cython.org Message-ID: Getting 502 here... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From ndbecker2 at gmail.com Thu Oct 8 01:12:37 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 07 Oct 2009 19:12:37 -0400 Subject: [Cython] C++ complex support References: <4ACB7FCC.9020901@student.matnat.uio.no> <4ACC44B4.50707@student.matnat.uio.no> <1AF56280-A480-450D-9165-D025F7CF7AE1@math.washington.edu> <18B3556C-0EEE-4341-8BC4-C2598A9B96A9@math.washington.edu> Message-ID: Lisandro Dalcin wrote: > On Wed, Oct 7, 2009 at 5:49 PM, Robert Bradshaw > wrote: >> >> Actually, would defined(std::complex) work? >> > > Of course not ... The preprocessor knows nothing about C/C++ types ... > >> Really, I don't have a >> strong preference of how it works as long as it just works for the >> user, in both C and C++, whether or not the compiler supports it, and >> without having to specify extra directives. >> > > Well, I'm almost there... The patch is attached. Should I upload it to > Trac, and reopen ticket #305? > > For the case of C, C99 complexes will be automatically used ONLY if > _Complex_I is defined... of if the user explicitly pass > "-DPYX_CCOMPLEX=1" at C-compile time (or a Cython-included C header > #define PYX_CCOMPLEX=1), or if the directive "ccomplex=True". > > I'm still in doubt about how to handle 'ccomplex=True'... Should it > just enable by default using "#define PYX_CCOMPLEX=1", or actually > impact in code generation (as currently does)... > > Ah! I forgot... I do not know how to implement z.conjugate(); the > C/C99/C++ support is there though... BTW, GCC seems to accept "~z" for > complex conjugation (no idea if it is C99-standard or a > GCC-extension)... Perhaps Cython should accept this (non-Python) > syntax? I think it is nice. > > Conjugate in std::complex is spelled conj(z) From dalcinl at gmail.com Thu Oct 8 01:38:59 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 7 Oct 2009 20:38:59 -0300 Subject: [Cython] C++ complex support In-Reply-To: References: <4ACC44B4.50707@student.matnat.uio.no> <1AF56280-A480-450D-9165-D025F7CF7AE1@math.washington.edu> <18B3556C-0EEE-4341-8BC4-C2598A9B96A9@math.washington.edu> Message-ID: On Wed, Oct 7, 2009 at 8:12 PM, Neal Becker wrote: > Lisandro Dalcin wrote: > >> On Wed, Oct 7, 2009 at 5:49 PM, Robert Bradshaw >> wrote: >>> >>> Actually, would defined(std::complex) work? >>> >> >> Of course not ... The preprocessor knows nothing about C/C++ types ... >> >>> Really, I don't have a >>> strong preference of how it works as long as it just works for the >>> user, in both C and C++, whether or not the compiler supports it, and >>> without having to specify extra directives. >>> >> >> Well, I'm almost there... The patch is attached. Should I upload it to >> Trac, and reopen ticket #305? >> >> For the case of C, ?C99 complexes will be automatically used ONLY if >> _Complex_I is defined... of if the user explicitly pass >> "-DPYX_CCOMPLEX=1" at C-compile time (or a Cython-included C header >> #define PYX_CCOMPLEX=1), or if the directive "ccomplex=True". >> >> I'm still in doubt about how to handle 'ccomplex=True'... Should it >> just enable by default using "#define PYX_CCOMPLEX=1", or actually >> impact in code generation (as currently does)... >> >> Ah! I forgot... I do not know how to implement z.conjugate(); the >> C/C99/C++ support is there though... BTW, GCC seems to accept "~z" for >> complex conjugation (no idea if it is C99-standard or a >> GCC-extension)... Perhaps Cython should accept this (non-Python) >> syntax? I think it is nice. >> >> > Conjugate in std::complex is spelled > conj(z) > Yes, I've used std::conj() in C++ from , and cconj[f|l] in C99 from "complex.h" ... So the C99/C++ level support is readily available, what I do not know is how to map "z = a.conjugate()" in Cython code and generate the required C code "z = %{type_name}s_conj(a)" ... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Thu Oct 8 01:52:23 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 7 Oct 2009 20:52:23 -0300 Subject: [Cython] C++ complex support In-Reply-To: <1FB090B0-0F2B-4741-99EC-1CDB98FC5F8F@math.washington.edu> References: <4ACC44B4.50707@student.matnat.uio.no> <1AF56280-A480-450D-9165-D025F7CF7AE1@math.washington.edu> <18B3556C-0EEE-4341-8BC4-C2598A9B96A9@math.washington.edu> <1FB090B0-0F2B-4741-99EC-1CDB98FC5F8F@math.washington.edu> Message-ID: On Wed, Oct 7, 2009 at 6:59 PM, Robert Bradshaw wrote: > > Don't reopen the ticket, make a new one for C++ complex support. > Done: http://trac.cython.org/cython_trac/ticket/398 >> For the case of C, ?C99 complexes will be automatically used ONLY if >> _Complex_I is defined... of if the user explicitly pass >> "-DPYX_CCOMPLEX=1" at C-compile time (or a Cython-included C header >> #define PYX_CCOMPLEX=1), or if the directive "ccomplex=True". >> >> I'm still in doubt about how to handle 'ccomplex=True'... Should it >> just enable by default using "#define PYX_CCOMPLEX=1", or actually >> impact in code generation (as currently does)... > > I would be OK with it just changing the flag, with the code > generation remaining unchanged. > OK, this is work TBD in my patch... >> Ah! I forgot... I do not know how to implement z.conjugate(); the >> C/C99/C++ support is there though... BTW, GCC seems to accept "~z" for >> complex conjugation (no idea if it is C99-standard or a >> GCC-extension)... Perhaps Cython should accept this (non-Python) >> syntax? I think it is nice. > > I know is sage we map ~z to 1/z (it is the __invert__ operator after > all). Python doesn't define an __invert__ for their native complex > type. I could go either way. > IMHO, my brain can parse "~z" as z.conjugate(), but would have a hard time realizing ~z is "1/z"... Anyway, you are the BDLF, it's up to you... Or the champion who actually implement support for z.conjugate()... Hey, Dag. Are you there? ;-) -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From lodatom at gmail.com Thu Oct 8 03:47:05 2009 From: lodatom at gmail.com (Mark Lodato) Date: Wed, 7 Oct 2009 21:47:05 -0400 Subject: [Cython] --embed and cython_freeze no longer work In-Reply-To: <233EC79F-F237-4790-83FA-DEF8E01460F6@hetland.org> References: <2F34C111-D81E-436B-94F2-FC476680D119@math.washington.edu> <75BA7DE6-995A-4A90-98DB-24758E80E118@math.washington.edu> <233EC79F-F237-4790-83FA-DEF8E01460F6@hetland.org> Message-ID: On Wed, Oct 7, 2009 at 5:45 AM, Magnus Lie Hetland wrote: > On Oct 7, 2009, at 05:07, Mark Lodato wrote: >>>> [...] I much prefer git to hg. > >> * git branch - no equivalent > > I don't know git, really ... is it possible to sum up the main > differences between this and "hg branch" briefly? Briefly: They do the same thing. The difference is that *other* git commands honor the current branch, while other hg commands (besides "commit") ignore it. For example, make a new branch, make a commit, and then switch back to the original branch. Now, what does log or view or tip or export or ... say? In git, they show you the current (i.e. original) branch, as if the new one did not exist. In Hg, they show the new branch as if the original one (the one you're currently on!) did not exist. So, what's the point of branching in Hg? Am I missing something? In general, Hg prefers "heavyweight" branches, where each branch is a clone (i.e. not using "hg branch"), while git prefers "lightweight" branches, where a "branch" is just a tag that is automatically updated when you commit.* This makes branching and merging very fast and very easy in git. It changes the way you work because it is so quick. Statements like the following have discouraged me from using hg branch: - "However, a good rule of thumb is to use branch names sparingly and for rather longer lived concepts like "release branches" (rel-1, rel-2, etc) and rather not for short lived work of single developers." [1] - "Mercurial does not yet offer a foolproof way to back out an erroneous merge." [2] - "In practice, this is something you won't do very often, as branch names tend to have fairly long lifetimes." [3] See also: http://whygitisbetterthanx.com/ -- Mark [1] http://mercurial.selenic.com/wiki/Branch [2] http://mercurial.selenic.com/wiki/NamedBranches [3] http://hgbook.red-bean.com/read/managing-releases-and-branchy-development.html#x_390 * To see how lightweight branches are, you can manually "git branch foo master": $ cp .git/refs/heads/master .git/refs/heads/foo What are these files? Just a commit id: $ cat .git/refs/heads/foo faba5d52ae82239f522c108b51fa18dbb1ae9a8b What does "git checkout foo" do? Besides updating the working copy, it basically does: $ echo "ref: refs/heads/foo" > .git/HEAD Most of the other git commands are simple as well. This is another reason why I like git - I can understand it! From lodatom at gmail.com Thu Oct 8 03:51:02 2009 From: lodatom at gmail.com (Mark Lodato) Date: Wed, 7 Oct 2009 21:51:02 -0400 Subject: [Cython] --embed and cython_freeze no longer work In-Reply-To: References: <2F34C111-D81E-436B-94F2-FC476680D119@math.washington.edu> <75BA7DE6-995A-4A90-98DB-24758E80E118@math.washington.edu> <233EC79F-F237-4790-83FA-DEF8E01460F6@hetland.org> Message-ID: On Oct 7, 2009, at 05:07, Mark Lodato wrote: > [...] I much prefer git to hg. I just found this comparison, which is pretty good: http://projects.scipy.org/numpy/wiki/GitMigrationProposal -- Mark From robertwb at math.washington.edu Thu Oct 8 04:02:21 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 7 Oct 2009 19:02:21 -0700 Subject: [Cython] Fwd: [sage-devel] sagemath infrastructure scheduled downtime References: <85e81ba30910071504w7d9359dbub2de09cc6249cf56@mail.gmail.com> Message-ID: This affects us as well, and chances are good after the switch we'll have a lot fewer issues. - Robert Begin forwarded message: > From: William Stein > Date: October 7, 2009 3:04:31 PM PDT > To: sagemath-users , sage-devel > , sage-release release at googlegroups.com>, cython at googlegroups.com, Mike Hansen > , mpir-devel , > David Farmer > Subject: [sage-devel] sagemath infrastructure scheduled downtime > Reply-To: sage-devel at googlegroups.com > > > Hello, > > Tomorrow evening (Thursday, October 8, about 7pm Pacific time) I plan > to shut down the sagemath.org and sagenb.org virtual machines for > about 3 hours to move the virtual machines from VMware on > "mod.math.washington.edu" to VirtualBox on > "boxen.math.washington.edu". During this time the DNS will be > switched over and several websites (cython.org, mpir.org, > sagemath.org) will be offline. > > VirtualBox is vastly better, so after this change I'll be able to > configure these virtual machines with more cores, RAM, and managing > them will be much easier. > > I'll be on irc at irc.freenode.net in #sage-devel during this time... > > -- William > > -- > William Stein > Associate Professor of Mathematics > University of Washington > http://wstein.org > > --~--~---------~--~----~------------~-------~--~----~ > To post to this group, send an email to sage-devel at googlegroups.com > To unsubscribe from this group, send an email to sage-devel- > unsubscribe at googlegroups.com > For more options, visit this group at http://groups.google.com/ > group/sage-devel > URL: http://www.sagemath.org > -~----------~----~----~----~------~----~------~--~--- > From robertwb at math.washington.edu Thu Oct 8 04:02:54 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 7 Oct 2009 19:02:54 -0700 Subject: [Cython] cannot access trac.cython.org In-Reply-To: References: Message-ID: <0D889A59-4988-41E2-AB41-04DA9799804F@math.washington.edu> Should be good now. See my previous email, hopefully there will be some improvements in the infrastructure by the end of the week. On Oct 7, 2009, at 4:03 PM, Lisandro Dalcin wrote: > Getting 502 here... > > -- > Lisandro Dalc?n > --------------- > Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) > Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) > Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) > PTLC - G?emes 3450, (3000) Santa Fe, Argentina > Tel/Fax: +54-(0)342-451.1594 > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev From robertwb at math.washington.edu Thu Oct 8 04:05:40 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 7 Oct 2009 19:05:40 -0700 Subject: [Cython] C++ complex support In-Reply-To: References: <4ACC44B4.50707@student.matnat.uio.no> <1AF56280-A480-450D-9165-D025F7CF7AE1@math.washington.edu> <18B3556C-0EEE-4341-8BC4-C2598A9B96A9@math.washington.edu> <1FB090B0-0F2B-4741-99EC-1CDB98FC5F8F@math.washington.edu> Message-ID: <73C8EAA2-8BF5-4FCA-93D8-C7677307B95F@math.washington.edu> On Oct 7, 2009, at 4:52 PM, Lisandro Dalcin wrote: > On Wed, Oct 7, 2009 at 6:59 PM, Robert Bradshaw > wrote: >> >> Don't reopen the ticket, make a new one for C++ complex support. >> > > Done: http://trac.cython.org/cython_trac/ticket/398 > >>> For the case of C, C99 complexes will be automatically used ONLY if >>> _Complex_I is defined... of if the user explicitly pass >>> "-DPYX_CCOMPLEX=1" at C-compile time (or a Cython-included C header >>> #define PYX_CCOMPLEX=1), or if the directive "ccomplex=True". >>> >>> I'm still in doubt about how to handle 'ccomplex=True'... Should it >>> just enable by default using "#define PYX_CCOMPLEX=1", or actually >>> impact in code generation (as currently does)... >> >> I would be OK with it just changing the flag, with the code >> generation remaining unchanged. >> > > OK, this is work TBD in my patch... > >>> Ah! I forgot... I do not know how to implement z.conjugate(); the >>> C/C99/C++ support is there though... BTW, GCC seems to accept >>> "~z" for >>> complex conjugation (no idea if it is C99-standard or a >>> GCC-extension)... Perhaps Cython should accept this (non-Python) >>> syntax? I think it is nice. >> >> I know is sage we map ~z to 1/z (it is the __invert__ operator after >> all). Python doesn't define an __invert__ for their native complex >> type. I could go either way. >> > > IMHO, my brain can parse "~z" as z.conjugate(), but would have a hard > time realizing ~z is "1/z"... Anyway, you are the BDLF, it's up to > you... Well, it's more handy for matrices, etc. that one would want to invert. Lets get some more input. > Or the champion who actually implement support for > z.conjugate()... Hey, Dag. Are you there? ;-) Dag is the one that brought it up, but +1 from me too. There's no ambiguity there :). - Robert From robertwb at math.washington.edu Thu Oct 8 04:14:29 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 7 Oct 2009 19:14:29 -0700 Subject: [Cython] --embed and cython_freeze no longer work In-Reply-To: References: <2F34C111-D81E-436B-94F2-FC476680D119@math.washington.edu> <75BA7DE6-995A-4A90-98DB-24758E80E118@math.washington.edu> <233EC79F-F237-4790-83FA-DEF8E01460F6@hetland.org> Message-ID: On Oct 7, 2009, at 6:51 PM, Mark Lodato wrote: > On Oct 7, 2009, at 05:07, Mark Lodato wrote: >> [...] I much prefer git to hg. > > I just found this comparison, which is pretty good: > http://projects.scipy.org/numpy/wiki/GitMigrationProposal That is a good page. Lots of interesting feedback (even if it is a bit OT). And no, I'm not advocating a switch, it was just curiosity. I also like git's cherry picking. As to the question of editing history, you can use qimport to turn normal commits in to queue commits, which means you don't really have to plan ahead, though it's not as flexible as git (unless perhaps you use something like pbranch). A disadvantage is that in my (first and second-hand experience) git has a much steeper learning curve. - Robert From cournape at gmail.com Thu Oct 8 04:42:29 2009 From: cournape at gmail.com (David Cournapeau) Date: Thu, 8 Oct 2009 11:42:29 +0900 Subject: [Cython] Is it possible to link to libraries at runtime with Cython In-Reply-To: <7f014ea60910070945x783853bbja741c983877c11d1@mail.gmail.com> References: <7f014ea60910070945x783853bbja741c983877c11d1@mail.gmail.com> Message-ID: <5b8d13220910071942x2395d1bam1cebcd99af5d1884@mail.gmail.com> On Thu, Oct 8, 2009 at 1:45 AM, Chris Colbert wrote: > using something similar to ctypes dlopen? > As mentioned by other, it will be hard to do it if you care about cross-platformness. Linking and loading dynamic binaries is different on almost every platform. For example, that's one of the fundamental difference between the mac os x and elf (linux and solaris) model. And of course windows is also totally different. Besides using ctypes, you could look at python sources - look at Python/import.c, Python/importdl.c and dynload_* for platform specifics. To give you an idea, it is ~ 5000 lines of code, David From vel.accel at gmail.com Thu Oct 8 04:57:00 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Wed, 7 Oct 2009 22:57:00 -0400 Subject: [Cython] --embed and cython_freeze no longer work In-Reply-To: References: <75BA7DE6-995A-4A90-98DB-24758E80E118@math.washington.edu> <233EC79F-F237-4790-83FA-DEF8E01460F6@hetland.org> Message-ID: <1e52e0880910071957m67dcc5cerc8c48b8dc3bfa9af@mail.gmail.com> On Wed, Oct 7, 2009 at 10:14 PM, Robert Bradshaw wrote: [...] > pbranch). A disadvantage is that in my (first and second-hand > experience) git has a much steeper learning curve. > > - Robert Ahh, and yet another case for thoughtfully considered documentation with lots of example snippets.. ;-) From vel.accel at gmail.com Thu Oct 8 05:27:49 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Wed, 7 Oct 2009 23:27:49 -0400 Subject: [Cython] Is it possible to link to libraries at runtime with Cython In-Reply-To: <5b8d13220910071942x2395d1bam1cebcd99af5d1884@mail.gmail.com> References: <7f014ea60910070945x783853bbja741c983877c11d1@mail.gmail.com> <5b8d13220910071942x2395d1bam1cebcd99af5d1884@mail.gmail.com> Message-ID: <1e52e0880910072027s5521ae74nf4f40933d76238ad@mail.gmail.com> On Wed, Oct 7, 2009 at 10:42 PM, David Cournapeau wrote: > On Thu, Oct 8, 2009 at 1:45 AM, Chris Colbert wrote: >> using something similar to ctypes dlopen? >> > > As mentioned by other, it will be hard to do it if you care about > cross-platformness. Linking and loading dynamic binaries is different > on almost every platform. For example, that's one of the fundamental > difference between the mac os x and elf (linux and solaris) model. And > of course windows is also totally different. > > Besides using ctypes, you could look at python sources - look at > Python/import.c, Python/importdl.c and dynload_* for platform > specifics. > > To give you an idea, it is ~ 5000 lines of code, > > David > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > Also, here's a 5 part article for those who might be interested. I'd love to see plugin frameworks more widely adopted. http://www.ddj.com/cpp/204202899 From dagss at student.matnat.uio.no Thu Oct 8 06:05:00 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: 08 Oct 2009 06:05:00 +0200 Subject: [Cython] C++ complex support Message-ID: <3337826740.1387218@smtp.netcom.no> It's was the middle of the night in Norway when you posted that :-) Anyway, I'm 1 on ~x meaning x.conjugate(), because I always vote for making Cython more like Python and less like C. I can do the stuff necessarry for conjugate(), or give you hints, which do you want? I won't be able to do it for another day. Dag Sverre Seljebotn -----Original Message----- From: Lisandro Dalcin Date: Thursday, Oct 8, 2009 1:53 am Subject: Re: [Cython] C++ complex support To: cython-dev at codespeak.netReply-To: cython-dev at codespeak.net On Wed, Oct 7, 2009 at 6:59 PM, Robert Bradshaw > wrote: >> >> Don't reopen the ticket, make a new one for C++ complex support. >> > >Done: http://trac.cython.org/cython_trac/ticket/398 > >>> For the case of C, ?C99 complexes will be automatically used ONLY if >>> _Complex_I is defined... of if the user explicitly pass >>> "-DPYX_CCOMPLEX=1" at C-compile time (or a Cython-included C header >>> #define PYX_CCOMPLEX=1), or if the directive "ccomplex=True". >>> >>> I'm still in doubt about how to handle 'ccomplex=True'... Should it >>> just enable by default using "#define PYX_CCOMPLEX=1", or actually >>> impact in code generation (as currently does)... >> >> I would be OK with it just changing the flag, with the code >> generation remaining unchanged. >> > >OK, this is work TBD in my patch... > >>> Ah! I forgot... I do not know how to implement z.conjugate(); the >>> C/C99/C++ support is there though... BTW, GCC seems to accept "~z" for >>> complex conjugation (no idea if it is C99-standard or a >>> GCC-extension)... Perhaps Cython should accept this (non-Python) >>> syntax? I think it is nice. >> >> I know is sage we map ~z to 1/z (it is the __invert__ operator after >> all). Python doesn't define an __invert__ for their native complex >> type. I could go either way. >> > >IMHO, my brain can parse "~z" as z.conjugate(), but would have a hard >time realizing ~z is "1/z"... Anyway, you are the BDLF, it's up to >you... Or the champion who actually implement support for >z.conjugate()... Hey, Dag. Are you there? ;-) > > > >-- >Lisandro Dalc?n >--------------- >Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) >Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) >Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) >PTLC - G?emes 3450, (3000) Santa Fe, Argentina >Tel/Fax: +54-(0)342-451.1594 >_______________________________________________ >Cython-dev mailing list >Cython-dev at codespeak.net >http://codespeak.net/mailman/listinfo/cython-dev > From dagss at student.matnat.uio.no Thu Oct 8 06:07:00 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: 08 Oct 2009 06:07:00 +0200 Subject: [Cython] C++ complex support Message-ID: <3337826873.1400571@smtp.netcom.no> seems a minus disappeared there... But I'm against ~x for conjugate. Dag Sverre Seljebotn -----Original Message----- From: "Dag Sverre Seljebotn" Date: Thursday, Oct 8, 2009 6:07 am Subject: Re: [Cython] C++ complex support To: CC: Reply-To: cython-dev at codespeak.net It's was the middle of the night in Norway when you posted that :-) > >Anyway, I'm 1 on ~x meaning x.conjugate(), because I always vote for making Cython more like Python and less like C. > >I can do the stuff necessarry for conjugate(), or give you hints, which do you want? I won't be able to do it for another day. > >Dag Sverre Seljebotn >-----Original Message----- >From: Lisandro Dalcin >Date: Thursday, Oct 8, 2009 1:53 am >Subject: Re: [Cython] C++ complex support >To: cython-dev at codespeak.netReply-To: cython-dev at codespeak.net > >On Wed, Oct 7, 2009 at 6:59 PM, Robert Bradshaw > wrote: >> >> Don't reopen the ticket, make a new one for C++ complex support. >> > >>Done: http://trac.cython.org/cython_trac/ticket/398 > >>>> For the case of C, ?C99 complexes will be automatically used ONLY if >>> _Complex_I is defined... of if the user explicitly pass >>> "-DPYX_CCOMPLEX=1" at C-compile time (or a Cython-included C header >>> #define PYX_CCOMPLEX=1), or if the directive "ccomplex=True". >>> >>> I'm still in doubt about how to handle 'ccomplex=True'... Should it >>> just enable by default using "#define PYX_CCOMPLEX=1", or actually >>> impact in code generation (as currently does)... >> >> I would be OK with it just changing the flag, with the code >> generation remaining unchanged. >> > >>OK, this is work TBD in my patch... > >>>> Ah! I forgot... I do not know how to implement z.conjugate(); the >>> C/C99/C++ support is there though... BTW, GCC seems to accept "~z" for >>> complex conjugation (no idea if it is C99-standard or a >>> GCC-extension)... Perhaps Cython should accept this (non-Python) >>> syntax? I think it is nice. >> >> I know is sage we map ~z to 1/z (it is the __invert__ operator after >> all). Python doesn't define an __invert__ for their native complex >> type. I could go either way. >> > >>IMHO, my brain can parse "~z" as z.conjugate(), but would have a hard >time realizing ~z is "1/z"... Anyway, you are the BDLF, it's up to >you... Or the champion who actually implement support for >z.conjugate()... Hey, Dag. Are you there? ;-) > >> > >>-- >Lisandro Dalc?n >--------------- >Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) >Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) >Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) >PTLC - G?emes 3450, (3000) Santa Fe, Argentina >Tel/Fax: +54-(0)342-451.1594 >_______________________________________________ >Cython-dev mailing list >Cython-dev at codespeak.net >http://codespeak.net/mailman/listinfo/cython-dev > > > From robertwb at math.washington.edu Thu Oct 8 06:13:13 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 7 Oct 2009 21:13:13 -0700 Subject: [Cython] C++ complex support In-Reply-To: <3337826740.1387218@smtp.netcom.no> References: <3337826740.1387218@smtp.netcom.no> Message-ID: On Oct 7, 2009, at 9:05 PM, Dag Sverre Seljebotn wrote: > It's was the middle of the night in Norway when you posted that :-) > > Anyway, I'm 1 Did you forget a sign there? > on ~x meaning x.conjugate(), because I always vote for making > Cython more like Python and less like C. It's currently an error for complex values in Python. > I can do the stuff necessarry for conjugate(), or give you hints, > which do you want? I won't be able to do it for another day. > > Dag Sverre Seljebotn > -----Original Message----- > From: Lisandro Dalcin > Date: Thursday, Oct 8, 2009 1:53 am > Subject: Re: [Cython] C++ complex support > To: cython-dev at codespeak.netReply-To: cython-dev at codespeak.net > > On Wed, Oct 7, 2009 at 6:59 PM, Robert Bradshaw >> wrote: >>> >>> Don't reopen the ticket, make a new one for C++ complex support. >>> >> >> Done: http://trac.cython.org/cython_trac/ticket/398 >> >>>> For the case of C, C99 complexes will be automatically used >>>> ONLY if >>>> _Complex_I is defined... of if the user explicitly pass >>>> "-DPYX_CCOMPLEX=1" at C-compile time (or a Cython-included C header >>>> #define PYX_CCOMPLEX=1), or if the directive "ccomplex=True". >>>> >>>> I'm still in doubt about how to handle 'ccomplex=True'... Should it >>>> just enable by default using "#define PYX_CCOMPLEX=1", or actually >>>> impact in code generation (as currently does)... >>> >>> I would be OK with it just changing the flag, with the code >>> generation remaining unchanged. >>> >> >> OK, this is work TBD in my patch... >> >>>> Ah! I forgot... I do not know how to implement z.conjugate(); the >>>> C/C99/C++ support is there though... BTW, GCC seems to accept >>>> "~z" for >>>> complex conjugation (no idea if it is C99-standard or a >>>> GCC-extension)... Perhaps Cython should accept this (non-Python) >>>> syntax? I think it is nice. >>> >>> I know is sage we map ~z to 1/z (it is the __invert__ operator after >>> all). Python doesn't define an __invert__ for their native complex >>> type. I could go either way. >>> >> >> IMHO, my brain can parse "~z" as z.conjugate(), but would have a hard >> time realizing ~z is "1/z"... Anyway, you are the BDLF, it's up to >> you... Or the champion who actually implement support for >> z.conjugate()... Hey, Dag. Are you there? ;-) >> >> >> >> -- >> Lisandro Dalc?n >> --------------- >> Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) >> Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) >> Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) >> PTLC - G?emes 3450, (3000) Santa Fe, Argentina >> Tel/Fax: +54-(0)342-451.1594 >> _______________________________________________ >> 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 From dagss at student.matnat.uio.no Thu Oct 8 06:22:00 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: 08 Oct 2009 06:22:00 +0200 Subject: [Cython] C++ complex support Message-ID: <3337827751.1469432@smtp.netcom.no> I know that it is not an incompatability as such, I just don't like it -- especially as, from the perspective of Python, it is called inverse, and it is used for that purpose in Sage. What does NumPy use ~ for? If it is conjugate I could be swayed, but I highly doubt it (I think it is used bitwise but can't check now). Also I don't see the need for a seperate operator for conjugate. I could learn to like x.conj or x.C as a shorter form which doesn't clash with the operator name (although likely not use it myself as I normally do incremental optimization). I'll be back in a few hours. Feel free to vote me out, but I'd think new syntax candy like this can safely wait for 0.13? Dag Sverre Seljebotn -----Original Message----- From: Robert Bradshaw Date: Thursday, Oct 8, 2009 6:14 am Subject: Re: [Cython] C++ complex support To: cython-dev at codespeak.netReply-To: cython-dev at codespeak.net On Oct 7, 2009, at 9:05 PM, Dag Sverre Seljebotn wrote: > >> It's was the middle of the night in Norway when you posted that :-) >> >> Anyway, I'm 1 > >Did you forget a sign there? > >> on ~x meaning x.conjugate(), because I always vote for making >> Cython more like Python and less like C. > >It's currently an error for complex values in Python. > >> I can do the stuff necessarry for conjugate(), or give you hints, >> which do you want? I won't be able to do it for another day. >> >> Dag Sverre Seljebotn >> -----Original Message----- >> From: Lisandro Dalcin >> Date: Thursday, Oct 8, 2009 1:53 am >> Subject: Re: [Cython] C++ complex support >> To: cython-dev at codespeak.netReply-To: cython-dev at codespeak.net >> >> On Wed, Oct 7, 2009 at 6:59 PM, Robert Bradshaw >>> wrote: >>>> >>>> Don't reopen the ticket, make a new one for C++ complex support. >>>> >>> >>> Done: http://trac.cython.org/cython_trac/ticket/398 >>> >>>>> For the case of C, C99 complexes will be automatically used >>>>> ONLY if >>>>> _Complex_I is defined... of if the user explicitly pass >>>>> "-DPYX_CCOMPLEX=1" at C-compile time (or a Cython-included C header >>>>> #define PYX_CCOMPLEX=1), or if the directive "ccomplex=True". >>>>> >>>>> I'm still in doubt about how to handle 'ccomplex=True'... Should it >>>>> just enable by default using "#define PYX_CCOMPLEX=1", or actually >>>>> impact in code generation (as currently does)... >>>> >>>> I would be OK with it just changing the flag, with the code >>>> generation remaining unchanged. >>>> >>> >>> OK, this is work TBD in my patch... >>> >>>>> Ah! I forgot... I do not know how to implement z.conjugate(); the >>>>> C/C99/C++ support is there though... BTW, GCC seems to accept >>>>> "~z" for >>>>> complex conjugation (no idea if it is C99-standard or a >>>>> GCC-extension)... Perhaps Cython should accept this (non-Python) >>>>> syntax? I think it is nice. >>>> >>>> I know is sage we map ~z to 1/z (it is the __invert__ operator after >>>> all). Python doesn't define an __invert__ for their native complex >>>> type. I could go either way. >>>> >>> >>> IMHO, my brain can parse "~z" as z.conjugate(), but would have a hard >>> time realizing ~z is "1/z"... Anyway, you are the BDLF, it's up to >>> you... Or the champion who actually implement support for >>> z.conjugate()... Hey, Dag. Are you there? ;-) >>> >>> >>> >>> -- >>> Lisandro Dalc?n >>> --------------- >>> Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) >>> Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) >>> Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) >>> PTLC - G?emes 3450, (3000) Santa Fe, Argentina >>> Tel/Fax: +54-(0)342-451.1594 >>> _______________________________________________ >>> 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 > >_______________________________________________ >Cython-dev mailing list >Cython-dev at codespeak.net >http://codespeak.net/mailman/listinfo/cython-dev > From wstein at gmail.com Thu Oct 8 07:13:30 2009 From: wstein at gmail.com (William Stein) Date: Wed, 7 Oct 2009 22:13:30 -0700 Subject: [Cython] [mpir-devel] Re: sagemath infrastructure scheduled downtime In-Reply-To: <85e81ba30910071723j5e353886ve814cc8987f7ed44@mail.gmail.com> References: <85e81ba30910071504w7d9359dbub2de09cc6249cf56@mail.gmail.com> <85e81ba30910071723j5e353886ve814cc8987f7ed44@mail.gmail.com> Message-ID: <85e81ba30910072213g6d5cb654q1329de3702890098@mail.gmail.com> Hi, 1. I rsynced all the servers from the old sagemath to the new virtual machine. If you put a line like this in your /etc/hosts file 128.208.160.197 sagemath.org trac.sagemath.org cython.org # etc. then you can see what the new website would look like if we switched over now. Again, the switchover won't happen until tomorrow. If you have any way to "hammer" this server, please try. Report any problems. 2. I rewrote my comparison of VMware and VirtualBox as a blog post: http://sagemath.blogspot.com/2009/10/virtualbox-versus-vmware-server.html William From vel.accel at gmail.com Thu Oct 8 07:43:13 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Thu, 8 Oct 2009 01:43:13 -0400 Subject: [Cython] [mpir-devel] Re: sagemath infrastructure scheduled downtime In-Reply-To: <85e81ba30910072213g6d5cb654q1329de3702890098@mail.gmail.com> References: <85e81ba30910071504w7d9359dbub2de09cc6249cf56@mail.gmail.com> <85e81ba30910071723j5e353886ve814cc8987f7ed44@mail.gmail.com> <85e81ba30910072213g6d5cb654q1329de3702890098@mail.gmail.com> Message-ID: <1e52e0880910072243o5a0ddc76h8848f89789edd84@mail.gmail.com> On Thu, Oct 8, 2009 at 1:13 AM, William Stein wrote: > Hi, > > 1. I rsynced all the servers from the old sagemath to the new virtual > machine. ?If you put a line like this in your /etc/hosts file > > 128.208.160.197 sagemath.org trac.sagemath.org cython.org ? # etc. > > then you can see what the new website would look like if we switched > over now. ?Again, the switchover won't happen until tomorrow. ? If you > have any way to "hammer" this server, please try. ? Report any > problems. > > 2. I rewrote my comparison of VMware and VirtualBox as a blog post: > > http://sagemath.blogspot.com/2009/10/virtualbox-versus-vmware-server.html > > William > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > Hi Bill. I hammered pretty good with a page capture prog. No probs except with Cython's wiki surge protector.. that's a config I'd suppose. Let me know if you need more hammerin'. The Sage site looks good, btw. From stefan_ml at behnel.de Thu Oct 8 08:58:33 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 08 Oct 2009 08:58:33 +0200 Subject: [Cython] Are min/max ever optimized? In-Reply-To: References: <7E426F06-A1C0-449A-B500-414BD0AD1204@hetland.org> <4ACC91D6.7040703@behnel.de> <83BF77BE-7B74-412F-84F1-7891790D7D31@hetland.org> Message-ID: <4ACD8D99.4010808@behnel.de> Robert Bradshaw wrote: > Note also that Danilo did some work on overloaded functions which > could be useful here too. It may, yes. Is there any documentation about what he actually did? I never saw any floating around, the related mailing list discussions were rather sparse (IMHO), and I certainly won't read all through the branch commit log to figure it out. On a related node, I really hate that the analyse types phase runs completely before the optimisations phase, as it removes available type information when coercing stuff to Python types. Later optimisations have to struggle to recover that when moving stuff back into C space. Maybe an "original_type" attribute would fix this already. We could simply copy "type" to "original_type" everywhere before running the analysis, and maybe replace that if we find something that's truly better in coerce_to() or in the analysis functions. Stefan From sturla at molden.no Thu Oct 8 13:41:36 2009 From: sturla at molden.no (Sturla Molden) Date: Thu, 08 Oct 2009 13:41:36 +0200 Subject: [Cython] C++ complex support In-Reply-To: <3337827751.1469432@smtp.netcom.no> References: <3337827751.1469432@smtp.netcom.no> Message-ID: <4ACDCFF0.7060705@molden.no> Dag Sverre Seljebotn wrote: > I know that it is not an incompatability as such, I just don't like it -- especially as, from the perspective of Python, it is called inverse, and it is used for that purpose in Sage. > > What does NumPy use ~ for? If it is conjugate I could be swayed, but I highly doubt it (I think it is used bitwise but can't check now). > NumPy does the same as Python. >>> import numpy as np >>> a = np.array([1,1,1], dtype=np.complex128) >>> a array([ 1.+0.j, 1.+0.j, 1.+0.j]) >>> ~a Traceback (most recent call last): File "", line 1, in ~a TypeError: bad operand type for unary ~: 'complex' >>> a.conjugate() array([ 1.-0.j, 1.-0.j, 1.-0.j]) Same as Python: >>> a = 1 + 0j >>> a (1+0j) >>> ~a Traceback (most recent call last): File "", line 1, in ~a TypeError: bad operand type for unary ~: 'complex' >>> a.conjugate() (1-0j) There is also a function numpy.conj that can be used instead of .conjugate() >>> a = np.array([1,1,1], dtype=np.complex128) >>> np.conj(a) array([ 1.-0.j, 1.-0.j, 1.-0.j]) S.M. From dagss at student.matnat.uio.no Thu Oct 8 13:54:37 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 08 Oct 2009 13:54:37 +0200 Subject: [Cython] Are min/max ever optimized? In-Reply-To: <4ACD8D99.4010808@behnel.de> References: <7E426F06-A1C0-449A-B500-414BD0AD1204@hetland.org> <4ACC91D6.7040703@behnel.de> <83BF77BE-7B74-412F-84F1-7891790D7D31@hetland.org> <4ACD8D99.4010808@behnel.de> Message-ID: <4ACDD2FD.7090206@student.matnat.uio.no> Stefan Behnel wrote: > Robert Bradshaw wrote: > >> Note also that Danilo did some work on overloaded functions which >> could be useful here too. >> > > It may, yes. Is there any documentation about what he actually did? I never > saw any floating around, the related mailing list discussions were rather > sparse (IMHO), and I certainly won't read all through the branch commit log > to figure it out. > > On a related node, I really hate that the analyse types phase runs > completely before the optimisations phase, as it removes available type > information when coercing stuff to Python types. Later optimisations have > to struggle to recover that when moving stuff back into C space. > Also any scheme relying on an "optimization" transform in the end is going to fail miserably with type inference, so it would be good to go away from that. However things are intrinsically bound together -- especially when type inference is considered. I was a strong defender of splitting type analysis earlier but I found I always ended up in cases where new problems are caused. The knowledge of the special properties of the "max" function rather has to become *part of* the type analysis -- it can't all be done in a transform. In this particular case I think the solution is to start having function declarations with multiple sets of signatures -- so that SimpleCallNode can consider a list of signatures in the entry of __builtin__.max rather than only a single signature, and if both arguments are "int" then the result type is an "int". Perhaps this is what Danilo implemented .. (it would have to be *something* like that). However I think (your idea?) of splitting "resolving" and "typing" into seperate phases is good. For special cases, one could thus e.g. transform __builtin__.max into MaxExprNode *before* typing happens, without interfering with user-defined functions that happen to be named "max". Partial typing of the tree I'm doubtful of though. Dag Sverre From sturla at molden.no Thu Oct 8 13:59:28 2009 From: sturla at molden.no (Sturla Molden) Date: Thu, 08 Oct 2009 13:59:28 +0200 Subject: [Cython] C++ complex support In-Reply-To: <4ACDCFF0.7060705@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> Message-ID: <4ACDD420.4060500@molden.no> I have two more things to say about this. First, support for C++ std::complex and C99 _Complex in Cython would be great. I recently tried to reimplement scipy.signal.lfilter using std::complex instead of hand-written complex arithmetics in C89. I got nearly 400% increase in performance. Compilers are often smarter than humans. Complex math is better left to the compiler. :-) Second, I think the NumPy method .conjugate() does wasteful work. There should have been complex conjugate dtypes that symbolically represent the complex conjugate. That would make .conjugate() O(1) for NumPy arrays instead of O(n). But that is not a Cython issue... S.M. From dagss at student.matnat.uio.no Thu Oct 8 14:15:25 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 08 Oct 2009 14:15:25 +0200 Subject: [Cython] C++ complex support In-Reply-To: <4ACDCFF0.7060705@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> Message-ID: <4ACDD7DD.3070505@student.matnat.uio.no> Sturla Molden wrote: > Dag Sverre Seljebotn wrote: > >> I know that it is not an incompatability as such, I just don't like it -- especially as, from the perspective of Python, it is called inverse, and it is used for that purpose in Sage. >> >> What does NumPy use ~ for? If it is conjugate I could be swayed, but I highly doubt it (I think it is used bitwise but can't check now). >> >> > > NumPy does the same as Python. > > > >>> import numpy as np > >>> a = np.array([1,1,1], dtype=np.complex128) > >>> a > array([ 1.+0.j, 1.+0.j, 1.+0.j]) > >>> ~a > > Traceback (most recent call last): > File "", line 1, in > ~a > TypeError: bad operand type for unary ~: 'complex' > > >>> a.conjugate() > array([ 1.-0.j, 1.-0.j, 1.-0.j]) > Thanks. Also it uses ~ for bitwise not on integers, so it seems there's very little chance of NumPy picking up ~ for conjugation (as it could lead to subtle bugs to have two entirely different behaviours depending on dtype). What's your opinion on Lisandro's proposal though? I checked the GCC docs, and it says: """ The operator `~' performs complex conjugation when used on a value with a complex type. This is a GNU extension; for values of floating type, you should use the ISO C99 functions |conjf|, |conj| and |conjl|, declared in || and also provided as built-in functions by GCC. """ I must say I'll have a hard time feeling good about overloading an existing operator for another purpose if this GCC-specific feature is the only motivation. In fact we already went in the opposite direction with the division operator (towards Python, and towards semantics of operator not being decided by the type it operates on!) Dag Sverre From dagss at student.matnat.uio.no Thu Oct 8 14:17:11 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 08 Oct 2009 14:17:11 +0200 Subject: [Cython] C++ complex support In-Reply-To: <4ACDD420.4060500@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDD420.4060500@molden.no> Message-ID: <4ACDD847.40400@student.matnat.uio.no> Sturla Molden wrote: > I have two more things to say about this. > > First, support for C++ std::complex and C99 _Complex in Cython would be > Note that C99 complex support is already there since 0.11.2, just make sure you include complex.h somehow. Dag Sverre From sccolbert at gmail.com Thu Oct 8 14:27:46 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 8 Oct 2009 14:27:46 +0200 Subject: [Cython] trouble getting a function pointer from ctypes to play nice with Cython... Message-ID: <7f014ea60910080527i2841444fh691d9fe2c56499f6@mail.gmail.com> Given our previous conversation, it will probably be easier to use ctypes to get the function handles for dynamically loaded libraries and *somehow* get that function pointer into Cython. My attempt is like so (for a simple example) but Cython is complaining during compilation: from ctypes import * cdef extern from "Python.h": void* PyLong_AsVoidPtr(object) cdef int a libc = CDLL('libc.so.6') timefunc = libc.time cdef object tptr = ctypes.addressof(timefunc) cdef int (*mytime)() mytime = PyLong_AsVoidPtr(tptr) a = mytime[0]() print a Error converting Pyrex file to C: ------------------------------------------------------------ ... libc = CDLL('libc.so.6') timefunc = libc.time cdef object tptr = ctypes.addressof(timefunc) cdef int (*mytime)() mytime = PyLong_AsVoidPtr(tptr) ^ ------------------------------------------------------------ /home/brucewayne/Desktop/cytypestest.pyx:13:25: Cannot assign type 'void *' to 'int (*)(void)' Any ideas how to get that at that pointer? I'm open to ideas that involve the use of really big hammers ;) Cheers! Chris From dagss at student.matnat.uio.no Thu Oct 8 14:34:09 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 08 Oct 2009 14:34:09 +0200 Subject: [Cython] trouble getting a function pointer from ctypes to play nice with Cython... In-Reply-To: <7f014ea60910080527i2841444fh691d9fe2c56499f6@mail.gmail.com> References: <7f014ea60910080527i2841444fh691d9fe2c56499f6@mail.gmail.com> Message-ID: <4ACDDC41.5060507@student.matnat.uio.no> Chris Colbert wrote: > Given our previous conversation, it will probably be easier to use > ctypes to get the function handles for dynamically loaded libraries > and *somehow* get that function pointer into Cython. > > My attempt is like so (for a simple example) but Cython is complaining > during compilation: > > > from ctypes import * > > cdef extern from "Python.h": > void* PyLong_AsVoidPtr(object) > > cdef int a > > libc = CDLL('libc.so.6') > timefunc = libc.time > > cdef object tptr = ctypes.addressof(timefunc) > cdef int (*mytime)() > mytime = PyLong_AsVoidPtr(tptr) > I think this should do it: ctypedef int (*timefuncptr)() cdef timefuncptr mytime mytime = ctypes.addressof(libc.time) That is, unless ctypes.addressof returns the address of the *pointer* to the function stored in libc.time (I'm not familiar enough with ctypes). In that case it is instead: mytime = (ctypes.addressof(libc.time))[0] Dag Sverre From dagss at student.matnat.uio.no Thu Oct 8 14:35:44 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 08 Oct 2009 14:35:44 +0200 Subject: [Cython] trouble getting a function pointer from ctypes to play nice with Cython... In-Reply-To: <4ACDDC41.5060507@student.matnat.uio.no> References: <7f014ea60910080527i2841444fh691d9fe2c56499f6@mail.gmail.com> <4ACDDC41.5060507@student.matnat.uio.no> Message-ID: <4ACDDCA0.1040803@student.matnat.uio.no> Dag Sverre Seljebotn wrote: > Chris Colbert wrote: >> Given our previous conversation, it will probably be easier to use >> ctypes to get the function handles for dynamically loaded libraries >> and *somehow* get that function pointer into Cython. >> >> My attempt is like so (for a simple example) but Cython is complaining >> during compilation: >> >> >> from ctypes import * >> >> cdef extern from "Python.h": >> void* PyLong_AsVoidPtr(object) >> >> cdef int a >> >> libc = CDLL('libc.so.6') >> timefunc = libc.time >> >> cdef object tptr = ctypes.addressof(timefunc) >> cdef int (*mytime)() >> mytime = PyLong_AsVoidPtr(tptr) >> > I think this should do it: > > ctypedef int (*timefuncptr)() > cdef timefuncptr mytime > mytime = ctypes.addressof(libc.time) Sorry, that should be mytime = ctypes.addressof(libc.time) i.e. convert to typed integer of pointer size before converting to pointer. The same goes for the example below. > > That is, unless ctypes.addressof returns the address of the *pointer* > to the function stored in libc.time (I'm not familiar enough with > ctypes). In that case it is instead: > > mytime = (ctypes.addressof(libc.time))[0] > > Dag Sverre > From dagss at student.matnat.uio.no Thu Oct 8 15:04:17 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 08 Oct 2009 15:04:17 +0200 Subject: [Cython] Object to Py_ssize_t conversion Message-ID: <4ACDE351.3090707@student.matnat.uio.no> I experience this: np.sqrt(some_float64) => TypeError: 'numpy.float64' object cannot be interpreted as an index However a) np.sqrt(...) works fine, as does and . b) In Python, int(np.sqrt(...)) and long(np.sqrt(...)) both works fine Is Py_ssize_t "special" when it comes to converting from Python objects? If so I find it mildly confusing and something which only increases learning curve... Dag Sverre From sccolbert at gmail.com Thu Oct 8 15:05:08 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 8 Oct 2009 15:05:08 +0200 Subject: [Cython] trouble getting a function pointer from ctypes to play nice with Cython... In-Reply-To: <4ACDDCA0.1040803@student.matnat.uio.no> References: <7f014ea60910080527i2841444fh691d9fe2c56499f6@mail.gmail.com> <4ACDDC41.5060507@student.matnat.uio.no> <4ACDDCA0.1040803@student.matnat.uio.no> Message-ID: <7f014ea60910080605x1cd335eew5b8cfc0468dc6016@mail.gmail.com> Ok, tried both of those methods, and they pass cython compilation, but then I get this error from gcc: brucewayne at broo:~/Desktop$ gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python2.6 -o cytypestest.so cytypestest.c cytypestest.c: In function ?initcytypestest?: cytypestest.c:707: error: subscripted value is pointer to function Cheers! Chris On Thu, Oct 8, 2009 at 2:35 PM, Dag Sverre Seljebotn wrote: > Dag Sverre Seljebotn wrote: >> Chris Colbert wrote: >>> Given our previous conversation, it will probably be easier to use >>> ctypes to get the function handles for dynamically loaded libraries >>> and *somehow* get that function pointer into Cython. >>> >>> My attempt is like so (for a simple example) but Cython is complaining >>> during compilation: >>> >>> >>> from ctypes import * >>> >>> cdef extern from "Python.h": >>> ? ? void* PyLong_AsVoidPtr(object) >>> >>> cdef int a >>> >>> libc = CDLL('libc.so.6') >>> timefunc = libc.time >>> >>> cdef object tptr = ctypes.addressof(timefunc) >>> cdef int (*mytime)() >>> mytime = PyLong_AsVoidPtr(tptr) >>> >> I think this should do it: >> >> ctypedef int (*timefuncptr)() >> cdef timefuncptr mytime >> mytime = ctypes.addressof(libc.time) > Sorry, that should be > > mytime = ctypes.addressof(libc.time) > > i.e. convert to typed integer of pointer size before converting to > pointer. The same goes for the example below. >> >> That is, unless ctypes.addressof returns the address of the *pointer* >> to the function stored in libc.time (I'm not familiar enough with >> ctypes). In that case it is instead: >> >> mytime = (ctypes.addressof(libc.time))[0] >> >> Dag Sverre >> > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > From sccolbert at gmail.com Thu Oct 8 15:36:13 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 8 Oct 2009 15:36:13 +0200 Subject: [Cython] trouble getting a function pointer from ctypes to play nice with Cython... In-Reply-To: <7f014ea60910080605x1cd335eew5b8cfc0468dc6016@mail.gmail.com> References: <7f014ea60910080527i2841444fh691d9fe2c56499f6@mail.gmail.com> <4ACDDC41.5060507@student.matnat.uio.no> <4ACDDCA0.1040803@student.matnat.uio.no> <7f014ea60910080605x1cd335eew5b8cfc0468dc6016@mail.gmail.com> Message-ID: <7f014ea60910080636q35d6bc52odf23d2d17d57d346@mail.gmail.com> alright I figured it out, I just dont dereference the function pointer before calling it. I don't understand why that works though... At any rate, here is a self contained working example for future googlers ############ # cytypestest.pyx ############ import ctypes libc = ctypes.CDLL('libc.so.6') ctypedef int (*timefuncptr)() cdef timefuncptr mytime mytime = (ctypes.addressof(libc.time))[0] print mytime() ######### # EOF ######### $cython cytypestest.pyx $gcc -shared -pthread -fPIC -fwrapv -O2 -Wall -fno-strict-aliasing -I/usr/include/python2.6 -o cytypestest.so cytypestest.c $python >>> import cytypestest 1255008817 On Thu, Oct 8, 2009 at 3:05 PM, Chris Colbert wrote: > Ok, tried both of those methods, and they pass cython compilation, but > then I get this error from gcc: > > brucewayne at broo:~/Desktop$ gcc -shared -pthread -fPIC -fwrapv -O2 > -Wall -fno-strict-aliasing -I/usr/include/python2.6 -o cytypestest.so > cytypestest.c > cytypestest.c: In function ?initcytypestest?: > cytypestest.c:707: error: subscripted value is pointer to function > > Cheers! > > Chris > > > On Thu, Oct 8, 2009 at 2:35 PM, Dag Sverre Seljebotn > wrote: >> Dag Sverre Seljebotn wrote: >>> Chris Colbert wrote: >>>> Given our previous conversation, it will probably be easier to use >>>> ctypes to get the function handles for dynamically loaded libraries >>>> and *somehow* get that function pointer into Cython. >>>> >>>> My attempt is like so (for a simple example) but Cython is complaining >>>> during compilation: >>>> >>>> >>>> from ctypes import * >>>> >>>> cdef extern from "Python.h": >>>> ? ? void* PyLong_AsVoidPtr(object) >>>> >>>> cdef int a >>>> >>>> libc = CDLL('libc.so.6') >>>> timefunc = libc.time >>>> >>>> cdef object tptr = ctypes.addressof(timefunc) >>>> cdef int (*mytime)() >>>> mytime = PyLong_AsVoidPtr(tptr) >>>> >>> I think this should do it: >>> >>> ctypedef int (*timefuncptr)() >>> cdef timefuncptr mytime >>> mytime = ctypes.addressof(libc.time) >> Sorry, that should be >> >> mytime = ctypes.addressof(libc.time) >> >> i.e. convert to typed integer of pointer size before converting to >> pointer. The same goes for the example below. >>> >>> That is, unless ctypes.addressof returns the address of the *pointer* >>> to the function stored in libc.time (I'm not familiar enough with >>> ctypes). In that case it is instead: >>> >>> mytime = (ctypes.addressof(libc.time))[0] >>> >>> Dag Sverre >>> >> >> _______________________________________________ >> Cython-dev mailing list >> Cython-dev at codespeak.net >> http://codespeak.net/mailman/listinfo/cython-dev >> > From sturla at molden.no Thu Oct 8 16:29:59 2009 From: sturla at molden.no (Sturla Molden) Date: Thu, 08 Oct 2009 16:29:59 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACDCFF0.7060705@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> Message-ID: <4ACDF767.7020901@molden.no> I have used Cython for numerical programming for quite a while. I'd like to share my experience with you Cython developers. There are two or three annoying issues I keep encounter, which I hope you can take into consideration for future tickets. First, is there any reason why Cython does not recognize const and restrict? In numerical code, the declarations const type *restrict const type * type *restrict can help the C compiler produce faster code. It helps the compiler to prevent redundant read and write from memory, and thus values can be kept in registers. Particularly the first is a strong statement that allows faster code to be written. const also helps the C or C++ compiler detect certain hard-to-find bugs. E.g. warning (C) or error (C++) if we accidentally assign const double* to double* and write to the buffer. Here is one example of C99 I wrote where "const double *restrict" is used to help the compiler optimize better: inline void solve_triangular_system(npy_intp n, const double *restrict U, double *b) { /* solves the triangular system U' * x = b using forward substitution. The values of b are over-written with x. cf. Goloub & van Loan (1996), page 90. */ for (npy_intp j=0; j( U + n*j*sizeof(double)) Using integers to store addresses is similar to pesky 1970s versions of C using long for void*... :( Third issue: Subarrays/slices. Dag Sverre's NumPy work allow ndarrays in Python, so declaring cdef np.ndarray[double, ndim=2, mode="c"] U we could have written U[j,i] instead of Uj[i]. Or uf there was a fast way of slicing, we could have written cdef np.ndarray[double, ndim=1, mode="c"] Uj Uj = U[j,:] Unfortunately, unlike Fortran 90, there is no fast way of creating and passing around sub-arrays in Cython. There will be Python overhead (object creation, refcounting), we must keep the GIL, etc. Looking in the manual, Cython's ndarray syntax looks almost as nice as Fortran 90. But that is until you realize *no function calls are being made*. When we need to call a function with an array as argument, we have to resort to C pointers for speed. But Cython does not allow pointer arithmetics. We thus must resort to something even more primitive: addresses stored in integers... From looking nice on the surface, Cython suddenly get worse than anything else. Even plain C is easier. Surely there has to be a better way? S.M. From dalcinl at gmail.com Thu Oct 8 16:32:56 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Thu, 8 Oct 2009 11:32:56 -0300 Subject: [Cython] C++ complex support In-Reply-To: <4ACDD847.40400@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> Message-ID: I was just pointing to GCC-specific syntax that perhaps we could use, I was not actually requesting for it !!! I really prefer your time being invested in reviewing the patch: http://trac.cython.org/cython_trac/ticket/398 BTW, What would be better from "creating" a C99/C++ complex number from re & im parts: use a macro or a inline function as we currently have? Would it be worth to also use a macro {complex_type}_coerce() to implement promotion to a complex type? Currently we are using {complex_type}_from_parts(realpart,0) for this... As the generated code has to support struct-based complexes, things like to 1/z need to promote "1" to complex... But for C99, actual promotion is not required (the compiler does that), and in C++ we have to at promote to at least for many operators to work. Any chance that special-casing the coercion with an appropriate macro could give faster execution? On Thu, Oct 8, 2009 at 9:17 AM, Dag Sverre Seljebotn wrote: > Sturla Molden wrote: >> I have two more things to say about this. >> >> First, support for C++ std::complex and C99 _Complex in Cython would be >> > Note that C99 complex support is already there since 0.11.2, just make > sure you include complex.h somehow. > > Dag Sverre > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Thu Oct 8 17:04:34 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Thu, 8 Oct 2009 12:04:34 -0300 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACDF767.7020901@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> Message-ID: On Thu, Oct 8, 2009 at 11:29 AM, Sturla Molden wrote: > > First, is there any reason why Cython does not recognize const and > restrict? > Probably it is just the lack of time to implement it. This also annoys me. But I remember Dag was interested in supporting 'restrict'. > In numerical code, the declarations > > ? const type *restrict > ? const type * > ? type *restrict > > can help the C compiler produce faster code. It helps the compiler to > prevent redundant read and write from memory, and thus values can be > kept in registers. Particularly the first is a strong statement that > allows faster code to be written. > > const also helps the C or C++ compiler detect certain hard-to-find bugs. > E.g. warning (C) or error (C++) if we accidentally assign const double* > to double* and write to the buffer. > BTW, I'm assuming you already use the trick below, right?: ctypedef double const_double "const double" At least this helps to more or less handle constness... > > If Cython did support these two qualifiers (const and restrict), I could > have kept it all in Cython. > Take into account that if you contribute anything to help in such support, then we can have this working sooner. > > Second issue: Why is it that Cython does not support pointer artithmetics? > I do not know... Perhaps because it can be easily emulated (see below) > Take a look at the following in the above code: > > ? const double *restrict Uj = U + n*j; /* pointer to row j */ > > This is needed because C (unlike Fortran) does not support 2D arrays. We > can fake this in Cython as > > ? cdef double *Uj > ? Uj = ( U + n*j*sizeof(double)) > > Using integers to store addresses is similar to pesky 1970s versions of > C using long for void*... :( > Would this work for you? cdef double* Uj = &U[n*j] > > Third issue: Subarrays/slices. > > From looking nice on the surface, Cython > suddenly get worse than anything else. > That statement sound a bit rude, so I'll be a bit rude :-) ... You can switch to a tool better suited for you needs, or you can contribute patches to improve Cython. From the very moment I've switched to Cython I found things annoying, but in never wasted time complaining about missing features: instead, I contributed a few patches and extensive testing on Linux 32/64 (GCC and Intel) and Win32 (MinGW and MSVC). So in short: I know you are a very experienced guy, I would really like to you to join Cython development! > > Even plain C is easier. Surely > there has to be a better way? > Yes, I think there is something better, though again there is lack of time (and in my particular case knowledge) to implement them: http://wiki.cython.org/enhancements/array http://wiki.cython.org/enhancements/simd -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From wstein at gmail.com Thu Oct 8 17:16:12 2009 From: wstein at gmail.com (William Stein) Date: Thu, 8 Oct 2009 08:16:12 -0700 Subject: [Cython] [mpir-devel] Re: sagemath infrastructure scheduled downtime In-Reply-To: <1e52e0880910072243o5a0ddc76h8848f89789edd84@mail.gmail.com> References: <85e81ba30910071504w7d9359dbub2de09cc6249cf56@mail.gmail.com> <85e81ba30910071723j5e353886ve814cc8987f7ed44@mail.gmail.com> <85e81ba30910072213g6d5cb654q1329de3702890098@mail.gmail.com> <1e52e0880910072243o5a0ddc76h8848f89789edd84@mail.gmail.com> Message-ID: <85e81ba30910080816hb41b905j9a20d66137a6d7f0@mail.gmail.com> On Wed, Oct 7, 2009 at 10:43 PM, Peter Alexander wrote: > On Thu, Oct 8, 2009 at 1:13 AM, William Stein wrote: >> Hi, >> >> 1. I rsynced all the servers from the old sagemath to the new virtual >> machine. ?If you put a line like this in your /etc/hosts file >> >> 128.208.160.197 sagemath.org trac.sagemath.org cython.org ? # etc. >> >> then you can see what the new website would look like if we switched >> over now. ?Again, the switchover won't happen until tomorrow. ? If you >> have any way to "hammer" this server, please try. ? Report any >> problems. >> >> 2. I rewrote my comparison of VMware and VirtualBox as a blog post: >> >> http://sagemath.blogspot.com/2009/10/virtualbox-versus-vmware-server.html >> >> William >> _______________________________________________ >> Cython-dev mailing list >> Cython-dev at codespeak.net >> http://codespeak.net/mailman/listinfo/cython-dev >> > > Hi Bill. I hammered pretty good with a page capture prog. No probs > except with Cython's wiki surge protector.. that's a config I'd > suppose. Let me know if you need more hammerin'. The Sage site looks > good, btw. Thanks!! Harald Schilly is the designer of the Sage site, and he's done a great job. -- William From ndbecker2 at gmail.com Thu Oct 8 18:50:29 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 08 Oct 2009 12:50:29 -0400 Subject: [Cython] C++ complex support References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> Message-ID: Lisandro Dalcin wrote: > BTW, What would be better from "creating" a C99/C++ complex number > from re & im parts: use a macro or a inline function as we currently > have? I don't know much about cython, so perhaps I misunderstand the question. In general, inline functions are _much_ preferred over macros. They are much easier for debugging, for one thing. From robertwb at math.washington.edu Thu Oct 8 19:02:05 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 8 Oct 2009 10:02:05 -0700 Subject: [Cython] Object to Py_ssize_t conversion In-Reply-To: <4ACDE351.3090707@student.matnat.uio.no> References: <4ACDE351.3090707@student.matnat.uio.no> Message-ID: On Oct 8, 2009, at 6:04 AM, Dag Sverre Seljebotn wrote: > I experience this: > > np.sqrt(some_float64) > => TypeError: 'numpy.float64' object cannot be interpreted as an > index > > However > a) np.sqrt(...) works fine, as does and . > b) In Python, int(np.sqrt(...)) and long(np.sqrt(...)) both works > fine > > Is Py_ssize_t "special" when it comes to converting from Python > objects? > If so I find it mildly confusing and something which only increases > learning curve... Py_ssize_t is meant for indexing, and fails for the same reason that >>> L = range(10) >>> L[2] 2 >>> L[2.5] Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers, not float fails. This is a feature, not a bug. - Robert From robertwb at math.washington.edu Thu Oct 8 19:29:51 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 8 Oct 2009 10:29:51 -0700 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACDF767.7020901@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> Message-ID: <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> On Oct 8, 2009, at 7:29 AM, Sturla Molden wrote: > I have used Cython for numerical programming for quite a while. I'd > like > to share my experience with you Cython developers. There are two or > three annoying issues I keep encounter, which I hope you can take into > consideration for future tickets. > > First, is there any reason why Cython does not recognize const and > restrict? That's because no one's actually implemented, not because we don't want it. We know its benefits. Note that const is not as trivial as it seems on the surface (though it wouldn't be a Herculean task either). We'd have to support stuff like struct foo { const char * x, int const * const ptr, long foo, }; > Second issue: Why is it that Cython does not support pointer > artithmetics? Um... we do. The following compiles just fine. cdef foo(double* data, int n, int j): cdef double* x = data + n*j return x[0] > cdef double *Uj > Uj = ( U + n*j*sizeof(double)) > > Using integers to store addresses is similar to pesky 1970s > versions of > C using long for void*... :( Yes, we would highly discourage this. > Third issue: Subarrays/slices. > > Dag Sverre's NumPy work allow ndarrays in Python, so declaring > > cdef np.ndarray[double, ndim=2, mode="c"] U > > we could have written U[j,i] instead of Uj[i]. Or uf there was a fast > way of slicing, we could have written > > cdef np.ndarray[double, ndim=1, mode="c"] Uj > Uj = U[j,:] > > Unfortunately, unlike Fortran 90, there is no fast way of creating and > passing around sub-arrays in Cython. There will be Python overhead > (object creation, refcounting), we must keep the GIL, etc. Looking in > the manual, Cython's ndarray syntax looks almost as nice as Fortran > 90. > But that is until you realize *no function calls are being made*. The overhead of object creation, refcounting, and the GIL is the tradeoff you get for not having to manually manage the memory and freely pass things back and forth between Python and C land. There's some work being done with even more lightweight array-like objects. In any case, for arrays of decent size, actually processing each element in an array is typically much more expensive than the single slicing step. Optimization is not about just removing inefficiency, it's about removing the inefficiency in the parts of your code where you spend 90% of your time. This is typically the inner loop, where I hope slicing isn't happening. > When we need to call a function with an array as argument, we have to > resort to C pointers for speed. But Cython does not allow pointer > arithmetics. We thus must resort to something even more primitive: > addresses stored in integers... From looking nice on the surface, > Cython > suddenly get worse than anything else. Even plain C is easier. Surely > there has to be a better way? It sounds like (1) you're not using Cython correctly and (2) there's still a lot of room for improvement (that we would gladly accept help with). Whether or not it's better than the other tools out there for the job is a matter of opinion, but I think it is, and is constantly getting better. - Robert From robertwb at math.washington.edu Thu Oct 8 19:38:06 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 8 Oct 2009 10:38:06 -0700 Subject: [Cython] Are min/max ever optimized? In-Reply-To: <4ACDD2FD.7090206@student.matnat.uio.no> References: <7E426F06-A1C0-449A-B500-414BD0AD1204@hetland.org> <4ACC91D6.7040703@behnel.de> <83BF77BE-7B74-412F-84F1-7891790D7D31@hetland.org> <4ACD8D99.4010808@behnel.de> <4ACDD2FD.7090206@student.matnat.uio.no> Message-ID: <9B5F1AD9-A379-49B5-8F47-65B292C7B6B3@math.washington.edu> On Oct 8, 2009, at 4:54 AM, Dag Sverre Seljebotn wrote: > Stefan Behnel wrote: >> Robert Bradshaw wrote: >> >>> Note also that Danilo did some work on overloaded functions which >>> could be useful here too. >>> >> >> It may, yes. Is there any documentation about what he actually >> did? I never >> saw any floating around, the related mailing list discussions were >> rather >> sparse (IMHO), and I certainly won't read all through the branch >> commit log >> to figure it out. Unfortunately not--he was sparse on is blog and would usually just email me instead of the list. In summary, he did C++ class declaration parsing, new/del on classes, function overloading, and operators. (The last two still need a bit of TLC, and references to make them useful.) >> On a related node, I really hate that the analyse types phase runs >> completely before the optimisations phase, as it removes available >> type >> information when coercing stuff to Python types. Well, we can run an optimization phase before as well, but they're typically more useful after type information has been deduced. >> Later optimisations have to struggle to recover that when moving >> stuff back into C space. We should probably make an original_type() method on ExprNodes that just returns type for all but coercion nodes, or something like that to make optimizations easier. > Also any scheme relying on an "optimization" transform in the end is > going to fail miserably with type inference, so it would be good to go > away from that. However things are intrinsically bound together -- > especially when type inference is considered. I was a strong > defender of > splitting type analysis earlier but I found I always ended up in cases > where new problems are caused. The knowledge of the special properties > of the "max" function rather has to become *part of* the type analysis > -- it can't all be done in a transform. > > In this particular case I think the solution is to start having > function > declarations with multiple sets of signatures -- so that > SimpleCallNode > can consider a list of signatures in the entry of __builtin__.max > rather > than only a single signature, and if both arguments are "int" then the > result type is an "int". Perhaps this is what Danilo implemented .. > (it > would have to be *something* like that). Yes, that's what he did. > However I think (your idea?) of splitting "resolving" and "typing" > into > seperate phases is good. For special cases, one could thus e.g. > transform __builtin__.max into MaxExprNode *before* typing happens, > without interfering with user-defined functions that happen to be > named > "max". Partial typing of the tree I'm doubtful of though. I pushed a bit towards this direction in to -devel as part of some preliminary type inference patches. - Robert From dagss at student.matnat.uio.no Thu Oct 8 19:54:24 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 08 Oct 2009 19:54:24 +0200 Subject: [Cython] Object to Py_ssize_t conversion In-Reply-To: References: <4ACDE351.3090707@student.matnat.uio.no> Message-ID: <4ACE2750.8080304@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 8, 2009, at 6:04 AM, Dag Sverre Seljebotn wrote: > >> I experience this: >> >> np.sqrt(some_float64) >> => TypeError: 'numpy.float64' object cannot be interpreted as an >> index >> >> However >> a) np.sqrt(...) works fine, as does and . >> b) In Python, int(np.sqrt(...)) and long(np.sqrt(...)) both works >> fine >> >> Is Py_ssize_t "special" when it comes to converting from Python >> objects? >> If so I find it mildly confusing and something which only increases >> learning curve... > > Py_ssize_t is meant for indexing, and fails for the same reason that > > >>> L = range(10) > >>> L[2] > 2 > >>> L[2.5] > Traceback (most recent call last): > File "", line 1, in > TypeError: list indices must be integers, not float > > fails. This is a feature, not a bug. OK, if this is a feature, help me out with this then: I need to iterate from 0 to "lmax". When I allocate an array, it is always allocated of size (lmax + 1)**2, and it is convenient to be able to deduce lmax from the array shape. What type should I use for lmax to conveniently convert from a float (because sqrt is float, but I know I can safely truncate) and guarantee that I support the range of NumPy arrays (which essentially use Py_ssize_t to store shape info)? The type must be signed, otherwise I fall into the range(-lmax, lmax) trap all the time. (For the record, I think the type system is complicated enough without this feature -- does it have usecases where an explicit call to e.g. a cython.asindex() function to invoke __index__ isn't clearer?) -- Dag Sverre From dagss at student.matnat.uio.no Thu Oct 8 19:57:38 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 08 Oct 2009 19:57:38 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACDF767.7020901@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> Message-ID: <4ACE2812.4020708@student.matnat.uio.no> Sturla Molden wrote: > Dag Sverre's NumPy work allow ndarrays in Python, so declaring > > cdef np.ndarray[double, ndim=2, mode="c"] U > > we could have written U[j,i] instead of Uj[i]. Or uf there was a fast > way of slicing, we could have written > > cdef np.ndarray[double, ndim=1, mode="c"] Uj > Uj = U[j,:] > > Unfortunately, unlike Fortran 90, there is no fast way of creating and > passing around sub-arrays in Cython. There will be Python overhead > (object creation, refcounting), we must keep the GIL, etc. Looking in > the manual, Cython's ndarray syntax looks almost as nice as Fortran 90. > But that is until you realize *no function calls are being made*. > > When we need to call a function with an array as argument, we have to > resort to C pointers for speed. But Cython does not allow pointer > arithmetics. We thus must resort to something even more primitive: > addresses stored in integers... From looking nice on the surface, Cython > suddenly get worse than anything else. Even plain C is easier. Surely > there has to be a better way? This is seriously bugging me too at the moment, however with the Cython time I have available it looks like it's going to be well into 2010 before I'm done with fixing this. Kurt gave it a good start as a side-effect of his work in summer though. -- Dag Sverre From robertwb at math.washington.edu Thu Oct 8 19:58:02 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 8 Oct 2009 10:58:02 -0700 Subject: [Cython] Object to Py_ssize_t conversion In-Reply-To: <4ACE2750.8080304@student.matnat.uio.no> References: <4ACDE351.3090707@student.matnat.uio.no> <4ACE2750.8080304@student.matnat.uio.no> Message-ID: On Oct 8, 2009, at 10:54 AM, Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: >> On Oct 8, 2009, at 6:04 AM, Dag Sverre Seljebotn wrote: >> >>> I experience this: >>> >>> np.sqrt(some_float64) >>> => TypeError: 'numpy.float64' object cannot be interpreted as an >>> index >>> >>> However >>> a) np.sqrt(...) works fine, as does and . >>> b) In Python, int(np.sqrt(...)) and long(np.sqrt(...)) both works >>> fine >>> >>> Is Py_ssize_t "special" when it comes to converting from Python >>> objects? >>> If so I find it mildly confusing and something which only increases >>> learning curve... >> >> Py_ssize_t is meant for indexing, and fails for the same reason that >> >>>>> L = range(10) >>>>> L[2] >> 2 >>>>> L[2.5] >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: list indices must be integers, not float >> >> fails. This is a feature, not a bug. > > OK, if this is a feature, help me out with this then: > > I need to iterate from 0 to "lmax". When I allocate an array, it is > always allocated of size (lmax + 1)**2, and it is convenient to be > able > to deduce lmax from the array shape. > > What type should I use for lmax to conveniently convert from a float > (because sqrt is float, but I know I can safely truncate) and > guarantee > that I support the range of NumPy arrays (which essentially use > Py_ssize_t to store shape info)? The type must be signed, otherwise I > fall into the range(-lmax, lmax) trap all the time. Is there not a ssize_t? > (For the record, I think the type system is complicated enough without > this feature -- does it have usecases where an explicit call to e.g. a > cython.asindex() function to invoke __index__ isn't clearer?) def __getitem__(self, Py_ssize_t ix): ... - Robert From dagss at student.matnat.uio.no Thu Oct 8 20:13:40 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 08 Oct 2009 20:13:40 +0200 Subject: [Cython] Object to Py_ssize_t conversion In-Reply-To: References: <4ACDE351.3090707@student.matnat.uio.no> <4ACE2750.8080304@student.matnat.uio.no> Message-ID: <4ACE2BD4.7050102@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 8, 2009, at 10:54 AM, Dag Sverre Seljebotn wrote: > >> Robert Bradshaw wrote: >>> On Oct 8, 2009, at 6:04 AM, Dag Sverre Seljebotn wrote: >>> >>>> I experience this: >>>> >>>> np.sqrt(some_float64) >>>> => TypeError: 'numpy.float64' object cannot be interpreted as an >>>> index >>>> >>>> However >>>> a) np.sqrt(...) works fine, as does and . >>>> b) In Python, int(np.sqrt(...)) and long(np.sqrt(...)) both works >>>> fine >>>> >>>> Is Py_ssize_t "special" when it comes to converting from Python >>>> objects? >>>> If so I find it mildly confusing and something which only increases >>>> learning curve... >>> Py_ssize_t is meant for indexing, and fails for the same reason that >>> >>>>>> L = range(10) >>>>>> L[2] >>> 2 >>>>>> L[2.5] >>> Traceback (most recent call last): >>> File "", line 1, in >>> TypeError: list indices must be integers, not float >>> >>> fails. This is a feature, not a bug. >> OK, if this is a feature, help me out with this then: >> >> I need to iterate from 0 to "lmax". When I allocate an array, it is >> always allocated of size (lmax + 1)**2, and it is convenient to be >> able >> to deduce lmax from the array shape. >> >> What type should I use for lmax to conveniently convert from a float >> (because sqrt is float, but I know I can safely truncate) and >> guarantee >> that I support the range of NumPy arrays (which essentially use >> Py_ssize_t to store shape info)? The type must be signed, otherwise I >> fall into the range(-lmax, lmax) trap all the time. > > Is there not a ssize_t? Not builtin to Cython, I have to extern ctypedef it. I know that *I* can get around it -- I'm mostly worried about what I should recommend to NumPy users (I have been recommending Py_ssize_t, but now I see that might not have been a good idea). But there's enough going on at the moment, so I'll stop short of trying to find better solutions for now. Thanks for clearing it up. -- Dag Sverre From dagss at student.matnat.uio.no Thu Oct 8 20:42:01 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 08 Oct 2009 20:42:01 +0200 Subject: [Cython] C++ complex support In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> Message-ID: <4ACE3279.3000809@student.matnat.uio.no> Lisandro Dalcin wrote: > I was just pointing to GCC-specific syntax that perhaps we could use, > I was not actually requesting for it !!! > > I really prefer your time being invested in reviewing the patch: > http://trac.cython.org/cython_trac/ticket/398 Robert wrote the support so he'd be much more qualified. (Also, I think you are free to push once you feel confident yourself that everything's OK.) Here's my feedback (easier on email): - I'm wondering if new macros for C compilation configuration should be prefixed CYTHON instead of PYX? (With the intent of adding CYTHON_* aliases for existing macros.) At least there's CYTHON_REFNANNY now. - In the change to ModuleNode.py there might be missing an #endif - I believe I've implemented a better strategy for sign_and_name myself in Buffer.py, I'm happy to do this change though as it overlaps with buffer code (basically give all user-defined types a prefix, like 'U', so that a type named "long_double" -- which is completely legal -- doesn't conflict). - It should be ::std::complex, not std::complex - I need to know why you removed proto_block='complex_numbers_utility_code'... (I just added it to fix a complicated bug. If removing it fixed anything we/I basically need to find a better solution, because removing it is sure to trigger another bug.) > BTW, What would be better from "creating" a C99/C++ complex number > from re & im parts: use a macro or a inline function as we currently > have? Would it be worth to also use a macro {complex_type}_coerce() to > implement promotion to a complex type? Currently we are using > {complex_type}_from_parts(realpart,0) for this... As the generated > code has to support struct-based complexes, things like to 1/z need to > promote "1" to complex... But for C99, actual promotion is not > required (the compiler does that), and in C++ we have to at promote to > at least for many operators to work. Any chance that > special-casing the coercion with an appropriate macro could give > faster execution? Hmm. The last idea sounds sound to me (although I'm not going to spend time on it personally, I'd rather have more features than speed regarding complex numbers at this point). -- Dag Sverre From dalcinl at gmail.com Thu Oct 8 23:40:22 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Thu, 8 Oct 2009 18:40:22 -0300 Subject: [Cython] C++ complex support In-Reply-To: <4ACE3279.3000809@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> <4ACE3279.3000809@student.matnat.uio.no> Message-ID: On Thu, Oct 8, 2009 at 3:42 PM, Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: >> I was just pointing to GCC-specific syntax that perhaps we could use, >> I was not actually requesting for it !!! >> >> I really prefer your time being invested in reviewing the patch: >> http://trac.cython.org/cython_trac/ticket/398 > > Robert wrote the support so he'd be much more qualified. (Also, I think > you are free to push once you feel confident yourself that everything's > OK.) Here's my feedback (easier on email): > > ?- I'm wondering if new macros for C compilation configuration should > be prefixed CYTHON instead of PYX? (With the intent of adding CYTHON_* > aliases for existing macros.) At least there's CYTHON_REFNANNY now. > Yes, of course... > > ?- In the change to ModuleNode.py there might be missing an #endif > Mmm.. Sure? I think you got confusing when parsing the patch on your mind... > ?- I believe I've implemented a better strategy for sign_and_name > myself in Buffer.py, I'm happy to do this change though as it overlaps > with buffer code (basically give all user-defined types a prefix, like > 'U', so that a type named "long_double" -- which is completely legal -- > doesn't conflict). > The generated type name is in the end "__pyx_t_long_double_complex"... Do you expect conflicts with user code? That's the way Robert implemented it, I've just added a line to remove an underscore between 'long' and 'double' to render nicer (IOW, just bike-shedding from my side)... > > ?- It should be ::std::complex, not std::complex > Ups!! Your are right... BTW, the try/catch stuff in "cpp_exception_utility_code" also have to be fixed ... > ?- I need to know why you removed > proto_block='complex_numbers_utility_code'... (I just added it to fix a > complicated bug. If removing it fixed anything we/I basically need to > find a better solution, because removing it is sure to trigger another bug.) > Because it did not seemed necessary to do that, but now I realize I was wong :-( ... I'll try to move stuff to "utility_code_proto_before_types"... I really want to remove that complex-specific block :-) BTW, I've split the utility codes a bit, but proper dependency handling have to be implemented... If you do not to any complex arithmetic, the arith macros/functions should not be generated... >> BTW, What would be better from "creating" a C99/C++ complex number >> from re & im parts: use a macro or a inline function as we currently >> have? Would it be worth to also use a macro {complex_type}_coerce() to >> implement promotion to a complex type? Currently we are using >> {complex_type}_from_parts(realpart,0) for this... As the generated >> code has to support struct-based complexes, things like to 1/z need to >> promote "1" to complex... But for C99, actual promotion is not >> required (the compiler does that), and in C++ we have to at promote to >> at least for many operators to work. Any chance that >> special-casing the coercion with an appropriate macro could give >> faster execution? > > Hmm. The last idea sounds sound to me (although I'm not going to spend > time on it personally, I'd rather have more features than speed > regarding complex numbers at this point). > OK, let's leave that for the future. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sccolbert at gmail.com Fri Oct 9 01:38:56 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Fri, 9 Oct 2009 01:38:56 +0200 Subject: [Cython] How do I compare the shape of two numpy arrays for equality? Message-ID: <7f014ea60910081638p33733cdaq5bcde4329c628a3b@mail.gmail.com> Since I have a "cimport numpy as np" at the top of my cython file, array1.shape == array2.shape is only true if array1 IS array2 because .shape return the npy_intp* pointer to the shape array. Is there a way for me check if the values in the shape array are equal (ala python) without having to drop into a loop? Cheers! Chris From wstein at gmail.com Fri Oct 9 02:42:43 2009 From: wstein at gmail.com (William Stein) Date: Thu, 8 Oct 2009 17:42:43 -0700 Subject: [Cython] [sage-devel] Re: [mpir-devel] Re: sagemath infrastructure scheduled downtime In-Reply-To: References: <85e81ba30910071504w7d9359dbub2de09cc6249cf56@mail.gmail.com> <85e81ba30910071723j5e353886ve814cc8987f7ed44@mail.gmail.com> <85e81ba30910072213g6d5cb654q1329de3702890098@mail.gmail.com> Message-ID: <85e81ba30910081742u59edf68dnccd2c8268d4a6d38@mail.gmail.com> On Thu, Oct 8, 2009 at 5:33 PM, Jason Grout wrote: > > William Stein wrote: >> Hi, >> >> 1. I rsynced all the servers from the old sagemath to the new virtual >> machine. ?If you put a line like this in your /etc/hosts file >> >> 128.208.160.197 sagemath.org trac.sagemath.org cython.org ? # etc. >> >> then you can see what the new website would look like if we switched >> over now. ?Again, the switchover won't happen until tomorrow. ? If you >> have any way to "hammer" this server, please try. ? Report any >> problems. > > > When I evaluate a cell in the notebook that produces a graphic, no > graphic appears. That is obviously not good. For safety, I will switch over everything except the notebook server tonight, and leave them for the weekend (or until this is sorted out). > Will you be transferring the most current version of sagenb.org, or will > we lose a day or two of work? Absolutely no data will be lost. I will be shutting everything down, rsyncing, changing dns, then turning everything on. So nothing will be lost. William From dwf at cs.toronto.edu Fri Oct 9 08:17:00 2009 From: dwf at cs.toronto.edu (David Warde-Farley) Date: Fri, 9 Oct 2009 02:17:00 -0400 Subject: [Cython] How do I compare the shape of two numpy arrays for equality? In-Reply-To: <7f014ea60910081638p33733cdaq5bcde4329c628a3b@mail.gmail.com> References: <7f014ea60910081638p33733cdaq5bcde4329c628a3b@mail.gmail.com> Message-ID: On 8-Oct-09, at 7:38 PM, Chris Colbert wrote: > Since I have a "cimport numpy as np" at the top of my cython file, > > array1.shape == array2.shape > > is only true if array1 IS array2 because .shape return the npy_intp* > pointer to the shape array. > > Is there a way for me check if the values in the shape array are equal > (ala python) without having to drop into a loop? You can use the macro PyArray_SAMESHAPE(a1, a2): http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PyArray_SAMESHAPE From robertwb at math.washington.edu Fri Oct 9 08:45:24 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 8 Oct 2009 23:45:24 -0700 Subject: [Cython] C++ complex support In-Reply-To: <4ACE3279.3000809@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> <4ACE3279.3000809@student.matnat.uio.no> Message-ID: <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> On Oct 8, 2009, at 11:42 AM, Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: >> I was just pointing to GCC-specific syntax that perhaps we could use, >> I was not actually requesting for it !!! >> >> I really prefer your time being invested in reviewing the patch: >> http://trac.cython.org/cython_trac/ticket/398 > > Robert wrote the support so he'd be much more qualified. (Also, I > think > you are free to push once you feel confident yourself that > everything's > OK.) Here's my feedback (easier on email): > > - I'm wondering if new macros for C compilation configuration should > be prefixed CYTHON instead of PYX? (With the intent of adding CYTHON_* > aliases for existing macros.) At least there's CYTHON_REFNANNY now. > > - In the change to ModuleNode.py there might be missing an #endif > > - I believe I've implemented a better strategy for sign_and_name > myself in Buffer.py, I'm happy to do this change though as it overlaps > with buffer code (basically give all user-defined types a prefix, like > 'U', so that a type named "long_double" -- which is completely > legal -- > doesn't conflict). > > - It should be ::std::complex, not std::complex > > - I need to know why you removed > proto_block='complex_numbers_utility_code'... (I just added it to > fix a > complicated bug. If removing it fixed anything we/I basically need to > find a better solution, because removing it is sure to trigger > another bug.) +1 to all of the above. Also - Do C++ complex numbers not support the unary - operation? - I don't think we need unary pos anywhere (it's just the identity for these values). - In light of the above, c99 and C++ complex arithmetic only differ by is_zero and conjugate, so perhaps we should bring the rest of the macro definitions out of the inner #if clauses. - In the @cython.cdivision(False) we should *not* be raising a ZeroDivisionError, we should only be raising it if cython.cdivision is True. - I like how you did multiple tests to cover all the implementations, but I'm not sure what the point of tests/run/ complex_numbers_cxx_T398.h is. Won't all the other tests use C++ complexes when they're compiled with C++? >> BTW, What would be better from "creating" a C99/C++ complex number >> from re & im parts: use a macro or a inline function as we currently >> have? Would it be worth to also use a macro {complex_type}_coerce >> () to >> implement promotion to a complex type? Currently we are using >> {complex_type}_from_parts(realpart,0) for this... As the generated >> code has to support struct-based complexes, things like to 1/z >> need to >> promote "1" to complex... But for C99, actual promotion is not >> required (the compiler does that), and in C++ we have to at >> promote to >> at least for many operators to work. Any chance that >> special-casing the coercion with an appropriate macro could give >> faster execution? > > Hmm. The last idea sounds sound to me (although I'm not going to spend > time on it personally, I'd rather have more features than speed > regarding complex numbers at this point). Sounds reasonable to me too. - Robert From robertwb at math.washington.edu Fri Oct 9 08:52:36 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 8 Oct 2009 23:52:36 -0700 Subject: [Cython] Object to Py_ssize_t conversion In-Reply-To: <4ACE2BD4.7050102@student.matnat.uio.no> References: <4ACDE351.3090707@student.matnat.uio.no> <4ACE2750.8080304@student.matnat.uio.no> <4ACE2BD4.7050102@student.matnat.uio.no> Message-ID: <3B634A03-1097-4EED-8AA5-EDB5DE5634F7@math.washington.edu> On Oct 8, 2009, at 11:13 AM, Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: >> On Oct 8, 2009, at 10:54 AM, Dag Sverre Seljebotn wrote: >> >>> Robert Bradshaw wrote: >>>> On Oct 8, 2009, at 6:04 AM, Dag Sverre Seljebotn wrote: >>>> >>>>> I experience this: >>>>> >>>>> np.sqrt(some_float64) >>>>> => TypeError: 'numpy.float64' object cannot be interpreted as an >>>>> index >>>>> >>>>> However >>>>> a) np.sqrt(...) works fine, as does and . >>>>> b) In Python, int(np.sqrt(...)) and long(np.sqrt(...)) both works >>>>> fine >>>>> >>>>> Is Py_ssize_t "special" when it comes to converting from Python >>>>> objects? >>>>> If so I find it mildly confusing and something which only >>>>> increases >>>>> learning curve... >>>> Py_ssize_t is meant for indexing, and fails for the same reason >>>> that >>>> >>>>>>> L = range(10) >>>>>>> L[2] >>>> 2 >>>>>>> L[2.5] >>>> Traceback (most recent call last): >>>> File "", line 1, in >>>> TypeError: list indices must be integers, not float >>>> >>>> fails. This is a feature, not a bug. >>> OK, if this is a feature, help me out with this then: >>> >>> I need to iterate from 0 to "lmax". When I allocate an array, it is >>> always allocated of size (lmax + 1)**2, and it is convenient to be >>> able >>> to deduce lmax from the array shape. >>> >>> What type should I use for lmax to conveniently convert from a float >>> (because sqrt is float, but I know I can safely truncate) and >>> guarantee >>> that I support the range of NumPy arrays (which essentially use >>> Py_ssize_t to store shape info)? The type must be signed, >>> otherwise I >>> fall into the range(-lmax, lmax) trap all the time. >> >> Is there not a ssize_t? > > Not builtin to Cython, I have to extern ctypedef it. Well, if we have size_t, we should probably support ssize_t as well. http://trac.cython.org/cython_trac/ticket/399 - Robert From robertwb at math.washington.edu Fri Oct 9 08:59:22 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 8 Oct 2009 23:59:22 -0700 Subject: [Cython] A (small) sunshine story In-Reply-To: <3ADAE2D6-4837-436A-9308-08F7D1924966@hetland.org> References: <3ADAE2D6-4837-436A-9308-08F7D1924966@hetland.org> Message-ID: <9984796D-4A9D-4E67-A132-E1AD4623D3A5@math.washington.edu> Thanks for sharing! - Robert On Oct 7, 2009, at 6:24 AM, Magnus Lie Hetland wrote: > I'm currently working on stuff related to various metric distance > functions, with the code written in Cython. Most of the data I'm > working are sets of float-vectors (represented as two-dimensional > NumPy arrays -- with each row being a vector). Works well. > > However, I had also implemented a string edit distance (plain > Levenshtein, for now), where the strings could have different lengths. > My first hunch was that using a full len(strings) by max(len(s) for s > in strings) NumPy array would be wasteful space-wise. So -- as a quick > hack, I simply used a list of strings. And since I was already > disregarding any Cython cleverness here, I simply used the plain > strings directly in the distance calculation as well. And it was > sloooow. > > I thought the quadratic nature of the distance function had much of > the blame for the slowness. However, I sat down now to see if I could > speed it up. I made some assumptions (used uint8 for the characters > and uint16 in a separate array of string lengths) and basically > declared all variables (storing map(ord, string) in the rows of the > NumPy array). > > The whole thing (which wasn't all *that* focused) took me roughly an > hour (including some fiddling with writing a timing script, to measure > the speedup properly). > > And from this moderate investment of time/energy, I got a speedup > factor of over 200! :-D > > - M (very happy with Cython right now :-) > > -- > Magnus Lie Hetland > http://hetland.org > > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev From robertwb at math.washington.edu Fri Oct 9 09:06:58 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Fri, 9 Oct 2009 00:06:58 -0700 Subject: [Cython] Bug day? In-Reply-To: <4AC7A5F2.6000503@student.matnat.uio.no> References: <4AC7A5F2.6000503@student.matnat.uio.no> Message-ID: On Oct 3, 2009, at 12:28 PM, Dag Sverre Seljebotn wrote: > Robert was talking about a bug day -- I can do a bug day any day > during > next week (09-16 CEST only). How about next Thursday (the 15th). In PDST, so that's you -9 hours, so I could join you at midnight here. Anyone else? > Also, before a bug-day I think we should tag all bugs which are > "newbie-friendly" so that newcomers can join if they want to. +1 - Robert From vel.accel at gmail.com Fri Oct 9 09:52:22 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Fri, 9 Oct 2009 03:52:22 -0400 Subject: [Cython] Bug day? In-Reply-To: References: <4AC7A5F2.6000503@student.matnat.uio.no> Message-ID: <1e52e0880910090052v42759639reb587e36f4c02140@mail.gmail.com> On Fri, Oct 9, 2009 at 3:06 AM, Robert Bradshaw wrote: > On Oct 3, 2009, at 12:28 PM, Dag Sverre Seljebotn wrote: > >> Robert was talking about a bug day -- I can do a bug day any day >> during >> next week (09-16 CEST only). > > How about next Thursday (the 15th). In PDST, so that's you -9 hours, > so I could join you at midnight here. Anyone else? > >> Also, before a bug-day I think we should tag all bugs which are >> "newbie-friendly" so that newcomers can join if they want to. > > +1 > > - Robert > > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > I'm happy to help on the ~newbie level if you feel I'm able. Another thing I eventually intend to document, are Cython's internal architecture/workings. I haven't investigated the sources to any great degree yet, though. From sccolbert at gmail.com Fri Oct 9 10:43:14 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Fri, 9 Oct 2009 10:43:14 +0200 Subject: [Cython] How do I compare the shape of two numpy arrays for equality? In-Reply-To: References: <7f014ea60910081638p33733cdaq5bcde4329c628a3b@mail.gmail.com> Message-ID: <7f014ea60910090143keae910did4d4f74b65273340@mail.gmail.com> Fantastic! Thanks! On Fri, Oct 9, 2009 at 8:17 AM, David Warde-Farley wrote: > > On 8-Oct-09, at 7:38 PM, Chris Colbert wrote: > >> Since I have a "cimport numpy as np" at the top of my cython file, >> >> array1.shape == array2.shape >> >> is only true if array1 IS array2 because .shape return the npy_intp* >> pointer to the shape array. >> >> Is there a way for me check if the values in the shape array are equal >> (ala python) without having to drop into a loop? > > You can use the macro PyArray_SAMESHAPE(a1, a2): > > http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PyArray_SAMESHAPE > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > From dagss at student.matnat.uio.no Fri Oct 9 10:48:18 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 09 Oct 2009 10:48:18 +0200 Subject: [Cython] How do I compare the shape of two numpy arrays for equality? In-Reply-To: <7f014ea60910090143keae910did4d4f74b65273340@mail.gmail.com> References: <7f014ea60910081638p33733cdaq5bcde4329c628a3b@mail.gmail.com> <7f014ea60910090143keae910did4d4f74b65273340@mail.gmail.com> Message-ID: <4ACEF8D2.3030305@student.matnat.uio.no> Chris Colbert wrote: > Fantastic! > > Thanks! > On Fri, Oct 9, 2009 at 8:17 AM, David Warde-Farley wrote: >> On 8-Oct-09, at 7:38 PM, Chris Colbert wrote: >> >>> Since I have a "cimport numpy as np" at the top of my cython file, >>> >>> array1.shape == array2.shape >>> >>> is only true if array1 IS array2 because .shape return the npy_intp* >>> pointer to the shape array. >>> >>> Is there a way for me check if the values in the shape array are equal >>> (ala python) without having to drop into a loop? >> You can use the macro PyArray_SAMESHAPE(a1, a2): >> >> http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PyArray_SAMESHAPE Make sure to call np.import_array() first! -- Dag Sverre From sccolbert at gmail.com Fri Oct 9 10:47:41 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Fri, 9 Oct 2009 10:47:41 +0200 Subject: [Cython] How do I compare the shape of two numpy arrays for equality? In-Reply-To: <4ACEF8D2.3030305@student.matnat.uio.no> References: <7f014ea60910081638p33733cdaq5bcde4329c628a3b@mail.gmail.com> <7f014ea60910090143keae910did4d4f74b65273340@mail.gmail.com> <4ACEF8D2.3030305@student.matnat.uio.no> Message-ID: <7f014ea60910090147i4ed5110fw3557550e5abbc39f@mail.gmail.com> duly noted. Thank you. On Fri, Oct 9, 2009 at 10:48 AM, Dag Sverre Seljebotn wrote: > Chris Colbert wrote: >> Fantastic! >> >> Thanks! >> On Fri, Oct 9, 2009 at 8:17 AM, David Warde-Farley wrote: >>> On 8-Oct-09, at 7:38 PM, Chris Colbert wrote: >>> >>>> Since I have a "cimport numpy as np" at the top of my cython file, >>>> >>>> array1.shape == array2.shape >>>> >>>> is only true if array1 IS array2 because .shape return the npy_intp* >>>> pointer to the shape array. >>>> >>>> Is there a way for me check if the values in the shape array are equal >>>> (ala python) without having to drop into a loop? >>> You can use the macro PyArray_SAMESHAPE(a1, a2): >>> >>> http://docs.scipy.org/doc/numpy/reference/c-api.array.html#PyArray_SAMESHAPE > > Make sure to call np.import_array() first! > > -- > Dag Sverre > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > From dagss at student.matnat.uio.no Fri Oct 9 10:58:05 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 09 Oct 2009 10:58:05 +0200 Subject: [Cython] Object to Py_ssize_t conversion In-Reply-To: <3B634A03-1097-4EED-8AA5-EDB5DE5634F7@math.washington.edu> References: <4ACDE351.3090707@student.matnat.uio.no> <4ACE2750.8080304@student.matnat.uio.no> <4ACE2BD4.7050102@student.matnat.uio.no> <3B634A03-1097-4EED-8AA5-EDB5DE5634F7@math.washington.edu> Message-ID: <4ACEFB1D.6010108@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 8, 2009, at 11:13 AM, Dag Sverre Seljebotn wrote: > >> Robert Bradshaw wrote: >>> On Oct 8, 2009, at 10:54 AM, Dag Sverre Seljebotn wrote: >>> >>>> Robert Bradshaw wrote: >>>>> On Oct 8, 2009, at 6:04 AM, Dag Sverre Seljebotn wrote: >>>>> >>>>>> I experience this: >>>>>> >>>>>> np.sqrt(some_float64) >>>>>> => TypeError: 'numpy.float64' object cannot be interpreted as an >>>>>> index >>>>>> >>>>>> However >>>>>> a) np.sqrt(...) works fine, as does and . >>>>>> b) In Python, int(np.sqrt(...)) and long(np.sqrt(...)) both works >>>>>> fine >>>>>> >>>>>> Is Py_ssize_t "special" when it comes to converting from Python >>>>>> objects? >>>>>> If so I find it mildly confusing and something which only >>>>>> increases >>>>>> learning curve... >>>>> Py_ssize_t is meant for indexing, and fails for the same reason >>>>> that >>>>> >>>>>>>> L = range(10) >>>>>>>> L[2] >>>>> 2 >>>>>>>> L[2.5] >>>>> Traceback (most recent call last): >>>>> File "", line 1, in >>>>> TypeError: list indices must be integers, not float >>>>> >>>>> fails. This is a feature, not a bug. >>>> OK, if this is a feature, help me out with this then: >>>> >>>> I need to iterate from 0 to "lmax". When I allocate an array, it is >>>> always allocated of size (lmax + 1)**2, and it is convenient to be >>>> able >>>> to deduce lmax from the array shape. >>>> >>>> What type should I use for lmax to conveniently convert from a float >>>> (because sqrt is float, but I know I can safely truncate) and >>>> guarantee >>>> that I support the range of NumPy arrays (which essentially use >>>> Py_ssize_t to store shape info)? The type must be signed, >>>> otherwise I >>>> fall into the range(-lmax, lmax) trap all the time. >>> Is there not a ssize_t? >> Not builtin to Cython, I have to extern ctypedef it. > > Well, if we have size_t, we should probably support ssize_t as well. > > http://trac.cython.org/cython_trac/ticket/399 I think I figured out a nice way to fix this issue in general though...optimize some_int = int(some_float) Nice and Pythonic and one doesn't have to bother with casts, types etc. http://trac.cython.org/cython_trac/ticket/400 -- Dag Sverre From ndbecker2 at gmail.com Fri Oct 9 13:19:17 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 09 Oct 2009 07:19:17 -0400 Subject: [Cython] C++ complex support References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> Message-ID: Robert Bradshaw wrote: > On Oct 8, 2009, at 11:42 AM, Dag Sverre Seljebotn wrote: > >> Lisandro Dalcin wrote: >>> I was just pointing to GCC-specific syntax that perhaps we could use, >>> I was not actually requesting for it !!! >>> >>> I really prefer your time being invested in reviewing the patch: >>> http://trac.cython.org/cython_trac/ticket/398 >> >> Robert wrote the support so he'd be much more qualified. (Also, I >> think >> you are free to push once you feel confident yourself that >> everything's >> OK.) Here's my feedback (easier on email): >> >> - I'm wondering if new macros for C compilation configuration should >> be prefixed CYTHON instead of PYX? (With the intent of adding CYTHON_* >> aliases for existing macros.) At least there's CYTHON_REFNANNY now. >> >> - In the change to ModuleNode.py there might be missing an #endif >> >> - I believe I've implemented a better strategy for sign_and_name >> myself in Buffer.py, I'm happy to do this change though as it overlaps >> with buffer code (basically give all user-defined types a prefix, like >> 'U', so that a type named "long_double" -- which is completely >> legal -- >> doesn't conflict). >> >> - It should be ::std::complex, not std::complex >> >> - I need to know why you removed >> proto_block='complex_numbers_utility_code'... (I just added it to >> fix a >> complicated bug. If removing it fixed anything we/I basically need to >> find a better solution, because removing it is sure to trigger >> another bug.) > > +1 to all of the above. Also > > - Do C++ complex numbers not support the unary - operation? On the c++ side, unary - is supported. From dagss at student.matnat.uio.no Fri Oct 9 16:33:54 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 09 Oct 2009 16:33:54 +0200 Subject: [Cython] Bug day? In-Reply-To: References: <4AC7A5F2.6000503@student.matnat.uio.no> Message-ID: <4ACF49D2.7010704@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 3, 2009, at 12:28 PM, Dag Sverre Seljebotn wrote: > > >> Robert was talking about a bug day -- I can do a bug day any day >> during >> next week (09-16 CEST only). >> > > How about next Thursday (the 15th). In PDST, so that's you -9 hours, > so I could join you at midnight here. Anyone else? > By midnight do you mean 00:00 or 23:50 the 15th? Or in other words, is that Friday for me or Thursday? At any rate, I think it should work for me. Dag Sverre From dalcinl at gmail.com Fri Oct 9 16:38:01 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 9 Oct 2009 11:38:01 -0300 Subject: [Cython] C++ complex support In-Reply-To: <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> Message-ID: New patch uploaded at http://trac.cython.org/cython_trac/ticket/398 1) I've introduced some renaming to mimic Py_c_sum, Py_c_diff, etc, in CPython. If you do not like it, I could revert it... IMHO, the generated C code is a bit more readable now (not so longish macro/function names, plus a more "standard" CPython naming) 2) now the only effect of the 'ccomplex' directive should be to set CYTHON_CCOMPLEX to 1 by default. Hope I got it right. I'm still in doubt about the hunk below diff -r cfcc88fdba0f Cython/Compiler/ExprNodes.py --- a/Cython/Compiler/ExprNodes.py Thu Oct 08 20:30:07 2009 -0300 +++ b/Cython/Compiler/ExprNodes.py Fri Oct 09 10:47:47 2009 -0300 @@ -933,8 +932,6 @@ def calculate_result_code(self): if self.type.is_pyobject: return self.result() - elif self.c99_complex: - return "%rj" % float(self.value) else: return "%s(0, %r)" % (self.type.from_parts, float(self.value)) @@ -946,8 +943,6 @@ float(self.value), code.error_goto_if_null(self.result(), self.pos))) code.put_gotref(self.py_result()) - else: - self.c99_complex = code.globalstate.directives['c99_complex'] On Fri, Oct 9, 2009 at 3:45 AM, Robert Bradshaw wrote: > On Oct 8, 2009, at 11:42 AM, Dag Sverre Seljebotn wrote: > >> Lisandro Dalcin wrote: >>> I was just pointing to GCC-specific syntax that perhaps we could use, >>> I was not actually requesting for it !!! >>> >>> I really prefer your time being invested in reviewing the patch: >>> http://trac.cython.org/cython_trac/ticket/398 >> >> Robert wrote the support so he'd be much more qualified. (Also, I >> think >> you are free to push once you feel confident yourself that >> everything's >> OK.) Here's my feedback (easier on email): >> >> ? - I'm wondering if new macros for C compilation configuration should >> be prefixed CYTHON instead of PYX? (With the intent of adding CYTHON_* >> aliases for existing macros.) At least there's CYTHON_REFNANNY now. >> >> ? - In the change to ModuleNode.py there might be missing an #endif >> >> ? - I believe I've implemented a better strategy for sign_and_name >> myself in Buffer.py, I'm happy to do this change though as it overlaps >> with buffer code (basically give all user-defined types a prefix, like >> 'U', so that a type named "long_double" -- which is completely >> legal -- >> doesn't conflict). >> >> ? - It should be ::std::complex, not std::complex >> >> ? - I need to know why you removed >> proto_block='complex_numbers_utility_code'... (I just added it to >> fix a >> complicated bug. If removing it fixed anything we/I basically need to >> find a better solution, because removing it is sure to trigger >> another bug.) > > +1 to all of the above. Also > Dag's requests: Done. BTW, I've removed 'complex_numbers_utility_code'. > > - Do C++ complex numbers not support the unary - operation? > Yes, they support it... I just got confused (thanks, Neal !) > - I don't think we need unary pos anywhere (it's just the identity > for these values). > OK. Removed. > - In light of the above, c99 and C++ complex arithmetic only differ > by is_zero and conjugate, so perhaps we should bring the rest of the > macro definitions out of the inner #if clauses. > OK. Done. > - In the @cython.cdivision(False) we should *not* be raising a > ZeroDivisionError, we should only be raising it if cython.cdivision > is True. > Well, I just hotfixed the test to make it pass... Now the patch has some XXX comments... I do not know what's going on, but the zero-test and raising is never generated... > - I like how you did multiple tests to cover all the implementations, > but I'm not sure what the point of tests/run/ > complex_numbers_cxx_T398.h is. Won't all the other tests use C++ > complexes when they're compiled with C++? > That's the only case that uses C++ and a explicit CYTHON_CCOMPLEX=1 ... The point is just to make sure that you can explicitly set the macro to 1 (in a header, or passing -DCYTHON_CCOMPLEX=1 at compiler time) and you will not get a 'macro redefined' warning or like that... you know how much I hate compiler warnings ;-) But if you still think that this testcase is superfluous, let me know and I'll remove it. >>> BTW, What would be better from "creating" a C99/C++ complex number >>> from re & im parts: use a macro or a inline function as we currently >>> have? Would it be worth to also use a macro {complex_type}_coerce >>> () to >>> implement promotion to a complex type? Currently we are using >>> {complex_type}_from_parts(realpart,0) for this... As the generated >>> code has to support struct-based complexes, things like to 1/z >>> need to >>> promote "1" to complex... But for C99, actual promotion is not >>> required (the compiler does that), and in C++ we have to at >>> promote to >>> at least for many operators to work. Any chance that >>> special-casing the coercion with an appropriate macro could give >>> faster execution? >> >> Hmm. The last idea sounds sound to me (although I'm not going to spend >> time on it personally, I'd rather have more features than speed >> regarding complex numbers at this point). > > Sounds reasonable to me too. > OK, but again let's leave this for the (hopefully near) future. > - Robert > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Fri Oct 9 17:16:07 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 9 Oct 2009 12:16:07 -0300 Subject: [Cython] Object to Py_ssize_t conversion In-Reply-To: <3B634A03-1097-4EED-8AA5-EDB5DE5634F7@math.washington.edu> References: <4ACDE351.3090707@student.matnat.uio.no> <4ACE2750.8080304@student.matnat.uio.no> <4ACE2BD4.7050102@student.matnat.uio.no> <3B634A03-1097-4EED-8AA5-EDB5DE5634F7@math.washington.edu> Message-ID: On Fri, Oct 9, 2009 at 3:52 AM, Robert Bradshaw wrote: > > Well, if we have size_t, we should probably support ssize_t as well. > Would this do the trick ? Or do you want to use the "true" ssize_t, even in older Python's ?? cdef extern from *: ctypedef int ssize_t "Py_ssize_t" The Py<->C conversion should not used the Index C-API calls, and should be platform-agnostic (because of my patch for extern ctypedef integrals).. Take a look at the code generated from the snippet below: cdef extern from *: ctypedef int ssize_t "Py_ssize_t" def test_ssize_t(a, b, c): """ >>> test_ssize_t(4.0, 3, -2) (4, 3, -2) """ cdef ssize_t x = a cdef ssize_t y = b cdef ssize_t z = c return (x, y, z) > > http://trac.cython.org/cython_trac/ticket/399 > So we really need it? I think now it is not essential... But I would like to have it anyway, just for symmetry with size_t ... What do you thing about aliasing the Cython-level ssize_t to the C-level Py_ssize_t? > - Robert > > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Fri Oct 9 17:17:16 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 9 Oct 2009 12:17:16 -0300 Subject: [Cython] Object to Py_ssize_t conversion In-Reply-To: <4ACEFB1D.6010108@student.matnat.uio.no> References: <4ACDE351.3090707@student.matnat.uio.no> <4ACE2750.8080304@student.matnat.uio.no> <4ACE2BD4.7050102@student.matnat.uio.no> <3B634A03-1097-4EED-8AA5-EDB5DE5634F7@math.washington.edu> <4ACEFB1D.6010108@student.matnat.uio.no> Message-ID: On Fri, Oct 9, 2009 at 5:58 AM, Dag Sverre Seljebotn wrote: > > I think I figured out a nice way to fix this issue in general > though...optimize > > some_int = int(some_float) > > Nice and Pythonic and one doesn't have to bother with casts, types etc. > > http://trac.cython.org/cython_trac/ticket/400 > Despite my previous comments, a big +1 for your idea... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sturla at molden.no Fri Oct 9 17:24:24 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 09 Oct 2009 17:24:24 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> Message-ID: <4ACF55A8.8030503@molden.no> Lisandro Dalcin wrote: > > BTW, I'm assuming you already use the trick below, right?: > > ctypedef double const_double "const double" > Is it true that ctypedef double *cdr_ptr_t "const double *restrict" does not work properly? > Would this work for you? > > cdef double* Uj = &U[n*j] > Now I feel a bit stupid because in my original Cython code I did just that. Actually I wrote cdef np.ndarray[double, ndim=2, mode="c"] U cdef double *Uj Uj = U[j,i] > So in short: I know you are a very experienced guy, I would really > like to you to join Cython development! > My ability to help is somewhat limited from not knowing the Cython code base. Nor do I feel I have sufficient knowledge about compiler technology. From sturla at molden.no Fri Oct 9 17:41:18 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 09 Oct 2009 17:41:18 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> Message-ID: <4ACF599E.6060402@molden.no> Robert Bradshaw wrote: >> Second issue: Why is it that Cython does not support pointer >> artithmetics? >> > > Um... we do. The following compiles just fine. > > cdef foo(double* data, int n, int j): > cdef double* x = data + n*j > return x[0] > That is great :-) Maybe it is Pyrex that don't allow pointer arithmetics? I must have picked up that crazy idea somewhere... This really makes a lot of my criticism go away. > The overhead of object creation, refcounting, and the GIL is the > tradeoff you get for not having to manually manage the memory and > freely pass things back and forth between Python and C land. There's > some work being done with even more lightweight array-like objects. > The problem is that keeping the GIL locked make the interpreter unresponsive. This can be a problem for numerical code. Will a statement like this just release and re-acquire the GIL? with nogil: pass Calling it now and then would keep the interpreter form freezing. > In any case, for arrays of decent size, actually processing each > element in an array is typically much more expensive than the single > slicing step. Optimization is not about just removing inefficiency, > it's about removing the inefficiency in the parts of your code where > you spend 90% of your time. This is typically the inner loop, where I > hope slicing isn't happening. > The C function I posted is called thousands of times... Using ndarrays as arguments was not an option. But numerical code is cleaner and easier to read with array objects (a la Fortran) than C pointers. > It sounds like (1) you're not using Cython correctly and (2) there's > still a lot of room for improvement (that we would gladly accept help > with). Both it seems :-) Sturla Molden From dalcinl at gmail.com Fri Oct 9 17:44:42 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 9 Oct 2009 12:44:42 -0300 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACF55A8.8030503@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF55A8.8030503@molden.no> Message-ID: On Fri, Oct 9, 2009 at 12:24 PM, Sturla Molden wrote: > Lisandro Dalcin wrote: >> >> BTW, I'm assuming you already use the trick below, right?: >> >> ctypedef double const_double "const double" >> > Is it true that > > ? ctypedef double *cdr_ptr_t "const double *restrict" > > does not work properly? > Ah!! I do not have the C grammar at hand to tell you... A cast like in Cython code would translate to a (const double *restrict) cast in C code... Is that valid C? > >> Would this work for you? >> >> cdef double* Uj = &U[n*j] >> > Now I feel a bit stupid because in my original Cython code I did just > that. Actually I wrote > > cdef np.ndarray[double, ndim=2, mode="c"] U > cdef double *Uj > Uj = U[j,i] > So, to this work Uj =&U[j,i] for getting a pointer to row "j" at offset "i"? > >> So in short: I know you are a very experienced guy, I would really >> like to you to join Cython development! >> > My ability to help is somewhat limited from not knowing the Cython code > base. Nor do I feel I have sufficient knowledge about compiler technology. > Me too! I do not know nothing about compiler technology, but your experience would still be really helpful in other things... For example, for release 0.11.3 I wrote at rather important patch (well, at least for me) for handling C integral types, now I'm working on better support for c99/c++ complexes... All this requires testting, review, and others playing of devil's advocates to stress my work to the limits (in correctness, completeness, and usability)... All this is almost entirely low-level C programing and Python C-API... I would love my patches to receive you review. In short, you do not need to have knowledge about compiler technology to make very valuable contributions... For example: write a cdef class with cdef object members and __dealloc__ method, this class should be GC-tracked... Now look carefully at the generated C-code, particularly the deallocation chain and the refcounting hackery... Could you provide some comments about if all this is correct? Something smells bad in my nose... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sturla at molden.no Fri Oct 9 17:50:52 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 09 Oct 2009 17:50:52 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACDF767.7020901@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> Message-ID: <4ACF5BDC.1040506@molden.no> Sturla Molden wrote: > In numerical code, the declarations > > const type *restrict > const type * > type *restrict > > can help the C compiler produce faster code. It helps the compiler to > prevent redundant read and write from memory, and thus values can be > kept in registers. I wonder how important this is on modern x86 and x64 CPUs? I believe it is common to see "C faster than Fortran" now, albeit C89 suffering from the pointer aliasing sickness. I guess better CPU cache and C compilers can hide the effect of some of this? Thus it could be that const and restrict are more important on DSP chips and the like? Actually many of them have C compilers that interpret const * as const *restrict. But DSPs is not exactly where I expect Cython to be used... S.M. From dalcinl at gmail.com Fri Oct 9 17:51:09 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 9 Oct 2009 12:51:09 -0300 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACF599E.6060402@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> <4ACF599E.6060402@molden.no> Message-ID: On Fri, Oct 9, 2009 at 12:41 PM, Sturla Molden wrote: >> The overhead of object creation, refcounting, and the GIL is the >> tradeoff you get for not having to manually manage the memory and >> freely pass things back and forth between Python and C land. There's >> some work being done with even more lightweight array-like objects. >> > The problem is that keeping the GIL locked make the interpreter > unresponsive. This can be a problem for numerical code. > > Will a statement like this just release and re-acquire the GIL? > > with nogil: > ? pass > > Calling it now and then would keep the interpreter form freezing. > /* "/u/dalcinl/tmp/with_nogil_pass.pyx":2 * def f(): * with nogil: # <<<<<<<<<<<<<< * pass */ { PyThreadState *_save; Py_UNBLOCK_THREADS /*try:*/ { } /*finally:*/ { Py_BLOCK_THREADS } } > The C function I posted is called thousands of times... Using ndarrays > as arguments was not an option. But numerical code is cleaner and easier > to read with array objects (a la Fortran) than C pointers. > Did you take a look at the relevant CEP's ? http://wiki.cython.org/enhancements/array http://wiki.cython.org/enhancements/simd -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sturla at molden.no Fri Oct 9 17:58:43 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 09 Oct 2009 17:58:43 +0200 Subject: [Cython] How do I compare the shape of two numpy arrays for equality? In-Reply-To: <7f014ea60910081638p33733cdaq5bcde4329c628a3b@mail.gmail.com> References: <7f014ea60910081638p33733cdaq5bcde4329c628a3b@mail.gmail.com> Message-ID: <4ACF5DB3.7050505@molden.no> Chris Colbert wrote: > Since I have a "cimport numpy as np" at the top of my cython file, > > array1.shape == array2.shape > > is only true if array1 IS array2 because .shape return the npy_intp* > pointer to the shape array. > > Is there a way for me check if the values in the shape array are equal > (ala python) without having to drop into a loop? How about casting the arrays to object, so you get a dictionary lookup on the shape attribute? Very slow though... Or write a cdef that takes two ndarrays as argument and returns 1 if the shapes are equal? Or assuming equal rank, simply use C library function memcmp from string.h? S.M. From dalcinl at gmail.com Fri Oct 9 18:06:06 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 9 Oct 2009 13:06:06 -0300 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACF5BDC.1040506@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> Message-ID: On Fri, Oct 9, 2009 at 12:50 PM, Sturla Molden wrote: > Sturla Molden wrote: >> In numerical code, the declarations >> >> ? ?const type *restrict >> ? ?const type * >> ? ?type *restrict >> >> can help the C compiler produce faster code. It helps the compiler to >> prevent redundant read and write from memory, and thus values can be >> kept in registers. > I wonder how important this is on modern x86 and x64 CPUs? I believe it > is common to see "C faster than Fortran" now, albeit C89 suffering from > the pointer aliasing sickness. Well , I see "restrict" as an extension to strict aliasing rules, but in this case to pointers of the same type... And "C faster than Fortran" could just be that Fortran compilers do not get as much work on optimization that C compilers... Could it be? -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sturla at molden.no Fri Oct 9 18:14:45 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 09 Oct 2009 18:14:45 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> <4ACF599E.6060402@molden.no> Message-ID: <4ACF6175.9020708@molden.no> Lisandro Dalcin wrote: > /* "/u/dalcinl/tmp/with_nogil_pass.pyx":2 > * def f(): > * with nogil: # <<<<<<<<<<<<<< > * pass > */ > { PyThreadState *_save; > Py_UNBLOCK_THREADS > /*try:*/ { > } > /*finally:*/ { > Py_BLOCK_THREADS > } > } > Ah, I forgot to give up the time slice though, to force a context shift. Otherwise the GIL could be grabbed back before any other active thread could request it. cdef extern from "windows.h": void Sleep(unsigned long) nogil def doevents(): with nogil: Sleep(0) Sleep(0) gives up the current time slice if a thread with equal or higher priority is ready to run. Otherwise it does nothing. > Did you take a look at the relevant CEP's ? > > http://wiki.cython.org/enhancements/array > http://wiki.cython.org/enhancements/simd > No. Thanks for pointing this out. Sturla From dagss at student.matnat.uio.no Fri Oct 9 18:44:44 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 09 Oct 2009 18:44:44 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACF55A8.8030503@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF55A8.8030503@molden.no> Message-ID: <4ACF687C.7090205@student.matnat.uio.no> Sturla Molden wrote: > Lisandro Dalcin wrote: >> So in short: I know you are a very experienced guy, I would really >> like to you to join Cython development! >> > My ability to help is somewhat limited from not knowing the Cython code > base. Nor do I feel I have sufficient knowledge about compiler technology. Well, everybody had to learn the codebase at some point (as Greg's the original author). As long as you have available time, I wouldn't worry about the rest -- and there's plenty of issues that don't require knowledge about compiler technology, only C and Python. And we're more than willing to help along the way, give leads, a strategy of attack for a ticket, etc. etc. -- Dag Sverre From dagss at student.matnat.uio.no Fri Oct 9 18:52:44 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 09 Oct 2009 18:52:44 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> Message-ID: <4ACF6A5C.7040102@student.matnat.uio.no> Lisandro Dalcin wrote: > On Fri, Oct 9, 2009 at 12:50 PM, Sturla Molden wrote: >> Sturla Molden wrote: >>> In numerical code, the declarations >>> >>> const type *restrict >>> const type * >>> type *restrict >>> >>> can help the C compiler produce faster code. It helps the compiler to >>> prevent redundant read and write from memory, and thus values can be >>> kept in registers. >> I wonder how important this is on modern x86 and x64 CPUs? I believe it >> is common to see "C faster than Fortran" now, albeit C89 suffering from >> the pointer aliasing sickness. For auto-vectorization of loops with GCC it is extremely important. I.e. a simple vectorizable for-loop will have SSE instructions generated if restrict is declared, otherwise not! So easily around 2x speedup from restrict in those cases. BTW, Intel C gets away with this basically through adding if-tests: if (pointer memory overlaps) { version of loop without SSE } else { version of loop with SSE } so that restrict isn't needed (though if you add them, you'll get less if-tests!) -- Dag Sverre From robertwb at math.washington.edu Fri Oct 9 18:59:29 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Fri, 9 Oct 2009 09:59:29 -0700 Subject: [Cython] Bug day? In-Reply-To: <4ACF49D2.7010704@student.matnat.uio.no> References: <4AC7A5F2.6000503@student.matnat.uio.no> <4ACF49D2.7010704@student.matnat.uio.no> Message-ID: <952A95F2-7298-456C-9A28-133978414FD9@math.washington.edu> On Oct 9, 2009, at 7:33 AM, Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: >> On Oct 3, 2009, at 12:28 PM, Dag Sverre Seljebotn wrote: >> >> >>> Robert was talking about a bug day -- I can do a bug day any day >>> during >>> next week (09-16 CEST only). >>> >> >> How about next Thursday (the 15th). In PDST, so that's you -9 hours, >> so I could join you at midnight here. Anyone else? >> > By midnight do you mean 00:00 or 23:50 the 15th? Or in other words, is > that Friday for me or Thursday? > > At any rate, I think it should work for me. Thursday. Technically Thursday for all of us (though I'll be staying up for it). - Robert From robertwb at math.washington.edu Fri Oct 9 19:06:12 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Fri, 9 Oct 2009 10:06:12 -0700 Subject: [Cython] Bug day? In-Reply-To: <1e52e0880910090052v42759639reb587e36f4c02140@mail.gmail.com> References: <4AC7A5F2.6000503@student.matnat.uio.no> <1e52e0880910090052v42759639reb587e36f4c02140@mail.gmail.com> Message-ID: On Oct 9, 2009, at 12:52 AM, Peter Alexander wrote: > On Fri, Oct 9, 2009 at 3:06 AM, Robert Bradshaw > wrote: >> On Oct 3, 2009, at 12:28 PM, Dag Sverre Seljebotn wrote: >> >>> Robert was talking about a bug day -- I can do a bug day any day >>> during >>> next week (09-16 CEST only). >> >> How about next Thursday (the 15th). In PDST, so that's you -9 hours, >> so I could join you at midnight here. Anyone else? >> >>> Also, before a bug-day I think we should tag all bugs which are >>> "newbie-friendly" so that newcomers can join if they want to. >> >> +1 >> >> - Robert >> >> >> _______________________________________________ >> Cython-dev mailing list >> Cython-dev at codespeak.net >> http://codespeak.net/mailman/listinfo/cython-dev >> > > I'm happy to help on the ~newbie level if you feel I'm able. Yes, that'd be great. We should all be on IRC to answer any questions. > Another thing I eventually intend to document, are Cython's internal > architecture/workings. > > I haven't investigated the sources to any great degree yet, though. That'd be really useful. Not quite as pressing, but getting into the code is a steep learning curve. So far what we have is http:// wiki.cython.org/HackerGuide and http://sage.math.washington.edu/home/ jkantor/cython_notes.pdf - Robert From craigcitro at gmail.com Fri Oct 9 19:08:00 2009 From: craigcitro at gmail.com (Craig Citro) Date: Fri, 9 Oct 2009 10:08:00 -0700 Subject: [Cython] Bug day? In-Reply-To: <952A95F2-7298-456C-9A28-133978414FD9@math.washington.edu> References: <4AC7A5F2.6000503@student.matnat.uio.no> <4ACF49D2.7010704@student.matnat.uio.no> <952A95F2-7298-456C-9A28-133978414FD9@math.washington.edu> Message-ID: > Thursday. Technically Thursday for all of us (though I'll be staying > up for it). > I think I'm going to try and do the same -- though I may start a little earlier (9PM-ish on Weds Seattle time). I'd say that the timing is bad for the US developers, but given all the folks I know in the US who might want to be involved, maybe the timing is in fact really good ... ;) -cc From robertwb at math.washington.edu Fri Oct 9 19:11:38 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Fri, 9 Oct 2009 10:11:38 -0700 Subject: [Cython] Object to Py_ssize_t conversion In-Reply-To: <4ACEFB1D.6010108@student.matnat.uio.no> References: <4ACDE351.3090707@student.matnat.uio.no> <4ACE2750.8080304@student.matnat.uio.no> <4ACE2BD4.7050102@student.matnat.uio.no> <3B634A03-1097-4EED-8AA5-EDB5DE5634F7@math.washington.edu> <4ACEFB1D.6010108@student.matnat.uio.no> Message-ID: On Oct 9, 2009, at 1:58 AM, Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: > I think I figured out a nice way to fix this issue in general > though...optimize > > some_int = int(some_float) > > Nice and Pythonic and one doesn't have to bother with casts, types > etc. > > http://trac.cython.org/cython_trac/ticket/400 Very good point! I see people do int(...) and float(...) all the time, and sometimes it's the only Python calls in their inner loops (and makes everything else into a Python call as well. Would int(...) return a long if it's going to be used in a C context? One issue is that I use int(...) when I want an actual Python object, though I'm sure we could figure something out. - Robert P.S. Defining ssize_t, even as an alias to Py_ssize_t (are they ever different?) would still probably be a good idea. From robertwb at math.washington.edu Fri Oct 9 19:16:53 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Fri, 9 Oct 2009 10:16:53 -0700 Subject: [Cython] C++ complex support In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> Message-ID: On Oct 9, 2009, at 7:38 AM, Lisandro Dalcin wrote: > New patch uploaded at http://trac.cython.org/cython_trac/ticket/398 > > 1) I've introduced some renaming to mimic Py_c_sum, Py_c_diff, etc, in > CPython. If you do not like it, I could revert it... IMHO, the > generated C code is a bit more readable now (not so longish > macro/function names, plus a more "standard" CPython naming) > > 2) now the only effect of the 'ccomplex' directive should be to set > CYTHON_CCOMPLEX to 1 by default. Hope I got it right. I'm still in > doubt about the hunk below > > > diff -r cfcc88fdba0f Cython/Compiler/ExprNodes.py > --- a/Cython/Compiler/ExprNodes.py Thu Oct 08 20:30:07 2009 -0300 > +++ b/Cython/Compiler/ExprNodes.py Fri Oct 09 10:47:47 2009 -0300 > @@ -933,8 +932,6 @@ > def calculate_result_code(self): > if self.type.is_pyobject: > return self.result() > - elif self.c99_complex: > - return "%rj" % float(self.value) > else: > return "%s(0, %r)" % (self.type.from_parts, float > (self.value)) > > @@ -946,8 +943,6 @@ > float(self.value), > code.error_goto_if_null(self.result(), > self.pos))) > code.put_gotref(self.py_result()) > - else: > - self.c99_complex = code.globalstate.directives > ['c99_complex'] I think that should be good now that we're not using it in the code generation >> - In the @cython.cdivision(False) we should *not* be raising a >> ZeroDivisionError, we should only be raising it if cython.cdivision >> is True. >> > > Well, I just hotfixed the test to make it pass... Now the patch has > some XXX comments... I do not know what's going on, but the zero-test > and raising is never generated... > >> - I like how you did multiple tests to cover all the implementations, >> but I'm not sure what the point of tests/run/ >> complex_numbers_cxx_T398.h is. Won't all the other tests use C++ >> complexes when they're compiled with C++? >> > > That's the only case that uses C++ and a explicit CYTHON_CCOMPLEX=1 > ... The point is just to make sure that you can explicitly set the > macro to 1 (in a header, or passing -DCYTHON_CCOMPLEX=1 at compiler > time) and you will not get a 'macro redefined' warning or like that... > you know how much I hate compiler warnings ;-) > > But if you still think that this testcase is superfluous, let me know > and I'll remove it. Sorry, I was thinking backwards. Yes, we should be raising a warning here. You can just comment out this patch and I'll worry about fixing it. - Robert From dalcinl at gmail.com Fri Oct 9 20:03:21 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 9 Oct 2009 15:03:21 -0300 Subject: [Cython] C++ complex support In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> Message-ID: On Fri, Oct 9, 2009 at 2:16 PM, Robert Bradshaw wrote: > >>> - In the @cython.cdivision(False) we should *not* be raising a >>> ZeroDivisionError, we should only be raising it if cython.cdivision >>> is True. >>> >> >> Well, I just hotfixed the test to make it pass... Now the patch has >> some XXX comments... I do not know what's going on, but the zero-test >> and raising is never generated... > > Sorry, I was thinking backwards. Yes, we should be raising a warning > here. > > You can just comment out this patch and I'll worry about fixing it. > Done. New patch uploaded. Do you think the patch is good enough to push? -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Fri Oct 9 20:14:45 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 9 Oct 2009 15:14:45 -0300 Subject: [Cython] Object to Py_ssize_t conversion In-Reply-To: References: <4ACDE351.3090707@student.matnat.uio.no> <4ACE2750.8080304@student.matnat.uio.no> <4ACE2BD4.7050102@student.matnat.uio.no> <3B634A03-1097-4EED-8AA5-EDB5DE5634F7@math.washington.edu> <4ACEFB1D.6010108@student.matnat.uio.no> Message-ID: On Fri, Oct 9, 2009 at 2:11 PM, Robert Bradshaw wrote: > On Oct 9, 2009, at 1:58 AM, Dag Sverre Seljebotn wrote: > > P.S. Defining ssize_t, even as an alias to Py_ssize_t (are they ever > different?) > In old Python, Py_ssize_t is just a 'int', see our own generated C code: #if PY_VERSION_HEX < 0x02050000 typedef int Py_ssize_t; #define PY_SSIZE_T_MAX INT_MAX #define PY_SSIZE_T_MIN INT_MIN I think that for Python<2.5, we could try to use the "correct" ssize_t in 64 bits, despite the fact that Py<2.4 does not properly support 64-bits... Honestly, I do not know what would be the proper things to do here... Python 2.4 is still in use, NumPy still supports it... I guess a Cython user would accept aht Py_ssize_t it is a 'int' in old Python (after all, the Py_ prefix indicates it is Python-specific), but I guess that Cython code with "sizeof(ssize_t)== sizeof(void*)" evaluating to false would be really disturbing... > > would still probably be a good idea. > Indeed... Let's wait a bit for more input... Then I could start hacking a patch. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dagss at student.matnat.uio.no Fri Oct 9 20:42:19 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 09 Oct 2009 20:42:19 +0200 Subject: [Cython] Object to Py_ssize_t conversion In-Reply-To: References: <4ACDE351.3090707@student.matnat.uio.no> <4ACE2750.8080304@student.matnat.uio.no> <4ACE2BD4.7050102@student.matnat.uio.no> <3B634A03-1097-4EED-8AA5-EDB5DE5634F7@math.washington.edu> <4ACEFB1D.6010108@student.matnat.uio.no> Message-ID: <4ACF840B.6010100@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 9, 2009, at 1:58 AM, Dag Sverre Seljebotn wrote: > >> Robert Bradshaw wrote: >> I think I figured out a nice way to fix this issue in general >> though...optimize >> >> some_int = int(some_float) >> >> Nice and Pythonic and one doesn't have to bother with casts, types >> etc. >> >> http://trac.cython.org/cython_trac/ticket/400 > > Very good point! I see people do int(...) and float(...) all the > time, and sometimes it's the only Python calls in their inner loops > (and makes everything else into a Python call as well. Would int(...) > return a long if it's going to be used in a C context? One issue is > that I use int(...) when I want an actual Python object, though I'm > sure we could figure something out. Yes, I'd never support something that disturbs the actual semantics, I was only thinking about optimizations (more advanced than what we do now -- would perhaps need to have a stack of "preferred result types" go inwards in during type analysis...) So an overflow check must always be generated (in case of int(1e200)). And this cannot be optimized: some_int = int(some_float) + 1 ...in case the +1 makes it overflow integer. (Or, well, that's a seperate optimization calling for overflow-checking arithmetic which can be turned off with a compiler directive.) -- Dag Sverre From dagss at student.matnat.uio.no Fri Oct 9 20:50:17 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 09 Oct 2009 20:50:17 +0200 Subject: [Cython] C++ complex support In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> Message-ID: <4ACF85E9.2060808@student.matnat.uio.no> Lisandro Dalcin wrote: > On Fri, Oct 9, 2009 at 2:16 PM, Robert Bradshaw > wrote: >>>> - In the @cython.cdivision(False) we should *not* be raising a >>>> ZeroDivisionError, we should only be raising it if cython.cdivision >>>> is True. >>>> >>> Well, I just hotfixed the test to make it pass... Now the patch has >>> some XXX comments... I do not know what's going on, but the zero-test >>> and raising is never generated... >> Sorry, I was thinking backwards. Yes, we should be raising a warning >> here. >> >> You can just comment out this patch and I'll worry about fixing it. >> > > Done. New patch uploaded. > > Do you think the patch is good enough to push? What happened with proto_block? From your comments I assumed you were going to just fold it into utility_code_proto_before_types; it seems it is just removed though. (Does test_numpy work with the patch?) Next week I'll add conjugate (I'm basically done already. In that work I might likely also turn "x.imag = y" into "__Pyx_SET_CIMAG(x, y)". Code blocks are cheap though, no reason not to have a dozen or two (until we get our act together and have utility code and type declarations all form a DAG). -- Dag Sverre From dalcinl at gmail.com Fri Oct 9 21:07:53 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 9 Oct 2009 16:07:53 -0300 Subject: [Cython] C++ complex support In-Reply-To: <4ACF85E9.2060808@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> <4ACF85E9.2060808@student.matnat.uio.no> Message-ID: On Fri, Oct 9, 2009 at 3:50 PM, Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: > > What happened with proto_block? From your comments I assumed you were > going to just fold it into utility_code_proto_before_types; it seems it > is just removed though. I moved required bits to 'utility_code_proto_before_types' > > (Does test_numpy work with the patch?) > Yes, it works... BTW, any chance you could look at these unused warnings? numpy_bufacc_T155.c:3693: warning: ?__Pyx_UnpackItem? defined but not used numpy_bufacc_T155.c:3703: warning: ?__Pyx_EndUnpack? defined but not used numpy_test.c:9951: warning: ?__Pyx_UnpackItem? defined but not used numpy_test.c:9961: warning: ?__Pyx_EndUnpack? defined but not used In case all is fine, perhaps you could (ab)use INLINE to silent GCC? > Next week I'll add conjugate (I'm basically done already. In that work I > might likely also turn "x.imag = y" into "__Pyx_SET_CIMAG(x, y)". > Good! BTW, how are you going to implement the setters for C99 ? > > Code blocks are cheap though, no reason not to have a dozen or two > (until we get our act together and have utility code and type > declarations all form a DAG). > If you are talking about the removing of comples proto block, my rationale is not about having too many blocks, it is just that having a dedicated block just for complexes seemed a bit, how to say? complex! I still think that pushing the required bits to 'utility_code_proto_before_types' is proper and explicit enough; a future Cython developers do not have to start asking: what might be going on here with complex numbers that requires so special treatement?? Of course, if you still think that the old way was better, let me know and I'll update the patch... BTW, Neal, have you watched my progress? Could you give a try to my patch? Some testing from your side and more comprensive testcases would be great. After all, you asked for it :-), now you have it. Plese, help me and give it a try... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dagss at student.matnat.uio.no Fri Oct 9 21:13:00 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: 09 Oct 2009 21:13:00 +0200 Subject: [Cython] Object to Py_ssize_t conversion Message-ID: <3337967584.33861@smtp.netcom.no> Sorry for wasting your time, I'll try not to suggest something fundamentally impossible next time. (Last part, that is.) Dag Sverre Seljebotn -----Original Message----- From: Dag Sverre Seljebotn Date: Friday, Oct 9, 2009 8:40 pm Subject: Re: [Cython] Object to Py_ssize_t conversion To: cython-dev at codespeak.netReply-To: cython-dev at codespeak.net Robert Bradshaw wrote: > On Oct 9, 2009, at 1:58 AM, Dag Sverre Seljebotn wrote: > >> Robert Bradshaw wrote: >> I think I figured out a nice way to fix this issue in general >> though...optimize >> >> some_int = int(some_float) >> >> Nice a From dagss at student.matnat.uio.no Fri Oct 9 21:14:00 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: 09 Oct 2009 21:14:00 +0200 Subject: [Cython] C++ complex support Message-ID: <3337967673.42794@smtp.netcom.no> Re setters, I haven't followed the details, so I'll just do something stupid and GCC specific and some of you others who know the details can clean it up afterwards :-) Dag Sverre Seljebotn -----Original Message----- From: Lisandro Dalcin Date: Friday, Oct 9, 2009 9:08 pm Subject: Re: [Cython] C++ complex support To: cython-dev at codespeak.netReply-To: cython-dev at codespeak.net On Fri, Oct 9, 2009 at 3:50 PM, Dag Sverre Seljebotn > wrote: >> Lisandro Dalcin wrote: >> >> What happened with proto_block? From your comments I assumed you were >> going to just fold it into utility_code_proto_before_types; it seems it >> is just removed though. > >I moved required bits to 'utility_code_proto_before_types' > >> >> (Does test_numpy work with the patch?) >> > >Yes, it works... BTW, any chance you could look at these unused warnings? > >numpy_bufacc_T155.c:3693: warning: ?__Pyx_UnpackItem? defined but not used >numpy_bufacc_T155.c:3703: warning: ?__Pyx_EndUnpack? defined but not used >numpy_test.c:9951: warning: ?__Pyx_UnpackItem? defined but not used >numpy_test.c:9961: warning: ?__Pyx_EndUnpack? defined but not used > > In case all is fine, perhaps you could (ab)use INLINE to silent GCC? > > >> Next week I'll add conjugate (I'm basically done already. In that work I >> might likely also turn "x.imag = y" into "__Pyx_SET_CIMAG(x, y)". >> > >Good! BTW, how are you going to implement the setters for C99 ? > >> >> Code blocks are cheap though, no reason not to have a dozen or two >> (until we get our act together and have utility code and type >> declarations all form a DAG). >> > >If you are talking about the removing of comples proto block, my >rationale is not about having too many blocks, it is just that having >a dedicated block just for complexes seemed a bit, how to say? >complex! I still think that pushing the required bits to >'utility_code_proto_before_types' is proper and explicit enough; a >future Cython developers do not have to start asking: what might be >going on here with complex numbers that requires so special >treatement?? Of course, if you still think that the old way was >better, let me know and I'll update the patch... > >BTW, Neal, have you watched my progress? Could you give a try to my >patch? Some testing from your side and more comprensive testcases >would be great. After all, you asked for it :-), now you have it. >Plese, help me and give it a try... > > > >-- >Lisandro Dalc?n >--------------- >Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) >Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) >Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) >PTLC - G?emes 3450, (3000) Santa Fe, Argentina >Tel/Fax: +54-(0)342-451.1594 >_______________________________________________ >Cython-dev mailing list >Cython-dev at codespeak.net >http://codespeak.net/mailman/listinfo/cython-dev > From ndbecker2 at gmail.com Sat Oct 10 00:49:33 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 09 Oct 2009 18:49:33 -0400 Subject: [Cython] C++ complex support References: <3337827751.1469432@smtp.netcom.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> <4ACF85E9.2060808@student.matnat.uio.no> Message-ID: Lisandro Dalcin wrote: ... > BTW, Neal, have you watched my progress? Could you give a try to my > patch? Some testing from your side and more comprensive testcases > would be great. After all, you asked for it :-), now you have it. > Plese, help me and give it a try... > > OK, I haven't tried to pull any non-release versions yet. What do I do to get the correct source? From dalcinl at gmail.com Sat Oct 10 01:02:19 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 9 Oct 2009 20:02:19 -0300 Subject: [Cython] C++ complex support In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> <4ACF85E9.2060808@student.matnat.uio.no> Message-ID: On Fri, Oct 9, 2009 at 7:49 PM, Neal Becker wrote: > Lisandro Dalcin wrote: > > ... >> BTW, Neal, have you watched my progress? Could you give a try to my >> patch? Some testing from your side and more comprensive testcases >> would be great. After all, you asked for it :-), now you have it. >> Plese, help me and give it a try... >> >> > OK, I haven't tried to pull any non-release versions yet. ?What do I do to > get the correct source? > 1) Get the sources Option a) Clone cython-devel repo $ hg clone http://hg.cython.org/cython-devel Option b) Or get a zip/tar.gz file in case you do not have Mercurial $ wget http://hg.cython.org/cython/archive/tip.tar.gz 2) Download my patch $ wget http://trac.cython.org/cython_trac/raw-attachment/ticket/398/ccomplex.diff 3) Apply my patch a) Using 'patch': $ patch -p1 < ccomplex.diff b) Using hg import $ hg import ccomplex.diff > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From ndbecker2 at gmail.com Sat Oct 10 01:22:23 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 09 Oct 2009 19:22:23 -0400 Subject: [Cython] C++ complex support References: <3337827751.1469432@smtp.netcom.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> <4ACF85E9.2060808@student.matnat.uio.no> Message-ID: Lisandro Dalcin wrote: > On Fri, Oct 9, 2009 at 7:49 PM, Neal Becker > wrote: >> Lisandro Dalcin wrote: >> >> ... >>> BTW, Neal, have you watched my progress? Could you give a try to my >>> patch? Some testing from your side and more comprensive testcases >>> would be great. After all, you asked for it :-), now you have it. >>> Plese, help me and give it a try... >>> >>> >> OK, I haven't tried to pull any non-release versions yet. What do I do >> to get the correct source? >> > > 1) Get the sources > > Option a) Clone cython-devel repo > $ hg clone http://hg.cython.org/cython-devel > > Option b) Or get a zip/tar.gz file in case you do not have Mercurial > $ wget http://hg.cython.org/cython/archive/tip.tar.gz > > 2) Download my patch > $ wget > http://trac.cython.org/cython_trac/raw-attachment/ticket/398/ccomplex.diff > > 3) Apply my patch > > a) Using 'patch': > $ patch -p1 < ccomplex.diff > > b) Using hg import > $ hg import ccomplex.diff > Thanks. How should I run tests? Just python runtests.py? I see complex_numbers_cxx_T398.pyx, seems it needs to be tested in c++ mode. Will python runtests.py do this? (and, how could I figure this out myself?) From ndbecker2 at gmail.com Sat Oct 10 01:25:37 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 09 Oct 2009 19:25:37 -0400 Subject: [Cython] C++ complex support References: <3337827751.1469432@smtp.netcom.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> <4ACF85E9.2060808@student.matnat.uio.no> Message-ID: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for complex_numbers_T305 File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_T305.so", line 158, in complex_numbers_T305 ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_T305.so", line 172, in complex_numbers_T305 Failed example: test_div_by_zero(4j) Exception raised: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(4j) NameError: name 'test_div_by_zero' is not defined ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_T305.so", line 174, in complex_numbers_T305 Failed example: test_div_by_zero(0) Expected: Traceback (most recent call last): ... ZeroDivisionError: float division Got: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(0) NameError: name 'test_div_by_zero' is not defined ====================================================================== ERROR: Doctest: complex_numbers_T305 ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for complex_numbers_T305 File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_T305.so", line 126, in complex_numbers_T305 ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_T305.so", line 140, in complex_numbers_T305 Failed example: test_div_by_zero(4j) Exception raised: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(4j) NameError: name 'test_div_by_zero' is not defined ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_T305.so", line 142, in complex_numbers_T305 Failed example: test_div_by_zero(0) Expected: Traceback (most recent call last): ... ZeroDivisionError: float division Got: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(0) NameError: name 'test_div_by_zero' is not defined ====================================================================== ERROR: Doctest: complex_numbers_c89_T398 ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for complex_numbers_c89_T398 File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c89_T398.so", line 158, in complex_numbers_c89_T398 ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c89_T398.so", line 172, in complex_numbers_c89_T398 Failed example: test_div_by_zero(4j) Exception raised: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(4j) NameError: name 'test_div_by_zero' is not defined ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c89_T398.so", line 174, in complex_numbers_c89_T398 Failed example: test_div_by_zero(0) Expected: Traceback (most recent call last): ... ZeroDivisionError: float division Got: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(0) NameError: name 'test_div_by_zero' is not defined ====================================================================== ERROR: Doctest: complex_numbers_c89_T398 ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for complex_numbers_c89_T398 File "/home/nbecker/cython- devel/BUILD/run/cpp/complex_numbers_c89_T398.so", line 147, in complex_numbers_c89_T398 ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_c89_T398.so", line 161, in complex_numbers_c89_T398 Failed example: test_div_by_zero(4j) Exception raised: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(4j) NameError: name 'test_div_by_zero' is not defined ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_c89_T398.so", line 163, in complex_numbers_c89_T398 Failed example: test_div_by_zero(0) Expected: Traceback (most recent call last): ... ZeroDivisionError: float division Got: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(0) NameError: name 'test_div_by_zero' is not defined ====================================================================== ERROR: Doctest: complex_numbers_c99_T398 ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for complex_numbers_c99_T398 File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c99_T398.so", line 164, in complex_numbers_c99_T398 ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c99_T398.so", line 178, in complex_numbers_c99_T398 Failed example: test_div_by_zero(4j) Exception raised: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(4j) NameError: name 'test_div_by_zero' is not defined ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c99_T398.so", line 180, in complex_numbers_c99_T398 Failed example: test_div_by_zero(0) Expected: Traceback (most recent call last): ... ZeroDivisionError: float division Got: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(0) NameError: name 'test_div_by_zero' is not defined ====================================================================== ERROR: Doctest: complex_numbers_c99_T398 ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for complex_numbers_c99_T398 File "/home/nbecker/cython- devel/BUILD/run/cpp/complex_numbers_c99_T398.so", line 101, in complex_numbers_c99_T398 ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_c99_T398.so", line 115, in complex_numbers_c99_T398 Failed example: test_div_by_zero(4j) Exception raised: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(4j) NameError: name 'test_div_by_zero' is not defined ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_c99_T398.so", line 117, in complex_numbers_c99_T398 Failed example: test_div_by_zero(0) Expected: Traceback (most recent call last): ... ZeroDivisionError: float division Got: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(0) NameError: name 'test_div_by_zero' is not defined ====================================================================== ERROR: Doctest: complex_numbers_cxx_T398 ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for complex_numbers_cxx_T398 File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_cxx_T398.so", line 156, in complex_numbers_cxx_T398 ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_cxx_T398.so", line 170, in complex_numbers_cxx_T398 Failed example: test_div_by_zero(4j) Exception raised: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(4j) NameError: name 'test_div_by_zero' is not defined ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_cxx_T398.so", line 172, in complex_numbers_cxx_T398 Failed example: test_div_by_zero(0) Expected: Traceback (most recent call last): ... ZeroDivisionError: float division Got: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(0) NameError: name 'test_div_by_zero' is not defined ====================================================================== ERROR: Doctest: complex_numbers_cxx_T398 ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest raise self.failureException(self.format_failure(new.getvalue())) AssertionError: Failed doctest test for complex_numbers_cxx_T398 File "/home/nbecker/cython- devel/BUILD/run/cpp/complex_numbers_cxx_T398.so", line 102, in complex_numbers_cxx_T398 ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_cxx_T398.so", line 116, in complex_numbers_cxx_T398 Failed example: test_div_by_zero(4j) Exception raised: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(4j) NameError: name 'test_div_by_zero' is not defined ---------------------------------------------------------------------- File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_cxx_T398.so", line 118, in complex_numbers_cxx_T398 Failed example: test_div_by_zero(0) Expected: Traceback (most recent call last): ... ZeroDivisionError: float division Got: Traceback (most recent call last): File "/usr/lib64/python2.6/doctest.py", line 1231, in __run compileflags, 1) in test.globs File "", line 1, in test_div_by_zero(0) NameError: name 'test_div_by_zero' is not defined ---------------------------------------------------------------------- Ran 1782 tests in 400.060s FAILED (errors=9) From dalcinl at gmail.com Sat Oct 10 01:59:33 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 9 Oct 2009 20:59:33 -0300 Subject: [Cython] C++ complex support In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACF85E9.2060808@student.matnat.uio.no> Message-ID: I've just uploaded a patch commenting out the failing test (as it is actually unrelated to my work) On Fri, Oct 9, 2009 at 8:55 PM, Lisandro Dalcin wrote: > OK, that was my fault... wait a minute... Open > "tests/run/complex_numbers_T305.pyx" and remove the lines below from > the doctest... > > ? ?>>> test_div_by_zero(4j) > ? ?-0.25j > ? ?>>> test_div_by_zero(0) > ? ?Traceback (most recent call last): > ? ?... > ? ?ZeroDivisionError: float division > > Then you can run > > # run tests for only complex-related tickets in Cython Trac using -T. > $ python runtests.py --no-cleanup -T305 -T398 > > You could also take a look at the generated code in BUILD/run/[c/cpp] > > And yes, runtests.py test each testcase with both C and C++ ... > > > On Fri, Oct 9, 2009 at 8:25 PM, Neal Becker wrote: >> Traceback (most recent call last): >> ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest >> ? ?raise self.failureException(self.format_failure(new.getvalue())) >> AssertionError: Failed doctest test for complex_numbers_T305 >> ?File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_T305.so", >> line 158, in complex_numbers_T305 >> >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_T305.so", line >> 172, in complex_numbers_T305 >> Failed example: >> ? ?test_div_by_zero(4j) >> Exception raised: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(4j) >> ? ?NameError: name 'test_div_by_zero' is not defined >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_T305.so", line >> 174, in complex_numbers_T305 >> Failed example: >> ? ?test_div_by_zero(0) >> Expected: >> ? ?Traceback (most recent call last): >> ? ?... >> ? ?ZeroDivisionError: float division >> Got: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(0) >> ? ?NameError: name 'test_div_by_zero' is not defined >> >> >> ====================================================================== >> ERROR: Doctest: complex_numbers_T305 >> ---------------------------------------------------------------------- >> Traceback (most recent call last): >> ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest >> ? ?raise self.failureException(self.format_failure(new.getvalue())) >> AssertionError: Failed doctest test for complex_numbers_T305 >> ?File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_T305.so", >> line 126, in complex_numbers_T305 >> >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_T305.so", >> line 140, in complex_numbers_T305 >> Failed example: >> ? ?test_div_by_zero(4j) >> Exception raised: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(4j) >> ? ?NameError: name 'test_div_by_zero' is not defined >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_T305.so", >> line 142, in complex_numbers_T305 >> Failed example: >> ? ?test_div_by_zero(0) >> Expected: >> ? ?Traceback (most recent call last): >> ? ?... >> ? ?ZeroDivisionError: float division >> Got: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(0) >> ? ?NameError: name 'test_div_by_zero' is not defined >> >> >> ====================================================================== >> ERROR: Doctest: complex_numbers_c89_T398 >> ---------------------------------------------------------------------- >> Traceback (most recent call last): >> ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest >> ? ?raise self.failureException(self.format_failure(new.getvalue())) >> AssertionError: Failed doctest test for complex_numbers_c89_T398 >> ?File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c89_T398.so", >> line 158, in complex_numbers_c89_T398 >> >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c89_T398.so", >> line 172, in complex_numbers_c89_T398 >> Failed example: >> ? ?test_div_by_zero(4j) >> Exception raised: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(4j) >> ? ?NameError: name 'test_div_by_zero' is not defined >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c89_T398.so", >> line 174, in complex_numbers_c89_T398 >> Failed example: >> ? ?test_div_by_zero(0) >> Expected: >> ? ?Traceback (most recent call last): >> ? ?... >> ? ?ZeroDivisionError: float division >> Got: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(0) >> ? ?NameError: name 'test_div_by_zero' is not defined >> >> >> ====================================================================== >> ERROR: Doctest: complex_numbers_c89_T398 >> ---------------------------------------------------------------------- >> Traceback (most recent call last): >> ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest >> ? ?raise self.failureException(self.format_failure(new.getvalue())) >> AssertionError: Failed doctest test for complex_numbers_c89_T398 >> ?File "/home/nbecker/cython- >> devel/BUILD/run/cpp/complex_numbers_c89_T398.so", line 147, in >> complex_numbers_c89_T398 >> >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_c89_T398.so", >> line 161, in complex_numbers_c89_T398 >> Failed example: >> ? ?test_div_by_zero(4j) >> Exception raised: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(4j) >> ? ?NameError: name 'test_div_by_zero' is not defined >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_c89_T398.so", >> line 163, in complex_numbers_c89_T398 >> Failed example: >> ? ?test_div_by_zero(0) >> Expected: >> ? ?Traceback (most recent call last): >> ? ?... >> ? ?ZeroDivisionError: float division >> Got: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(0) >> ? ?NameError: name 'test_div_by_zero' is not defined >> >> >> ====================================================================== >> ERROR: Doctest: complex_numbers_c99_T398 >> ---------------------------------------------------------------------- >> Traceback (most recent call last): >> ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest >> ? ?raise self.failureException(self.format_failure(new.getvalue())) >> AssertionError: Failed doctest test for complex_numbers_c99_T398 >> ?File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c99_T398.so", >> line 164, in complex_numbers_c99_T398 >> >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c99_T398.so", >> line 178, in complex_numbers_c99_T398 >> Failed example: >> ? ?test_div_by_zero(4j) >> Exception raised: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(4j) >> ? ?NameError: name 'test_div_by_zero' is not defined >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c99_T398.so", >> line 180, in complex_numbers_c99_T398 >> Failed example: >> ? ?test_div_by_zero(0) >> Expected: >> ? ?Traceback (most recent call last): >> ? ?... >> ? ?ZeroDivisionError: float division >> Got: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(0) >> ? ?NameError: name 'test_div_by_zero' is not defined >> >> >> ====================================================================== >> ERROR: Doctest: complex_numbers_c99_T398 >> ---------------------------------------------------------------------- >> Traceback (most recent call last): >> ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest >> ? ?raise self.failureException(self.format_failure(new.getvalue())) >> AssertionError: Failed doctest test for complex_numbers_c99_T398 >> ?File "/home/nbecker/cython- >> devel/BUILD/run/cpp/complex_numbers_c99_T398.so", line 101, in >> complex_numbers_c99_T398 >> >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_c99_T398.so", >> line 115, in complex_numbers_c99_T398 >> Failed example: >> ? ?test_div_by_zero(4j) >> Exception raised: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(4j) >> ? ?NameError: name 'test_div_by_zero' is not defined >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_c99_T398.so", >> line 117, in complex_numbers_c99_T398 >> Failed example: >> ? ?test_div_by_zero(0) >> Expected: >> ? ?Traceback (most recent call last): >> ? ?... >> ? ?ZeroDivisionError: float division >> Got: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(0) >> ? ?NameError: name 'test_div_by_zero' is not defined >> >> >> ====================================================================== >> ERROR: Doctest: complex_numbers_cxx_T398 >> ---------------------------------------------------------------------- >> Traceback (most recent call last): >> ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest >> ? ?raise self.failureException(self.format_failure(new.getvalue())) >> AssertionError: Failed doctest test for complex_numbers_cxx_T398 >> ?File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_cxx_T398.so", >> line 156, in complex_numbers_cxx_T398 >> >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_cxx_T398.so", >> line 170, in complex_numbers_cxx_T398 >> Failed example: >> ? ?test_div_by_zero(4j) >> Exception raised: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(4j) >> ? ?NameError: name 'test_div_by_zero' is not defined >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_cxx_T398.so", >> line 172, in complex_numbers_cxx_T398 >> Failed example: >> ? ?test_div_by_zero(0) >> Expected: >> ? ?Traceback (most recent call last): >> ? ?... >> ? ?ZeroDivisionError: float division >> Got: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(0) >> ? ?NameError: name 'test_div_by_zero' is not defined >> >> >> ====================================================================== >> ERROR: Doctest: complex_numbers_cxx_T398 >> ---------------------------------------------------------------------- >> Traceback (most recent call last): >> ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest >> ? ?raise self.failureException(self.format_failure(new.getvalue())) >> AssertionError: Failed doctest test for complex_numbers_cxx_T398 >> ?File "/home/nbecker/cython- >> devel/BUILD/run/cpp/complex_numbers_cxx_T398.so", line 102, in >> complex_numbers_cxx_T398 >> >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_cxx_T398.so", >> line 116, in complex_numbers_cxx_T398 >> Failed example: >> ? ?test_div_by_zero(4j) >> Exception raised: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(4j) >> ? ?NameError: name 'test_div_by_zero' is not defined >> ---------------------------------------------------------------------- >> File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_cxx_T398.so", >> line 118, in complex_numbers_cxx_T398 >> Failed example: >> ? ?test_div_by_zero(0) >> Expected: >> ? ?Traceback (most recent call last): >> ? ?... >> ? ?ZeroDivisionError: float division >> Got: >> ? ?Traceback (most recent call last): >> ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run >> ? ? ? ?compileflags, 1) in test.globs >> ? ? ?File "", line 1, in >> ? ? ? ?test_div_by_zero(0) >> ? ?NameError: name 'test_div_by_zero' is not defined >> >> >> ---------------------------------------------------------------------- >> Ran 1782 tests in 400.060s >> >> FAILED (errors=9) >> >> >> _______________________________________________ >> Cython-dev mailing list >> Cython-dev at codespeak.net >> http://codespeak.net/mailman/listinfo/cython-dev >> > > > > -- > Lisandro Dalc?n > --------------- > Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) > Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) > Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) > PTLC - G?emes 3450, (3000) Santa Fe, Argentina > Tel/Fax: +54-(0)342-451.1594 > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Sat Oct 10 01:55:16 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 9 Oct 2009 20:55:16 -0300 Subject: [Cython] C++ complex support In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACF85E9.2060808@student.matnat.uio.no> Message-ID: OK, that was my fault... wait a minute... Open "tests/run/complex_numbers_T305.pyx" and remove the lines below from the doctest... >>> test_div_by_zero(4j) -0.25j >>> test_div_by_zero(0) Traceback (most recent call last): ... ZeroDivisionError: float division Then you can run # run tests for only complex-related tickets in Cython Trac using -T. $ python runtests.py --no-cleanup -T305 -T398 You could also take a look at the generated code in BUILD/run/[c/cpp] And yes, runtests.py test each testcase with both C and C++ ... On Fri, Oct 9, 2009 at 8:25 PM, Neal Becker wrote: > Traceback (most recent call last): > ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest > ? ?raise self.failureException(self.format_failure(new.getvalue())) > AssertionError: Failed doctest test for complex_numbers_T305 > ?File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_T305.so", > line 158, in complex_numbers_T305 > > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_T305.so", line > 172, in complex_numbers_T305 > Failed example: > ? ?test_div_by_zero(4j) > Exception raised: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(4j) > ? ?NameError: name 'test_div_by_zero' is not defined > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_T305.so", line > 174, in complex_numbers_T305 > Failed example: > ? ?test_div_by_zero(0) > Expected: > ? ?Traceback (most recent call last): > ? ?... > ? ?ZeroDivisionError: float division > Got: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(0) > ? ?NameError: name 'test_div_by_zero' is not defined > > > ====================================================================== > ERROR: Doctest: complex_numbers_T305 > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest > ? ?raise self.failureException(self.format_failure(new.getvalue())) > AssertionError: Failed doctest test for complex_numbers_T305 > ?File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_T305.so", > line 126, in complex_numbers_T305 > > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_T305.so", > line 140, in complex_numbers_T305 > Failed example: > ? ?test_div_by_zero(4j) > Exception raised: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(4j) > ? ?NameError: name 'test_div_by_zero' is not defined > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_T305.so", > line 142, in complex_numbers_T305 > Failed example: > ? ?test_div_by_zero(0) > Expected: > ? ?Traceback (most recent call last): > ? ?... > ? ?ZeroDivisionError: float division > Got: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(0) > ? ?NameError: name 'test_div_by_zero' is not defined > > > ====================================================================== > ERROR: Doctest: complex_numbers_c89_T398 > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest > ? ?raise self.failureException(self.format_failure(new.getvalue())) > AssertionError: Failed doctest test for complex_numbers_c89_T398 > ?File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c89_T398.so", > line 158, in complex_numbers_c89_T398 > > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c89_T398.so", > line 172, in complex_numbers_c89_T398 > Failed example: > ? ?test_div_by_zero(4j) > Exception raised: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(4j) > ? ?NameError: name 'test_div_by_zero' is not defined > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c89_T398.so", > line 174, in complex_numbers_c89_T398 > Failed example: > ? ?test_div_by_zero(0) > Expected: > ? ?Traceback (most recent call last): > ? ?... > ? ?ZeroDivisionError: float division > Got: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(0) > ? ?NameError: name 'test_div_by_zero' is not defined > > > ====================================================================== > ERROR: Doctest: complex_numbers_c89_T398 > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest > ? ?raise self.failureException(self.format_failure(new.getvalue())) > AssertionError: Failed doctest test for complex_numbers_c89_T398 > ?File "/home/nbecker/cython- > devel/BUILD/run/cpp/complex_numbers_c89_T398.so", line 147, in > complex_numbers_c89_T398 > > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_c89_T398.so", > line 161, in complex_numbers_c89_T398 > Failed example: > ? ?test_div_by_zero(4j) > Exception raised: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(4j) > ? ?NameError: name 'test_div_by_zero' is not defined > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_c89_T398.so", > line 163, in complex_numbers_c89_T398 > Failed example: > ? ?test_div_by_zero(0) > Expected: > ? ?Traceback (most recent call last): > ? ?... > ? ?ZeroDivisionError: float division > Got: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(0) > ? ?NameError: name 'test_div_by_zero' is not defined > > > ====================================================================== > ERROR: Doctest: complex_numbers_c99_T398 > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest > ? ?raise self.failureException(self.format_failure(new.getvalue())) > AssertionError: Failed doctest test for complex_numbers_c99_T398 > ?File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c99_T398.so", > line 164, in complex_numbers_c99_T398 > > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c99_T398.so", > line 178, in complex_numbers_c99_T398 > Failed example: > ? ?test_div_by_zero(4j) > Exception raised: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(4j) > ? ?NameError: name 'test_div_by_zero' is not defined > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_c99_T398.so", > line 180, in complex_numbers_c99_T398 > Failed example: > ? ?test_div_by_zero(0) > Expected: > ? ?Traceback (most recent call last): > ? ?... > ? ?ZeroDivisionError: float division > Got: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(0) > ? ?NameError: name 'test_div_by_zero' is not defined > > > ====================================================================== > ERROR: Doctest: complex_numbers_c99_T398 > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest > ? ?raise self.failureException(self.format_failure(new.getvalue())) > AssertionError: Failed doctest test for complex_numbers_c99_T398 > ?File "/home/nbecker/cython- > devel/BUILD/run/cpp/complex_numbers_c99_T398.so", line 101, in > complex_numbers_c99_T398 > > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_c99_T398.so", > line 115, in complex_numbers_c99_T398 > Failed example: > ? ?test_div_by_zero(4j) > Exception raised: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(4j) > ? ?NameError: name 'test_div_by_zero' is not defined > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_c99_T398.so", > line 117, in complex_numbers_c99_T398 > Failed example: > ? ?test_div_by_zero(0) > Expected: > ? ?Traceback (most recent call last): > ? ?... > ? ?ZeroDivisionError: float division > Got: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(0) > ? ?NameError: name 'test_div_by_zero' is not defined > > > ====================================================================== > ERROR: Doctest: complex_numbers_cxx_T398 > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest > ? ?raise self.failureException(self.format_failure(new.getvalue())) > AssertionError: Failed doctest test for complex_numbers_cxx_T398 > ?File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_cxx_T398.so", > line 156, in complex_numbers_cxx_T398 > > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_cxx_T398.so", > line 170, in complex_numbers_cxx_T398 > Failed example: > ? ?test_div_by_zero(4j) > Exception raised: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(4j) > ? ?NameError: name 'test_div_by_zero' is not defined > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/c/complex_numbers_cxx_T398.so", > line 172, in complex_numbers_cxx_T398 > Failed example: > ? ?test_div_by_zero(0) > Expected: > ? ?Traceback (most recent call last): > ? ?... > ? ?ZeroDivisionError: float division > Got: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(0) > ? ?NameError: name 'test_div_by_zero' is not defined > > > ====================================================================== > ERROR: Doctest: complex_numbers_cxx_T398 > ---------------------------------------------------------------------- > Traceback (most recent call last): > ?File "/usr/lib64/python2.6/doctest.py", line 2131, in runTest > ? ?raise self.failureException(self.format_failure(new.getvalue())) > AssertionError: Failed doctest test for complex_numbers_cxx_T398 > ?File "/home/nbecker/cython- > devel/BUILD/run/cpp/complex_numbers_cxx_T398.so", line 102, in > complex_numbers_cxx_T398 > > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_cxx_T398.so", > line 116, in complex_numbers_cxx_T398 > Failed example: > ? ?test_div_by_zero(4j) > Exception raised: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(4j) > ? ?NameError: name 'test_div_by_zero' is not defined > ---------------------------------------------------------------------- > File "/home/nbecker/cython-devel/BUILD/run/cpp/complex_numbers_cxx_T398.so", > line 118, in complex_numbers_cxx_T398 > Failed example: > ? ?test_div_by_zero(0) > Expected: > ? ?Traceback (most recent call last): > ? ?... > ? ?ZeroDivisionError: float division > Got: > ? ?Traceback (most recent call last): > ? ? ?File "/usr/lib64/python2.6/doctest.py", line 1231, in __run > ? ? ? ?compileflags, 1) in test.globs > ? ? ?File "", line 1, in > ? ? ? ?test_div_by_zero(0) > ? ?NameError: name 'test_div_by_zero' is not defined > > > ---------------------------------------------------------------------- > Ran 1782 tests in 400.060s > > FAILED (errors=9) > > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From greg.ewing at canterbury.ac.nz Sat Oct 10 02:22:08 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 10 Oct 2009 13:22:08 +1300 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACF599E.6060402@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> <4ACF599E.6060402@molden.no> Message-ID: <4ACFD3B0.40209@canterbury.ac.nz> Sturla Molden wrote: > Maybe it is Pyrex that don't allow pointer arithmetics? I must have > picked up that crazy idea somewhere... Pyrex won't let you write the declaration and assignment in one statement, but this is fine: cdef foo(double* data, int n, int j): cdef double* x x = data + n*j return x[0] > Will a statement like this just release and re-acquire the GIL? > > with nogil: > pass Yes, that should work, I think. Pyrex generates this for it: /*with nogil:*/ { PyThreadState *_save; Py_UNBLOCK_THREADS /*try:*/ { } /*finally:*/ { Py_BLOCK_THREADS } -- Greg From dalcinl at gmail.com Sat Oct 10 02:54:43 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 9 Oct 2009 21:54:43 -0300 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACFD3B0.40209@canterbury.ac.nz> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> <4ACF599E.6060402@molden.no> <4ACFD3B0.40209@canterbury.ac.nz> Message-ID: On Fri, Oct 9, 2009 at 9:22 PM, Greg Ewing wrote: > > Pyrex won't let you write the declaration and assignment > in one statement, but this is fine: > Greg, could you explain me why this is the case with Pyrex? Just lack of time to implement it? Or are you against this feature? -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From greg.ewing at canterbury.ac.nz Sat Oct 10 03:02:54 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 10 Oct 2009 14:02:54 +1300 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> <4ACF599E.6060402@molden.no> <4ACFD3B0.40209@canterbury.ac.nz> Message-ID: <4ACFDD3E.2090304@canterbury.ac.nz> Lisandro Dalcin wrote: > Greg, could you explain me why this is the case with Pyrex? Just lack > of time to implement it? Or are you against this feature? I'm not against it, but I never thought of it as something that was particularly important to have, so I never bothered with it. There were much more important things to be worked on (and there still are). -- Greg From ndbecker2 at gmail.com Sat Oct 10 13:13:02 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 10 Oct 2009 07:13:02 -0400 Subject: [Cython] C++ complex support References: <3337827751.1469432@smtp.netcom.no> <4ACF85E9.2060808@student.matnat.uio.no> Message-ID: Probably not related to complex, but I get: ====================================================================== ERROR: compiling (cpp) cpp_exceptions_T265 ---------------------------------------------------------------------- Traceback (most recent call last): File "runtests.py", line 243, in runTest self.runCompileTest() File "runtests.py", line 247, in runCompileTest self.directory, self.expect_errors, self.annotate) File "runtests.py", line 338, in compile self.run_cython(directory, module, workdir, incdir, annotate) File "runtests.py", line 296, in run_cython full_module_name=module) File "/home/nbecker/cython-devel/Cython/Compiler/Main.py", line 733, in compile return compile_single(source, options, full_module_name) File "/home/nbecker/cython-devel/Cython/Compiler/Main.py", line 678, in compile_single return run_pipeline(source, options, full_module_name) File "/home/nbecker/cython-devel/Cython/Compiler/Main.py", line 566, in run_pipeline err, enddata = context.run_pipeline(pipeline, source) File "/home/nbecker/cython-devel/Cython/Compiler/Main.py", line 217, in run_pipeline data = phase(data) File "/home/nbecker/cython-devel/Cython/Compiler/Main.py", line 150, in generate_pyx_code module_node.process_implementation(options, result) File "/home/nbecker/cython-devel/Cython/Compiler/ModuleNode.py", line 72, in process_implementation self.generate_c_code(env, options, result) File "/home/nbecker/cython-devel/Cython/Compiler/ModuleNode.py", line 274, in generate_c_code self.body.generate_function_definitions(env, code) File "/home/nbecker/cython-devel/Cython/Compiler/Nodes.py", line 341, in generate_function_definitions stat.generate_function_definitions(env, code) File "/home/nbecker/cython-devel/Cython/Compiler/Nodes.py", line 1112, in generate_function_definitions self.body.generate_execution_code(code) File "/home/nbecker/cython-devel/Cython/Compiler/Nodes.py", line 347, in generate_execution_code stat.generate_execution_code(code) File "/home/nbecker/cython-devel/Cython/Compiler/Nodes.py", line 2834, in generate_execution_code self.expr.generate_evaluation_code(code) File "/home/nbecker/cython-devel/Cython/Compiler/ExprNodes.py", line 440, in generate_evaluation_code self.generate_result_code(code) File "/home/nbecker/cython-devel/Cython/Compiler/ExprNodes.py", line 2480, in generate_result_code elif func_type.exception_value.type.is_pyobject: AttributeError: 'unicode' object has no attribute 'type' Lisandro Dalcin wrote: > I've just uploaded a patch commenting out the failing test (as it is > actually unrelated to my work) > Where would I find that patch? From stefan_ml at behnel.de Fri Oct 9 19:56:33 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 09 Oct 2009 19:56:33 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACF599E.6060402@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> <4ACF599E.6060402@molden.no> Message-ID: <4ACF7951.8020505@behnel.de> Sturla Molden wrote: > The problem is that keeping the GIL locked make the interpreter > unresponsive. This can be a problem for numerical code. You could potentially use a more finegrained lock (e.g. at an array object level, maybe using a weak hash table) and just free the GIL around the array access. But you'll have to manage that manually then. And it's certainly more work and more overhead than with the GIL. > Will a statement like this just release and re-acquire the GIL? > > with nogil: > pass Yes. It would be a bug if Cython or the C compiler ever droped code that may have side-effects, which is certainly the case here. >> In any case, for arrays of decent size, actually processing each >> element in an array is typically much more expensive than the single >> slicing step. Optimization is not about just removing inefficiency, >> it's about removing the inefficiency in the parts of your code where >> you spend 90% of your time. This is typically the inner loop, where I >> hope slicing isn't happening. >> > The C function I posted is called thousands of times... Using ndarrays > as arguments was not an option. But numerical code is cleaner and easier > to read with array objects (a la Fortran) than C pointers. We can talk about overloading the signature of functions that receive buffer objects and that only a) access the buffer itself, b) use its attributes and/or c) pass it on into other functions. Assigning the buffer object to global variables is straight out. Such a function would then additionally accept a plain Py_buffer, i.e. cdef some_func(object[int, 2] b, x,y,z): for i in range(b.shape(0)): b[i,0] = 1 would result in a C function cdef some_func(Py_buffer b, x,y,z): (potentially declared nogil, never mind the syntax), and a wrapper function cdef some_func(object[int, 2] b, x,y,z): that calls the first after extracting the buffer. That wouldn't immediately fix the issue of slicing, but at least it would reduce any Python overhead in calling such a function. It wouldn't break ref-counting either, since we know that one of the functions on the call stack holds a reference to the buffer during the call. And it could even be extended to support slicing by internally creating a new (stack allocated) Py_buffer that holds the right memory layout for the slice. It's not like anything of this is really strictly impossible, it just takes time to think through and then time to implement. Stefan From dagss at student.matnat.uio.no Sat Oct 10 14:42:51 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 10 Oct 2009 14:42:51 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACF7951.8020505@behnel.de> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> <4ACF599E.6060402@molden.no> <4ACF7951.8020505@behnel.de> Message-ID: <4AD0814B.8010303@student.matnat.uio.no> Stefan Behnel wrote: > Sturla Molden wrote: > >> The problem is that keeping the GIL locked make the interpreter >> unresponsive. This can be a problem for numerical code. >> > > You could potentially use a more finegrained lock (e.g. at an array object > level, maybe using a weak hash table) and just free the GIL around the > array access. But you'll have to manage that manually then. And it's > certainly more work and more overhead than with the GIL. > > > >> Will a statement like this just release and re-acquire the GIL? >> >> with nogil: >> pass >> > > Yes. It would be a bug if Cython or the C compiler ever droped code that > may have side-effects, which is certainly the case here. > > > >>> In any case, for arrays of decent size, actually processing each >>> element in an array is typically much more expensive than the single >>> slicing step. Optimization is not about just removing inefficiency, >>> it's about removing the inefficiency in the parts of your code where >>> you spend 90% of your time. This is typically the inner loop, where I >>> hope slicing isn't happening. >>> >>> >> The C function I posted is called thousands of times... Using ndarrays >> as arguments was not an option. But numerical code is cleaner and easier >> to read with array objects (a la Fortran) than C pointers. >> > > We can talk about overloading the signature of functions that receive > buffer objects and that only a) access the buffer itself, b) use its > attributes and/or c) pass it on into other functions. Assigning the buffer > object to global variables is straight out. > > Such a function would then additionally accept a plain Py_buffer, i.e. > > cdef some_func(object[int, 2] b, x,y,z): > for i in range(b.shape(0)): > b[i,0] = 1 > > would result in a C function > > cdef some_func(Py_buffer b, x,y,z): > > (potentially declared nogil, never mind the syntax), and a wrapper function > > cdef some_func(object[int, 2] b, x,y,z): > > that calls the first after extracting the buffer. > > That wouldn't immediately fix the issue of slicing, but at least it would > reduce any Python overhead in calling such a function. It wouldn't break > ref-counting either, since we know that one of the functions on the call > stack holds a reference to the buffer during the call. > > And it could even be extended to support slicing by internally creating a > new (stack allocated) Py_buffer that holds the right memory layout for the > slice. > > It's not like anything of this is really strictly impossible, it just takes > time to think through and then time to implement. > Exactly what you describe above is what's been planned for half a year and which Kurt gave a start on in summer :-) Dag Sverre From sccolbert at gmail.com Sat Oct 10 16:27:52 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Sat, 10 Oct 2009 16:27:52 +0200 Subject: [Cython] are numpy arrays automatically passed by reference? Message-ID: <7f014ea60910100727i29f36306h5835a20278a03cc0@mail.gmail.com> for example if I have something like this: cimport numpy as np cdef void foo(np.ndarray arr): def bar(np.ndarray arr): foo(arr) is arr getting passed by value or by reference? When I wrap other C libraries, I have to do a foo(&cobject) to pass cobject by reference and have foo defined as: cdef foo(somectype* cobject): cobject.intvalue = 3 The reason I ask is because even though i'm not explicity passing the numpy arrays by reference, I can still access the struct memember via dotted notation (arr.strides[2] for example). Since Cython doesnt have a -> operator, its not exactly clear what is going on here in this situation. Cheers! Chris From dagss at student.matnat.uio.no Sat Oct 10 16:38:14 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 10 Oct 2009 16:38:14 +0200 Subject: [Cython] are numpy arrays automatically passed by reference? In-Reply-To: <7f014ea60910100727i29f36306h5835a20278a03cc0@mail.gmail.com> References: <7f014ea60910100727i29f36306h5835a20278a03cc0@mail.gmail.com> Message-ID: <4AD09C56.1000807@student.matnat.uio.no> Chris Colbert wrote: > for example if I have something like this: > > cimport numpy as np > > cdef void foo(np.ndarray arr): > > > > def bar(np.ndarray arr): > foo(arr) > > > is arr getting passed by value or by reference? > It's passed like any Python object, which is to say, by reference. Python objects are *always* passed by reference. > When I wrap other C libraries, I have to do a foo(&cobject) to pass > cobject by reference and have foo defined as: > > cdef foo(somectype* cobject): > cobject.intvalue = 3 > > > The reason I ask is because even though i'm not explicity passing the > numpy arrays by reference, I can still access the struct memember via > dotted notation (arr.strides[2] for example). Since Cython doesnt have > a -> operator, its not exactly clear what is going on here in this > situation. > Cython translates x.y to -> when x is either a typed Python extension type or a pointer, and keeps it as "." for a struct. This is less than ideal for speaking with C++ but keep in mind that Cython/Pyrex was designed for C where this simplification could be made. Dag Sverre From sccolbert at gmail.com Sat Oct 10 16:52:03 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Sat, 10 Oct 2009 16:52:03 +0200 Subject: [Cython] are numpy arrays automatically passed by reference? In-Reply-To: <4AD09C56.1000807@student.matnat.uio.no> References: <7f014ea60910100727i29f36306h5835a20278a03cc0@mail.gmail.com> <4AD09C56.1000807@student.matnat.uio.no> Message-ID: <7f014ea60910100752g334a22dx4746fd889d1cdc61@mail.gmail.com> Thanks for the clarification Dag. Cheers! On Sat, Oct 10, 2009 at 4:38 PM, Dag Sverre Seljebotn wrote: > Chris Colbert wrote: >> for example if I have something like this: >> >> cimport numpy as np >> >> cdef void foo(np.ndarray arr): >> ? ? ? ? ? ? >> >> >> def bar(np.ndarray arr): >> ? ? ? ?foo(arr) >> >> >> is arr getting passed by value or by reference? >> > It's passed like any Python object, which is to say, by reference. > Python objects are *always* passed by reference. > >> When I wrap other C libraries, I have to do a ?foo(&cobject) ?to pass >> cobject by reference and have foo defined as: >> >> cdef foo(somectype* cobject): >> ? ? ? ? cobject.intvalue = 3 >> >> >> The reason I ask is because even though i'm not explicity passing the >> numpy arrays by reference, I can still access the struct memember via >> dotted notation (arr.strides[2] for example). Since Cython doesnt have >> a -> operator, its not exactly clear what is going on here in this >> situation. >> > Cython translates x.y to -> when x is either a typed Python extension > type or a pointer, and keeps it as "." for a struct. This is less than > ideal for speaking with C++ but keep in mind that Cython/Pyrex was > designed for C where this simplification could be made. > > Dag Sverre > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > From stefan_ml at behnel.de Sat Oct 10 17:15:40 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 10 Oct 2009 17:15:40 +0200 Subject: [Cython] CEP 108: bytes/str/unicode Message-ID: <4AD0A51C.3060106@behnel.de> Hi, I implemented the string CEP 108. http://wiki.cython.org/enhancements/stringliterals According to the tests, it looks good so far. I'll push the final fixes to cython-devel as soon as it's back online. One thing I changed was that you can assign a str literal to both char* and bytes, i.e. cdef char* s = "abc" cdef bytes b = "abc" will both work. I think that makes sense, given that char* and bytes are mostly equivalent otherwise. This only regards compile-time coerced literals, so you still cannot assign cdef str s = "abc" cdef bytes b = s # ERROR! which depends on runtime semantics. Also, cdef unicode u = "abc" # ERROR! is prohibited. You must use a unicode literal here. Any comments on this change? Stefan From sccolbert at gmail.com Sat Oct 10 17:42:12 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Sat, 10 Oct 2009 17:42:12 +0200 Subject: [Cython] the cython.org site appears to be down.. Message-ID: <7f014ea60910100842g514dfae7hccd73ae2e7ef0499@mail.gmail.com> I can't connect from germany. just an FYI Cheers, Chris From dalcinl at gmail.com Sat Oct 10 17:49:26 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sat, 10 Oct 2009 12:49:26 -0300 Subject: [Cython] CEP 108: bytes/str/unicode In-Reply-To: <4AD0A51C.3060106@behnel.de> References: <4AD0A51C.3060106@behnel.de> Message-ID: On Sat, Oct 10, 2009 at 12:15 PM, Stefan Behnel wrote: > Hi, > > I implemented the string CEP 108. > > http://wiki.cython.org/enhancements/stringliterals > Great! > According to the tests, it looks good so far. I'll push the final fixes to > cython-devel as soon as it's back online. > > One thing I changed was that you can assign a str literal to both char* and > bytes, i.e. > > ? ? ? ?cdef char* s = "abc" > ? ? ? ?cdef bytes b = "abc" > > will both work. I think that makes sense, given that char* and bytes are > mostly equivalent otherwise. Mmm... Perhaps you could start by requiring an explicit 'b' prefix? cdef bytes a = b"xyz" # OK cdef bytes b = "xyz" # ERROR We can relax this later (or just ignore this comment) if this restriction does not make sense... > This only regards compile-time coerced > literals, so you still cannot assign > > ? ? ? ?cdef str s = "abc" > ? ? ? ?cdef bytes b = s ? ? ?# ERROR! > That would be an error at Cython compile-time, right? In such case, of course +1. > which depends on runtime semantics. Also, > > ? ? ? ?cdef unicode u = "abc" ?# ERROR! > > is prohibited. You must use a unicode literal here. > Fine, does make sense. Explicit is better than implicit (that's the reason I've asked for an explicit 'b' prefix when the target type is 'bytes'). > Any comments on this change? > > Stefan > How things will work in the case of "from __future__ import unicode_literals" ?? (I cannot currently access the CEP, perhaps the answer is there, in such case do not waste your time explaining it here.) > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dagss at student.matnat.uio.no Sat Oct 10 17:59:47 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 10 Oct 2009 17:59:47 +0200 Subject: [Cython] the cython.org site appears to be down.. In-Reply-To: <7f014ea60910100842g514dfae7hccd73ae2e7ef0499@mail.gmail.com> References: <7f014ea60910100842g514dfae7hccd73ae2e7ef0499@mail.gmail.com> Message-ID: <4AD0AF73.30001@student.matnat.uio.no> Chris Colbert wrote: > I can't connect from germany. This is planned downtime, see previous posts by William Stein. -- Dag Sverre From dalcinl at gmail.com Sat Oct 10 18:01:33 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sat, 10 Oct 2009 13:01:33 -0300 Subject: [Cython] C++ complex support In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACF85E9.2060808@student.matnat.uio.no> Message-ID: On Sat, Oct 10, 2009 at 8:13 AM, Neal Becker wrote: > Probably not related to complex, but I get: > > ====================================================================== > ERROR: compiling (cpp) cpp_exceptions_T265 > ---------------------------------------------------------------------- > ....... > ? ?elif func_type.exception_value.type.is_pyobject: > AttributeError: 'unicode' object has no attribute 'type' > Yes, that test also fails here... > Lisandro Dalcin wrote: > >> I've just uploaded a patch commenting out the failing test (as it is >> actually unrelated to my work) >> > Where would I find that patch? > In the same location as before (I've replaced the old file with the updated one) http://trac.cython.org/cython_trac/raw-attachment/ticket/398/ccomplex.diff However, it seems that the server it's still down... Remember that running like this: $ python runtests.py --no-cleanup -T305 -T398 you will only run the complex-related test cases (relevant trac tickets #305 and #398)... And the generated code will be left (because of the --no-cleanup option) in "BUILD/run/c" and "BUILD/run/cpp" -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From stefan_ml at behnel.de Sat Oct 10 18:11:51 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 10 Oct 2009 18:11:51 +0200 Subject: [Cython] CEP 108: bytes/str/unicode In-Reply-To: References: <4AD0A51C.3060106@behnel.de> Message-ID: <4AD0B247.1050602@behnel.de> Lisandro Dalcin wrote: > On Sat, Oct 10, 2009 at 12:15 PM, Stefan Behnel wrote: >> I implemented the string CEP 108. >> >> One thing I changed was that you can assign a str literal to both char* and >> bytes, i.e. >> >> cdef char* s = "abc" >> cdef bytes b = "abc" >> >> will both work. I think that makes sense, given that char* and bytes are >> mostly equivalent otherwise. > > Mmm... Perhaps you could start by requiring an explicit 'b' prefix? > > cdef bytes a = b"xyz" # OK > cdef bytes b = "xyz" # ERROR > > We can relax this later (or just ignore this comment) if this > restriction does not make sense... It's not that it doesn't make sense, it's rather a case that (IMHO) has an equilibrium of pros and cons. For example, you can do cdef char* c = "abc" cdef bytes b1 = c cdef bytes b2 = "abc" but you can't do cdef bytes b = "abc" It's easy to argue that the latter is a Python literal, sure, and that makes me +0 for denying it. Also because s = "abc" will actually give you a str object. > How things will work in the case of "from __future__ import > unicode_literals" ?? The CEP doesn't mention it, but that's just because there isn't any impact. If you request unicode literals, you get them. That's handled in the parser. Stefan From dalcinl at gmail.com Sat Oct 10 19:21:06 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sat, 10 Oct 2009 14:21:06 -0300 Subject: [Cython] CEP 108: bytes/str/unicode In-Reply-To: <4AD0B247.1050602@behnel.de> References: <4AD0A51C.3060106@behnel.de> <4AD0B247.1050602@behnel.de> Message-ID: On Sat, Oct 10, 2009 at 1:11 PM, Stefan Behnel wrote: > > It's not that it doesn't make sense, it's rather a case that (IMHO) has an > equilibrium of pros and cons. For example, you can do > > ? ? ? ?cdef char* c = "abc" > ? ? ? ?cdef bytes b1 = c > ? ? ? ?cdef bytes b2 = "abc" > > but you can't do > > ? ? ? ?cdef bytes b = "abc" > > It's easy to argue that the latter is a Python literal, sure, and that > makes me +0 for denying it. Yes, it is a Py string literal, but what KIND of string literal? We have three kinds of litelals: b"abc", a bare "abc", and u"abc" ... > Also because > > ? ? ? ?s = "abc" > > will actually give you a str object. > That's the behavior that I always advocated: an unprefixed literal will get the "default" Python-level 'str' type in both Py2/Py3 ... However, if the user uses explicit 'bytes' or 'unicode' types, then I assume she knows what she is doing and has a reason to make such explicit typing, and then she should not be bothered to explicitly specify the KIND ('b' or 'u') of the literal... Please note that this is just FUD from my side and I'm not sure at all that if such strictness is actually a good idea... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From wstein at gmail.com Sat Oct 10 19:38:56 2009 From: wstein at gmail.com (William Stein) Date: Sat, 10 Oct 2009 10:38:56 -0700 Subject: [Cython] the cython.org site appears to be down.. In-Reply-To: <4AD0AF73.30001@student.matnat.uio.no> References: <7f014ea60910100842g514dfae7hccd73ae2e7ef0499@mail.gmail.com> <4AD0AF73.30001@student.matnat.uio.no> Message-ID: <85e81ba30910101038p195d988ci21823b5295346e45@mail.gmail.com> On Sat, Oct 10, 2009 at 8:59 AM, Dag Sverre Seljebotn wrote: > Chris Colbert wrote: >> I can't connect from germany. > > This is planned downtime, see previous posts by William Stein. > Everything should be back up now. Please report any future issues. William From robertwb at math.washington.edu Sat Oct 10 19:50:34 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 10 Oct 2009 10:50:34 -0700 Subject: [Cython] CEP 108: bytes/str/unicode In-Reply-To: <4AD0A51C.3060106@behnel.de> References: <4AD0A51C.3060106@behnel.de> Message-ID: <8AD2B35D-F666-48CA-9B9B-527448670E3B@math.washington.edu> On Oct 10, 2009, at 8:15 AM, Stefan Behnel wrote: > Hi, > > I implemented the string CEP 108. > > http://wiki.cython.org/enhancements/stringliterals > > According to the tests, it looks good so far. I'll push the final > fixes to > cython-devel as soon as it's back online. Excellent, thanks! > One thing I changed was that you can assign a str literal to both > char* and > bytes, i.e. > > cdef char* s = "abc" > cdef bytes b = "abc" > > will both work. I think that makes sense, given that char* and bytes > are > mostly equivalent otherwise. This only regards compile-time coerced > literals, Sounds good to me. - Robert From robertwb at math.washington.edu Sat Oct 10 20:42:31 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 10 Oct 2009 11:42:31 -0700 Subject: [Cython] C++ complex support In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> Message-ID: <04848F2D-2131-468E-BAB1-DD3575D5678F@math.washington.edu> On Oct 9, 2009, at 11:03 AM, Lisandro Dalcin wrote: > On Fri, Oct 9, 2009 at 2:16 PM, Robert Bradshaw > wrote: >> >>>> - In the @cython.cdivision(False) we should *not* be raising a >>>> ZeroDivisionError, we should only be raising it if cython.cdivision >>>> is True. >>>> >>> >>> Well, I just hotfixed the test to make it pass... Now the patch has >>> some XXX comments... I do not know what's going on, but the zero- >>> test >>> and raising is never generated... >> >> Sorry, I was thinking backwards. Yes, we should be raising a warning >> here. >> >> You can just comment out this patch and I'll worry about fixing it. >> > > Done. New patch uploaded. > > Do you think the patch is good enough to push? Yes. Thanks for doing this! Please push. - Robert From stefan_ml at behnel.de Sat Oct 10 21:48:06 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 10 Oct 2009 21:48:06 +0200 Subject: [Cython] CEP 108: bytes/str/unicode In-Reply-To: References: <4AD0A51C.3060106@behnel.de> <4AD0B247.1050602@behnel.de> Message-ID: <4AD0E4F6.80802@behnel.de> Lisandro Dalcin wrote: > On Sat, Oct 10, 2009 at 1:11 PM, Stefan Behnel wrote: >> It's not that it doesn't make sense, it's rather a case that (IMHO) has an >> equilibrium of pros and cons. For example, you can do >> >> cdef char* c = "abc" >> cdef bytes b1 = c >> cdef bytes b2 = "abc" >> >> but you can't do >> >> cdef bytes b = "abc" >[...] > an unprefixed literal > will get the "default" Python-level 'str' type in both Py2/Py3 ... > However, if the user uses explicit 'bytes' or 'unicode' types, then I > assume she knows what she is doing and has a reason to make such > explicit typing, and then she should not be bothered to explicitly > specify the KIND ('b' or 'u') of the literal... I think it's easier to remove this little feature for now. We can always put it back in for a 0.12.1, it's just three lines (commented out in StringNode). After such a fundamental change between 0.11 and 0.12, I think it's better to start off strict, so that users become aware of the change and can adapt their code. Much better than being too forgiving and allowing things that break even more stuff when we realise it was not a good idea. I pushed my remaining changes. Please give it some testing, so that we can all get an idea about how much it breaks and what can be improved. Stefan From sturla at molden.no Sat Oct 10 23:45:36 2009 From: sturla at molden.no (Sturla Molden) Date: Sat, 10 Oct 2009 23:45:36 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACF7951.8020505@behnel.de> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> <4ACF599E.6060402@molden.no> <4ACF7951.8020505@behnel.de> Message-ID: <4AD10080.3070200@molden.no> Stefan Behnel skrev: > cdef some_func(object[int, 2] b, x,y,z): > that calls the first after extracting the buffer. > > That wouldn't immediately fix the issue of slicing, but at least it would > reduce any Python overhead in calling such a function. It wouldn't break > ref-counting either, since we know that one of the functions on the call > stack holds a reference to the buffer during the call. Are you sure it would work? What if somesone does a "del b" in some_func? If you do not incref b before calling the function, what would a del do to the refcount? From sturla at molden.no Sat Oct 10 23:48:13 2009 From: sturla at molden.no (Sturla Molden) Date: Sat, 10 Oct 2009 23:48:13 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF55A8.8030503@molden.no> Message-ID: <4AD1011D.4070007@molden.no> Lisandro Dalcin skrev: > For example, for release 0.11.3 I wrote at rather important patch > (well, at least for me) for handling C integral types, now I'm working > on better support for c99/c++ complexes... All this requires testting, > review, and others playing of devil's advocates to stress my work to > the limits (in correctness, completeness, and usability)... All this > is almost entirely low-level C programing and Python C-API... I would > love my patches to receive you review. > > In short, you do not need to have knowledge about compiler technology > to make very valuable contributions... > > For example: write a cdef class with cdef object members and > __dealloc__ method, this class should be GC-tracked... Now look > carefully at the generated C-code, particularly the deallocation chain > and the refcounting hackery... Could you provide some comments about > if all this is correct? Something smells bad in my nose... > > > These are things I probably could help out with. S.M. From ndbecker2 at gmail.com Sun Oct 11 01:48:31 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 10 Oct 2009 19:48:31 -0400 Subject: [Cython] complex performance issue? Message-ID: I expected this code to be efficient, and wanted to see what c++ code it produced: def test3 (np.ndarray[np.complex128_t, ndim=1] in1): cdef int xmax = in1.shape[0] for i in range (xmax): in1[i].imag = 0 /* "/home/nbecker/raysat/mod/test2.pyx":27 * cdef int xmax = in1.shape[0] * for i in range (xmax): * in1[i].imag = 0 # <<<<<<<<<<<<<< * */ __pyx_t_2 = PyObject_GetItem(__pyx_v_in1, __pyx_v_i); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyObject_SetAttr(__pyx_t_2, __pyx_n_ui_imag, __pyx_int_0) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } ... Looks to me like it's using 'SetAttr' to set the .imag value. Not good. From dagss at student.matnat.uio.no Sun Oct 11 05:58:00 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: 11 Oct 2009 05:58:00 +0200 Subject: [Cython] complex performance issue? Message-ID: <3338085523.27270@smtp.netcom.no> you need to type I. Dag Sverre Seljebotn -----Original Message----- From: Neal Becker Date: Sunday, Oct 11, 2009 1:49 am Subject: [Cython] complex performance issue? To: cython-dev at codespeak.netReply-To: cython-dev at codespeak.net I expected this code to be efficient, and wanted to see what c++ code it >produced: > >def test3 (np.ndarray[np.complex128_t, ndim=1] in1): > cdef int xmax = in1.shape[0] > for i in range (xmax): > in1[i].imag = 0 > > /* "/home/nbecker/raysat/mod/test2.pyx":27 > * cdef int xmax = in1.shape[0] > * for i in range (xmax): > * in1[i].imag = 0 # <<<<<<<<<<<<<< > * > */ > __pyx_t_2 = PyObject_GetItem(__pyx_v_in1, __pyx_v_i); if (!__pyx_t_2) >{__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; >goto __pyx_L1_error;} > __Pyx_GOTREF(__pyx_t_2); > if (PyObject_SetAttr(__pyx_t_2, __pyx_n_ui_imag, __pyx_int_0) < 0) >{__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; >goto __pyx_L1_error;} > __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; > } > >... > >Looks to me like it's using 'SetAttr' to set the .imag value. Not good. > > > >_______________________________________________ >Cython-dev mailing list >Cython-dev at codespeak.net >http://codespeak.net/mailman/listinfo/cython-dev > From dagss at student.matnat.uio.no Sun Oct 11 08:23:00 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: 11 Oct 2009 08:23:00 +0200 Subject: [Cython] complex performance issue? Message-ID: <3338094184.45029@smtp.netcom.no> sorry... I meant, type "i". Dag Sverre Seljebotn -----Original Message----- From: "Dag Sverre Seljebotn" Date: Sunday, Oct 11, 2009 5:59 am Subject: Re: [Cython] complex performance issue? To: CC: Reply-To: cython-dev at codespeak.net you need to type I. > >Dag Sverre Seljebotn >-----Original Message----- >From: Neal Becker >Date: Sunday, Oct 11, 2009 1:49 am >Subject: [Cython] complex performance issue? >To: cython-dev at codespeak.netReply-To: cython-dev at codespeak.net > >I expected this code to be efficient, and wanted to see what c++ code it >produced: > >>def test3 (np.ndarray[np.complex128_t, ndim=1] in1): > cdef int xmax = in1.shape[0] > for i in range (xmax): > in1[i].imag = 0 > >> /* "/home/nbecker/raysat/mod/test2.pyx":27 > * cdef int xmax = in1.shape[0] > * for i in range (xmax): > * in1[i].imag = 0 # <<<<<<<<<<<<<< > * > */ > __pyx_t_2 = PyObject_GetItem(__pyx_v_in1, __pyx_v_i); if (!__pyx_t_2) >{__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; >goto __pyx_L1_error;} > __Pyx_GOTREF(__pyx_t_2); > if (PyObject_SetAttr(__pyx_t_2, __pyx_n_ui_imag, __pyx_int_0) < 0) >{__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; __pyx_clineno = __LINE__; >goto __pyx_L1_error;} > __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; > } > >>... > >>Looks to me like it's using 'SetAttr' to set the .imag value. Not good. > >> > >>_______________________________________________ >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 > From stefan_ml at behnel.de Sun Oct 11 09:10:10 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 11 Oct 2009 09:10:10 +0200 Subject: [Cython] the cython.org site appears to be down.. In-Reply-To: <85e81ba30910101038p195d988ci21823b5295346e45@mail.gmail.com> References: <7f014ea60910100842g514dfae7hccd73ae2e7ef0499@mail.gmail.com> <4AD0AF73.30001@student.matnat.uio.no> <85e81ba30910101038p195d988ci21823b5295346e45@mail.gmail.com> Message-ID: <4AD184D2.1030105@behnel.de> William Stein wrote: > Everything should be back up now. Please report any future issues. The Cython Wiki seems to have disappeared from DNS: $ ping wiki.cython.org ping: unknown host wiki.cython.org $ nslookup wiki.cython.org ... ** server can't find wiki.cython.org: NXDOMAIN It only works when I override the IP in /etc/hosts. Stefan From wstein at gmail.com Sun Oct 11 09:16:25 2009 From: wstein at gmail.com (William Stein) Date: Sun, 11 Oct 2009 00:16:25 -0700 Subject: [Cython] the cython.org site appears to be down.. In-Reply-To: <4AD184D2.1030105@behnel.de> References: <7f014ea60910100842g514dfae7hccd73ae2e7ef0499@mail.gmail.com> <4AD0AF73.30001@student.matnat.uio.no> <85e81ba30910101038p195d988ci21823b5295346e45@mail.gmail.com> <4AD184D2.1030105@behnel.de> Message-ID: <85e81ba30910110016s59a0b085j44cc2b9e5dc5e59@mail.gmail.com> On Sun, Oct 11, 2009 at 12:10 AM, Stefan Behnel wrote: > > William Stein wrote: >> Everything should be back up now. ?Please report any future issues. > > The Cython Wiki seems to have disappeared from DNS: > > ?$ ping wiki.cython.org > ?ping: unknown host wiki.cython.org > ?$ nslookup wiki.cython.org > ?... > ?** server can't find wiki.cython.org: NXDOMAIN > > It only works when I override the IP in /etc/hosts. > > Stefan Thanks for reporting this. Unfortunately, there is nothing I can do about it, since I don't see the same problem: flat:~ wstein$ nslookup wiki.cython.org Server: 10.0.1.1 Address: 10.0.1.1#53 Non-authoritative answer: wiki.cython.org canonical name = cython.org. Name: cython.org Address: 128.208.160.197 wstein at sage:~$ nslookup wiki.cython.org Server: 128.95.120.1 Address: 128.95.120.1#53 Non-authoritative answer: wiki.cython.org canonical name = cython.org. Name: cython.org Address: 128.208.160.197 ... and I have no idea what could cause what you see except that it might just take a certain amount of time for your DNS to get updated? William From stefan_ml at behnel.de Sun Oct 11 09:52:48 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 11 Oct 2009 09:52:48 +0200 Subject: [Cython] CEP 108: bytes/str/unicode - handling encoding issues In-Reply-To: <4AD0A51C.3060106@behnel.de> References: <4AD0A51C.3060106@behnel.de> Message-ID: <4AD18ED0.9070908@behnel.de> Hi again, I just added a section to the CEP about encoding issues. Any comments on the solution (last paragraph) below? Stefan """ === Encoding === Letting non-identifier (i.e. non-ASCII) strings switch their type at runtime introduces various issues with encodings. Following PEP 3120, the default source code encoding in Cython is UTF-8, and users can override this encoding as described in PEP 263. Problems arise when users enter plain strings containing escaped characters that are not representable in the current source code encoding. In this case, there is no way to determine what bytes should be used in the Python 2 byte string. Example: {{{ # encoding: ASCII b = b'abc\xFF' s = 'abc\xFF' u = u'abc\xFF' }}} Both the byte string (b) and the unicode string (u) have well defined content. If {{{\xFF}}} is interpreted as byte value, the str value (s) has well defined byte content in Python 2, but it does not have a meaningful content under Python 3, as there is no indication on how to interpret {{{\xFF}}} as a unicode character. If, on the other hand, {{{\xFF}}} is interpreted as unicode character value, the str value becomes well defined in Python 3, but cannot be represented as a byte sequence in Python 2. Depending on whether the string is read as unicode string or byte string by the parser, further issues can arise. Imagine this case: {{{ #encoding: UTF-8 s = 'abc\xFF' }}} If {{{\xFF}} is interpreted as byte sequence here, the string cannot be decoded as UTF-8. If it is interpreted as a unicode character, i.e. the string is read as a unicode string, the character can be encoded to UTF-8 to result in a valid two byte sequence. However, it is not clear if this is what a user expects. Also, Python 2.6 reads the above string as a four byte string, not a five byte UTF-8 string. The only obvious way to prevent both confusion and runtime errors is to disallow unprefixed strings that cannot be decoded under the current source code encoding. Following Python 2 string semantics, Cython will therefore read {{{str}}} literals as byte strings, and then try to decode them using the source code encoding at compile time. All strings that fail to decode will be rejected. """ From dalcinl at gmail.com Sun Oct 11 23:32:09 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sun, 11 Oct 2009 18:32:09 -0300 Subject: [Cython] CEP 108: bytes/str/unicode - handling encoding issues In-Reply-To: <4AD18ED0.9070908@behnel.de> References: <4AD0A51C.3060106@behnel.de> <4AD18ED0.9070908@behnel.de> Message-ID: On Sun, Oct 11, 2009 at 4:52 AM, Stefan Behnel wrote: > > I just added a section to the CEP about encoding issues. Any comments on > the solution (last paragraph) below? > > The only obvious way to prevent both confusion and runtime errors is to > disallow unprefixed strings that cannot be decoded under the current source > code encoding. Following Python 2 string semantics, Cython will therefore > read {{{str}}} literals as byte strings, and then try to decode them using > the source code encoding at compile time. All strings that fail to decode > will be rejected. > """ Definitely +1. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From thesweeheng at gmail.com Mon Oct 12 05:24:26 2009 From: thesweeheng at gmail.com (Tan Swee Heng) Date: Mon, 12 Oct 2009 11:24:26 +0800 Subject: [Cython] Bug day? In-Reply-To: References: <4AC7A5F2.6000503@student.matnat.uio.no> <1e52e0880910090052v42759639reb587e36f4c02140@mail.gmail.com> Message-ID: Could we have a link to http://sage.math.washington.edu/home/jkantor/cython_notes.pdf on the Wiki page at http://wiki.cython.org/DevDocs? I think it would be helpful for newbies like me trying to understand the Cython code. Swee Heng That'd be really useful. Not quite as pressing, but getting into the > code is a steep learning curve. So far what we have is http:// > wiki.cython.org/HackerGuide and http://sage.math.washington.edu/home/ > jkantor/cython_notes.pdf > > - Robert > > _______________________________________________ > 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/20091012/309dbc36/attachment.htm From stefan_ml at behnel.de Mon Oct 12 08:39:17 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 12 Oct 2009 08:39:17 +0200 Subject: [Cython] Bug day? In-Reply-To: References: <4AC7A5F2.6000503@student.matnat.uio.no> <1e52e0880910090052v42759639reb587e36f4c02140@mail.gmail.com> Message-ID: <4AD2CF15.3050004@behnel.de> Tan Swee Heng wrote: > Could we have a link to > http://sage.math.washington.edu/home/jkantor/cython_notes.pdf on the Wiki > page at http://wiki.cython.org/DevDocs? I think it would be helpful for > newbies like me trying to understand the Cython code. I linked to it from both that page and the hacker guide. Stefan From robertwb at math.washington.edu Mon Oct 12 18:47:17 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 12 Oct 2009 09:47:17 -0700 Subject: [Cython] Bug day? In-Reply-To: References: <4AC7A5F2.6000503@student.matnat.uio.no> <1e52e0880910090052v42759639reb587e36f4c02140@mail.gmail.com> Message-ID: Great idea. It's a wiki--just make yourself an account and stick it up. On Oct 11, 2009, at 8:24 PM, Tan Swee Heng wrote: > Could we have a link to http://sage.math.washington.edu/home/jkantor/cython_notes.pdf > on the Wiki page at http://wiki.cython.org/DevDocs? I think it > would be helpful for newbies like me trying to understand the Cython > code. > > Swee Heng > > That'd be really useful. Not quite as pressing, but getting into the > code is a steep learning curve. So far what we have is http:// > wiki.cython.org/HackerGuide and http://sage.math.washington.edu/home/ > jkantor/cython_notes.pdf > > - Robert > > _______________________________________________ > 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 From sccolbert at gmail.com Mon Oct 12 22:00:20 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Mon, 12 Oct 2009 22:00:20 +0200 Subject: [Cython] would someone mind pointing out the mistake i'm making, i just can't see it Message-ID: <7f014ea60910121300h9b7bdc9ya84632521a07dd4a@mail.gmail.com> so I have this function: (the print statements are just for debugging) cdef np.npy_intp* clone_array_shape(np.ndarray arr): # the proper way to do this would be to use malloc # to create a new npy_intp* array of the proper size # but then we would have to track it and make a call to free # it's easier just to create the two different possible sizes # on the stack. # only arrays with len(shape)== 2 or 3 will pass validation cdef int ndim = arr.ndim cdef np.npy_intp shape_2[2] cdef np.npy_intp shape_3[3] if ndim == 2: shape_2[0] = arr.shape[0] shape_2[1] = arr.shape[1] print arr.shape[0] print arr.shape[1] return shape_2 else: shape_3[0] = arr.shape[0] shape_3[1] = arr.shape[1] shape_3[2] = arr.shape[2] print arr.shape[0] print arr.shape[1] print arr.shape[2] print shape_3[0] print shape_3[1] print shape_3[2] return shape_3 and I make this call to it: cdef np.npy_intp* shape = clone_array_shape(src) #src has shape (30, 30, 3) print shape[0] print shape[1] print shape[2] these are the prints i get: 30 30 3 30 30 3 30 140688641376440 27208864 i cant for the life of me, figure out where the error is coming in? Does anyone see it? Cheers! Chris From sturla at molden.no Mon Oct 12 22:11:12 2009 From: sturla at molden.no (Sturla Molden) Date: Mon, 12 Oct 2009 22:11:12 +0200 Subject: [Cython] would someone mind pointing out the mistake i'm making, i just can't see it In-Reply-To: <7f014ea60910121300h9b7bdc9ya84632521a07dd4a@mail.gmail.com> References: <7f014ea60910121300h9b7bdc9ya84632521a07dd4a@mail.gmail.com> Message-ID: <4AD38D60.9070806@molden.no> Chris Colbert skrev: > i cant for the life of me, figure out where the error is coming in? > > Does anyone see it? > You are returning a pointer to local arrays. The pointer is invalid when the function returns. S.M. From robert.kern at gmail.com Mon Oct 12 22:12:26 2009 From: robert.kern at gmail.com (Robert Kern) Date: Mon, 12 Oct 2009 15:12:26 -0500 Subject: [Cython] would someone mind pointing out the mistake i'm making, i just can't see it In-Reply-To: <7f014ea60910121300h9b7bdc9ya84632521a07dd4a@mail.gmail.com> References: <7f014ea60910121300h9b7bdc9ya84632521a07dd4a@mail.gmail.com> Message-ID: On 2009-10-12 15:00 PM, Chris Colbert wrote: > so I have this function: (the print statements are just for debugging) > > cdef np.npy_intp* clone_array_shape(np.ndarray arr): > # the proper way to do this would be to use malloc > # to create a new npy_intp* array of the proper size > # but then we would have to track it and make a call to free > # it's easier just to create the two different possible sizes > # on the stack. > > # only arrays with len(shape)== 2 or 3 will pass validation > cdef int ndim = arr.ndim > cdef np.npy_intp shape_2[2] > cdef np.npy_intp shape_3[3] This is your problem. The reason that you don't have to keep track of the pointer and free() it with declarations like these is that they *only* live inside the function. You cannot return them. You must PyMem_Malloc() an appropriately sized pointer, return the pointer, and PyMem_Free() it later. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From sccolbert at gmail.com Mon Oct 12 22:13:15 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Mon, 12 Oct 2009 22:13:15 +0200 Subject: [Cython] would someone mind pointing out the mistake i'm making, i just can't see it In-Reply-To: <4AD38D60.9070806@molden.no> References: <7f014ea60910121300h9b7bdc9ya84632521a07dd4a@mail.gmail.com> <4AD38D60.9070806@molden.no> Message-ID: <7f014ea60910121313t2655b1dq4abe8b1dcd441b60@mail.gmail.com> Ah, that would explain it. Thanks! On Mon, Oct 12, 2009 at 10:11 PM, Sturla Molden wrote: > Chris Colbert skrev: >> i cant for the life of me, figure out where the error is coming in? >> >> Does ?anyone see it? >> > You are returning a pointer to local arrays. The pointer is invalid when > the function returns. > > S.M. > > > > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > From sccolbert at gmail.com Mon Oct 12 22:15:58 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Mon, 12 Oct 2009 22:15:58 +0200 Subject: [Cython] would someone mind pointing out the mistake i'm making, i just can't see it In-Reply-To: References: <7f014ea60910121300h9b7bdc9ya84632521a07dd4a@mail.gmail.com> Message-ID: <7f014ea60910121315g53228256l53d90b6891b59ba@mail.gmail.com> Ok, I gotcha. My lack of formal programming training is on display today :) Thanks Sturla and Robert! Chris On Mon, Oct 12, 2009 at 10:12 PM, Robert Kern wrote: > On 2009-10-12 15:00 PM, Chris Colbert wrote: >> so I have this function: (the print statements are just for debugging) >> >> cdef np.npy_intp* clone_array_shape(np.ndarray arr): >> ? ? ?# the proper way to do this would be to use malloc >> ? ? ?# to create a new npy_intp* array of the proper size >> ? ? ?# but then we would have to track it and make a call to free >> ? ? ?# it's easier just to create the two different possible sizes >> ? ? ?# on the stack. >> >> ? ? ?# only arrays with len(shape)== 2 or 3 will pass validation >> ? ? ?cdef int ndim = arr.ndim >> ? ? ?cdef np.npy_intp shape_2[2] >> ? ? ?cdef np.npy_intp shape_3[3] > > This is your problem. The reason that you don't have to keep track of the > pointer and free() it with declarations like these is that they *only* live > inside the function. You cannot return them. You must PyMem_Malloc() an > appropriately sized pointer, return the pointer, and PyMem_Free() it later. > > -- > Robert Kern > > "I have come to believe that the whole world is an enigma, a harmless enigma > ?that is made terrible by our own mad attempt to interpret it as though it had > ?an underlying truth." > ? -- Umberto Eco > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > From sturla at molden.no Mon Oct 12 22:23:09 2009 From: sturla at molden.no (Sturla Molden) Date: Mon, 12 Oct 2009 22:23:09 +0200 Subject: [Cython] would someone mind pointing out the mistake i'm making, i just can't see it In-Reply-To: References: <7f014ea60910121300h9b7bdc9ya84632521a07dd4a@mail.gmail.com> Message-ID: <4AD3902D.40207@molden.no> Robert Kern skrev: > > This is your problem. The reason that you don't have to keep track of the > pointer and free() it with declarations like these is that they *only* live > inside the function. You cannot return them. You must PyMem_Malloc() an > appropriately sized pointer, return the pointer, and PyMem_Free() it later. > > Or one could just use a numpy ndarray. Something like this (not tested): cdef np.ndarray clone_array_shape(np.ndarray arr) except -1: cdef np.npy_intp ndim = arr.ndim, i cdef np.ndarray[np.npy_intp] shape = np.zeros(ndim, dtype=int) for i in range(ndim): shape[i] = arr.shape[i] return shape Which avoids possible memory leaks by not calling free, and avoids the need to error check in the return value from malloc. S.M. From sturla at molden.no Mon Oct 12 22:49:19 2009 From: sturla at molden.no (Sturla Molden) Date: Mon, 12 Oct 2009 22:49:19 +0200 Subject: [Cython] would someone mind pointing out the mistake i'm making, i just can't see it In-Reply-To: <7f014ea60910121315g53228256l53d90b6891b59ba@mail.gmail.com> References: <7f014ea60910121300h9b7bdc9ya84632521a07dd4a@mail.gmail.com> <7f014ea60910121315g53228256l53d90b6891b59ba@mail.gmail.com> Message-ID: <4AD3964F.7060808@molden.no> Chris Colbert skrev: > Ok, I gotcha. My lack of formal programming training is on display today :) > > Thanks Sturla and Robert! > This is a very easy mistake to make, particularly if you are used to working with Python or Java. Dangling pointers is (IMHO) one of the most common C mistakes. Variable-length arrays in C99 makes this mistake even easier to make. In C++ you can avoid the problem using std::vector<> instead of local arrays or new[] / delete[]. In Cython you can avoid the problem using numpy ndarrays instead of local C arrays or malloc/free. If you absolutely insist on using malloc/free in Cython, I suggest you wrap it in a extension object that commit suicide on garbage collection. Something like this (not tested): cimport stdlib cdef class mallocbuffer: cdef readonly void *buf cdef readonly size_t nbytes def __cinit__(membuffer self, size_t nbytes): self.buf = stdlib.malloc(nbytes) if (self.buf == NULL): raise MemoryError, 'malloc failed' self.nbytes = nbytes def __dealloc__(membuffer self): if (self.buf): stdlib.free(self.buf) Sturla Molden From sturla at molden.no Mon Oct 12 22:56:44 2009 From: sturla at molden.no (Sturla Molden) Date: Mon, 12 Oct 2009 22:56:44 +0200 Subject: [Cython] would someone mind pointing out the mistake i'm making, i just can't see it In-Reply-To: <4AD3964F.7060808@molden.no> References: <7f014ea60910121300h9b7bdc9ya84632521a07dd4a@mail.gmail.com> <7f014ea60910121315g53228256l53d90b6891b59ba@mail.gmail.com> <4AD3964F.7060808@molden.no> Message-ID: <4AD3980C.8040601@molden.no> Sturla Molden skrev: > > cimport stdlib > > cdef class mallocbuffer: > > cdef readonly void *buf > cdef readonly size_t nbytes > > def __cinit__(membuffer self, size_t nbytes): > self.buf = stdlib.malloc(nbytes) > if (self.buf == NULL): > raise MemoryError, 'malloc failed' > self.nbytes = nbytes > > def __dealloc__(membuffer self): > if (self.buf): stdlib.free(self.buf) > Oops, two minor typos (it's getting late) :-) cdef class membuffer: cdef readonly void *buf cdef readonly Py_ssize_t nbytes def __cinit__(membuffer self, Py_ssize_t nbytes): self.buf = stdlib.malloc(nbytes) if (self.buf == NULL): raise MemoryError, 'malloc failed' self.nbytes = nbytes def __dealloc__(membuffer self): if (self.buf): stdlib.free(self.buf) S.M. From sturla at molden.no Mon Oct 12 23:30:15 2009 From: sturla at molden.no (Sturla Molden) Date: Mon, 12 Oct 2009 23:30:15 +0200 Subject: [Cython] would someone mind pointing out the mistake i'm making, i just can't see it In-Reply-To: <4AD3980C.8040601@molden.no> References: <7f014ea60910121300h9b7bdc9ya84632521a07dd4a@mail.gmail.com> <7f014ea60910121315g53228256l53d90b6891b59ba@mail.gmail.com> <4AD3964F.7060808@molden.no> <4AD3980C.8040601@molden.no> Message-ID: <4AD39FE7.5010806@molden.no> Sturla Molden skrev: > cdef class membuffer: > > cdef readonly void *buf > cdef readonly Py_ssize_t nbytes > > def __cinit__(membuffer self, Py_ssize_t nbytes): > self.buf = stdlib.malloc(nbytes) > if (self.buf == NULL): > raise MemoryError, 'malloc failed' > self.nbytes = nbytes > > def __dealloc__(membuffer self): > if (self.buf): stdlib.free(self.buf) > This design pattern is very important, because is avoids accidental memory leaks if an exception is raised. For the same reason, Python's C API has CObjects for storing C objects. They are used like this (ignoring error checking on malloc): cdef extern from "Python.h": object PyCObject_FromVoidPointer(void *cobj, void (*destr*)(void*)) void *PyCObject_AsVoidPointer(object self) cdef object buf = PyCObject_FromVoidPointer(stdlib.malloc(nbytes),stdlib.free) cdef void *pbuf = PyCObject_AsVoidPointer(buf) The advantage is, similar to the membuffer class above, that a matching call to free is gurarranteed. If you just put calls to malloc/free randomly into Cython, a portion of the code could be skipped when an exception is raised, and a memory leak would result. Manual memory management is more tricky than it appears on the surface. In plain C, there are no exceptions, but you can still get the problem if someone uses setjmp/longjmp. If you know there is no longjmps, you can use malloc/free rather safely. In C++ there are exceptions, and std::vector is therefore much safter than operators new[] and delete[]. It is generally newer safe to use new[] and delete[] outside constructors and destructors, and doing so is the number one cause of memory leaks in C++. Unfortunately, C++ textbook teach bad habits, including using operator new[] anywhere. Cython is just like C++: you can get exceptions thrown! Therefore, put all manual allocations in __cinit__ and all manual deallocations in __dealloc__. That will prevent bad resource leaks in case of an exception being raised. Just putting calls to malloc/free randomly into Cython code is syntactially legal, but not a design pattern I would recommend. Sorry for ranting... S.M. From stefan_ml at behnel.de Tue Oct 13 06:23:42 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 13 Oct 2009 06:23:42 +0200 Subject: [Cython] would someone mind pointing out the mistake i'm making, i just can't see it In-Reply-To: <4AD3964F.7060808@molden.no> References: <7f014ea60910121300h9b7bdc9ya84632521a07dd4a@mail.gmail.com> <7f014ea60910121315g53228256l53d90b6891b59ba@mail.gmail.com> <4AD3964F.7060808@molden.no> Message-ID: <4AD400CE.8060009@behnel.de> Sturla Molden wrote: > raise MemoryError, 'malloc failed' Note that Python has a C-API function PyErr_NoMemory() for this purpose, which uses a preallocated exception instance. In the case of a memory error, this can actually make a difference. Stefan From ndbecker2 at gmail.com Wed Oct 14 12:45:51 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 14 Oct 2009 06:45:51 -0400 Subject: [Cython] object lifetime Message-ID: Coming from boost::python, there are lots of choices for policies regarding lifetime of arguments to functions and return values. How is this addressed in cython? For example, if an external C function returns a double*, who is responsible for deleting it, and how? (free might not be the correct thing). Similar issues for parameters passed to external C functions. From dagss at student.matnat.uio.no Wed Oct 14 12:53:33 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 14 Oct 2009 12:53:33 +0200 Subject: [Cython] object lifetime In-Reply-To: References: Message-ID: <4AD5ADAD.9060107@student.matnat.uio.no> Neal Becker wrote: > Coming from boost::python, there are lots of choices for policies regarding > lifetime of arguments to functions and return values. How is this addressed > in cython? > > For example, if an external C function returns a double*, who is responsible > for deleting it, and how? (free might not be the correct thing). > You decide who is responsible for deleting it. Unless something is done explicitly either Cython-side or C-side, it will not be deleted. Cython doesn't really "care" about things like this -- when you call a C function, all that happens is the call and the transfer of values. If you want memory management you must do it yourself (for instance, by creating a cdef class which stores the pointer and does the appropriate memory release in its __dealloc__). Dag Sverre From ndbecker2 at gmail.com Wed Oct 14 13:31:13 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 14 Oct 2009 07:31:13 -0400 Subject: [Cython] [patch] Add ITER support to numpy.pxd Message-ID: diff -r 021e25a3bb69 Cython/Includes/numpy.pxd --- a/Cython/Includes/numpy.pxd Tue Oct 13 11:20:37 2009 -0300 +++ b/Cython/Includes/numpy.pxd Wed Oct 14 07:30:35 2009 -0400 @@ -477,6 +477,10 @@ void PyArray_MultiIter_NEXTi(broadcast multi, npy_intp i) nogil bint PyArray_MultiIter_NOTDONE(broadcast multi) nogil + bint PyArray_ITER_NOTDONE (flatiter x) nogil + void PyArray_ITER_NEXT (flatiter x) nogil + void* PyArray_ITER_DATA (flatiter x) nogil + # Functions from __multiarray_api.h # Functions taking dtype and returning object/ndarray are disabled From vel.accel at gmail.com Wed Oct 14 13:34:05 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Wed, 14 Oct 2009 11:34:05 +0000 Subject: [Cython] Bug day? In-Reply-To: References: <4AC7A5F2.6000503@student.matnat.uio.no> <1e52e0880910090052v42759639reb587e36f4c02140@mail.gmail.com> Message-ID: <1e52e0880910140434y50561342k6ad378d142714a6c@mail.gmail.com> On Mon, Oct 12, 2009 at 4:47 PM, Robert Bradshaw wrote: > Great idea. It's a wiki--just make yourself an account and stick it up. > > On Oct 11, 2009, at 8:24 PM, Tan Swee Heng wrote: > >> Could we have a link to http://sage.math.washington.edu/home/jkantor/cython_notes.pdf >> ?on the Wiki page at http://wiki.cython.org/DevDocs? I think it >> would be helpful for newbies like me trying to understand the Cython >> code. >> >> Swee Heng >> >> That'd be really useful. Not quite as pressing, but getting into the >> code is a steep learning curve. So far what we have is http:// >> wiki.cython.org/HackerGuide and http://sage.math.washington.edu/home/ >> jkantor/cython_notes.pdf >> >> - Robert >> >> _______________________________________________ >> 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 > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > Hi all, What's the latest word on bug day and the decided upon time (America, EST) so I can see if I'm able to attend. I want to be useful to you in this regard, so if you feel that my current Cython awareness isn't suitable enough yet for this purpose, please don't feel obligated to accommodate me. I still have plenty of documentation work to do. I'm happy to do whatever is needed. From stefan_ml at behnel.de Wed Oct 14 16:14:19 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 14 Oct 2009 16:14:19 +0200 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects Message-ID: <4AD5DCBB.8070309@behnel.de> Hi, it looks like Py3.1 has its own way of defining external C-APIs: http://docs.python.org/3.1/extending/extending.html#using-capsules I guess we should switch to that method for C code being compiled under Py3.1+, so that Cython modules become compatible with other C extensions that start using that mechanism. Stefan From chrisde88 at yahoo.de Wed Oct 14 17:02:23 2009 From: chrisde88 at yahoo.de (Christian) Date: Wed, 14 Oct 2009 08:02:23 -0700 (PDT) Subject: [Cython] Argument unpacking not working Message-ID: <575443.74391.qm@web24102.mail.ird.yahoo.com> Hi, I have the following use case with OpenGL: My colours are stored in 4-element tuples and should be passed to a OpenGL function by function unpacking color = (0, 0, 0, 1) glColor4f(*color) But this doesn't work with Cython. I get the following error: Error converting Pyrex file to C: ------------------------------------------------------------ ... def set_color(): color = (0, 0, 0, 1) glColor4f(*color) ^ ------------------------------------------------------------ gltest.pyx:16:13: Keyword arguments not allowed in cdef functions. I am not using any keyword arguments. Are they internally used? What is the problem? The workaround would be very verbose and more over those statements are spread all over my code. Thanks in advance! Christian From dalcinl at gmail.com Wed Oct 14 17:24:27 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 14 Oct 2009 12:24:27 -0300 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: <4AD5DCBB.8070309@behnel.de> References: <4AD5DCBB.8070309@behnel.de> Message-ID: On Wed, Oct 14, 2009 at 11:14 AM, Stefan Behnel wrote: > Hi, > > it looks like Py3.1 has its own way of defining external C-APIs: > > http://docs.python.org/3.1/extending/extending.html#using-capsules > > I guess we should switch to that method for C code being compiled under > Py3.1+, so that Cython modules become compatible with other C extensions > that start using that mechanism. > You said *should*, but I think we **must**... It seems that the legacy PyCObject API is ALREADy removed in Py3.2... Just svn update's py3k trunk, and I cannot build mpi4py because of this... I'll not make any comments about that decision. Instead, I'll spend my time porting Cython to use the new API. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From stefan_ml at behnel.de Wed Oct 14 17:29:56 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 14 Oct 2009 17:29:56 +0200 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: References: <4AD5DCBB.8070309@behnel.de> Message-ID: <4AD5EE74.3020809@behnel.de> Lisandro Dalcin wrote: > On Wed, Oct 14, 2009 at 11:14 AM, Stefan Behnel wrote: >> Hi, >> >> it looks like Py3.1 has its own way of defining external C-APIs: >> >> http://docs.python.org/3.1/extending/extending.html#using-capsules >> >> I guess we should switch to that method for C code being compiled under >> Py3.1+, so that Cython modules become compatible with other C extensions >> that start using that mechanism. >> > > You said *should*, but I think we **must**... It seems that the legacy > PyCObject API is ALREADy removed in Py3.2... Just svn update's py3k > trunk, and I cannot build mpi4py because of this... > > I'll not make any comments about that decision. Instead, I'll spend my > time porting Cython to use the new API. Thanks, Lisandro. I'll open a ticket on trac and assign it to you. Stefan From stefan_ml at behnel.de Wed Oct 14 17:47:17 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 14 Oct 2009 17:47:17 +0200 Subject: [Cython] Argument unpacking not working In-Reply-To: <575443.74391.qm@web24102.mail.ird.yahoo.com> References: <575443.74391.qm@web24102.mail.ird.yahoo.com> Message-ID: <4AD5F285.6060307@behnel.de> Christian wrote: > I have the following use case with OpenGL: > > My colours are stored in 4-element tuples and should be passed to a > OpenGL function by function unpacking > > color = (0, 0, 0, 1) > glColor4f(*color) > > But this doesn't work with Cython. I get the following error: > > > Error converting Pyrex file to C: > ------------------------------------------------------------ > ... > > def set_color(): > color = (0, 0, 0, 1) > glColor4f(*color) > ^ > ------------------------------------------------------------ > > gltest.pyx:16:13: Keyword arguments not allowed in cdef functions. Admittedly, the error message is misleading here. This is a feature that is not supported. The problem is that Cython cannot know at compile time that you pass the right number of arguments to the function and that they have the right type etc. So it would need to generate the corresponding tuple unpacking and type conversion code, store the values in a series of temporary variables, and then call the C function with them. Without having looked into this any deeper, I think this can be supported fairly easily using a parse tree transformation that simply injects the unpacking step and types the temporary variables according to the C function signature. But it isn't currently supported. Stefan From stefan_ml at behnel.de Wed Oct 14 17:51:01 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 14 Oct 2009 17:51:01 +0200 Subject: [Cython] Argument unpacking not working In-Reply-To: <575443.74391.qm@web24102.mail.ird.yahoo.com> References: <575443.74391.qm@web24102.mail.ird.yahoo.com> Message-ID: <4AD5F365.8070203@behnel.de> Christian wrote: > I have the following use case with OpenGL: > > My colours are stored in 4-element tuples and should be passed to a > OpenGL function by function unpacking > > color = (0, 0, 0, 1) > glColor4f(*color) > > But this doesn't work with Cython. I get the following error: > > > Error converting Pyrex file to C: > ------------------------------------------------------------ > ... > > def set_color(): > color = (0, 0, 0, 1) > glColor4f(*color) > ^ > ------------------------------------------------------------ > > gltest.pyx:16:13: Keyword arguments not allowed in cdef functions. I created a ticket for supporting this: http://trac.cython.org/cython_trac/ticket/408 Stefan From stefan_ml at behnel.de Wed Oct 14 17:38:31 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 14 Oct 2009 17:38:31 +0200 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: References: <4AD5DCBB.8070309@behnel.de> Message-ID: <4AD5F077.2000303@behnel.de> Lisandro Dalcin wrote: > On Wed, Oct 14, 2009 at 11:14 AM, Stefan Behnel wrote: >> it looks like Py3.1 has its own way of defining external C-APIs: >> >> http://docs.python.org/3.1/extending/extending.html#using-capsules >> >> I guess we should switch to that method for C code being compiled under >> Py3.1+, so that Cython modules become compatible with other C extensions >> that start using that mechanism. >> > > You said *should*, but I think we **must**... It seems that the legacy > PyCObject API is ALREADy removed in Py3.2... Just svn update's py3k > trunk, and I cannot build mpi4py because of this... > > I'll not make any comments about that decision. Instead, I'll spend my > time porting Cython to use the new API. This is now ticket 407: http://trac.cython.org/cython_trac/ticket/407 Stefan From dalcinl at gmail.com Wed Oct 14 18:18:25 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 14 Oct 2009 13:18:25 -0300 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: <4AD5EE74.3020809@behnel.de> References: <4AD5DCBB.8070309@behnel.de> <4AD5EE74.3020809@behnel.de> Message-ID: On Wed, Oct 14, 2009 at 12:29 PM, Stefan Behnel wrote: > > Lisandro Dalcin wrote: >> On Wed, Oct 14, 2009 at 11:14 AM, Stefan Behnel wrote: >>> Hi, >>> >>> it looks like Py3.1 has its own way of defining external C-APIs: >>> >>> http://docs.python.org/3.1/extending/extending.html#using-capsules >>> >>> I guess we should switch to that method for C code being compiled under >>> Py3.1+, so that Cython modules become compatible with other C extensions >>> that start using that mechanism. >>> >> >> You said *should*, but I think we **must**... It seems that the legacy >> PyCObject API ?is ALREADy removed in Py3.2... Just svn update's py3k >> trunk, and I cannot build mpi4py because of this... >> >> I'll not make any comments about that decision. Instead, I'll spend my >> time porting Cython to use the new API. > > Thanks, Lisandro. > > I'll open a ticket on trac and assign it to you. > Fine... BTW, I'm right now hacking on refnanny machinery... I think I'll use PyLong_{From|As}VoidPtr for importing/exporting the API structure... Making it simpler will make it also portable across all CPython versions. Additionally, I'll make a heavy renaming of some refnanny stuff, things will be now named "__Pyx_RefNanny[XXX]". -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dagss at student.matnat.uio.no Wed Oct 14 18:51:00 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 14 Oct 2009 18:51:00 +0200 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: <4AD5DCBB.8070309@behnel.de> References: <4AD5DCBB.8070309@behnel.de> Message-ID: <4AD60174.4050607@student.matnat.uio.no> Stefan Behnel wrote: > Hi, > > it looks like Py3.1 has its own way of defining external C-APIs: > > http://docs.python.org/3.1/extending/extending.html#using-capsules > > I guess we should switch to that method for C code being compiled under > Py3.1+, so that Cython modules become compatible with other C extensions > that start using that mechanism. Am I right in thinking that this is basically a standardization of what we do with Cython's __pyx_capi? So we'd just have a 1:1 correspondance with what we put in capsules and what we put in __pyx_capi? -- Dag Sverre From robertwb at math.washington.edu Wed Oct 14 19:38:39 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 14 Oct 2009 10:38:39 -0700 Subject: [Cython] Bug day? In-Reply-To: <1e52e0880910140434y50561342k6ad378d142714a6c@mail.gmail.com> References: <4AC7A5F2.6000503@student.matnat.uio.no> <1e52e0880910090052v42759639reb587e36f4c02140@mail.gmail.com> <1e52e0880910140434y50561342k6ad378d142714a6c@mail.gmail.com> Message-ID: > Hi all, > > What's the latest word on bug day and the decided upon time (America, > EST) Bug day will officially start at 9am Central Eastern Summer Time tomorrow (Thursday) which is midnight (Wednesday night) Pacific Daylight TIme, 3am Eastern Daylight time, and continuing as long as we can. Those of us on the west coast will probably start earlier a couple of hours earlier and stay up as late as we can--you can join us when you get up. > so I can see if I'm able to attend. I want to be useful to you in > this regard, so if you feel that my current Cython awareness isn't > suitable enough yet for this purpose, please don't feel obligated to > accommodate me. I still have plenty of documentation work to do. I'm > happy to do whatever is needed. Please do join us--there's plenty of low hanging fruit and having all of us around to answer questions is the perfect time for someone like you to be there. - Robert From vel.accel at gmail.com Wed Oct 14 19:54:31 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Wed, 14 Oct 2009 17:54:31 +0000 Subject: [Cython] Bug day? In-Reply-To: References: <4AC7A5F2.6000503@student.matnat.uio.no> <1e52e0880910090052v42759639reb587e36f4c02140@mail.gmail.com> <1e52e0880910140434y50561342k6ad378d142714a6c@mail.gmail.com> Message-ID: <1e52e0880910141054o220412a0v6c6a658cf650ed58@mail.gmail.com> On Wed, Oct 14, 2009 at 5:38 PM, Robert Bradshaw wrote: >> Hi all, >> >> What's the latest word on bug day and the decided upon time (America, >> EST) > > Bug day will officially start at 9am Central Eastern Summer Time > tomorrow (Thursday) which is midnight (Wednesday night) Pacific > Daylight TIme, 3am Eastern Daylight time, and continuing as long as we > can. Those of us on the west coast will probably start earlier a > couple of hours earlier and stay up as late as we can--you can join us > when you get up. > >> so I can see if I'm able to attend. I want to be useful to you in >> this regard, so if you feel that my current Cython awareness isn't >> suitable enough yet for this purpose, please don't feel obligated to >> accommodate me. I still have plenty of documentation work to do. I'm >> happy to do whatever is needed. > > Please do join us--there's plenty of low hanging fruit and having all > of us around to answer questions is the perfect time for someone like > you to be there. > > - Robert > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > Ok good, and this will be irc.. what's the channel? Also I just installed a clean gentoo system so I've got to get more things up and running (not that's important to you, but..). Lastly, I keep crazy hours, so I'll join in as I'm able. From stefan_ml at behnel.de Wed Oct 14 19:26:39 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 14 Oct 2009 19:26:39 +0200 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: References: <4AD5DCBB.8070309@behnel.de> <4AD5EE74.3020809@behnel.de> Message-ID: <4AD609CF.6040900@behnel.de> Lisandro Dalcin wrote: > I think I'll use > PyLong_{From|As}VoidPtr for importing/exporting the API structure... > Making it simpler will make it also portable across all CPython > versions. But it wouldn't make it compatible with other non-Cython C-APIs, would it? I think that's a requirement. If there's a standard way, Cython should be 100% compatible with that. > Additionally, I'll make a heavy renaming of some refnanny stuff, > things will be now named "__Pyx_RefNanny[XXX]". What's that for? Stefan From robertwb at math.washington.edu Wed Oct 14 20:39:18 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 14 Oct 2009 11:39:18 -0700 Subject: [Cython] Bug day? In-Reply-To: <1e52e0880910141054o220412a0v6c6a658cf650ed58@mail.gmail.com> References: <4AC7A5F2.6000503@student.matnat.uio.no> <1e52e0880910090052v42759639reb587e36f4c02140@mail.gmail.com> <1e52e0880910140434y50561342k6ad378d142714a6c@mail.gmail.com> <1e52e0880910141054o220412a0v6c6a658cf650ed58@mail.gmail.com> Message-ID: <9121CC3B-2F9D-4F0C-9360-829398488902@math.washington.edu> On Oct 14, 2009, at 10:54 AM, Peter Alexander wrote: > On Wed, Oct 14, 2009 at 5:38 PM, Robert Bradshaw > wrote: >>> Hi all, >>> >>> What's the latest word on bug day and the decided upon time >>> (America, >>> EST) >> >> Bug day will officially start at 9am Central Eastern Summer Time >> tomorrow (Thursday) which is midnight (Wednesday night) Pacific >> Daylight TIme, 3am Eastern Daylight time, and continuing as long as >> we >> can. Those of us on the west coast will probably start earlier a >> couple of hours earlier and stay up as late as we can--you can join >> us >> when you get up. >> >>> so I can see if I'm able to attend. I want to be useful to you in >>> this regard, so if you feel that my current Cython awareness isn't >>> suitable enough yet for this purpose, please don't feel obligated to >>> accommodate me. I still have plenty of documentation work to do. I'm >>> happy to do whatever is needed. >> >> Please do join us--there's plenty of low hanging fruit and having all >> of us around to answer questions is the perfect time for someone like >> you to be there. >> >> - Robert >> >> _______________________________________________ >> Cython-dev mailing list >> Cython-dev at codespeak.net >> http://codespeak.net/mailman/listinfo/cython-dev >> > > Ok good, and this will be irc.. what's the channel? Also I just > installed a clean gentoo system so I've got to get more things up and > running (not that's important to you, but..). Lastly, I keep crazy > hours, so I'll join in as I'm able. #cython on irc.freenode.net. See you there. - Robert From dalcinl at gmail.com Wed Oct 14 20:37:18 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 14 Oct 2009 15:37:18 -0300 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: <4AD609CF.6040900@behnel.de> References: <4AD5DCBB.8070309@behnel.de> <4AD5EE74.3020809@behnel.de> <4AD609CF.6040900@behnel.de> Message-ID: On Wed, Oct 14, 2009 at 2:26 PM, Stefan Behnel wrote: > > Lisandro Dalcin wrote: >> I think I'll use >> PyLong_{From|As}VoidPtr for importing/exporting the API structure... >> Making it simpler will make it also portable across all CPython >> versions. > > But it wouldn't make it compatible with other non-Cython C-APIs, would it? > I think that's a requirement. If there's a standard way, Cython should be > 100% compatible with that. > Please note I was talking JUST about the refnanny support module. The import/export of its C-API (actually a pointer to a struct) what rather ad-hoc and used PyCObject... I do not really see the point of bothering about the refnanny module "properly" exporting its API and complicating the implementation now that CObjects are not available in all Python runtimes. > >> Additionally, I'll make a heavy renaming of some refnanny stuff, >> things will be now named "__Pyx_RefNanny[XXX]". > > What's that for? > Just for the sake of the generated C code being more easier to follow and understand... We always talk about "refnanny", why not generate the C code using that name consistently where appropriate. Additionally, I'm changing the way of using the CYTHON_REFNANNY macro with the preprocessor... Now you have to explicitly #define it to 1, (as we require for complex support, and C-level profiling) ... See the attached patch to see exactly what I'm talking about. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 -------------- next part -------------- A non-text attachment was scrubbed... Name: refnanny.diff Type: text/x-patch Size: 8412 bytes Desc: not available Url : http://codespeak.net/pipermail/cython-dev/attachments/20091014/45663416/attachment.bin From dagss at student.matnat.uio.no Wed Oct 14 20:44:57 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 14 Oct 2009 20:44:57 +0200 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: References: <4AD5DCBB.8070309@behnel.de> <4AD5EE74.3020809@behnel.de> <4AD609CF.6040900@behnel.de> Message-ID: <4AD61C29.9050901@student.matnat.uio.no> Lisandro Dalcin wrote: > On Wed, Oct 14, 2009 at 2:26 PM, Stefan Behnel wrote: >> Lisandro Dalcin wrote: >>> I think I'll use >>> PyLong_{From|As}VoidPtr for importing/exporting the API structure... >>> Making it simpler will make it also portable across all CPython >>> versions. >> But it wouldn't make it compatible with other non-Cython C-APIs, would it? >> I think that's a requirement. If there's a standard way, Cython should be >> 100% compatible with that. >> > > Please note I was talking JUST about the refnanny support module. The > import/export of its C-API (actually a pointer to a struct) what > rather ad-hoc and used PyCObject... I do not really see the point of > bothering about the refnanny module "properly" exporting its API and > complicating the implementation now that CObjects are not available in > all Python runtimes. > >>> Additionally, I'll make a heavy renaming of some refnanny stuff, >>> things will be now named "__Pyx_RefNanny[XXX]". >> What's that for? >> > > Just for the sake of the generated C code being more easier to follow > and understand... We always talk about "refnanny", why not generate > the C code using that name consistently where appropriate. > Additionally, I'm changing the way of using the CYTHON_REFNANNY macro > with the preprocessor... Now you have to explicitly #define it to 1, > (as we require for complex support, and C-level profiling) ... I'd say it is the complex support and profiling who's got it wrong and CYTHON_REFNANNY that's got it right. Being able to do "-DOPTION" and use #ifdef is *very* common. -- Dag Sverre From dalcinl at gmail.com Wed Oct 14 21:19:28 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 14 Oct 2009 16:19:28 -0300 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: <4AD61C29.9050901@student.matnat.uio.no> References: <4AD5DCBB.8070309@behnel.de> <4AD5EE74.3020809@behnel.de> <4AD609CF.6040900@behnel.de> <4AD61C29.9050901@student.matnat.uio.no> Message-ID: On Wed, Oct 14, 2009 at 3:44 PM, Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: >> On Wed, Oct 14, 2009 at 2:26 PM, Stefan Behnel wrote: >>> Lisandro Dalcin wrote: >>>> I think I'll use >>>> PyLong_{From|As}VoidPtr for importing/exporting the API structure... >>>> Making it simpler will make it also portable across all CPython >>>> versions. >>> But it wouldn't make it compatible with other non-Cython C-APIs, would it? >>> I think that's a requirement. If there's a standard way, Cython should be >>> 100% compatible with that. >>> >> >> Please note I was talking JUST about the refnanny support module. The >> import/export of its C-API (actually a pointer to a struct) what >> rather ad-hoc and used PyCObject... I do not really see the point of >> bothering about the refnanny module "properly" exporting its API and >> complicating the implementation now that CObjects are not available in >> all Python runtimes. >> >>>> Additionally, I'll make a heavy renaming of some refnanny stuff, >>>> things will be now named "__Pyx_RefNanny[XXX]". >>> What's that for? >>> >> >> Just for the sake of the generated C code being more easier to follow >> and understand... We always talk about "refnanny", why not generate >> the C code using that name consistently where appropriate. >> Additionally, I'm changing the way of using the CYTHON_REFNANNY macro >> with the preprocessor... Now you have to explicitly #define it to 1, >> (as we require for complex support, and C-level profiling) ... > > I'd say it is the complex support and profiling who's got it wrong and > CYTHON_REFNANNY that's got it right. Being able to do "-DOPTION" and use > #ifdef is *very* common. > Well, we can discuss about that, but #if MACRO ... #endif is also common... And suppose someone does -DMACRO=0 ... Moreover, paste this in some file in tmp.c #if ABC #warning ABC is true #else #warning ABC is false #endif #ifdef XYZ #warning XYZ is defined #else #warning XYZ is not def #endif int main(int a, char**b){} and next compile like this: $ gcc -DABC -DXYZ=0 cmacro.c I get this output: cmacro.c:3:2: warning: #warning ABC is true cmacro.c:9:2: warning: #warning XYZ is defined So it seems that (at least with GCC) your bare -DFOO way still does the right thing, while my counter example #ifdef FOO...#endif with -DFOO=0 gives unexpected results... So IMO my proposed change should go in. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dagss at student.matnat.uio.no Wed Oct 14 21:23:29 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 14 Oct 2009 21:23:29 +0200 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: References: <4AD5DCBB.8070309@behnel.de> <4AD5EE74.3020809@behnel.de> <4AD609CF.6040900@behnel.de> <4AD61C29.9050901@student.matnat.uio.no> Message-ID: <4AD62531.5040307@student.matnat.uio.no> Lisandro Dalcin wrote: > On Wed, Oct 14, 2009 at 3:44 PM, Dag Sverre Seljebotn > wrote: >> Lisandro Dalcin wrote: >>> On Wed, Oct 14, 2009 at 2:26 PM, Stefan Behnel wrote: >>>> Lisandro Dalcin wrote: >>>>> I think I'll use >>>>> PyLong_{From|As}VoidPtr for importing/exporting the API structure... >>>>> Making it simpler will make it also portable across all CPython >>>>> versions. >>>> But it wouldn't make it compatible with other non-Cython C-APIs, would it? >>>> I think that's a requirement. If there's a standard way, Cython should be >>>> 100% compatible with that. >>>> >>> Please note I was talking JUST about the refnanny support module. The >>> import/export of its C-API (actually a pointer to a struct) what >>> rather ad-hoc and used PyCObject... I do not really see the point of >>> bothering about the refnanny module "properly" exporting its API and >>> complicating the implementation now that CObjects are not available in >>> all Python runtimes. >>> >>>>> Additionally, I'll make a heavy renaming of some refnanny stuff, >>>>> things will be now named "__Pyx_RefNanny[XXX]". >>>> What's that for? >>>> >>> Just for the sake of the generated C code being more easier to follow >>> and understand... We always talk about "refnanny", why not generate >>> the C code using that name consistently where appropriate. >>> Additionally, I'm changing the way of using the CYTHON_REFNANNY macro >>> with the preprocessor... Now you have to explicitly #define it to 1, >>> (as we require for complex support, and C-level profiling) ... >> I'd say it is the complex support and profiling who's got it wrong and >> CYTHON_REFNANNY that's got it right. Being able to do "-DOPTION" and use >> #ifdef is *very* common. >> > > Well, we can discuss about that, but #if MACRO ... #endif is also > common... And suppose someone does -DMACRO=0 ... > > Moreover, paste this in some file in tmp.c > > #if ABC > #warning ABC is true > #else > #warning ABC is false > #endif > > #ifdef XYZ > #warning XYZ is defined > #else > #warning XYZ is not def > #endif > > int main(int a, char**b){} > > and next compile like this: > > $ gcc -DABC -DXYZ=0 cmacro.c > > I get this output: > > cmacro.c:3:2: warning: #warning ABC is true > cmacro.c:9:2: warning: #warning XYZ is defined > > So it seems that (at least with GCC) your bare -DFOO way still does > the right thing, while my counter example #ifdef FOO...#endif with > -DFOO=0 gives unexpected results... > > So IMO my proposed change should go in. OK I'm +1 now. -- Dag Sverre From dalcinl at gmail.com Wed Oct 14 21:28:00 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 14 Oct 2009 16:28:00 -0300 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: <4AD62531.5040307@student.matnat.uio.no> References: <4AD5DCBB.8070309@behnel.de> <4AD5EE74.3020809@behnel.de> <4AD609CF.6040900@behnel.de> <4AD61C29.9050901@student.matnat.uio.no> <4AD62531.5040307@student.matnat.uio.no> Message-ID: On Wed, Oct 14, 2009 at 4:23 PM, Dag Sverre Seljebotn wrote: >> So IMO my proposed change should go in. > > OK I'm +1 now. > Whole patch (had you time for a fast look?)? Or just talking about the macro? -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dagss at student.matnat.uio.no Wed Oct 14 21:39:23 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 14 Oct 2009 21:39:23 +0200 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: References: <4AD5DCBB.8070309@behnel.de> <4AD5EE74.3020809@behnel.de> <4AD609CF.6040900@behnel.de> <4AD61C29.9050901@student.matnat.uio.no> <4AD62531.5040307@student.matnat.uio.no> Message-ID: <4AD628EB.6090303@student.matnat.uio.no> Lisandro Dalcin wrote: > On Wed, Oct 14, 2009 at 4:23 PM, Dag Sverre Seljebotn > wrote: >>> So IMO my proposed change should go in. >> OK I'm +1 now. >> > > Whole patch (had you time for a fast look?)? Or just talking about the macro? I was talking about the patch, but I had a quick look now and I'm +1 (not that I tested it, but looks nice). Thanks! -- Dag Sverre From dalcinl at gmail.com Wed Oct 14 22:42:05 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 14 Oct 2009 17:42:05 -0300 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: <4AD628EB.6090303@student.matnat.uio.no> References: <4AD5DCBB.8070309@behnel.de> <4AD5EE74.3020809@behnel.de> <4AD609CF.6040900@behnel.de> <4AD61C29.9050901@student.matnat.uio.no> <4AD62531.5040307@student.matnat.uio.no> <4AD628EB.6090303@student.matnat.uio.no> Message-ID: On Wed, Oct 14, 2009 at 4:39 PM, Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: >> On Wed, Oct 14, 2009 at 4:23 PM, Dag Sverre Seljebotn >> wrote: >>>> So IMO my proposed change should go in. >>> OK I'm +1 now. >>> >> >> Whole patch (had you time for a fast look?)? Or just talking about the macro? > > I was talking about the patch, but I had a quick look now and I'm +1 > (not that I tested it, but looks nice). Thanks! > http://hg.cython.org/cython-devel/rev/35e516d48a86 -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Wed Oct 14 23:53:37 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 14 Oct 2009 18:53:37 -0300 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: <4AD5F077.2000303@behnel.de> References: <4AD5DCBB.8070309@behnel.de> <4AD5F077.2000303@behnel.de> Message-ID: On Wed, Oct 14, 2009 at 12:38 PM, Stefan Behnel wrote: > > This is now ticket 407: > > http://trac.cython.org/cython_trac/ticket/407 > And now you have a working (2.3-2.7 and 3.1-3.2) patch ready for review: http://trac.cython.org/cython_trac/attachment/ticket/407/capi-import-export.diff -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From stefan_ml at behnel.de Thu Oct 15 08:04:58 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Oct 2009 08:04:58 +0200 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: References: <4AD5DCBB.8070309@behnel.de> <4AD5F077.2000303@behnel.de> Message-ID: <4AD6BB8A.10901@behnel.de> Lisandro Dalcin wrote: > On Wed, Oct 14, 2009 at 12:38 PM, Stefan Behnel wrote: >> This is now ticket 407: >> >> http://trac.cython.org/cython_trac/ticket/407 > > And now you have a working (2.3-2.7 and 3.1-3.2) patch ready for review: > > http://trac.cython.org/cython_trac/attachment/ticket/407/capi-import-export.diff Ok, that's a pretty straight-forward change. I didn't test it yet, but it looks good to me. Please push it. One remark: the Py3 docs contain this section: """ Whichever method you choose, it?s important to name your Capsules properly. The function PyCapsule_New() takes a name parameter (const char *); you?re permitted to pass in a NULL name, but we strongly encourage you to specify a name. Properly named Capsules provide a degree of runtime type-safety; there is no feasible way to tell one unnamed Capsule from another. In particular, Capsules used to expose C APIs should be given a name following this convention: modulename.attributename The convenience function PyCapsule_Import() makes it easy to load a C API provided via a Capsule, but only if the Capsule?s name matches this convention. This behavior gives C API users a high degree of certainty that the Capsule they load contains the correct C API. """ So we are not quite conformant with that as we a) do not prepend the module name and b) append the complete signature. I actually find it much safer to have the signature in there, and I actually doubt that the module name adds anything to that. After all, the import goes though the module anyway. So I actually think the way Cython does it is better than what the CPython docs propose. Should we bring this up on python-dev? Stefan From stefan_ml at behnel.de Thu Oct 15 08:05:58 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Oct 2009 08:05:58 +0200 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: <4AD60174.4050607@student.matnat.uio.no> References: <4AD5DCBB.8070309@behnel.de> <4AD60174.4050607@student.matnat.uio.no> Message-ID: <4AD6BBC6.9070409@behnel.de> Dag Sverre Seljebotn wrote: > Stefan Behnel wrote: >> it looks like Py3.1 has its own way of defining external C-APIs: >> >> http://docs.python.org/3.1/extending/extending.html#using-capsules >> >> I guess we should switch to that method for C code being compiled under >> Py3.1+, so that Cython modules become compatible with other C extensions >> that start using that mechanism. > > Am I right in thinking that this is basically a standardization of what > we do with Cython's __pyx_capi? So we'd just have a 1:1 correspondance > with what we put in capsules and what we put in __pyx_capi? Lisandros patch does that, yes. Except for the module name and the signature. See my other post. Stefan From stefan_ml at behnel.de Thu Oct 15 07:51:02 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Oct 2009 07:51:02 +0200 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: References: <4AD5DCBB.8070309@behnel.de> <4AD5EE74.3020809@behnel.de> <4AD609CF.6040900@behnel.de> Message-ID: <4AD6B846.4040104@behnel.de> Lisandro Dalcin wrote: > On Wed, Oct 14, 2009 at 2:26 PM, Stefan Behnel wrote: >> Lisandro Dalcin wrote: >>> I think I'll use >>> PyLong_{From|As}VoidPtr for importing/exporting the API structure... >>> Making it simpler will make it also portable across all CPython >>> versions. >> But it wouldn't make it compatible with other non-Cython C-APIs, would it? > > Please note I was talking JUST about the refnanny support module. Ah, ok, sure. That's ok with me. >>> Additionally, I'll make a heavy renaming of some refnanny stuff, >>> things will be now named "__Pyx_RefNanny[XXX]". >> What's that for? > > Just for the sake of the generated C code being more easier to follow > and understand... We always talk about "refnanny", why not generate > the C code using that name consistently where appropriate. > Additionally, I'm changing the way of using the CYTHON_REFNANNY macro > with the preprocessor... Now you have to explicitly #define it to 1, > (as we require for complex support, and C-level profiling) ... Got you wrong again, sorry. Certainly sounds more consistent. Stefan From stefan_ml at behnel.de Thu Oct 15 08:49:00 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Oct 2009 08:49:00 +0200 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: <4AD60174.4050607@student.matnat.uio.no> References: <4AD5DCBB.8070309@behnel.de> <4AD60174.4050607@student.matnat.uio.no> Message-ID: <4AD6C5DC.9050309@behnel.de> Dag Sverre Seljebotn wrote: > Stefan Behnel wrote: >> it looks like Py3.1 has its own way of defining external C-APIs: >> >> http://docs.python.org/3.1/extending/extending.html#using-capsules >> >> I guess we should switch to that method for C code being compiled under >> Py3.1+, so that Cython modules become compatible with other C extensions >> that start using that mechanism. > > Am I right in thinking that this is basically a standardization of what > we do with Cython's __pyx_capi? So we'd just have a 1:1 correspondance > with what we put in capsules and what we put in __pyx_capi? Actually, rereading their examples now, it's not quite the same thing. Cython exports a dict that contains PyCObjects/PyCapsules for each function, whereas their proposed approach is encapsulated by a header file that is presented to work like this: Export: - you create a void* array containing function pointers - you wrap the pointer to it in a PyCapsule - you write a header file around it that defines the names and an import function in whatever way. Import: The import function in the header file calls PyCapsule_Import(fq_module_attribute_name, non_blocking_flag) to import the module and retrieve the pointer by attribute name. The header file additionally defines a call macro that just statically knows at what offset in the pointer table you find the right function. Look at the example header file at the link above for details. I actually find Pyrex's/Cython's way of doing that a *lot* nicer and safer. However, the main machinery for C-API users is that you get a header file from whatever source, #include it in your C source, call the import function it defines, and can then call the function as you see fit. That's the same for both cases, so the way Cython exports the C-API is just fine IMO. OTOH, PyCapsule_Import() won't work on Cython modules, as it doesn't export a plain void* but a dict of void*. Also, Cython can't directly cimport a C-API that's defined in the described way. Instead, you have to use the header file and call the import function manually. But that's not too much overhead, as you have to define the functions anyway. Switching to the described way would really remove features from Cython here, with no added gain. Stefan From dagss at student.matnat.uio.no Thu Oct 15 10:42:24 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 15 Oct 2009 10:42:24 +0200 Subject: [Cython] C++ complex support In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACDD420.4060500@molden.no> <4ACDD847.40400@student.matnat.uio.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> <4ACF85E9.2060808@student.matnat.uio.no> Message-ID: <4AD6E070.2020500@student.matnat.uio.no> Lisandro Dalcin wrote: > On Fri, Oct 9, 2009 at 3:50 PM, Dag Sverre Seljebotn > wrote: > > >> Next week I'll add conjugate (I'm basically done already. In that work I >> might likely also turn "x.imag = y" into "__Pyx_SET_CIMAG(x, y)". >> >> > > Good! BTW, how are you going to implement the setters for C99 ? > conjugate added. Turns out I didn't need to go as deeply into it as I thought so imag and real attributes stands as they are. If there was a good motivating cause for changing that I can still do it, but if so somebody please post the C code that should be generated instead of the current behaviour (is the issue that we shouldn't depend on __real__(x) to be an lvalue but use some function instead?) Dag Sverre From stefan_ml at behnel.de Thu Oct 15 15:29:27 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Oct 2009 15:29:27 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> Message-ID: <4AD723B7.5000802@behnel.de> Moving this over to cython-dev. Neal Becker wrote: > Stefan Behnel wrote: >> Neal Becker wrote: >>> Without the cast, I get this message: >>> Py_XINCREF(raw.base) >>> ^ >>> ------------------------------------------------------------ >>> >>> /home/nbecker/raysat/mod/sum.pyx:152:22: Cannot assign type >>> 'python_object.PyObject *' to 'PyObject *' >>> >>> Am I missing some cimport to get the right PyObject? >> Please try commenting out the following line at the beginning of >> numpy.pxd: >> >> from python_object cimport PyObject >> >> Stefan > Error converting Pyrex file to C: > ------------------------------------------------------------ > ... > char *data > int ndim "nd" > npy_intp *shape "dimensions" > npy_intp *strides > dtype descr > PyObject* base > ^ > ------------------------------------------------------------ > > /home/nbecker/raysat/mod/numpy.pxd:154:12: 'PyObject' is not a type > identifier I would have thought that "PyObject" was a builtin type known to Cython by now, but it seems not. I found ticket #320 now, which I think is worth solving by making PyObject a builtin type. http://trac.cython.org/cython_trac/ticket/320 Stefan From dalcinl at gmail.com Thu Oct 15 17:40:44 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Thu, 15 Oct 2009 12:40:44 -0300 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: <4AD6C5DC.9050309@behnel.de> References: <4AD5DCBB.8070309@behnel.de> <4AD60174.4050607@student.matnat.uio.no> <4AD6C5DC.9050309@behnel.de> Message-ID: On Thu, Oct 15, 2009 at 3:49 AM, Stefan Behnel wrote: > > Dag Sverre Seljebotn wrote: >> Stefan Behnel wrote: >>> it looks like Py3.1 has its own way of defining external C-APIs: >>> >>> http://docs.python.org/3.1/extending/extending.html#using-capsules >>> >>> I guess we should switch to that method for C code being compiled under >>> Py3.1+, so that Cython modules become compatible with other C extensions >>> that start using that mechanism. >> >> Am I right in thinking that this is basically a standardization of what >> we do with Cython's __pyx_capi? So we'd just have a 1:1 correspondance >> with what we put in capsules and what we put in __pyx_capi? > > Actually, rereading their examples now, it's not quite the same thing. > Cython exports a dict that contains PyCObjects/PyCapsules for each > function, whereas their proposed approach is encapsulated by a header file > that is presented to work like this: > > Export: > > - you create a void* array containing function pointers > - you wrap the pointer to it in a PyCapsule > - you write a header file around it that defines the names and an import > ?function in whatever way. > > Import: > > The import function in the header file calls > > ? ? ? ?PyCapsule_Import(fq_module_attribute_name, non_blocking_flag) > > to import the module and retrieve the pointer by attribute name. > > The header file additionally defines a call macro that just statically > knows at what offset in the pointer table you find the right function. > > Look at the example header file at the link above for details. > > I actually find Pyrex's/Cython's way of doing that a *lot* nicer and safer. > > However, the main machinery for C-API users is that you get a header file > from whatever source, #include it in your C source, call the import > function it defines, and can then call the function as you see fit. That's > the same for both cases, so the way Cython exports the C-API is just fine IMO. > > OTOH, PyCapsule_Import() won't work on Cython modules, as it doesn't export > a plain void* but a dict of void*. > > Also, Cython can't directly cimport a C-API that's defined in the described > way. Instead, you have to use the header file and call the import function > manually. But that's not too much overhead, as you have to define the > functions anyway. Switching to the described way would really remove > features from Cython here, with no added gain. > > Stefan > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > After such comprehensive review, do you understand now why I said that I was not going to make any comment and just fix Cython to make it work ;-) ? For the Pyrex/Cython POV, the new PyCapsule has very little to add... HOWEVER, still we could take advantage of the strictness of PyCapsule... using full module/[class]/funcname alongside the signature would be a good way to prevent (malicious) Python code to change the c-api dicts and vtable dicts and break things... I'm not a security guy, but just in case ... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Thu Oct 15 17:47:21 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Thu, 15 Oct 2009 12:47:21 -0300 Subject: [Cython] C++ complex support In-Reply-To: <4AD6E070.2020500@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> <4ACF85E9.2060808@student.matnat.uio.no> <4AD6E070.2020500@student.matnat.uio.no> Message-ID: On Thu, Oct 15, 2009 at 5:42 AM, Dag Sverre Seljebotn wrote: > Lisandro Dalcin wrote: >> On Fri, Oct 9, 2009 at 3:50 PM, Dag Sverre Seljebotn >> wrote: >> >> >>> Next week I'll add conjugate (I'm basically done already. In that work I >>> might likely also turn "x.imag = y" into "__Pyx_SET_CIMAG(x, y)". >>> >>> >> >> Good! BTW, how are you going to implement the setters for C99 ? >> > conjugate added. Many thanks. > Turns out I didn't need to go as deeply into it as I > thought so imag and real attributes stands as they are. If there was a > good motivating cause for changing that I can still do it, > The only concern for me is portability, nothing more... > but if so > somebody please post the C code that should be generated instead of the > current behaviour (is the issue that we shouldn't depend on __real__(x) > to be an lvalue ?but use some function instead?) > That's the problem.. I do not know how to set real/imag in a portable way in C99. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From wesmckinn at gmail.com Thu Oct 15 18:24:03 2009 From: wesmckinn at gmail.com (Wes McKinney) Date: Thu, 15 Oct 2009 12:24:03 -0400 Subject: [Cython] Spreading Cython code across multiple pyx files Message-ID: <6c476c8a0910150924l47048bfaq7cf6b6f7dff885da@mail.gmail.com> I'm starting to have a lot of Cython code, and I would like to figure out how to compile many pyx files into a single extension. I tried just listing the pyx files and am getting strange compilation errors like "multiple definitions of initEXTNAME". I googled a bit and didn't immediately find anything on this. It's listed as TODO in the online documentation. Thanks a lot, Wes From stefan_ml at behnel.de Thu Oct 15 19:00:10 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 15 Oct 2009 19:00:10 +0200 Subject: [Cython] Spreading Cython code across multiple pyx files In-Reply-To: <6c476c8a0910150924l47048bfaq7cf6b6f7dff885da@mail.gmail.com> References: <6c476c8a0910150924l47048bfaq7cf6b6f7dff885da@mail.gmail.com> Message-ID: <4AD7551A.1030208@behnel.de> Wes McKinney wrote: > I'm starting to have a lot of Cython code, and I would like to figure > out how to compile many pyx files into a single extension. I tried > just listing the pyx files and am getting strange compilation errors > like "multiple definitions of initEXTNAME". I googled a bit and didn't > immediately find anything on this. It's listed as TODO in the online > documentation. You can split the module into separate chunks (usually called xyz.pxi with an "i" for "include") and then include them into your main module .pyx file using 'include "xyz.pxi"'. There are also more sophisticated mechanisms (via cimport) to run efficient call between different modules, but if you want all your code to end up in one big module that the C compiler can optimise via aggressive inlining and friends, there's nothing better than a plain include. Stefan From dagss at student.matnat.uio.no Thu Oct 15 19:02:14 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 15 Oct 2009 19:02:14 +0200 Subject: [Cython] Spreading Cython code across multiple pyx files In-Reply-To: <6c476c8a0910150924l47048bfaq7cf6b6f7dff885da@mail.gmail.com> References: <6c476c8a0910150924l47048bfaq7cf6b6f7dff885da@mail.gmail.com> Message-ID: <4AD75596.8070403@student.matnat.uio.no> Wes McKinney wrote: > I'm starting to have a lot of Cython code, and I would like to figure > out how to compile many pyx files into a single extension. I tried > just listing the pyx files and am getting strange compilation errors > like "multiple definitions of initEXTNAME". I googled a bit and didn't > immediately find anything on this. It's listed as TODO in the online > documentation. The documentation is up-to-date in this respect. This is TODO. However you can use the "include" statement to include multiple pxi files into a single pyx, which could kind of give you what you want. Note that even with pure Python, you can't really split a module across multiple .py files... -- Dag Sverre From dagss at student.matnat.uio.no Thu Oct 15 21:01:59 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 15 Oct 2009 21:01:59 +0200 Subject: [Cython] [patch] Add ITER support to numpy.pxd In-Reply-To: References: Message-ID: <4AD771A7.5060309@student.matnat.uio.no> Neal Becker wrote: > diff -r 021e25a3bb69 Cython/Includes/numpy.pxd > --- a/Cython/Includes/numpy.pxd Tue Oct 13 11:20:37 2009 -0300 > +++ b/Cython/Includes/numpy.pxd Wed Oct 14 07:30:35 2009 -0400 > @@ -477,6 +477,10 @@ > void PyArray_MultiIter_NEXTi(broadcast multi, npy_intp i) nogil > bint PyArray_MultiIter_NOTDONE(broadcast multi) nogil > > + bint PyArray_ITER_NOTDONE (flatiter x) nogil > + void PyArray_ITER_NEXT (flatiter x) nogil > + void* PyArray_ITER_DATA (flatiter x) nogil > + > # Functions from __multiarray_api.h > > # Functions taking dtype and returning object/ndarray are disabled > Thanks, they're up. -- Dag Sverre From dalcinl at gmail.com Thu Oct 15 21:13:16 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Thu, 15 Oct 2009 16:13:16 -0300 Subject: [Cython] Spreading Cython code across multiple pyx files In-Reply-To: <4AD75596.8070403@student.matnat.uio.no> References: <6c476c8a0910150924l47048bfaq7cf6b6f7dff885da@mail.gmail.com> <4AD75596.8070403@student.matnat.uio.no> Message-ID: On Thu, Oct 15, 2009 at 2:02 PM, Dag Sverre Seljebotn wrote: > > However you can use the "include" statement to include multiple pxi > files into a single pyx, which could kind of give you what you want. > I (ab)use of this in my own projects. However, I have a high price to pay.. HTML annotation does not work well with this, it does not follow includes... and then inspecting the generated C sources is a bit of PITA. I was not able to figure out how to fix it, but if any does an push a fix, I would really appreciate the effort. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Thu Oct 15 22:32:39 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Thu, 15 Oct 2009 17:32:39 -0300 Subject: [Cython] Py3.1 supports C-APIs through PyCapsule objects In-Reply-To: References: <4AD5DCBB.8070309@behnel.de> <4AD60174.4050607@student.matnat.uio.no> <4AD6C5DC.9050309@behnel.de> Message-ID: Fix pushed and ticket closed. http://hg.cython.org/cython-devel/rev/8a58f1544bd8 On Thu, Oct 15, 2009 at 12:40 PM, Lisandro Dalcin wrote: > On Thu, Oct 15, 2009 at 3:49 AM, Stefan Behnel wrote: >> >> Dag Sverre Seljebotn wrote: >>> Stefan Behnel wrote: >>>> it looks like Py3.1 has its own way of defining external C-APIs: >>>> >>>> http://docs.python.org/3.1/extending/extending.html#using-capsules >>>> >>>> I guess we should switch to that method for C code being compiled under >>>> Py3.1+, so that Cython modules become compatible with other C extensions >>>> that start using that mechanism. >>> >>> Am I right in thinking that this is basically a standardization of what >>> we do with Cython's __pyx_capi? So we'd just have a 1:1 correspondance >>> with what we put in capsules and what we put in __pyx_capi? >> >> Actually, rereading their examples now, it's not quite the same thing. >> Cython exports a dict that contains PyCObjects/PyCapsules for each >> function, whereas their proposed approach is encapsulated by a header file >> that is presented to work like this: >> >> Export: >> >> - you create a void* array containing function pointers >> - you wrap the pointer to it in a PyCapsule >> - you write a header file around it that defines the names and an import >> ?function in whatever way. >> >> Import: >> >> The import function in the header file calls >> >> ? ? ? ?PyCapsule_Import(fq_module_attribute_name, non_blocking_flag) >> >> to import the module and retrieve the pointer by attribute name. >> >> The header file additionally defines a call macro that just statically >> knows at what offset in the pointer table you find the right function. >> >> Look at the example header file at the link above for details. >> >> I actually find Pyrex's/Cython's way of doing that a *lot* nicer and safer. >> >> However, the main machinery for C-API users is that you get a header file >> from whatever source, #include it in your C source, call the import >> function it defines, and can then call the function as you see fit. That's >> the same for both cases, so the way Cython exports the C-API is just fine IMO. >> >> OTOH, PyCapsule_Import() won't work on Cython modules, as it doesn't export >> a plain void* but a dict of void*. >> >> Also, Cython can't directly cimport a C-API that's defined in the described >> way. Instead, you have to use the header file and call the import function >> manually. But that's not too much overhead, as you have to define the >> functions anyway. Switching to the described way would really remove >> features from Cython here, with no added gain. >> >> Stefan >> _______________________________________________ >> Cython-dev mailing list >> Cython-dev at codespeak.net >> http://codespeak.net/mailman/listinfo/cython-dev >> > > After such comprehensive review, do you understand now why I said that > I was not going to make any comment and just fix Cython to make it > work ;-) ? For the Pyrex/Cython POV, the new PyCapsule has very little > to add... > > HOWEVER, still we could take advantage of the strictness of > PyCapsule... using full module/[class]/funcname alongside the > signature would be a good way to prevent (malicious) Python code to > change the c-api dicts and vtable dicts and break things... I'm not a > security guy, but just in case ... > > > > > > -- > Lisandro Dalc?n > --------------- > Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) > Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) > Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) > PTLC - G?emes 3450, (3000) Santa Fe, Argentina > Tel/Fax: +54-(0)342-451.1594 > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From greg.ewing at canterbury.ac.nz Fri Oct 16 00:14:24 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 16 Oct 2009 11:14:24 +1300 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: <4AD723B7.5000802@behnel.de> References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> Message-ID: <4AD79EC0.5070206@canterbury.ac.nz> Stefan Behnel wrote: > I would have thought that "PyObject" was a builtin type known to Cython by > now, but it seems not. I found ticket #320 now, which I think is worth > solving by making PyObject a builtin type. I'm not sure that's a good idea. I deliberately didn't make it a builtin type in Pyrex, because if you're using the language properly, you're not supposed to need it. I didn't want to create an attractive nuisance that would let people fall into the trap of using 'PyObject' when they should really be using 'object'. IMO it would be better to think about how to enhance the language to remove the need for using PyObject in the first place. -- Greg From dalcinl at gmail.com Fri Oct 16 01:23:22 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Thu, 15 Oct 2009 20:23:22 -0300 Subject: [Cython] bitten again by typetesting and None Message-ID: I've just realized that my code is broken in many places... Suppose I have cdef class MyClass: cdef int val now I do: cdef object o = None cdef int i = (o).val And this does not fail, and then the "i" variable have garbage... Do we really need to allow 'None' when using "?" in the cast?? -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From robertwb at math.washington.edu Fri Oct 16 08:30:45 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 15 Oct 2009 23:30:45 -0700 Subject: [Cython] bitten again by typetesting and None In-Reply-To: References: Message-ID: <9746E7A9-DE3C-4394-BDFD-87227BCA991D@math.washington.edu> On Oct 15, 2009, at 4:23 PM, Lisandro Dalcin wrote: > I've just realized that my code is broken in many places... > > Suppose I have > > cdef class MyClass: > cdef int val > > now I do: > > cdef object o = None > > cdef int i = (o).val > > > And this does not fail, and then the "i" variable have garbage... > > Do we really need to allow 'None' when using "?" in the cast?? I was trying to think of a usecase and I really can't. I guess it's just for consistency with cdef MyClass x = foo() - Robert From robertwb at math.washington.edu Fri Oct 16 08:33:07 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 15 Oct 2009 23:33:07 -0700 Subject: [Cython] Bug day? In-Reply-To: <9121CC3B-2F9D-4F0C-9360-829398488902@math.washington.edu> References: <4AC7A5F2.6000503@student.matnat.uio.no> <1e52e0880910090052v42759639reb587e36f4c02140@mail.gmail.com> <1e52e0880910140434y50561342k6ad378d142714a6c@mail.gmail.com> <1e52e0880910141054o220412a0v6c6a658cf650ed58@mail.gmail.com> <9121CC3B-2F9D-4F0C-9360-829398488902@math.washington.edu> Message-ID: <92D974CA-92E5-4A2A-A6B8-706E6BB4B06E@math.washington.edu> Thanks to everyone who showed up--I think we got a fair amount done and knocked out some nasty bugs (and had a good time doing it). 0.12 isn't ready yet, but it's a lot closer. - Robert From stefan_ml at behnel.de Fri Oct 16 08:50:52 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Oct 2009 08:50:52 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: <4AD79EC0.5070206@canterbury.ac.nz> References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> Message-ID: <4AD817CC.9030907@behnel.de> Greg Ewing wrote: > Stefan Behnel wrote: > >> I would have thought that "PyObject" was a builtin type known to Cython by >> now, but it seems not. I found ticket #320 now, which I think is worth >> solving by making PyObject a builtin type. > > I'm not sure that's a good idea. I deliberately didn't make > it a builtin type in Pyrex, because if you're using the language > properly, you're not supposed to need it. I didn't want to > create an attractive nuisance that would let people fall > into the trap of using 'PyObject' when they should really > be using 'object'. > > IMO it would be better to think about how to enhance the > language to remove the need for using PyObject in the first > place. Back to the "stolen"/"borrowed" reference support, then. Stefan From stefan_ml at behnel.de Fri Oct 16 08:58:03 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Oct 2009 08:58:03 +0200 Subject: [Cython] bitten again by typetesting and None In-Reply-To: <9746E7A9-DE3C-4394-BDFD-87227BCA991D@math.washington.edu> References: <9746E7A9-DE3C-4394-BDFD-87227BCA991D@math.washington.edu> Message-ID: <4AD8197B.3060307@behnel.de> Robert Bradshaw wrote: > On Oct 15, 2009, at 4:23 PM, Lisandro Dalcin wrote: > >> I've just realized that my code is broken in many places... >> >> Suppose I have >> >> cdef class MyClass: >> cdef int val >> >> now I do: >> >> cdef object o = None >> >> cdef int i = (o).val >> >> >> And this does not fail, and then the "i" variable have garbage... >> >> Do we really need to allow 'None' when using "?" in the cast?? > > I was trying to think of a usecase and I really can't. I guess it's > just for consistency with > > cdef MyClass x = foo() I agree that extension type casts should be exact and tested ones should fail for None. http://trac.cython.org/cython_trac/ticket/417 Stefan From dagss at student.matnat.uio.no Fri Oct 16 09:29:08 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 16 Oct 2009 09:29:08 +0200 Subject: [Cython] [cython-users] Re: PyObject* definitions in std .pxd import files In-Reply-To: References: <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD72639.3060508@behnel.de> Message-ID: <4AD820C4.6010205@student.matnat.uio.no> Robert Bradshaw wrote: > > On Oct 15, 2009, at 4:59 PM, Lisandro Dalcin wrote: > >> On Thu, Oct 15, 2009 at 10:40 AM, Stefan Behnel >> wrote: >>> >>> >>> Neal Becker wrote: >>>> I think this works: >>>> >>>> 1) In numpy.pxd, use: >>>> from python_ref cimport PyObject >>>> >>>> 2) In sum.pyx: >>>> >>>> from python_ref cimport Py_XINCREF, Py_XDECREF, PyObject >>> >>> Yes, that should be ok. >>> >>> I looked around a bit more in Cython/Includes/, and it seems like it >>> really >>> needs some broader cleanup. There are a couple of redefinitions of >>> PyObject >>> and various function definitions that use PyObject* and should use >>> object >>> instead. >>> >> >> Could we use this for PyObject ?: >> >> ctypedef struct PyObject > > The question is whether to allow casting objects to any struct > pointer, or making PyObject special. Another option would be to give a > syntax to mark structs as raw versions of objects, which could handle > PyTypeObject, etc. > > I'm with Greg, however, that most of the time we should be looking at > the usecases and deciding if we can avoid having to treat objects as > pointers. (E.g. being able to declare a variable as an object that > might be NULL.) That being said, I'm not sure it's possible to come up > with nice solutions to everything, and if the user wants to do > something messy maybe we shouldn't be adding it to the language. Even so, there's a lot of code which already uses various forms of custom-declared PyObject*. My primary concern here is that I think we should go further with disallowing myobject If we include PyObject as a builtin type, it becomes possible to allow myobject but disallow the above. Even if we do add syntax features for dealing with these situations (declaring borrowed and stolen references and objects which can be NULL...personally I'm starting to think there is too much special-purpose syntax already...) it's quite a matter to break backwards compatability and disallow existing code from getting a PyObject*! Requiring that people remove their own definitions of PyObject and use the builtin instead is much less of a matter. So I'd say there's a case for a) Add a builtin PyObject* b) Once that is done, start emitting warning for anything but myobject and myobject (the builtin one only); then emit an error in the next release. Dag Sverre From sturla at molden.no Fri Oct 16 09:29:23 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 16 Oct 2009 09:29:23 +0200 Subject: [Cython] Spreading Cython code across multiple pyx files In-Reply-To: <4AD75596.8070403@student.matnat.uio.no> References: <6c476c8a0910150924l47048bfaq7cf6b6f7dff885da@mail.gmail.com> <4AD75596.8070403@student.matnat.uio.no> Message-ID: Den 15. okt. 2009 kl. 19.02 skrev Dag Sverre Seljebotn : > Note that even with pure Python, you can't really split a module > across > multiple .py files... > But you can import a zip file as a package or import modules from a zip file. From dagss at student.matnat.uio.no Fri Oct 16 10:48:35 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 16 Oct 2009 10:48:35 +0200 Subject: [Cython] C++ complex support In-Reply-To: References: <3337827751.1469432@smtp.netcom.no> <4ACE3279.3000809@student.matnat.uio.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> <4ACF85E9.2060808@student.matnat.uio.no> <4AD6E070.2020500@student.matnat.uio.no> Message-ID: <4AD83363.90004@student.matnat.uio.no> Can http://trac.cython.org/cython_trac/ticket/398 be closed now, or is there still stuff left to do? (We can create a follow-up for C99-compatible attribute setters.) Dag Sverre Lisandro Dalcin wrote: > On Thu, Oct 15, 2009 at 5:42 AM, Dag Sverre Seljebotn > wrote: > >> Lisandro Dalcin wrote: >> >>> On Fri, Oct 9, 2009 at 3:50 PM, Dag Sverre Seljebotn >>> wrote: >>> >>> >>> >>>> Next week I'll add conjugate (I'm basically done already. In that work I >>>> might likely also turn "x.imag = y" into "__Pyx_SET_CIMAG(x, y)". >>>> >>>> >>>> >>> Good! BTW, how are you going to implement the setters for C99 ? >>> >>> >> conjugate added. >> > > Many thanks. > > >> Turns out I didn't need to go as deeply into it as I >> thought so imag and real attributes stands as they are. If there was a >> good motivating cause for changing that I can still do it, >> >> > > The only concern for me is portability, nothing more... > > >> but if so >> somebody please post the C code that should be generated instead of the >> current behaviour (is the issue that we shouldn't depend on __real__(x) >> to be an lvalue but use some function instead?) >> >> > > That's the problem.. I do not know how to set real/imag in a portable > way in C99. > > > From jason-sage at creativetrax.com Fri Oct 16 11:24:05 2009 From: jason-sage at creativetrax.com (jason-sage at creativetrax.com) Date: Fri, 16 Oct 2009 04:24:05 -0500 Subject: [Cython] __richcmp__ and inheritance Message-ID: <4AD83BB5.5050209@creativetrax.com> I've just been struggling with understanding how inheritance and __richcmp__ are related. Here is my example code: cdef class A: cdef int a def __init__(self, a): self.a=a def __hash__(self): return self.a def __richcmp__(A self, A other, int op): print "using op: ",op if op == 2: # == return self.a == other.a cdef class B(A): def __init__(self, a): self.a=a+1 def __hash__(self): return self.a*2 Mike Hansen found some reference somewhere that said that either all of __hash__, __richcmp__, and __cmp__ are inherited or none are (I didn't see this in the manual, but maybe I was looking in the wrong place??). So, predictably: sage: A(2)==A(2) using op: 2 True sage: B(2)==B(2) False However, the confusing part is this: sage: B(2).__eq__(B(2)) using op: 2 True Also, unlike most other special methods, I noticed that if I defined __richcmp__ as below (removing the type declaration for self): def __richcmp__(self, A other, int op): print "using op: ",op if op == 2: # == return self.a == other.a then self can't access the cdef'd "a" attribute. I think most other commands recognize that self is of type A. That took a bit to figure out, and I don't remember that being in the Cython docs either. Thanks, Jason From dagss at student.matnat.uio.no Fri Oct 16 13:48:43 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 16 Oct 2009 13:48:43 +0200 Subject: [Cython] [cython-users] Re: PyObject* definitions in std .pxd import files In-Reply-To: References: <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD72639.3060508@behnel.de> <4AD820C4.6010205@student.matnat.uio.no> Message-ID: <4AD85D9B.4030708@student.matnat.uio.no> Neal Becker wrote: > I'd just like to point out that the problem I ran into was not at all an > unusual use case. I was trying out cython to interface to some hypothetical > C code. The first test was C code with this interface: > > void F (double* in, double* out) > > where 'out' was a numpy array allocated by cython. No problem with this use > case. > > The second test was > > double* F (double* in) > > where the output was allocated by the C code and needed to be adopted into a > numpy array. This is where trouble began. I would think this use case > would also be quite common. > Yes, I hope this is easier to deal with in a year. It *can* be made quite user-friendly just by creating some utility functions to deal with it though. Dag Sverre From dagss at student.matnat.uio.no Fri Oct 16 13:59:55 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 16 Oct 2009 13:59:55 +0200 Subject: [Cython] Dependency tracking Message-ID: <4AD8603B.9010805@student.matnat.uio.no> I've started to use SCons for building Cython (a lovely experience compared to distutils .. I'll upload the necesarry files and write some docs some happy day). It has excellent support for plugging in dependency tracking of pyx files (i.e. get list of cimported pxd files, include pxi files and cdef extern-ed h files). Is there a dependency finder for Cython sources somewhere? I would think Sage has something like this developed... I don't care about performance this time around. Dag Sverre From stefan_ml at behnel.de Fri Oct 16 14:14:24 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Oct 2009 14:14:24 +0200 Subject: [Cython] Dependency tracking In-Reply-To: <4AD8603B.9010805@student.matnat.uio.no> References: <4AD8603B.9010805@student.matnat.uio.no> Message-ID: <4AD863A0.6040009@behnel.de> Dag Sverre Seljebotn wrote: > I've started to use SCons for building Cython (a lovely experience > compared to distutils .. I'll upload the necesarry files and write some > docs some happy day). It has excellent support for plugging in > dependency tracking of pyx files (i.e. get list of cimported pxd files, > include pxi files and cdef extern-ed h files). Sounds nice. There's also a descendent of setuptools that sounds interesting: http://pypi.python.org/pypi/distribute > Is there a dependency finder for Cython sources somewhere? I don't remember where exactly that's generated, but at least Main.py reads the dependency files from the last compiler run in read_dependency_file(). I think it's collected somewhere in the parser. Stefan From stefan_ml at behnel.de Fri Oct 16 14:15:57 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Oct 2009 14:15:57 +0200 Subject: [Cython] Dependency tracking In-Reply-To: <4AD8603B.9010805@student.matnat.uio.no> References: <4AD8603B.9010805@student.matnat.uio.no> Message-ID: <4AD863FD.6060803@behnel.de> Dag Sverre Seljebotn wrote: > Is there a dependency finder for Cython sources somewhere? Note that you can't determine the transitive dependencies (e.g. of .pxd or .pxi files) without parsing, so the best you can do is what the current code does anyway. Stefan From magnus at hetland.org Fri Oct 16 14:20:16 2009 From: magnus at hetland.org (Magnus Lie Hetland) Date: Fri, 16 Oct 2009 14:20:16 +0200 Subject: [Cython] Dependency tracking In-Reply-To: <4AD8603B.9010805@student.matnat.uio.no> References: <4AD8603B.9010805@student.matnat.uio.no> Message-ID: On Oct 16, 2009, at 13:59, Dag Sverre Seljebotn wrote: > I've started to use SCons for building Cython (a lovely experience > compared to distutils .. I'll upload the necesarry files and write > some > docs some happy day). It has excellent support for plugging in > dependency tracking of pyx files (i.e. get list of cimported pxd > files, > include pxi files and cdef extern-ed h files). Do you mean that you're using SCons for building other programs that you've written in the Cython language, or that you're using it to build the Cython distribution itself? If it's the former, that sounds very interesting. All my build setups (setup.py + Makefile) have been a bit semi-hackish so far, IMO... :-} -- Magnus Lie Hetland http://hetland.org From ndbecker2 at gmail.com Fri Oct 16 14:38:33 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 16 Oct 2009 08:38:33 -0400 Subject: [Cython] Dependency tracking References: <4AD8603B.9010805@student.matnat.uio.no> Message-ID: Dag Sverre Seljebotn wrote: > I've started to use SCons for building Cython (a lovely experience > compared to distutils .. I'll upload the necesarry files and write some > docs some happy day). It has excellent support for plugging in > dependency tracking of pyx files (i.e. get list of cimported pxd files, > include pxi files and cdef extern-ed h files). > > Is there a dependency finder for Cython sources somewhere? I would think > Sage has something like this developed... > > I don't care about performance this time around. > > Dag Sverre I'm an scons fan. Can I get a copy? From dagss at student.matnat.uio.no Fri Oct 16 14:42:03 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 16 Oct 2009 14:42:03 +0200 Subject: [Cython] Dependency tracking In-Reply-To: References: <4AD8603B.9010805@student.matnat.uio.no> Message-ID: <4AD86A1B.3040409@student.matnat.uio.no> Magnus Lie Hetland wrote: > On Oct 16, 2009, at 13:59, Dag Sverre Seljebotn wrote: > > >> I've started to use SCons for building Cython (a lovely experience >> compared to distutils .. I'll upload the necesarry files and write >> some >> docs some happy day). It has excellent support for plugging in >> dependency tracking of pyx files (i.e. get list of cimported pxd >> files, >> include pxi files and cdef extern-ed h files). >> > > Do you mean that you're using SCons for building other programs that > you've written in the Cython language, or that you're using it to > build the Cython distribution itself? > > If it's the former, that sounds very interesting. All my build setups > (setup.py + Makefile) have been a bit semi-hackish so far, IMO... :-} > The former (definitely!, we don't want a SCons dependency for Cython). It's very nice, but there's some warts I'd like to fix before taking the time to bundle it with Cython. If you want something temporarily to hack with (or cooperate on), tell me. Dag Sverre From magnus at hetland.org Fri Oct 16 14:44:54 2009 From: magnus at hetland.org (Magnus Lie Hetland) Date: Fri, 16 Oct 2009 14:44:54 +0200 Subject: [Cython] Dependency tracking In-Reply-To: <4AD86A1B.3040409@student.matnat.uio.no> References: <4AD8603B.9010805@student.matnat.uio.no> <4AD86A1B.3040409@student.matnat.uio.no> Message-ID: <0CB0D7A7-5993-40DA-9479-9F25A1428AFF@hetland.org> On Oct 16, 2009, at 14:42, Dag Sverre Seljebotn wrote: > The former (definitely!, we don't want a SCons dependency for Cython). > It's very nice, but there's some warts I'd like to fix before taking > the > time to bundle it with Cython. If you want something temporarily to > hack > with (or cooperate on), tell me. I surely would :) (I've barely used SCons in the past, so I may not be able to contribute much. But who knows, maybe I'll stumble across something ;) -- Magnus Lie Hetland http://hetland.org From dagss at student.matnat.uio.no Fri Oct 16 14:46:50 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 16 Oct 2009 14:46:50 +0200 Subject: [Cython] Dependency tracking In-Reply-To: References: <4AD8603B.9010805@student.matnat.uio.no> Message-ID: <4AD86B3A.5040708@student.matnat.uio.no> Neal Becker wrote: > Dag Sverre Seljebotn wrote: > > >> I've started to use SCons for building Cython (a lovely experience >> compared to distutils .. I'll upload the necesarry files and write some >> docs some happy day). It has excellent support for plugging in >> dependency tracking of pyx files (i.e. get list of cimported pxd files, >> include pxi files and cdef extern-ed h files). >> >> Is there a dependency finder for Cython sources somewhere? I would think >> Sage has something like this developed... >> >> I don't care about performance this time around. >> >> Dag Sverre >> > > I'm an scons fan. Can I get a copy? > OK the next time I have a spare moment I'll try to upload something somewhere. (It's mostly David's work and can be found in numscons, but I did some changes and plan more.) Dag Sverre From dalcinl at gmail.com Fri Oct 16 16:37:55 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 16 Oct 2009 11:37:55 -0300 Subject: [Cython] C++ complex support In-Reply-To: <4AD83363.90004@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <74B67B9B-D16B-4DDC-B43C-FEF7BE5111F1@math.washington.edu> <4ACF85E9.2060808@student.matnat.uio.no> <4AD6E070.2020500@student.matnat.uio.no> <4AD83363.90004@student.matnat.uio.no> Message-ID: On Fri, Oct 16, 2009 at 5:48 AM, Dag Sverre Seljebotn wrote: > Can > > http://trac.cython.org/cython_trac/ticket/398 > > be closed now, or is there still stuff left to do? > > (We can create a follow-up for C99-compatible attribute setters.) > I should implement the external ctypedef stuff as I did for integrals, but that could also go in a new ticket... So I would say yes, close the ticket. Before closing, could you add a new comment a link to the changeset you pushed for z.conjugate() ? -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sturla at molden.no Fri Oct 16 16:40:42 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 16 Oct 2009 16:40:42 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: <4AD79EC0.5070206@canterbury.ac.nz> References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> Message-ID: <4AD885EA.7020403@molden.no> Greg Ewing skrev: > IMO it would be better to think about how to enhance the > language to remove the need for using PyObject in the first > place. > From my own experience: - When sorting a list, we know refcounts do not change, we just need to swap pointers quickly around. We can use PyObject* for this, but not object because Cython/Pyrex starts refcounting. - When re-implementing scipy.signal.lfilter, I used two buffers for filter delays (z values), which was swapped for every sample filtered. Just using pointers is fast, using object is slow. Suggestion 1: Provide a new built-in type "cobject", indicating PyObject* without automatic refcounting. This might lead to more efficient code, avoiding the second layer of indirection we'd get from object *. It might actually be implemented as simple as ctypedef PyObject *cobject. Now we can write code like this: cdef _sort( cobject array[] ) nogil: # here we can swap array[i] and array[j] quickly def sort(object iterable): cdef np.ndarray[object] array = np.array(iterable, dtype=object) cdef Py_ssize_t n, i with nogil: _sort( array.data) # allow cobject*, but not object* n = array.shape[0] for i in range(n): iterable[i] = array[i] Advantage: Very simple to implement and gives efficient C. This is basically how PyObject is used in Pyrex/Cython anyway. Disadvantage: no benefit for numerical programmers like myself. Suggestion 2: Introduce a weakref keyword. Basically a qualifier to a Python object that means 'turn off refcounting please'. A weakref object would not require the GIL. It would be the responsibility of the programmer not to mess up refcounts and ensure that a reference to the object is actually kept. And efficient sort could now look like this: cdef _sort(weakref np.ndarray[weakref object] array) nogil: # here we can swap array[i] and array[j] quickly, # weakrefs are not refcounted def sort(object iterable): cdef np.ndarray[object] array = np.array(iterable, dtype=object) cdef weakref np.ndarray[weakref object] wref_array = array cdef Py_ssize_t n, i with nogil: _sort( wref_array ) n = array.shape[0] for i in range(n): iterable[i] = array[i] Advantage: "cdef weakref np.ndarray[double] array" would be a major advantage for numerical programming, as it allows ndarrays to be passed to functions in nogil blocks. This would allow a "weakref np.ndarray" to be used like a Fortran 90 pointer, i.e. operator [] indexes the referenced buffer, not the pointer. Suggestion 3: Allow pointers to Python objects (object *) which would indicate a second layer of indirection (PyObject**). It would be the responsibility of the programmer to ensure that an object* always points to a living object. Now an efficient sort could look like this: cdef _sort(object *parray[]) nogil: # Here we can swap parray[i] and parray[j] without # any refcounting slowing us down or locking the # interpreter. parray[i][0] is iterable[i]. def sort(object iterable): cdef np.ndarray[object] tmp cdef Py_ssize_t n, i cdef np.ndarray[object*] array = np.zeros(len(iterable), dtype=int) n = len(lst) for i in range(n): array[i] = &(iterable[i]) with nogil: _sort( array.data ) tmp = np.array(lst, dtype=object) for i in range(n): tmp[i] = array[i][0] for i in range(n): iterable[i] = tmp[i] Problem: some people will probably discover that np.ndarray[PyObject*] is more efficient and use that instead. Thus, including object* may not work as intended - i.e. PyObject would still be used. The double indirection also makes the syntax more messy. Advantage: allows pointers to ndarrays for numerical programming: cdef np.ndarray[double] array = np.zeros(10) cdef np.ndarray[double] *parray parray = &array It would look nicer if unary * did work, so we could write *parray[i] instead of parray[0][i]. This syntax is error prone, though, as someone could easily write parray[i] instead of parray[0][i]. With a dtype of object, the mistake might not be caught by the compiler either, but crash at run-time. Indexing becomes a havoc: cdef np.ndarray[object] b cdef np.ndarray[np.npy_intp] tmp = np.arange(&b.data, &b.data + len(b) * sizeof(object*), sizeof(object*)) cdef np.ndarray[object] *a = &b => index a[0][i] to get b[i], a not refcounted, content refcounted cdef np.ndarray[object*] *a = &tmp => index a[0][i][0] to get b[i], nothing refcounted cdef np.ndarray[object*] a = tmp => index a[i][0] to get b[i], a refcounted, content not refcounted cdef object *a = b.data => index a[i] to get b[i], a not refcounted, content refcounted cdef object **a = tmp.data => index a[0][i] to get b[i], nothing refcounted This is a syntactical mess and error prone. One could also consider to allow both cobject and object*, making the sort functions something like this: cdef _sort(np.ndarray[cobject] *parray) nogil: # faster than using object *parray[], as indexes are transposed: # parray[0][i] is iterable[i], instead of parray[i][0], adding further confusion. The bad thing is that this is how PyObject** often is used in Pyrex/Cython code. Having a weakref keyword is much more safe and clean, and better in any way I can think of. Except that it is more difficult to implement. Finally, if you are afraid of dangling pointers, none of these suggestions are any worse than this: cdef char *pstr string = "whatever" pstr = string My personal preference would thus be a weakref keyword (or something similar) if that kind of syntax is feasible. It gives full control over refcounting, removes the need to use PyObject*, and allows "Fortran pointers" for numpy programming. One just has to educate programmers to use numpy arrays instead of allocating C buffers with malloc: cdef object tmp cdef weakref np.ndarray[weakref object] arr arr = tmp = np.zeros(10, dtype=object) instead of: cdef PyObject **arr = malloc(10 * sizeof(PyObject*)) It should do almost the same, while preventing common C mistakes like forgetting (or not bothering) to check the return value from malloc, forgetting to call free afterwards, skipping the call to free in case of an exception, etc. At least, please don't allow object* in the language. I really don't want to waste my time debugging someone's source code using it (and bad experience tells me I am going to...) Regards, Sturla Molden From dalcinl at gmail.com Fri Oct 16 16:44:16 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 16 Oct 2009 11:44:16 -0300 Subject: [Cython] bitten again by typetesting and None In-Reply-To: <4AD8197B.3060307@behnel.de> References: <9746E7A9-DE3C-4394-BDFD-87227BCA991D@math.washington.edu> <4AD8197B.3060307@behnel.de> Message-ID: On Fri, Oct 16, 2009 at 3:58 AM, Stefan Behnel wrote: > > Robert Bradshaw wrote: >> On Oct 15, 2009, at 4:23 PM, Lisandro Dalcin wrote: >> >>> I've just realized that my code is broken in many places... >>> >>> Suppose I have >>> >>> cdef class MyClass: >>> ? ?cdef int val >>> >>> now I do: >>> >>> cdef object o = None >>> >>> cdef int i = (o).val >>> >>> >>> And this does not fail, and then the "i" variable have garbage... >>> >>> Do we really need to allow 'None' when using "?" in the cast?? >> >> I was trying to think of a usecase and I really can't. I guess it's >> just for consistency with >> >> cdef MyClass x = foo() > > I agree that extension type casts should be exact and tested ones should > fail for None. > What did you meant with "exact" ? Subclasses should pass the typetest, right? > > http://trac.cython.org/cython_trac/ticket/417 > Thanks. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Fri Oct 16 16:46:50 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 16 Oct 2009 11:46:50 -0300 Subject: [Cython] Spreading Cython code across multiple pyx files In-Reply-To: References: <6c476c8a0910150924l47048bfaq7cf6b6f7dff885da@mail.gmail.com> <4AD75596.8070403@student.matnat.uio.no> Message-ID: On Fri, Oct 16, 2009 at 4:29 AM, Sturla Molden wrote: > > Den 15. okt. 2009 kl. 19.02 skrev Dag Sverre Seljebotn ?>: > >> Note that even with pure Python, you can't really split a module >> across >> multiple .py files... >> > > But you can import a zip file as a package or import modules from a > zip file. > Does zipimport support C extension modules? I think not (though IIRC setuptool's has support for this) -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From ndbecker2 at gmail.com Fri Oct 16 16:53:43 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 16 Oct 2009 10:53:43 -0400 Subject: [Cython] [cython-users] Re: more ref counting References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> Message-ID: Do any of these suggestions address my problem with array base? ctypedef class numpy.ndarray [object PyArrayObject]: cdef __cythonbufferdefaults__ = {"mode": "strided"} cdef: # Only taking a few of the most commonly used and stable fields. # One should use PyArray_* macros instead to access the C fields. char *data int ndim "nd" npy_intp *shape "dimensions" npy_intp *strides dtype descr object base <<< my addition Problem was that base could be NULL, and attempting to assign to it would try to call DECREF, and BOOM. From sturla at molden.no Fri Oct 16 16:58:54 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 16 Oct 2009 16:58:54 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ACF6A5C.7040102@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> Message-ID: <4AD88A2E.2080901@molden.no> Dag Sverre Seljebotn skrev: > For auto-vectorization of loops with GCC it is extremely important. I.e. > a simple vectorizable for-loop will have SSE instructions generated if > restrict is declared, otherwise not! So easily around 2x speedup from > restrict in those cases. I was wondering it it could be solved using some keyword arguments to the buffer syntax? cdef np.ndarray[double] a => a.data is declared "char*" cdef np.ndarray[double, qual='const'] a => a.data is declared "const char* " cdef np.ndarray[double, qual='const,restrict'] a => a.data is declared "const char*restrict" cdef np.ndarray[double, qual='restrict'] a => a.data is declared "char*restrict " Or perhaps one qualifier for data and one for pointer? cdef np.ndarray[double, dqual='const', pqual='restrict,const'] a => a->data is declared "const char*const restrict" If the compiler is smart enough, it should see that the pointer is restricted (even though it's a char*) or that elements are const, regardless of typecast to double*. Or one could generate code that casts the pointer from char* to const double* or whatever,with correct qualifiers. That would not require an extension of Cython's syntax, just arguments for declaring the buffer. S.M. From stefan_ml at behnel.de Fri Oct 16 17:04:00 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Oct 2009 17:04:00 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4AD10080.3070200@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> <4ACF599E.6060402@molden.no> <4ACF7951.8020505@behnel.de> <4AD10080.3070200@molden.no> Message-ID: <4AD88B60.1000205@behnel.de> Sturla Molden wrote: > Stefan Behnel skrev: >> cdef some_func(object[int, 2] b, x,y,z): >> that calls the first after extracting the buffer. >> >> That wouldn't immediately fix the issue of slicing, but at least it would >> reduce any Python overhead in calling such a function. It wouldn't break >> ref-counting either, since we know that one of the functions on the call >> stack holds a reference to the buffer during the call. > > Are you sure it would work? What if somesone does a "del b" in > some_func? If you do not incref b before calling the function, what > would a del do to the refcount? Two comments: 1) we don't currently support del for local variables, so that's not currently an issue 2) if we support del, then using it on the buffer parameter would simply prevent the optimisation from happening, i.e. that's a case where the function splitting doesn't apply (see the parts of my mail that you stripped). Stefan From stefan_ml at behnel.de Fri Oct 16 17:06:51 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Oct 2009 17:06:51 +0200 Subject: [Cython] bitten again by typetesting and None In-Reply-To: References: <9746E7A9-DE3C-4394-BDFD-87227BCA991D@math.washington.edu> <4AD8197B.3060307@behnel.de> Message-ID: <4AD88C0B.80006@behnel.de> Lisandro Dalcin wrote: > On Fri, Oct 16, 2009 at 3:58 AM, Stefan Behnel wrote: >>> cdef MyClass x = foo() >> I agree that extension type casts should be exact and tested ones should >> fail for None. > > What did you meant with "exact" ? Subclasses should pass the typetest, right? Sorry, sure, "anything that qualifies as a true instance of the checked class", including subclasses. Stefan From stefan_ml at behnel.de Fri Oct 16 17:08:48 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Oct 2009 17:08:48 +0200 Subject: [Cython] Spreading Cython code across multiple pyx files In-Reply-To: References: <6c476c8a0910150924l47048bfaq7cf6b6f7dff885da@mail.gmail.com> <4AD75596.8070403@student.matnat.uio.no> Message-ID: <4AD88C80.8070104@behnel.de> Lisandro Dalcin wrote: > On Fri, Oct 16, 2009 at 4:29 AM, Sturla Molden wrote: >> Den 15. okt. 2009 kl. 19.02 skrev Dag Sverre Seljebotn > >: >> >>> Note that even with pure Python, you can't really split a module >>> across >>> multiple .py files... >>> >> But you can import a zip file as a package or import modules from a >> zip file. >> > > Does zipimport support C extension modules? I think not (though IIRC > setuptool's has support for this) Only so far as it extracts the .so file to a hidden subdirectory of your home directory. So I'd rather call the support non-existent. The problem is that the dynamic loader needs to access the shared library, and those rarely support ZIP files. Stefan From magnus at hetland.org Fri Oct 16 17:12:08 2009 From: magnus at hetland.org (Magnus Lie Hetland) Date: Fri, 16 Oct 2009 17:12:08 +0200 Subject: [Cython] Another (small) sunshine story Message-ID: <081E8EFD-F0E7-4B94-BA79-17DA31CF8BC3@hetland.org> Perhaps only useful for morale/enthusiasm, I'd think this sort of thing is still on topic, so... :-> I've been having problems with part of my code. I ended up rewriting a very similar piece of code somewhere else, and it was **much** faster. Didn't quite get it, but just shrugged and let it go. Then I wanted to run some more ambitious experiments with the old code. My progress bar told me (when it finally got enough progress to tell me anything) that the experiment would probably take a couple of weeks! Now, this estimate was probably highly inaccurate, but still a bit too high for my taste -- I had hoped to get some results by the next day... (Actually, I found this estimate when I looked at the computer the morning after I started the experiment.) So I just gave up. Until a colleague convinced me to have another look. It turns out I had renamed my iteration variables, and some related variables used to index a rather large NumPy array ... but I *hadn't* updated the cdef declarations -- so they were still for the old names. Easy enough to fix. Now half the experiment has run, and there's an estimated 20 minutes left :-D Now, the speedup probably isn't *quite* as dramatic as it seems (as I suspect the estimate of the progress bar was a bit off -- but it had only managed to get 2% done during the night). But still ... I guess the large factor here is because I had a double for loop with NumPy indexing in the innermost loop. So if each of these gets a speedup factor, the total there should be the cube of that speedup factor, right? Anyway: Once again, Cython let me do experiments I probably wouldn't have done otherwise. Yay :) (Or, to put it differently: Once again, I'm too n00bish to make my experiment run fast enough the first time around ;) - M -- Magnus Lie Hetland http://hetland.org From stefan_ml at behnel.de Fri Oct 16 17:14:23 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Oct 2009 17:14:23 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: <4AD885EA.7020403@molden.no> References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> Message-ID: <4AD88DCF.3040906@behnel.de> Sturla Molden wrote: > - When sorting a list, we know refcounts do not change, we just need to > swap pointers quickly around. We can use PyObject* for this, but not > object because Cython/Pyrex starts refcounting. I think that can be implemented as an optimisation. Just write a,b = b,a or maybe l[i], l[j] = l[j], l[i] in your code and add a tweak to Cython that lets it drop the ref-counting in this exact case. Stefan From dalcinl at gmail.com Fri Oct 16 17:15:36 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 16 Oct 2009 12:15:36 -0300 Subject: [Cython] bitten again by typetesting and None In-Reply-To: <4AD88C0B.80006@behnel.de> References: <9746E7A9-DE3C-4394-BDFD-87227BCA991D@math.washington.edu> <4AD8197B.3060307@behnel.de> <4AD88C0B.80006@behnel.de> Message-ID: On Fri, Oct 16, 2009 at 12:06 PM, Stefan Behnel wrote: > > Lisandro Dalcin wrote: >> On Fri, Oct 16, 2009 at 3:58 AM, Stefan Behnel wrote: >>>> cdef MyClass x = foo() >>> I agree that extension type casts should be exact and tested ones should >>> fail for None. >> >> What did you meant with "exact" ? Subclasses should pass the typetest, right? > > Sorry, sure, "anything that qualifies as a true instance of the checked > class", including subclasses. > BTW, that would be also the case for builtin types? IIUC, currently we check for *exactly* the type. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sturla at molden.no Fri Oct 16 17:25:09 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 16 Oct 2009 17:25:09 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> Message-ID: <4AD89055.3090302@molden.no> Neal Becker skrev: > Do any of these suggestions address my problem with array base? > > ctypedef class numpy.ndarray [object PyArrayObject]: > cdef __cythonbufferdefaults__ = {"mode": "strided"} > > cdef: > # Only taking a few of the most commonly used and stable fields. > # One should use PyArray_* macros instead to access the C > fields. > char *data > int ndim "nd" > npy_intp *shape "dimensions" > npy_intp *strides > dtype descr > object base <<< my addition > > Problem was that base could be NULL, and attempting to assign to it would > try to call DECREF, and BOOM. > You have to use Py_XDECREF and Py_XINCREF instead of Py_DECREF and Py_INCREF. S.M. From dagss at student.matnat.uio.no Fri Oct 16 17:31:56 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 16 Oct 2009 17:31:56 +0200 Subject: [Cython] Another (small) sunshine story In-Reply-To: <081E8EFD-F0E7-4B94-BA79-17DA31CF8BC3@hetland.org> References: <081E8EFD-F0E7-4B94-BA79-17DA31CF8BC3@hetland.org> Message-ID: <4AD891EC.10005@student.matnat.uio.no> Magnus Lie Hetland wrote: > Perhaps only useful for morale/enthusiasm, I'd think this sort of > thing is still on topic, so... :-> > > I've been having problems with part of my code. I ended up rewriting a > very similar piece of code somewhere else, and it was **much** faster. > Didn't quite get it, but just shrugged and let it go. > > Then I wanted to run some more ambitious experiments with the old > code. My progress bar told me (when it finally got enough progress to > tell me anything) that the experiment would probably take a couple of > weeks! Now, this estimate was probably highly inaccurate, but still a > bit too high for my taste -- I had hoped to get some results by the > next day... (Actually, I found this estimate when I looked at the > computer the morning after I started the experiment.) So I just gave > up. Until a colleague convinced me to have another look. > > It turns out I had renamed my iteration variables, and some related > variables used to index a rather large NumPy array ... but I *hadn't* > updated the cdef declarations -- so they were still for the old names. > > Easy enough to fix. Now half the experiment has run, and there's an > estimated 20 minutes left :-D > Thanks for the morale booster! The problem you had here can be reduced when the planned "undeclared" warning/error is supported: @cython.errors(undeclared=True) def f(): cdef int speling cdef object x x = 3 # ok spelling = 3 # gives error Dag Sverre From sturla at molden.no Fri Oct 16 17:32:18 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 16 Oct 2009 17:32:18 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: <4AD88DCF.3040906@behnel.de> References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> <4AD88DCF.3040906@behnel.de> Message-ID: <4AD89202.5020107@molden.no> Stefan Behnel skrev: > in your code and add a tweak to Cython that lets it drop the ref-counting > in this exact case. > > I am sure it would be easy, if I knew your code base. (Which btw I am hoping to learn, but with little success so far.) S.M. From ndbecker2 at gmail.com Fri Oct 16 17:32:36 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 16 Oct 2009 11:32:36 -0400 Subject: [Cython] [cython-users] Re: more ref counting References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> <4AD89055.3090302@molden.no> Message-ID: Sturla Molden wrote: > Neal Becker skrev: >> Do any of these suggestions address my problem with array base? >> >> ctypedef class numpy.ndarray [object PyArrayObject]: >> cdef __cythonbufferdefaults__ = {"mode": "strided"} >> >> cdef: >> # Only taking a few of the most commonly used and stable >> # fields. One should use PyArray_* macros instead to access >> # the C >> fields. >> char *data >> int ndim "nd" >> npy_intp *shape "dimensions" >> npy_intp *strides >> dtype descr >> object base <<< my addition >> >> Problem was that base could be NULL, and attempting to assign to it would >> try to call DECREF, and BOOM. >> > You have to use Py_XDECREF and Py_XINCREF instead of Py_DECREF and > Py_INCREF. > > S.M. I didn't use either one. Cython used Py_DECREF automatically, because 'base' was and 'object'. From stefan_ml at behnel.de Fri Oct 16 17:34:38 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Oct 2009 17:34:38 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> Message-ID: <4AD8928E.80400@behnel.de> Neal Becker wrote: > Do any of these suggestions address my problem with array base? No. Sturla is considering efficiency issues introduced by ref-counting overhead. Your question was about NULL values. Stefan From magnus at hetland.org Fri Oct 16 17:34:57 2009 From: magnus at hetland.org (Magnus Lie Hetland) Date: Fri, 16 Oct 2009 17:34:57 +0200 Subject: [Cython] Another (small) sunshine story In-Reply-To: <4AD891EC.10005@student.matnat.uio.no> References: <081E8EFD-F0E7-4B94-BA79-17DA31CF8BC3@hetland.org> <4AD891EC.10005@student.matnat.uio.no> Message-ID: On Oct 16, 2009, at 17:31, Dag Sverre Seljebotn wrote: > Thanks for the morale booster! The problem you had here can be reduced > when the planned "undeclared" warning/error is supported: Sounds nice :) -- Magnus Lie Hetland http://hetland.org From dagss at student.matnat.uio.no Fri Oct 16 17:39:39 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 16 Oct 2009 17:39:39 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4AD88A2E.2080901@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> Message-ID: <4AD893BB.2020904@student.matnat.uio.no> Sturla Molden wrote: > Dag Sverre Seljebotn skrev: > >> For auto-vectorization of loops with GCC it is extremely important. I.e. >> a simple vectorizable for-loop will have SSE instructions generated if >> restrict is declared, otherwise not! So easily around 2x speedup from >> restrict in those cases. >> > > I was wondering it it could be solved using some keyword arguments to > the buffer syntax? > > cdef np.ndarray[double] a => a.data is declared "char*" > cdef np.ndarray[double, qual='const'] a => a.data is declared "const char* " > cdef np.ndarray[double, qual='const,restrict'] a => a.data is declared > "const char*restrict" > cdef np.ndarray[double, qual='restrict'] a => a.data is declared > "char*restrict " > > Or perhaps one qualifier for data and one for pointer? > > cdef np.ndarray[double, dqual='const', pqual='restrict,const'] a => > a->data is declared "const char*const restrict" > > If the compiler is smart enough, it should see that the pointer is > restricted (even though it's a char*) or that elements are const, > regardless of typecast to double*. Or one could generate code that casts > the pointer from char* to const double* or whatever,with correct qualifiers. > > That would not require an extension of Cython's syntax, just arguments > for declaring the buffer. > I've been meaning to add this for ages (well, 8 months), I just haven't got around to it. It will probably be added the day I need it myself... (I was thinking something simple like "np.ndarray[double, exclusive=True]". There's a case for keeping the "restrict" keyword but it communicates rather badly to non-C-folks, which after all are some of the main target audience of Cython/NumPy. A readonly flag is already inferred today, but if that's more difficult to do later then we add "readonly" or "const" as well.) Dag Sverre From dagss at student.matnat.uio.no Fri Oct 16 17:44:11 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 16 Oct 2009 17:44:11 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: <4AD89202.5020107@molden.no> References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> <4AD88DCF.3040906@behnel.de> <4AD89202.5020107@molden.no> Message-ID: <4AD894CB.2050601@student.matnat.uio.no> Sturla Molden wrote: > Stefan Behnel skrev: > >> in your code and add a tweak to Cython that lets it drop the ref-counting >> in this exact case. >> >> >> > I am sure it would be easy, if I knew your code base. (Which btw I am > hoping to learn, but with little success so far.) > It's not the easiest code base to penetrate, for sure. What has happened in some cases is that somebody commits to doing a simple task and then gets mentored/gets a plan of attack written out. I.e. if you're saying you want to do this, I'm sure some of us could write up a recipe of how to go about it (which is still a lot less than doing it ourself, and dissipates knowledge of the code base in addition). Dag Sverre From stefan_ml at behnel.de Fri Oct 16 17:45:02 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Oct 2009 17:45:02 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: <4AD89202.5020107@molden.no> References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> <4AD88DCF.3040906@behnel.de> <4AD89202.5020107@molden.no> Message-ID: <4AD894FE.5070002@behnel.de> Sturla Molden wrote: > Stefan Behnel skrev: >> in your code and add a tweak to Cython that lets it drop the ref-counting >> in this exact case. >> > I am sure it would be easy, if I knew your code base. I didn't say it would be easy, just that I think that would be the right place to do it. Ref-counting is done at code generation time, and IIRC, parallel assignments are actually split by the parser, long before type analysis. So we may end up needing a SwapAssignmentNode here, that gets inserted instead of the parallel assignment node after type analysis (i.e. during the optimisations phase). (I know, that's CySpeak to someone who has never seen a parse tree dump - sorry) > (Which btw I am hoping to learn, but with little success so far.) Oh, that's just because most of the non-obvious stuff is shared with Pyrex. Honestly, did you take this as a starting point? http://wiki.cython.org/DevDocs http://wiki.cython.org/HackerGuide It's not perfect (and certainly far from complete), but it might still give a better start than reading source lines. Personally, I think the best way to get started is to insert a PrintTree() step into the pipeline in Main.py, and just read the tree dump that comes out of a compilation. You might want to stick to a rather short module, though. Stefan From sturla at molden.no Fri Oct 16 17:53:30 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 16 Oct 2009 17:53:30 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> <4AD89055.3090302@molden.no> Message-ID: <4AD896FA.1050304@molden.no> Neal Becker skrev: > I didn't use either one. Cython used Py_DECREF automatically, because > 'base' was and 'object'. > > Ok, but forgive me for being ignorant: Why do you want write access to base? Surely NumPy takes care of setting the base array for you. S.M. From stefan_ml at behnel.de Fri Oct 16 17:56:51 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 16 Oct 2009 17:56:51 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4AD893BB.2020904@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> Message-ID: <4AD897C3.6030309@behnel.de> Dag Sverre Seljebotn wrote: > Sturla Molden wrote: >> cdef np.ndarray[double] a => a.data is declared "char*" >> cdef np.ndarray[double, qual='const'] a => a.data is declared "const char* " >> cdef np.ndarray[double, qual='const,restrict'] a => a.data is declared >> "const char*restrict" >> cdef np.ndarray[double, qual='restrict'] a => a.data is declared >> "char*restrict " >> > I've been meaning to add this for ages (well, 8 months), I just haven't > got around to it. It will probably be added the day I need it myself... You could at least write up a ticket that you can point people to who bring up the same idea. ;) > (I was thinking something simple like "np.ndarray[double, > exclusive=True]". There's a case for keeping the "restrict" keyword but > it communicates rather badly to non-C-folks, which after all are some of > the main target audience of Cython/NumPy. A readonly flag is already > inferred today, but if that's more difficult to do later then we add > "readonly" or "const" as well.) To me, the meaning of "exclusive" in this context isn't immediately obvious either, whereas "readonly" is. General remark: if this results in specific C keywords being generated, I'd prefer using the C keywords in the Cython code as well. People who do not know them will simply have to learn what they do in order to use them properly. A helpful comment (or maybe paragraph) in the docs will make that easy enough. Stefan From dagss at student.matnat.uio.no Fri Oct 16 18:01:56 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 16 Oct 2009 18:01:56 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: <4AD896FA.1050304@molden.no> References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> <4AD89055.3090302@molden.no> <4AD896FA.1050304@molden.no> Message-ID: <4AD898F4.70304@student.matnat.uio.no> Sturla Molden wrote: > Neal Becker skrev: > >> I didn't use either one. Cython used Py_DECREF automatically, because >> 'base' was and 'object'. >> >> >> > Ok, but forgive me for being ignorant: Why do you want write access to > base? Surely NumPy takes care of setting the base array for you. > The usecase here was wrapping a C library, and wrapping data returned by the C lib in an ndarray. Setting base is necesarry to free the memory... Dag Sverre From sturla at molden.no Fri Oct 16 18:51:45 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 16 Oct 2009 18:51:45 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: <4AD898F4.70304@student.matnat.uio.no> References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> <4AD89055.3090302@molden.no> <4AD896FA.1050304@molden.no> <4AD898F4.70304@student.matnat.uio.no> Message-ID: <4AD8A4A1.4060105@molden.no> Dag Sverre Seljebotn skrev: > he usecase here was wrapping a C library, and wrapping data returned by > the C lib in an ndarray. Setting base is necesarry to free the memory... > > Here is an example that I and Ga?l Varoquaux wrote some time ago. It is an ndarray that uses named shared memory as buffer, and is pickled by name, i.e. the buffer is not copied by pickle, only its name. Thus it can be quickly recreated in a different process, allowing processes to communicate shared-memory ndarrays using multiprocessing.Queue. The way we set base is actually by calling np.asarray on an object that has an __array_interface__ attribute, which is a Python dictionary. We don't write to the base attribute directly. http://folk.uio.no/sturlamo/python/sharedmem-feb13-2009.zip The array passed to np.asarray is BufferWrapperArray, defined like this (mostly Robert Kern's code): def get_fortran_strides(shape, dtype): """ Create a strides entry for the given structural information for a Fortran-strided array. """ strides = tuple(dtype.itemsize * np.cumprod((1,) + shape[:-1])) return strides class BufferWrapperArray(object): """ An object that exists to expose a BufferWrapper with an __array_interface__. """ def __init__(self, wrapper, shape, dtype, order, strides, offset): self.wrapper = wrapper if strides is None: if order == 'C': strides = None else: strides = get_fortran_strides(shape, dtype) self.__array_interface__ = dict( data = (wrapper.get_address() + offset, False), descr = dtype.descr, shape = shape, strides = strides, typestr = dtype.str, version = 3, ) Without going into details, the shared memory segment (created with Windows API or System V IPC) is owned by a "Handle" class written in Cython. It commits suicide by calling __dealloc__ when no references to it are kept. That is what frees up the memory. The chain of references down to the ndarray is then this: Handle --> SharedMemoryBuffer --> BufferWrapper --> BufferWrapperArray --> ndarray The ndarray is constructed in plain Python, using an int to store the data address in the __array_interface__. The boolean that comes after the address in the 'data' tuple, says that the ndarray does not own the memory. The transition from Cython to Python is between SharedMemoryBuffer and BufferWrapper. Thus we never set base directly, np.asarray takes care of that. Sturla Molden From robertwb at math.washington.edu Fri Oct 16 19:23:09 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Fri, 16 Oct 2009 10:23:09 -0700 Subject: [Cython] __richcmp__ and inheritance In-Reply-To: <4AD83BB5.5050209@creativetrax.com> References: <4AD83BB5.5050209@creativetrax.com> Message-ID: <287CC1C2-F0AD-436A-9F96-ED99A4A5364F@math.washington.edu> On Oct 16, 2009, at 2:24 AM, jason-sage at creativetrax.com wrote: > I've just been struggling with understanding how inheritance and > __richcmp__ are related. Here is my example code: > > cdef class A: > cdef int a > def __init__(self, a): > self.a=a > > def __hash__(self): > return self.a > > def __richcmp__(A self, A other, int op): > print "using op: ",op > if op == 2: # == > return self.a == other.a > > cdef class B(A): > def __init__(self, a): > self.a=a+1 > > def __hash__(self): > return self.a*2 > > > Mike Hansen found some reference somewhere that said that either all > of > __hash__, __richcmp__, and __cmp__ are inherited or none are (I didn't > see this in the manual, but maybe I was looking in the wrong place??). This is in the Python/C API docs. > So, predictably: > > sage: A(2)==A(2) > using op: 2 > True > sage: B(2)==B(2) > False > > However, the confusing part is this: > > sage: B(2).__eq__(B(2)) > using op: 2 > True > > > > > Also, unlike most other special methods, I noticed that if I defined > __richcmp__ as below (removing the type declaration for self): > > def __richcmp__(self, A other, int op): > print "using op: ",op > if op == 2: # == > return self.a == other.a > > then self can't access the cdef'd "a" attribute. I think most other > commands recognize that self is of type A. That took a bit to figure > out, and I don't remember that being in the Cython docs either. That is because "self" may be either the first or second operand. It's the same with __add__, etc. (there's no __radd__). This does need to be better documented--in fact the documentation is being overhauled right now. - Robert From robertwb at math.washington.edu Fri Oct 16 19:33:53 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Fri, 16 Oct 2009 10:33:53 -0700 Subject: [Cython] bitten again by typetesting and None In-Reply-To: References: <9746E7A9-DE3C-4394-BDFD-87227BCA991D@math.washington.edu> <4AD8197B.3060307@behnel.de> <4AD88C0B.80006@behnel.de> Message-ID: <6DA6CB19-5F9E-452F-B607-190A221283FC@math.washington.edu> On Oct 16, 2009, at 8:15 AM, Lisandro Dalcin wrote: > On Fri, Oct 16, 2009 at 12:06 PM, Stefan Behnel > wrote: >> >> Lisandro Dalcin wrote: >>> On Fri, Oct 16, 2009 at 3:58 AM, Stefan Behnel wrote: >>>>> cdef MyClass x = foo() >>>> I agree that extension type casts should be exact and tested ones >>>> should >>>> fail for None. >>> >>> What did you meant with "exact" ? Subclasses should pass the >>> typetest, right? >> >> Sorry, sure, "anything that qualifies as a true instance of the >> checked >> class", including subclasses. >> > > BTW, that would be also the case for builtin types? IIUC, currently we > check for *exactly* the type. No, I think that behavior should remain as is (for reasons previously documented). - Robert From ndbecker2 at gmail.com Fri Oct 16 20:21:54 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 16 Oct 2009 14:21:54 -0400 Subject: [Cython] [cython-users] Re: more ref counting References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> <4AD89055.3090302@molden.no> <4AD896FA.1050304@molden.no> <4AD898F4.70304@student.matnat.uio.no> <4AD8A4A1.4060105@molden.no> Message-ID: Interesting. Doesn't exactly sound easier than what I did :) I haven't been able to find any doc about this "The boolean that comes after the address in the 'data' tuple, says that the ndarray does not own the memory. " I couldn't seem to track it down in numpy source either. I guess it's related to PyObject_AsWriteBuffer? From sturla at molden.no Fri Oct 16 22:06:52 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 16 Oct 2009 22:06:52 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> <4AD89055.3090302@molden.no> <4AD896FA.1050304@molden.no> <4AD898F4.70304@student.matnat.uio.no> <4AD8A4A1.4060105@molden.no> Message-ID: <4AD8D25C.8030506@molden.no> Neal Becker skrev: > I haven't been able to find any doc about this "The boolean that comes after > the address in the 'data' tuple, says that the ndarray does not own the > memory. " Oops!!! The boolean is a read-only flag for the data. Thus False indicates read-write access. Anyhow, it seems the __array_interface__ is deprecated in favour of PEP 3118. http://docs.scipy.org/doc/numpy/reference/arrays.interface.html http://www.python.org/dev/peps/pep-3118/ Though I am not sure how to use PEP 3118 from plain Python, if it's even possible. Annoying mess... S.M. From craigcitro at gmail.com Fri Oct 16 22:15:38 2009 From: craigcitro at gmail.com (Craig Citro) Date: Fri, 16 Oct 2009 13:15:38 -0700 Subject: [Cython] Dependency tracking In-Reply-To: <4AD8603B.9010805@student.matnat.uio.no> References: <4AD8603B.9010805@student.matnat.uio.no> Message-ID: > Is there a dependency finder for Cython sources somewhere? I would think > Sage has something like this developed... > Yep, we've got something in our setup.py -- start looking around like 432 of $SAGE_ROOT/devel/sage/setup.py. If memory serves, Robert Bradshaw wrote this (he, Gonzalo Tornaria and I all worked on the Sage build system a bit back in November). -cc From dagss at student.matnat.uio.no Fri Oct 16 22:23:31 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 16 Oct 2009 22:23:31 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: <4AD8D25C.8030506@molden.no> References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> <4AD89055.3090302@molden.no> <4AD896FA.1050304@molden.no> <4AD898F4.70304@student.matnat.uio.no> <4AD8A4A1.4060105@molden.no> <4AD8D25C.8030506@molden.no> Message-ID: <4AD8D643.5000207@student.matnat.uio.no> Sturla Molden wrote: > Neal Becker skrev: >> I haven't been able to find any doc about this "The boolean that comes after >> the address in the 'data' tuple, says that the ndarray does not own the >> memory. " > Oops!!! The boolean is a read-only flag for the data. Thus False > indicates read-write access. > > Anyhow, it seems the __array_interface__ is deprecated in favour of PEP > 3118. > > http://docs.scipy.org/doc/numpy/reference/arrays.interface.html > http://www.python.org/dev/peps/pep-3118/ > > Though I am not sure how to use PEP 3118 from plain Python, if it's even > possible. Annoying mess... NumPy doesn't support PEP 3118 yet. -- Dag Sverre From sturla at molden.no Fri Oct 16 22:50:16 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 16 Oct 2009 22:50:16 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4AD893BB.2020904@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> Message-ID: <4AD8DC88.7030109@molden.no> Dag Sverre Seljebotn skrev: > I've been meaning to add this for ages (well, 8 months), I just haven't > got around to it. It will probably be added the day I need it myself... > > Would this just require a few changes to Cython/Compiler/Buffer.py? From cdleary at gmail.com Sat Oct 17 00:41:22 2009 From: cdleary at gmail.com (Christopher D. Leary) Date: Fri, 16 Oct 2009 15:41:22 -0700 Subject: [Cython] [cython-user] metaprogramming in Cython In-Reply-To: <39cd2aff0910161534u48e6ccdah1e7bf621a16a1bec@mail.gmail.com> References: <39cd2aff0910161534u48e6ccdah1e7bf621a16a1bec@mail.gmail.com> Message-ID: <39cd2aff0910161541v2bc0075v4321c9d3ce5eb3ca@mail.gmail.com> Whoops, didn't see that a cython-user list had actually been created. Will redirect over there. Sorry for the spam, - Leary On Fri, Oct 16, 2009 at 3:34 PM, Christopher D. Leary wrote: > Hi all! Big fan of Cython thus far -- many thanks to the devs. > > I'm trying to figure out how to save some typing and maintenance -- I > have a bunch of flat C variables in a "breakfast::stats" > pseudo-namepsace like the following in libbreakfast.pxd: > > cdef extern from "breakfast_stats.h": > ? ?int breakfast_stats_spams_eaten > ? ?int breakfast_stats_hams_eaten > ? ?int breakfast_stats_eggs_eaten > > But I'd like to turn it into a stats "singleton", accessible from an > interpreted environment like so: > >>>> import libbreakfast >>>> libbreakfast.stats.spams_eaten > 12 >>>> libbreakfast.stats.hams_eaten = 3 > > I know I can create a separate Cython module to have a similar effect, > but I'm trying to learn the Cython language, so let's assume I want to > keep it all in a single module. > > In Python, I would have the option of using a Stats class with > __getattr__/__setattr__ defined to prefix the attr_name with > 'breakfast_stats_' and proxy to globals() -- this would prevent me > from having to break out each property explicitly, and the Cython code > would not need to be updated each time a stat were added or removed. > Is there a way that I can achieve a similar result in Cython? > > - Leary > From cdleary at gmail.com Sat Oct 17 00:34:53 2009 From: cdleary at gmail.com (Christopher D. Leary) Date: Fri, 16 Oct 2009 15:34:53 -0700 Subject: [Cython] [cython-user] metaprogramming in Cython Message-ID: <39cd2aff0910161534u48e6ccdah1e7bf621a16a1bec@mail.gmail.com> Hi all! Big fan of Cython thus far -- many thanks to the devs. I'm trying to figure out how to save some typing and maintenance -- I have a bunch of flat C variables in a "breakfast::stats" pseudo-namepsace like the following in libbreakfast.pxd: cdef extern from "breakfast_stats.h": int breakfast_stats_spams_eaten int breakfast_stats_hams_eaten int breakfast_stats_eggs_eaten But I'd like to turn it into a stats "singleton", accessible from an interpreted environment like so: >>> import libbreakfast >>> libbreakfast.stats.spams_eaten 12 >>> libbreakfast.stats.hams_eaten = 3 I know I can create a separate Cython module to have a similar effect, but I'm trying to learn the Cython language, so let's assume I want to keep it all in a single module. In Python, I would have the option of using a Stats class with __getattr__/__setattr__ defined to prefix the attr_name with 'breakfast_stats_' and proxy to globals() -- this would prevent me from having to break out each property explicitly, and the Cython code would not need to be updated each time a stat were added or removed. Is there a way that I can achieve a similar result in Cython? - Leary From greg.ewing at canterbury.ac.nz Sat Oct 17 01:09:12 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 17 Oct 2009 12:09:12 +1300 Subject: [Cython] Dependency tracking In-Reply-To: <4AD8603B.9010805@student.matnat.uio.no> References: <4AD8603B.9010805@student.matnat.uio.no> Message-ID: <4AD8FD18.5070508@canterbury.ac.nz> Dag Sverre Seljebotn wrote: > Is there a dependency finder for Cython sources somewhere? I would think > Sage has something like this developed... Current Pyrex has a built-in dependency tracker, but I don't think it has made it into Cython yet. -- Greg From stefan_ml at behnel.de Sat Oct 17 01:12:04 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 17 Oct 2009 01:12:04 +0200 Subject: [Cython] Dependency tracking In-Reply-To: <4AD8FD18.5070508@canterbury.ac.nz> References: <4AD8603B.9010805@student.matnat.uio.no> <4AD8FD18.5070508@canterbury.ac.nz> Message-ID: <4AD8FDC4.6030404@behnel.de> Greg Ewing wrote: > Dag Sverre Seljebotn wrote: > >> Is there a dependency finder for Cython sources somewhere? I would think >> Sage has something like this developed... > > Current Pyrex has a built-in dependency tracker, but > I don't think it has made it into Cython yet. Well, as I wrote in my other post, it writes out .dep files, and I actually assume that's still the same for both. Stefan From greg.ewing at canterbury.ac.nz Sat Oct 17 01:26:28 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 17 Oct 2009 12:26:28 +1300 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: <4AD894CB.2050601@student.matnat.uio.no> References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> <4AD88DCF.3040906@behnel.de> <4AD89202.5020107@molden.no> <4AD894CB.2050601@student.matnat.uio.no> Message-ID: <4AD90124.608@canterbury.ac.nz> Dag Sverre Seljebotn wrote: > and > dissipates knowledge of the code base in addition). ^^^^^^^^^^ I think you mean "disseminate". Dissipating something implies that it gets lost, which is the opposite of what we want! -- Greg From greg.ewing at canterbury.ac.nz Sat Oct 17 02:00:21 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 17 Oct 2009 13:00:21 +1300 Subject: [Cython] Dependency tracking In-Reply-To: <4AD8FDC4.6030404@behnel.de> References: <4AD8603B.9010805@student.matnat.uio.no> <4AD8FD18.5070508@canterbury.ac.nz> <4AD8FDC4.6030404@behnel.de> Message-ID: <4AD90915.6090901@canterbury.ac.nz> Stefan Behnel wrote: > Well, as I wrote in my other post, it writes out .dep files, and I actually > assume that's still the same for both. Ah, in that case, it sounds like you do have it, or at least some version of it. -- Greg From dsimmons.com at gmail.com Sat Oct 17 03:59:23 2009 From: dsimmons.com at gmail.com (David Simmons-Duffin) Date: Fri, 16 Oct 2009 21:59:23 -0400 Subject: [Cython] LiE in Cython In-Reply-To: References: Message-ID: <640BE099-657D-4AD6-8A9E-99F909D435FF@gmail.com> A few months ago, I wrote the Cython list asking for some help writing a cython interface to the computer algebra package LiE. http://www-math.univ-poitiers.fr/~maavl/LiE/ There was some mention of interest in such a thing among sage people, and possibly others. But I needed the interface for a specific project, and it was recommended that I concentrate on writing it for that purpose and then think later about what to do publicly with the code. That project is now mostly finished, and I'd like to share the LiE python module. Any advice on the best way of making it accessible? It's not the most beautiful piece of code ever -- I was a cython novice when I started writing it. But it's quite functional, and capable of doing a wide range of lie group representation theory computations in python. Ideally, I want it to be easy for other people to contribute to and improve the code, without too much oversight from me. I don't know how much time I'll have personally to work on it, but I know it's useful, so I thought it was important to get it out there. Should I use github? Google code? Something else? Will it be easy to let others edit/patch/document the code? Thanks! David From dagss at student.matnat.uio.no Sat Oct 17 07:43:35 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 17 Oct 2009 07:43:35 +0200 Subject: [Cython] [cython-users] Re: more ref counting In-Reply-To: <4AD90124.608@canterbury.ac.nz> References: <4AD5D78E.1070100@behnel.de> <4AD5DDA8.8060007@behnel.de> <4AD60080.8030701@student.matnat.uio.no> <4AD62B6B.7050203@student.matnat.uio.no> <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD723B7.5000802@behnel.de> <4AD79EC0.5070206@canterbury.ac.nz> <4AD885EA.7020403@molden.no> <4AD88DCF.3040906@behnel.de> <4AD89202.5020107@molden.no> <4AD894CB.2050601@student.matnat.uio.no> <4AD90124.608@canterbury.ac.nz> Message-ID: <4AD95987.9020708@student.matnat.uio.no> Greg Ewing wrote: > Dag Sverre Seljebotn wrote: >> and >> dissipates knowledge of the code base in addition). > ^^^^^^^^^^ > > I think you mean "disseminate". Dissipating something > implies that it gets lost, which is the opposite of > what we want! > :-) -- Dag Sverre From dagss at student.matnat.uio.no Sat Oct 17 08:32:14 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 17 Oct 2009 08:32:14 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4AD8DC88.7030109@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> Message-ID: <4AD964EE.60606@student.matnat.uio.no> Sturla Molden wrote: > Dag Sverre Seljebotn skrev: >> I've been meaning to add this for ages (well, 8 months), I just haven't >> got around to it. It will probably be added the day I need it myself... >> >> > Would this just require a few changes to Cython/Compiler/Buffer.py? Mostly. It's not hard work, as usual the main work is involved in writing test cases and measuring performance improvement etc.. What's not in Buffer.py: 1) The buffer pointer is unpacked into a local variable which is declared by using a type object from PyrexTypes.py (i.e. Buffer.py just uses a type from PyrexTypes.py to specify the type). So one might want to add support for "restrict" pointer types in PyrexTypes.py to support declaring the variable. 2) For adding the option to add to the []-syntax one *might* have to have a look in ParseTreeTransforms.py, although I don't remember -- perhaps I moved it to Buffer.py. As for syntax, can we perhaps agree for np.ndarray[int, restrict=True] asdf for now? -- Dag Sverre From robertwb at math.washington.edu Sat Oct 17 09:44:12 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 17 Oct 2009 00:44:12 -0700 Subject: [Cython] LiE in Cython In-Reply-To: <640BE099-657D-4AD6-8A9E-99F909D435FF@gmail.com> References: <640BE099-657D-4AD6-8A9E-99F909D435FF@gmail.com> Message-ID: <28D76DF0-696E-427F-9C0E-A8DC7F534FC5@math.washington.edu> I've never used the LiE package myself, but I've heard of other people using it. I'm cc-ing sage-devel which is probably a better audience. I'd just post your code anywhere, and would guess if/when someone finds it useful it would be a good start for a sage .spkg. - Robert On Oct 16, 2009, at 6:59 PM, David Simmons-Duffin wrote: > A few months ago, I wrote the Cython list asking for some help writing > a cython interface to the computer algebra package LiE. > > http://www-math.univ-poitiers.fr/~maavl/LiE/ > > There was some mention of interest in such a thing among sage people, > and possibly others. But I needed the interface for a specific > project, and it was recommended that I concentrate on writing it for > that purpose and then think later about what to do publicly with the > code. That project is now mostly finished, and I'd like to share the > LiE python module. > > Any advice on the best way of making it accessible? It's not the most > beautiful piece of code ever -- I was a cython novice when I started > writing it. But it's quite functional, and capable of doing a wide > range of lie group representation theory computations in python. > Ideally, I want it to be easy for other people to contribute to and > improve the code, without too much oversight from me. I don't know > how much time I'll have personally to work on it, but I know it's > useful, so I thought it was important to get it out there. > > Should I use github? Google code? Something else? Will it be easy to > let others edit/patch/document the code? > > Thanks! > David > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev From robertwb at math.washington.edu Sat Oct 17 09:54:34 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 17 Oct 2009 00:54:34 -0700 Subject: [Cython] [cython-users] Re: PyObject* definitions in std .pxd import files In-Reply-To: <4AD820C4.6010205@student.matnat.uio.no> References: <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD72639.3060508@behnel.de> <4AD820C4.6010205@student.matnat.uio.no> Message-ID: <1AE1B9C2-AC58-49C9-8826-3C325F1B2FCD@math.washington.edu> On Oct 16, 2009, at 12:29 AM, Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: >> >> On Oct 15, 2009, at 4:59 PM, Lisandro Dalcin wrote: >> >>> On Thu, Oct 15, 2009 at 10:40 AM, Stefan Behnel >>> >>> wrote: >>>> >>>> >>>> Neal Becker wrote: >>>>> I think this works: >>>>> >>>>> 1) In numpy.pxd, use: >>>>> from python_ref cimport PyObject >>>>> >>>>> 2) In sum.pyx: >>>>> >>>>> from python_ref cimport Py_XINCREF, Py_XDECREF, PyObject >>>> >>>> Yes, that should be ok. >>>> >>>> I looked around a bit more in Cython/Includes/, and it seems like >>>> it >>>> really >>>> needs some broader cleanup. There are a couple of redefinitions of >>>> PyObject >>>> and various function definitions that use PyObject* and should use >>>> object >>>> instead. >>>> >>> >>> Could we use this for PyObject ?: >>> >>> ctypedef struct PyObject >> >> The question is whether to allow casting objects to any struct >> pointer, or making PyObject special. Another option would be to >> give a >> syntax to mark structs as raw versions of objects, which could handle >> PyTypeObject, etc. >> >> I'm with Greg, however, that most of the time we should be looking at >> the usecases and deciding if we can avoid having to treat objects as >> pointers. (E.g. being able to declare a variable as an object that >> might be NULL.) That being said, I'm not sure it's possible to come >> up >> with nice solutions to everything, and if the user wants to do >> something messy maybe we shouldn't be adding it to the language. > Even so, there's a lot of code which already uses various forms of > custom-declared PyObject*. My primary concern here is that I think we > should go further with disallowing > > myobject > > If we include PyObject as a builtin type, it becomes possible to allow > myobject but disallow the above. > > Even if we do add syntax features for dealing with these situations > (declaring borrowed and stolen references and objects which can be > NULL...personally I'm starting to think there is too much > special-purpose syntax already...) it's quite a matter to break > backwards compatability and disallow existing code from getting a > PyObject*! Requiring that people remove their own definitions of > PyObject and use the builtin instead is much less of a matter. > > So I'd say there's a case for > > a) Add a builtin PyObject* > b) Once that is done, start emitting warning for anything but > myobject and myobject (the builtin one only); then > emit an error in the next release. I'm not entirely convinced. For one thing, I'd rather people have to cimport PyObject rather than have it by default in the namespace (as most people should not be using it at all, so it would make thing more confusing/encourage bad code). Is myobject really so bad? - Robert From robertwb at math.washington.edu Sat Oct 17 10:02:03 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 17 Oct 2009 01:02:03 -0700 Subject: [Cython] Dependency tracking In-Reply-To: References: <4AD8603B.9010805@student.matnat.uio.no> Message-ID: On Oct 16, 2009, at 1:15 PM, Craig Citro wrote: >> Is there a dependency finder for Cython sources somewhere? I would >> think >> Sage has something like this developed... >> > > Yep, we've got something in our setup.py -- start looking around like > 432 of $SAGE_ROOT/devel/sage/setup.py. If memory serves, Robert > Bradshaw wrote this (he, Gonzalo Tornaria and I all worked on the Sage > build system a bit back in November). For the reference, http://hg.sagemath.org/sage-main/file/tip/ setup.py . It just uses regex to find dependancies, the only clever part is it works out the entire dependancy tree at once rather than file-by-file (which would be O(n^2) and got to be really slow for us, even just opening O(n^2) files). Really, we should probably incorporate this into our build_ext. I'm torn about .dep files--they're easier and faster to "parse," but it's another file per .pyx/.pxd laying around in the directory... Another option would be to stick this information in the header of the .c file (in comments). - Robert From stefan_ml at behnel.de Sat Oct 17 10:02:25 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 17 Oct 2009 10:02:25 +0200 Subject: [Cython] Unprefixed single character strings fail to compare to integers Message-ID: <4AD97A11.3080301@behnel.de> Hi, Dag stumbled over a problem with the str/bytes/unicode split. http://trac.cython.org/cython_trac/ticket/412 Since str literals no longer start out as char*, the following no longer works: cdef int i = 'x' # this works if i == 'x': # this doesn't print True The problem is that the comparison considers 'x' a Python string and thus coerces i to a Python int for comparison, which obviously fails. There are a a couple of ways to deal with this: 1) disallow unprefixed char literals also in a C context and require users to write cdef int i = c'x' if i == c'x': 2) special case this everywhere we need it, i.e. currently in StringNode.coerce_to() and then also in BinopNode 3) let single-char str literals start out as C 'char' type and only coerce to Python str at need Personally, I would prefer either 1) or 3), the latter likely being more convenient but potentially introducing new pitfalls elsewhere (to be seen). Comments? Stefan From dagss at student.matnat.uio.no Sat Oct 17 10:15:11 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 17 Oct 2009 10:15:11 +0200 Subject: [Cython] [cython-users] Re: PyObject* definitions in std .pxd import files In-Reply-To: <1AE1B9C2-AC58-49C9-8826-3C325F1B2FCD@math.washington.edu> References: <4AD6B542.7040504@student.matnat.uio.no> <919276F4-4192-4D78-817D-30BE16E165EC@math.washington.edu> <4AD6C877.6020508@behnel.de> <4AD7191E.7060301@behnel.de> <4AD72639.3060508@behnel.de> <4AD820C4.6010205@student.matnat.uio.no> <1AE1B9C2-AC58-49C9-8826-3C325F1B2FCD@math.washington.edu> Message-ID: <4AD97D0F.7050106@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 16, 2009, at 12:29 AM, Dag Sverre Seljebotn wrote: > >> Robert Bradshaw wrote: >>> On Oct 15, 2009, at 4:59 PM, Lisandro Dalcin wrote: >>> >>>> On Thu, Oct 15, 2009 at 10:40 AM, Stefan Behnel >>>> >>>> wrote: >>>>> >>>>> Neal Becker wrote: >>>>>> I think this works: >>>>>> >>>>>> 1) In numpy.pxd, use: >>>>>> from python_ref cimport PyObject >>>>>> >>>>>> 2) In sum.pyx: >>>>>> >>>>>> from python_ref cimport Py_XINCREF, Py_XDECREF, PyObject >>>>> Yes, that should be ok. >>>>> >>>>> I looked around a bit more in Cython/Includes/, and it seems like >>>>> it >>>>> really >>>>> needs some broader cleanup. There are a couple of redefinitions of >>>>> PyObject >>>>> and various function definitions that use PyObject* and should use >>>>> object >>>>> instead. >>>>> >>>> Could we use this for PyObject ?: >>>> >>>> ctypedef struct PyObject >>> The question is whether to allow casting objects to any struct >>> pointer, or making PyObject special. Another option would be to >>> give a >>> syntax to mark structs as raw versions of objects, which could handle >>> PyTypeObject, etc. >>> >>> I'm with Greg, however, that most of the time we should be looking at >>> the usecases and deciding if we can avoid having to treat objects as >>> pointers. (E.g. being able to declare a variable as an object that >>> might be NULL.) That being said, I'm not sure it's possible to come >>> up >>> with nice solutions to everything, and if the user wants to do >>> something messy maybe we shouldn't be adding it to the language. >> Even so, there's a lot of code which already uses various forms of >> custom-declared PyObject*. My primary concern here is that I think we >> should go further with disallowing >> >> myobject >> >> If we include PyObject as a builtin type, it becomes possible to allow >> myobject but disallow the above. >> >> Even if we do add syntax features for dealing with these situations >> (declaring borrowed and stolen references and objects which can be >> NULL...personally I'm starting to think there is too much >> special-purpose syntax already...) it's quite a matter to break >> backwards compatability and disallow existing code from getting a >> PyObject*! Requiring that people remove their own definitions of >> PyObject and use the builtin instead is much less of a matter. >> >> So I'd say there's a case for >> >> a) Add a builtin PyObject* >> b) Once that is done, start emitting warning for anything but >> myobject and myobject (the builtin one only); then >> emit an error in the next release. > > I'm not entirely convinced. For one thing, I'd rather people have to > cimport PyObject rather than have it by default in the namespace (as > most people should not be using it at all, so it would make thing more > confusing/encourage bad code). Is myobject really so bad? > There's e.g. an issue with structs as dtypes to ndarrays: # 1) Forget to do this: cdef np.ndarray[SomeStruct] typedarr # 2) Then: typedarr = arr call_f_func(arr.data) # hope for segfault This silently converts a Python buffer object to a SomeStruct*, rather than getting the underlying pointer that we wanted. As casting an object to a SomeStruct never makes sense... however I guess for *some* structs, it makes sense. The problem might be though that I should have renamed the "data" field for ndarray Cython-side instead of keeping it in numpy.pxd -- called it raw_data or buf instead. -- Dag Sverre From stefan_ml at behnel.de Sat Oct 17 10:22:11 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 17 Oct 2009 10:22:11 +0200 Subject: [Cython] Unprefixed single character strings fail to compare to integers In-Reply-To: <4AD97A11.3080301@behnel.de> References: <4AD97A11.3080301@behnel.de> Message-ID: <4AD97EB3.3040700@behnel.de> Stefan Behnel wrote: > Dag stumbled over a problem with the str/bytes/unicode split. > > http://trac.cython.org/cython_trac/ticket/412 > > Since str literals no longer start out as char*, the following no longer works: > > cdef int i = 'x' # this works > > if i == 'x': # this doesn't > print True > > The problem is that the comparison considers 'x' a Python string and thus > coerces i to a Python int for comparison, which obviously fails. > > There are a a couple of ways to deal with this: > > 1) disallow unprefixed char literals also in a C context and require users > to write > > cdef int i = c'x' > > if i == c'x': > > 2) special case this everywhere we need it, i.e. currently in > StringNode.coerce_to() and then also in BinopNode > > 3) let single-char str literals start out as C 'char' type and only coerce > to Python str at need > > > Personally, I would prefer either 1) or 3), the latter likely being more > convenient but potentially introducing new pitfalls elsewhere (to be seen). ... like this, for example: cdef char* s = 'x' print s == 'x' What is this code even supposed to mean? It currently prints 'True', but that's only obvious when you know some magic internals about Cython's string handling. Stefan From robertwb at math.washington.edu Sat Oct 17 10:26:38 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 17 Oct 2009 01:26:38 -0700 Subject: [Cython] Unprefixed single character strings fail to compare to integers In-Reply-To: <4AD97A11.3080301@behnel.de> References: <4AD97A11.3080301@behnel.de> Message-ID: <10B7EF25-8750-4C8B-85B6-55ACAD8D4C72@math.washington.edu> On Oct 17, 2009, at 1:02 AM, Stefan Behnel wrote: > Hi, > > Dag stumbled over a problem with the str/bytes/unicode split. > > http://trac.cython.org/cython_trac/ticket/412 > > Since str literals no longer start out as char*, the following no > longer works: > > cdef int i = 'x' # this works > > if i == 'x': # this doesn't > print True > > The problem is that the comparison considers 'x' a Python string and > thus > coerces i to a Python int for comparison, which obviously fails. > > There are a a couple of ways to deal with this: > > 1) disallow unprefixed char literals also in a C context and require > users > to write > > cdef int i = c'x' > > if i == c'x': > > 2) special case this everywhere we need it, i.e. currently in > StringNode.coerce_to() and then also in BinopNode > > 3) let single-char str literals start out as C 'char' type and only > coerce > to Python str at need > > > Personally, I would prefer either 1) or 3), the latter likely being > more > convenient but potentially introducing new pitfalls elsewhere (to be > seen). > > Comments? I'm for (2) or (3), with a preference for (2). Option (1) will break code (which I'm strongly against) and (3) seems prone to pitfalls as you mention. - Robert From robertwb at math.washington.edu Sat Oct 17 10:34:46 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 17 Oct 2009 01:34:46 -0700 Subject: [Cython] Short circuit slower than nested if In-Reply-To: References: <3336366795.144255@smtp.netcom.no> Message-ID: FYI, this was fixed during our bug squash yesterday. On Sep 21, 2009, at 11:53 PM, Tan Swee Heng wrote: > I tested it with cython-unstable-fe0733adf6f0. The bug seems to > remain. > > Should I submit this as a bug on http://trac.cython.org/cython_trac? > > Swee Heng > > On Mon, Sep 21, 2009 at 2:33 PM, Dag Sverre Seljebotn > wrote: > This is a bug. But it looks like something which might be fixed in - > unstable. Could you get cython-unstable from http://hg.cython.org/ > and see of there's still a problem? > > Dag Sverre Seljebotn > -----Original Message----- > From: Tan Swee Heng > Date: Sunday, Sep 20, 2009 11:30 pm > Subject: [Cython] Short circuit slower than nested if > To: cython-dev at codespeak.netReply-To: cython-dev at codespeak.net > > Hi, I've search the archives for 'short circuit' but did not find an > answer. So I am posting here. > > > >Consider the following code (app.pyx): > > > > from hashlib import sha1 > > > > cdef long expensive(long n, long k): > > return long(sha1('%s:%s' % (n, k)).hexdigest()[:4], base=16) < > 256 > > > > def test1(long n): > > cdef long i, sum = 0 > > for i in range(n): > > if expensive(i, 0) and expensive(i, 1): # short-circuit > > sum += i > > print sum > > > > def test2(long n): > > cdef long i, sum = 0 > > for i in range(n): > > if expensive(i, 0): # nested-if > > if expensive(i, 1): > > sum += i > > print sum > > > >If this was pure Python, the performance of test1() and test2() > would be the same. However with Cython, test1() was twice as slow as > test2(). > > > >Looking at app.c: > > > > // if expensive(i, 0) and expensive(i, 1): # > <<<<<<<<<<<<<< > > if (__pyx_f_3app_expensive(__pyx_v_i, 0)) { > > __pyx_t_2 = __pyx_f_3app_expensive(__pyx_v_i, 1); > > } else { > > __pyx_t_2 = __pyx_f_3app_expensive(__pyx_v_i, 0); > > } > > > >and > > > > // if expensive(i, 0): # <<<<<<<<<<<<<< > > __pyx_t_2 = __pyx_f_3app_expensive(__pyx_v_i, 0); > > if (__pyx_t_2) { > > > > // if expensive(i, 1): # <<<<<<<<<<<<<< > > __pyx_t_2 = __pyx_f_3app_expensive(__pyx_v_i, 1); > > if (__pyx_t_2) { > > > >For the short-circuit version, the first test is sometimes > evaluated twice. For the nested-if version, it is evaluated exactly > once. > > > >Q: For the short-circuit, would the right behaviour be to store the > result of the first evaluation in a temporary variable instead? > > > >I am new to Cython so pardon me if this is not the right place to > ask. If a patch is preferred, I can give it a try although I will > take some time to get familiar with the code. > > > >Swee Heng > > > > > _______________________________________________ > 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 From sturla at molden.no Sat Oct 17 14:10:30 2009 From: sturla at molden.no (Sturla Molden) Date: Sat, 17 Oct 2009 14:10:30 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> Message-ID: <4AD9B436.4000604@molden.no> Robert Bradshaw skrev: >> First, is there any reason why Cython does not recognize const and >> restrict? > > That's because no one's actually implemented, not because we don't > want it. We know its benefits. Note that const is not as trivial as > it seems on the surface (though it wouldn't be a Herculean task > either). We'd have to support stuff like > > struct foo { > const char * x, > int const * const ptr, > long foo, > }; Actually, one can get around the intricacies of pointer qualifiers using a C trick: The declaration int * const const_pointer = ... can be expanded over two lines with a temporary typedef: typedef int *tmp_t; const tmp_t const_pointer = ... We can thus avoid the const qualifier appearing after the star. Personally I consider expressions like "int const * const ptr" obfuscated and verbose. Syntax should be easy to read. In the two-line declaration of const_pointer, it is obvious what is intended to be constant. In the western world we also tend to read left to right. typedef const int *const const_pointer_to_const_int; is the same as typedef const int *ptr_to_const_int; typedef const ptr_to_const_int const_ptr_to_const_int; But the one-liner, we have to read the declaration right to left. In the two-liner we read left to right, as we are used to. Code that are difficult to read is un-Pythonic. There is also somthing in the Zen of Python that there should be one way of doing things. But C allows a myriad of ways to write the same declarations. I therefore don't think is would be necessary to support all of C's possible placements of qualifiers like const, static and restrict. S.M. From sturla at molden.no Sat Oct 17 15:32:36 2009 From: sturla at molden.no (Sturla Molden) Date: Sat, 17 Oct 2009 15:32:36 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4AD964EE.60606@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> Message-ID: <4AD9C774.4000803@molden.no> Dag Sverre Seljebotn skrev: > > 1) The buffer pointer is unpacked into a local variable which is > declared by using a type object from PyrexTypes.py (i.e. Buffer.py just > uses a type from PyrexTypes.py to specify the type). So one might want > to add support for "restrict" pointer types in PyrexTypes.py to support > declaring the variable. > Hm... buf_lookup_c_code generates pointer code like this: ((type)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + in) with type e.g. being double *, m = nd-2, and n = nd-1. Will an optimising C compiler be smart enough to put this in a local variable (or register) if it sees this expression re-typed over and over again? Unless it can do that, we will have no use for the restrict qualifier. Thus, the compiler must be 100% sure the value never changes. The variables in the expression must be in the local scope, and preferably declared constants. Obviously we cannot declare i0 .. im, in constant. char *const buf = bufinfo.buf; const Py_ssize_t s0 = bufinfo.strides[0]; const Py_ssize_t s1 = bufinfo.strides[1]; const Py_ssize_t s2 = bufinfo.strides[2]; ... const Py_ssize_t sN = bufinfo.strides[N]; This is more or less what Cython does. I am a bit uncertain about the buf in Cythons current version, but I presume the compiler will see it as local if the bufinfo is local. There is another potential problem with the machine code. We cannot generate code like *((double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + i0) = rvalue; and expect this to work (or even be accepted by the C compiler), because that's an lvalue cast. Since I don't get pesky compiler warnings, it either means Cython is doing "the right thing", or it means my GCC is not pedantic enough. The "right thing" would be to put ((double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + i0) into a local variable, and pray that an aggressive compiler will be able to move the first part of tmp out of the local scope... { double *tmp = (double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + i0; *tmp = rvalue; } Is this what Cython does? I am not quite sure. Perhaps someone can tell me. In hand-written code I would do this by hand. double * restrict tmp = (double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm); for (in=0; i0 < bufinfo.shape[n]; in++) tmp[in] = rvalue; But I'd be surprised if Cython could do this kind of transform. So we probably have to rely on the C compiler getting rid of (double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) from the inner scope. The restrict qualifier should be inserted like this: { double * restrict tmp = ... *tmp = rvalue; } Meaning we probably don't have to change what buf_lookup_c_code and friends emit, except that we might consider casting buf to "char *const" instead. However, restrict would be useless here unless the compiler can optimize "(double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm)" away form the inner loop! But what if (double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) appear as rvalue? Do we just get something like this? double lvalue; lvalue = *((double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + i0); If so, we could still utilize the restrict qualifier by using an auxillary pointer variable: double lvalue; double * restrict tmp = ((double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + i0); lvalue = *tmp; Does Cython do this? I'm not sure, but I don't think we need to make buf_lookup_c_code to take the qualifier into account for whatever it produces. It should be declared in the tmp (as above). The same would also be the case for an ndarray of const doubles: double lvalue const double *tmp = ((double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + i0); lvalue = *tmp; In an ideal world, Cython should emit an error for this: { const double * tmp = ... *tmp = rvalue; } Omitting the error check but it is not a catastrophy, though, because the C compiler will complain. Regards, Sturla Molden So it is free to keep it in a register. But how can the the compiler know that (double *)((char*)buf + i1*s1 + i2*s2 + ... + iN*sN) is constant? I think the answer is it cannot. If buf i a local variable in the scope, it might be able to infer that nobody writes to it. But preferably we should have a local const pointer storing buf, i.e char *const buf = (char *)bufinfo.buf; Now, if the compiler sees this expression again and again, ((double *)(buf + i1*s1 + i2*s2 + ... + iN*sN)) it should be able to keep ((double *)(buf + i1*s1 + i2*s2 + ... + iN*sN)) in a register. Particularly if the strides also are constant in the scope. char *const buf = buinfo.buf; const Py_ssize_t s0 = bufinfo.strides[0]; const Py_ssize_t s1 = bufinfo.strides[1]; const Py_ssize_t s2 = bufinfo.strides[2]; [...] const Py_ssize_t sN = bufinfo.strides[N]; > 2) For adding the option to add to the []-syntax one *might* have to > have a look in ParseTreeTransforms.py, although I don't remember -- > perhaps I moved it to Buffer.py. I think that is in analyse_buffer_options in Buffer.py. > As for syntax, can we perhaps agree for > > np.ndarray[int, restrict=True] asdf > > for now? > From ndbecker2 at gmail.com Sat Oct 17 17:29:09 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Sat, 17 Oct 2009 11:29:09 -0400 Subject: [Cython] Issues with numerical programming with Cython References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> Message-ID: Sturla Molden wrote: > Dag Sverre Seljebotn skrev: >> >> 1) The buffer pointer is unpacked into a local variable which is >> declared by using a type object from PyrexTypes.py (i.e. Buffer.py just >> uses a type from PyrexTypes.py to specify the type). So one might want >> to add support for "restrict" pointer types in PyrexTypes.py to support >> declaring the variable. >> > > > Hm... > > buf_lookup_c_code generates pointer code like this: > > ((type)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + in) > > with type e.g. being double *, m = nd-2, and n = nd-1. > > > Will an optimising C compiler be smart enough to put this in a local > variable (or register) if it sees this expression re-typed over and over > again? > Not certain, but if you're asking whether redundant computations will be merged when the compiler can determine the dependent variables could not have changed, I believe it should. In gcc, look at `-fgcse' Perform a global common subexpression elimination pass. This pass also performs global constant and copy propagation. and related. I'm no expert in gcc, but this _sounds_ like what you're looking for. From robertwb at math.washington.edu Sat Oct 17 18:57:55 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 17 Oct 2009 09:57:55 -0700 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4AD9B436.4000604@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <2B1FBF76-B07B-4239-9A3C-75D44DC73738@math.washington.edu> <4AD9B436.4000604@molden.no> Message-ID: On Oct 17, 2009, at 5:10 AM, Sturla Molden wrote: > Robert Bradshaw skrev: >>> First, is there any reason why Cython does not recognize const and >>> restrict? >> >> That's because no one's actually implemented, not because we don't >> want it. We know its benefits. Note that const is not as trivial as >> it seems on the surface (though it wouldn't be a Herculean task >> either). We'd have to support stuff like >> >> struct foo { >> const char * x, >> int const * const ptr, >> long foo, >> }; > Actually, one can get around the intricacies of pointer qualifiers > using > a C trick: > > The declaration > > int * const const_pointer = ... > > can be expanded over two lines with a temporary typedef: > > typedef int *tmp_t; > const tmp_t const_pointer = ... > > We can thus avoid the const qualifier appearing after the star. > > Personally I consider expressions like "int const * const ptr" > obfuscated and verbose. Syntax should be easy to read. In the two-line > declaration of const_pointer, it is obvious what is intended to be > constant. > > In the western world we also tend to read left to right. > > typedef const int *const const_pointer_to_const_int; > > is the same as > > typedef const int *ptr_to_const_int; > typedef const ptr_to_const_int const_ptr_to_const_int; > > But the one-liner, we have to read the declaration right to left. In > the > two-liner we read left to right, as we are used to. Code that are > difficult to read is un-Pythonic. There is also somthing in the Zen of > Python that there should be one way of doing things. But C allows a > myriad of ways to write the same declarations. I therefore don't think > is would be necessary to support all of C's possible placements of > qualifiers like const, static and restrict. Parsing is easy, it's a question of upgrading the type system to respect all of the (messy) semantics through the end. Though I agree most people don't need the full C complexity, half-way supporting a feature like const is sometimes more confusing than not supporting it at all. - Robert From dagss at student.matnat.uio.no Sat Oct 17 20:04:01 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 17 Oct 2009 20:04:01 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4AD9C774.4000803@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> Message-ID: <4ADA0711.2010101@student.matnat.uio.no> Sturla Molden wrote: > Dag Sverre Seljebotn skrev: >> 1) The buffer pointer is unpacked into a local variable which is >> declared by using a type object from PyrexTypes.py (i.e. Buffer.py just >> uses a type from PyrexTypes.py to specify the type). So one might want >> to add support for "restrict" pointer types in PyrexTypes.py to support >> declaring the variable. >> > > > Hm... > > buf_lookup_c_code generates pointer code like this: > > ((type)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + in) > > with type e.g. being double *, m = nd-2, and n = nd-1. > > > Will an optimising C compiler be smart enough to put this in a local > variable (or register) if it sees this expression re-typed over and over > again? > > Unless it can do that, we will have no use for the restrict qualifier. > > Thus, the compiler must be 100% sure the value never changes. The > variables in the expression must be in the local scope, and preferably > declared constants. Obviously we cannot declare i0 .. im, in constant. > > char *const buf = bufinfo.buf; > const Py_ssize_t s0 = bufinfo.strides[0]; > const Py_ssize_t s1 = bufinfo.strides[1]; > const Py_ssize_t s2 = bufinfo.strides[2]; > ... > const Py_ssize_t sN = bufinfo.strides[N]; > > This is more or less what Cython does. I am a bit uncertain about the > buf in Cythons current version, but I presume the compiler will see it > as local if the bufinfo is local. > > There is another potential problem with the machine code. We cannot > generate code like > > *((double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + i0) = rvalue; > > and expect this to work (or even be accepted by the C compiler), because > that's an lvalue cast. Since I don't get pesky compiler warnings, it > either means Cython is doing "the right thing", or it means my GCC is > not pedantic enough. > > The "right thing" would be to put ((double *)((char*)buf + i0*s0 + i1*s1 > + ... + im*sm) + i0) into a local variable, and pray that an aggressive > compiler will be able to move the first part of tmp out of the local > scope... > > { > double *tmp = (double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) > + i0; > *tmp = rvalue; > } > > Is this what Cython does? I am not quite sure. Perhaps someone can tell me. No, it breaks the rules here -- nobody's complained about it so I guess the compiler that people have used it with is relaxed about this. It would be rather easy to change though. > In hand-written code I would do this by hand. > > double * restrict tmp = (double *)((char*)buf + i0*s0 + i1*s1 + ... + > im*sm); > for (in=0; i0 < bufinfo.shape[n]; in++) > tmp[in] = rvalue; > > But I'd be surprised if Cython could do this kind of transform. So we Yep, we've assumed the C compiler moves stuff out of loops if they can be. > probably have to rely on the C compiler getting rid of (double > *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) from the inner scope. > > The restrict qualifier should be inserted like this: > > { > double * restrict tmp = ... > *tmp = rvalue; > } Hmm. Are you sure the compiler can do the restrict magic if we do a cast on every access? It is optimizing multiple accesses/pipelining/SSE to different or contiguous parts of the same array after all... We could "restrict"-type "buf" though -- unpack it into local variables like the strides, and cast it to the right type. So: double * restrict buf; Py_ssize_t stride0; /* cdef ndarray[double, mode="c"] typedarr = arr */ ... buf = (double*)bufinfo.buf; stride0 = bufinfo.strides[0] / sizeof(double); // note div by sizeof ... /* x = typedarr[i, j] */ x = buf[stride0 * i + j] However if there are quicker solutions than this (i.e. your temporary pointer idea works) then great. BTW if you're in my area (Blindern) it might be easier (at least on my hands) to meet for an hour with a laptop for a cup of coffee and go through it than long emails. -- Dag Sverre From dagss at student.matnat.uio.no Sat Oct 17 21:40:52 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 17 Oct 2009 21:40:52 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ADA0711.2010101@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADA0711.2010101@student.matnat.uio.no> Message-ID: <534407993bf4b749732711c7d7ebc7e9.squirrel@webmail.uio.no> > Sturla Molden wrote: >> Dag Sverre Seljebotn skrev: >>> 1) The buffer pointer is unpacked into a local variable which is >>> declared by using a type object from PyrexTypes.py (i.e. Buffer.py just >>> uses a type from PyrexTypes.py to specify the type). So one might want >>> to add support for "restrict" pointer types in PyrexTypes.py to support >>> declaring the variable. >>> >> >> >> Hm... >> >> buf_lookup_c_code generates pointer code like this: >> >> ((type)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + in) >> >> with type e.g. being double *, m = nd-2, and n = nd-1. >> >> >> Will an optimising C compiler be smart enough to put this in a local >> variable (or register) if it sees this expression re-typed over and over >> again? >> >> Unless it can do that, we will have no use for the restrict qualifier. >> >> Thus, the compiler must be 100% sure the value never changes. The >> variables in the expression must be in the local scope, and preferably >> declared constants. Obviously we cannot declare i0 .. im, in constant. >> >> char *const buf = bufinfo.buf; >> const Py_ssize_t s0 = bufinfo.strides[0]; >> const Py_ssize_t s1 = bufinfo.strides[1]; >> const Py_ssize_t s2 = bufinfo.strides[2]; >> ... >> const Py_ssize_t sN = bufinfo.strides[N]; >> >> This is more or less what Cython does. I am a bit uncertain about the >> buf in Cythons current version, but I presume the compiler will see it >> as local if the bufinfo is local. >> >> There is another potential problem with the machine code. We cannot >> generate code like >> >> *((double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + i0) = rvalue; >> >> and expect this to work (or even be accepted by the C compiler), because >> that's an lvalue cast. Since I don't get pesky compiler warnings, it >> either means Cython is doing "the right thing", or it means my GCC is >> not pedantic enough. >> >> The "right thing" would be to put ((double *)((char*)buf + i0*s0 + i1*s1 >> + ... + im*sm) + i0) into a local variable, and pray that an aggressive >> compiler will be able to move the first part of tmp out of the local >> scope... >> >> { >> double *tmp = (double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) >> + i0; >> *tmp = rvalue; >> } >> >> Is this what Cython does? I am not quite sure. Perhaps someone can tell >> me. > > No, it breaks the rules here -- nobody's complained about it so I guess > the compiler that people have used it with is relaxed about this. > > It would be rather easy to change though. > >> In hand-written code I would do this by hand. >> >> double * restrict tmp = (double *)((char*)buf + i0*s0 + i1*s1 + ... + >> im*sm); >> for (in=0; i0 < bufinfo.shape[n]; in++) >> tmp[in] = rvalue; >> >> But I'd be surprised if Cython could do this kind of transform. So we > > Yep, we've assumed the C compiler moves stuff out of loops if they can be. > >> probably have to rely on the C compiler getting rid of (double >> *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) from the inner scope. >> >> The restrict qualifier should be inserted like this: >> >> { >> double * restrict tmp = ... >> *tmp = rvalue; >> } > > Hmm. Are you sure the compiler can do the restrict magic if we do a cast > on every access? It is optimizing multiple accesses/pipelining/SSE to > different or contiguous parts of the same array after all... > > We could "restrict"-type "buf" though -- unpack it into local variables > like the strides, and cast it to the right type. So: > > double * restrict buf; > Py_ssize_t stride0; > > /* cdef ndarray[double, mode="c"] typedarr = arr */ > ... > buf = (double*)bufinfo.buf; > stride0 = bufinfo.strides[0] / sizeof(double); // note div by sizeof > > ... > > /* x = typedarr[i, j] */ > x = buf[stride0 * i + j] > > However if there are quicker solutions than this (i.e. your temporary > pointer idea works) then great. Actually this solution can't be used in general (only for contiguous arrays) since the strides do not have to be divisible by element size (like, taking an attribute slice out of a record array). I guess we need a set of benchmarks for different styles of writing C code and see what gets optimized and what not...it would be nice to have one approach that works both with contiguous and record arrays, but performance comes first. Dag Sverre From sturla at molden.no Sat Oct 17 23:56:43 2009 From: sturla at molden.no (Sturla Molden) Date: Sat, 17 Oct 2009 23:56:43 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ADA0711.2010101@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADA0711.2010101@student.matnat.uio.no> Message-ID: <4ADA3D9B.4090607@molden.no> Dag Sverre Seljebotn skrev: > > No, it breaks the rules here -- nobody's complained about it so I guess > the compiler that people have used it with is relaxed about this. > I was worried about that. But lvalue casts are (formally speaking) undefined behavior. >> >> The restrict qualifier should be inserted like this: >> >> { >> double * restrict tmp = ... >> *tmp = rvalue; >> } > > Hmm. Are you sure the compiler can do the restrict magic if we do a cast > on every access? No, I'm not... There are two important things: 1. The compiler does not know that buf has no alias. But since the compiler knows tmp is restricted, and all read-write from memory goes through tmp, I don't think it matters that buf is not restriced. I.e. buf is never de-referenced, so it does not matter it is not restrict. Restrict only matters for pointers that are de-referenced. Though, it would not hurt having buf declared restrict either. 2. Buf changing value would be a problem. In this case, tmp must be recomputed, and thus whatever tmp points to must be read from memory again. If the compiler can infere that it cannot happen, it should not be a problem, as it can throw the extra assignment to tmp away. We can make sure that it knows this by declaring buf "char * const", though just having buf as a local variable would probably suffice. If it's local, and never written to, it cannot change. But as with restrict, it would not hurt to have buf declared const as well. > > We could "restrict"-type "buf" though -- unpack it into local variables > like the strides, and cast it to the right type. So: > Yes. > double * restrict buf; > Py_ssize_t stride0; > > /* cdef ndarray[double, mode="c"] typedarr = arr */ > ... > buf = (double*)bufinfo.buf; > stride0 = bufinfo.strides[0] / sizeof(double); // note div by sizeof It must be: char * restrict buf; otherwise strides might not work right (as you mentioned). The machine code for these expressions should be identical: (char*)buf + sizeof(double) (double*)buf + 1 I would not optimize for performance here... I would introduce two more auxillary variables than today: one used to store the buffer and the other to avoid lvalue cast. Both should get the restrict qualifier if requested. So if we have this Cython code: cdef double lvalue, rvalue cdef np.ndarray[double, ndim=3, mode="c", restrict=True] array array[i,j,k] = rvalue lvalue = array[i,j,k] I think we should aim at producing this C code: /* cdef double lvalue, rvalue */ double lvalue, rvalue; /* cdef np.ndarray[double, ndim=3, mode="c", restrict=True] array */ char *const restrict buf = (char *)bufinfo.buf; const Py_ssize_t s0 = bufinfo.strides[0]; const Py_ssize_t s1 = bufinfo.strides[1]; const Py_ssize_t s2 = bufinfo.strides[2]; typedef double *restrict array_ptr_t; register array_ptr_t array; /* array[i,j,k] = rvalue */ array = (double *)(buf + s0*i0 + s1*i1); *(array + i2) = rvalue; /* lvalue = array[i,j,k] */ array = (double *)(buf + s0*i0 + s1*i1); lvalue = *(array + i2); A good optimizing C compiler should see that a lot of this is redundant, and omit that from the code. So we would finally get something like this compiled: array = (double *)(buf + s0*i0 + s1*i1); { register double tmp = rvalue; *(array + i2) = tmp; lvalue = tmp; } I cannot optimize much better by hand... If we just have cdef np.ndarray[double, ndim=3, mode="c"] array the generated C would omit restrict but not const: char *const buf = (char *)bufinfo.buf; const Py_ssize_t s0 = bufinfo.strides[0]; const Py_ssize_t s1 = bufinfo.strides[1]; const Py_ssize_t s2 = bufinfo.strides[2]; typedef double *restrict array_ptr_t; register array_ptr_t array; P.S. I am often in Oslo (at Domus Medica), but not at the moment. It's about 5 min walk from IFI. Sturla From sturla at molden.no Sun Oct 18 00:45:35 2009 From: sturla at molden.no (Sturla Molden) Date: Sun, 18 Oct 2009 00:45:35 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ADA3D9B.4090607@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADA0711.2010101@student.matnat.uio.no> <4ADA3D9B.4090607@molden.no> Message-ID: <4ADA490F.3080701@molden.no> Sturla Molden skrev: > The compiler does not know that buf has no alias. But since > the compiler knows tmp is restricted, and all read-write > from memory goes through tmp, I don't think it matters that buf > is not restriced. I.e. buf is never de-referenced, so it does > not matter it is not restrict. Restrict only matters for > pointers that are de-referenced. Though, it would not hurt > having buf declared restrict either. > > 2. Buf changing value would be a problem. In this case, tmp must > be recomputed, and thus whatever tmp points to must be read > from memory again. If the compiler can infere that it cannot > happen, it should not be a problem, as it can throw the extra > assignment to tmp away. We can make sure that it knows > this by declaring buf "char * const", though just having buf > as a local variable would probably suffice. If it's local, and > never written to, it cannot change. But as with restrict, it > would not hurt to have buf declared const as well. > What I am trying to say is that it would not matter if we had used a correctly sized integer to store the address of the buffer: const Py_intptr_t buf = (Py_intptr_t) bufinfo.buf; The compiler has no way of knowing that an integer stores an address. Yet, it should not affect whatever this compiles to: double *restrict array; array = (double *)(buf + s0*i0 + s1*i1); *(array + i0) = rvalue; lvalue = *(array + i0); Thus, it should not matter if we omit restrict from buf. After all, it would be meaningless to speak of a restricted integer. We could thus safely use any of these: char *const buf = (char *) bufinfo.buf; char *const restrict buf = (char *) bufinfo.buf; const Py_intptr_t buf = (Py_intptr_t) bufinfo.buf; What matters is that the pointer that gets dereferenced (i.e. *array) has the restrict qualifier. P.S. I'll leave it as an exercise to the reader why buf should not be declared Py_ssize_t. It belongs to the category of C pedantery. Sturla From sturla at molden.no Sun Oct 18 01:30:59 2009 From: sturla at molden.no (Sturla Molden) Date: Sun, 18 Oct 2009 01:30:59 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ADA490F.3080701@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADA0711.2010101@student.matnat.uio.no> <4ADA3D9B.4090607@molden.no> <4ADA490F.3080701@molden.no> Message-ID: <4ADA53B3.5080707@molden.no> Sturla Molden skrev: > double *restrict array; > array = (double *)(buf + s0*i0 + s1*i1); > > *(array + i0) = rvalue; > lvalue = *(array + i0); > > Pardon the typo that I have made in all of my C code (*arrgh*). It should be double *restrict array; array = (double *)(buf + s0*i0 + s1*i1); *(array + i2) = rvalue; lvalue = *(array + i2); Sturla From sturla at molden.no Sun Oct 18 02:52:33 2009 From: sturla at molden.no (Sturla Molden) Date: Sun, 18 Oct 2009 02:52:33 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ADA53B3.5080707@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADA0711.2010101@student.matnat.uio.no> <4ADA3D9B.4090607@molden.no> <4ADA490F.3080701@molden.no> <4ADA53B3.5080707@molden.no> Message-ID: <4ADA66D1.701@molden.no> Sturla Molden skrev: > double *restrict array; > array = (double *)(buf + s0*i0 + s1*i1); > > *(array + i2) = rvalue; > lvalue = *(array + i2); > > This might be a use case for using the little known "comma operator". It will avoid major changes to the current Cython code. For those who don't know, the comma operator in C looks like this: ( expression1 , expression2 ) The comma operator first evaluates expression1 for side effects, throws that value away, evaluates expression2, and returns this value as the result of the whole expression. Buffer lookup code generated by buf_lookup_c_code in Buffer.py would thus follow this pattern: (array = (type)(buf + s0*i0 + s1*i1), array + i2) This is because *(array = (type)(buf + s0*i0 + s1*i1), array + i2) = rvalue; is the same as array = (type)(buf + s0*i0 + s1*i1); *(array + i2) = rvalue; And lvalue = *(array = (type)(buf + s0*i0 + s1*i1), array + i2); is the same as array = (type)(buf + s0*i0 + s1*i1); lvalue = *(array + i2); Using a comma expression takes the current lvalue cast (undefined behaviour in C) away from the code emitted by buf_lookup_c_code and friends. As mentioned previously: *array is an extra auxillary pointer variable we must introduce. If we want the ndarray to be restricted, then *array should be declared with this qualifier. We don't need to declare anything else with restrict. Ok ... now it's time to look at Buffer.py... Sturla From stefan_ml at behnel.de Sun Oct 18 17:04:42 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 18 Oct 2009 17:04:42 +0200 Subject: [Cython] Compiler run crashes CPython 3.1.1/3.2 Message-ID: <4ADB2E8A.9010503@behnel.de> Hi, while working on the Py3 exception code, I discovered that something in the tree transformation or tree assertion code makes the Python interpreter crash during the test suite run. I didn't manage to track it down yet, but at least I'm certain that this can be reproduced without loading any Cython built modules (including the refnanny), so it's not a problem with the code that Cython generates but with CPython itself. It looks like something in the tree traversal code corrupts sys.exc_info by leaving a reference to a deallocated exception in there. Trying to print it (e.g. after running a doctest) will then lead to the crash. I tried this with both Python 3.1.1 and the latest Py3k branch (3.2) and got the same result. To make sure that this isn't just a problem on my side, could someone else please try the steps below with CPython 3.1.1 and the latest cython-devel? To reproduce it, please do this: 1) apply the attached patch that simply prints sys.exc_info() during the tree assertions phase of the compiler run 2) run python3.1 runtests.py --no-cleanup --no-cpp --no-pyregr \ --no-doctest -vv 'compile\.first_assignment' 3) potentially re-run step 2) This will run a single compile test and crashes reliably for me during the tree-assertions phase. You may have to re-run step 2) as the first run will 2to3-ify the source and then run the test without crashing. Only the subsequent runs will crash reliably. Thanks, Stefan -------------- next part -------------- A non-text attachment was scrubbed... Name: crash-patch.patch Type: text/x-patch Size: 479 bytes Desc: not available Url : http://codespeak.net/pipermail/cython-dev/attachments/20091018/34aec14f/attachment.bin From sturla at molden.no Sun Oct 18 19:46:07 2009 From: sturla at molden.no (Sturla Molden) Date: Sun, 18 Oct 2009 19:46:07 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4AD897C3.6030309@behnel.de> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD897C3.6030309@behnel.de> Message-ID: <4ADB545F.3000807@molden.no> Stefan Behnel skrev: > To me, the meaning of "exclusive" in this context isn't immediately obvious > either, whereas "readonly" is. > > General remark: if this results in specific C keywords being generated, I'd > prefer using the C keywords in the Cython code as well. People who do not > know them will simply have to learn what they do in order to use them > properly. A helpful comment (or maybe paragraph) in the docs will make that > easy enough. > > If we use the following idiom to look up C contiguous buffers, (auxptr = (dtype*)(buf + s0*i0 + s1*i1), auxptr + i2) we can use these four declarations for auxptr: dtype *auxptr; const dtype *auxptr; dtype *restrict auxptr; const dtype *restrict auxptr; This can be controlled via two boolean keyword arguments to the buffer declarator. I suggest "restrict" and "readonly", both defaulting to False. "restrict" because it is simular to C99, and Dag Sverre said so... "readonly" because there is a field with this name in struct Py_buffer; it also makes it obvious what is readonly. I.e. using "const" as keyword could confuse the user. What is const, data or pointer? (The latter makes no sence as we must assign to auxptr, but the user don't know that. What I thus want to create is: cdef np.ndarray[dtype, mode="c"] array --> dtype *auxptr cdef np.ndarray[dtype, mode="c", readonly=True] array --> const dtype *auxptr cdef np.ndarray[dtype, mode="c", restrict=True] array --> dtype *restrict auxptr cdef np.ndarray[dtype, mode="c", restrict=True, readonly=True] array --> const dtype *restrict auxptr I am writing a special subclass of CPtrType for auxptr in PyrexTypes.py, to get the qualifiers into C. Then it's more or less just a matter of changing the buffer lookup macros in Buffer.py. This is not just to allow const and restrict on ndarrays. It's also to make Cython generate valid C for accessing Py_buffers. Currently there is an lvalue cast; not a major mistake, but it could compile incorrectly or generate pesky compiler warnings. Since I am pedantic about programming correctly, I find it annoying on a general level... But we get correct C for free with support for "readonly" and "restrict" on ndarras. By the way, should mode="fortran" imply "restrict=True"? After all, aliasing is prohibited in Fortran. So one might consider no aliasing a property of Fortran-mode ndarrays, in addition to column-major ordering. Sturla Molden From sturla at molden.no Sun Oct 18 20:02:14 2009 From: sturla at molden.no (Sturla Molden) Date: Sun, 18 Oct 2009 20:02:14 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ADA66D1.701@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADA0711.2010101@student.matnat.uio.no> <4ADA3D9B.4090607@molden.no> <4ADA490F.3080701@molden.no> <4ADA53B3.5080707@molden.no> <4ADA66D1.701@molden.no> Message-ID: <4ADB5826.3060600@molden.no> Another thing: (auxptr = (dtype*)(buf + s0*i0 + s1*i1), auxptr + i2) Here, buf should preferably be declared char *const buf = bufinfo.buf; but I'm not sure how to correctly set the initializer. Auxillary variables are declared in IntroduceBufferAuxiliaryVars.handle_scope, but their values are set in put_unpack_buffer_aux_into_scope... And it might also be that put_unpack_buffer_aux_into_scope are called more than once on a buffer (I don't know). So I might just use "char *buf" to begin with, and hope the compiler sees that its value does not change. There is one more confusing thing though, this will actually be legal: cdef np.ndarray[double, mode="c", readonly=True] array array = np.zeros(10) array = np.zeros(10) But this will fail, at least when compiling the generated C: array[n] = rvalue There should probably be an error check for this in Cython, instead of letting the C compiler trap the error, but that is low priority. I don't want this to raise a TypeError at runtime, as it would with immutable types, as we don't want that kind of overhead in numerical code. Sturla Molden From dagss at student.matnat.uio.no Sun Oct 18 21:17:08 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sun, 18 Oct 2009 21:17:08 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ADB545F.3000807@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD897C3.6030309@behnel.de> <4ADB545F.3000807@molden.no> Message-ID: <462d91ed509e147f08d021fb45c54159.squirrel@webmail.uio.no> > Stefan Behnel skrev: >> To me, the meaning of "exclusive" in this context isn't immediately >> obvious >> either, whereas "readonly" is. >> >> General remark: if this results in specific C keywords being generated, >> I'd >> prefer using the C keywords in the Cython code as well. People who do >> not >> know them will simply have to learn what they do in order to use them >> properly. A helpful comment (or maybe paragraph) in the docs will make >> that >> easy enough. >> >> > If we use the following idiom to look up C contiguous buffers, > > (auxptr = (dtype*)(buf + s0*i0 + s1*i1), auxptr + i2) > > we can use these four declarations for auxptr: > > dtype *auxptr; > const dtype *auxptr; > dtype *restrict auxptr; > const dtype *restrict auxptr; > > This can be controlled via two boolean keyword arguments to the buffer > declarator. I suggest "restrict" and "readonly", both defaulting to > False. > > "restrict" because it is simular to C99, and Dag Sverre said so... > > "readonly" because there is a field with this name in struct Py_buffer; > it also makes it obvious what is readonly. I.e. using "const" as keyword > could confuse the user. What is const, data or pointer? (The latter > makes no sence as we must assign to auxptr, but the user don't know that. Note also that there already *is* a readonly, as it is passed as a flag to GetBuffer... but it is auto-detected from the usage the buffer gets in a function. We might need manual control of it once we support passing buffers across function boundaries though. > What I thus want to create is: > > cdef np.ndarray[dtype, mode="c"] array > --> dtype *auxptr > > cdef np.ndarray[dtype, mode="c", readonly=True] array > --> const dtype *auxptr > > cdef np.ndarray[dtype, mode="c", restrict=True] array > --> dtype *restrict auxptr > > cdef np.ndarray[dtype, mode="c", restrict=True, readonly=True] array > --> const dtype *restrict auxptr > > > I am writing a special subclass of CPtrType for auxptr in PyrexTypes.py, > to get the qualifiers into C. Then it's more or less just a matter of > changing the buffer lookup macros in Buffer.py. Perhaps you could just make "restrict" and "const" properties of CPtrType? That's my first idea (although there might be reasons it doesn't work). > This is not just to allow const and restrict on ndarrays. It's also to > make Cython generate valid C for accessing Py_buffers. Currently there > is an lvalue cast; not a major mistake, but it could compile > incorrectly or generate pesky compiler warnings. Since I am pedantic > about programming correctly, I find it annoying on a general level... No problem, and thanks, it's certainly not the intention to have things wrong. > But we get correct C for free with support for "readonly" and "restrict" > on ndarras. > > By the way, should mode="fortran" imply "restrict=True"? After all, > aliasing is prohibited in Fortran. So one might consider no aliasing a > property of Fortran-mode ndarrays, in addition to column-major ordering. -1. "Fortran" is used in NumPy (and PEP 3118) as an order specifier...it is possible to have two arrays which overlap but where arr.flags.is_f_contiguous is True, so assuming restrict would be confusing IMO. We might contemplate having mode="fortran,restrict" though, if it's too verbose with restrict=True. The plan is to add support for typedefs of buffer types as well in the end, which migth further help. Dag Sverre From dagss at student.matnat.uio.no Sun Oct 18 21:31:17 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sun, 18 Oct 2009 21:31:17 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ADB5826.3060600@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADA0711.2010101@student.matnat.uio.no> <4ADA3D9B.4090607@molden.no> <4ADA490F.3080701@molden.no> <4ADA53B3.5080707@molden.no> <4ADA66D1.701@molden.no> <4ADB5826.3060600@molden.no> Message-ID: <7841d7fb7e3d7e210bf16172c84ef453.squirrel@webmail.uio.no> > > Another thing: > > (auxptr = (dtype*)(buf + s0*i0 + s1*i1), auxptr + i2) > > Here, buf should preferably be declared > > char *const buf = bufinfo.buf; > > but I'm not sure how to correctly set the initializer. Hmm. Well you *can* reassign buffers anywhere, I kind of assumed (wrongfully?) that the readonly flag was for const char* buf; The above will be difficult to achieve I think (perhaps with the exception of arrays passed as function arguments which are never set in the function .. it would be slightly hackish, so I'd like to see a benchmark of it actually doing a difference before vouching for it. I think the C compiler should easily see that a pointer is only set once.) > Auxillary variables are declared in > IntroduceBufferAuxiliaryVars.handle_scope, but their values are set in > put_unpack_buffer_aux_into_scope... And it might also be that > put_unpack_buffer_aux_into_scope are called more than once on a buffer Indeed, if you just reassign its associated variable somewhere: cdef ndarray[int] a = b # called first time a = c # called second time > (I don't know). So I might just use "char *buf" to begin with, and hope > the compiler sees that its value does not change. That's what I'd do. > There is one more confusing thing though, this will actually be legal: > > cdef np.ndarray[double, mode="c", readonly=True] array > array = np.zeros(10) > array = np.zeros(10) > > But this will fail, at least when compiling the generated C: > > array[n] = rvalue > > There should probably be an error check for this in Cython, instead of > letting the C compiler trap the error, but that is low priority. I don't > want this to raise a TypeError at runtime, as it would with immutable > types, as we don't want that kind of overhead in numerical code. Definitely a Cython compiler error. If you get to the end of your todolist and still have time, the place to check such things is in IndexNode in ExprNode.py...in analyse(), I think. (And the code in there is not pretty, but just add another hack...) Just ask, Dag Sverre From sturla at molden.no Sun Oct 18 21:40:36 2009 From: sturla at molden.no (Sturla Molden) Date: Sun, 18 Oct 2009 21:40:36 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <462d91ed509e147f08d021fb45c54159.squirrel@webmail.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD897C3.6030309@behnel.de> <4ADB545F.3000807@molden.no> <462d91ed509e147f08d021fb45c54159.squirrel@webmail.uio.no> Message-ID: <4ADB6F34.10307@molden.no> Dag Sverre Seljebotn skrev: > Perhaps you could just make "restrict" and "const" properties of CPtrType? > That's my first idea (although there might be reasons it doesn't work). > > More or less what I did, except in a subclass. BTW: Who instantiate BufferType object from PyrexType.py? They are already created when handle_scopy is called on IntroduceBufferAuxiliaryVars. But I have bit trouble following the flow of Cython's code. I think analyse_buffer_options is called to create BufferType, but where? > No problem, and thanks, it's certainly not the intention to have things > wrong. > > It's not wrong, nor right, just undefined. :-) S.M. From sturla at molden.no Sun Oct 18 21:53:39 2009 From: sturla at molden.no (Sturla Molden) Date: Sun, 18 Oct 2009 21:53:39 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <7841d7fb7e3d7e210bf16172c84ef453.squirrel@webmail.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADA0711.2010101@student.matnat.uio.no> <4ADA3D9B.4090607@molden.no> <4ADA490F.3080701@molden.no> <4ADA53B3.5080707@molden.no> <4ADA66D1.701@molden.no> <4ADB5826.3060600@molden.no> <7841d7fb7e3d7e210bf16172c84ef453.squirrel@webmail.uio.no> Message-ID: <4ADB7243.4040804@molden.no> Dag Sverre Seljebotn skrev: >> Another thing: >> >> (auxptr = (dtype*)(buf + s0*i0 + s1*i1), auxptr + i2) >> >> Here, buf should preferably be declared >> >> char *const buf = bufinfo.buf; >> >> but I'm not sure how to correctly set the initializer. >> > > Hmm. Well you *can* reassign buffers anywhere, I kind of assumed > (wrongfully?) that the readonly flag was for > > const char* buf; > Oh, no ... we don't need "const char * buf" for readonly. The "*const" is there to tell the compiler the address stored in buf never change. Thus it is easier to put it in a register and/or throw redundant (buf + s0*i0 + s1*i1) expressions away. For the same reason the strides would preferably be declared const as well. But since they can be reassigned we cannot have them const. Readonly comes in as a const on what auxptr points to. That means with readonly we have char *buf const double *auxptr (Buf is never dereferenced, so it could even be an integer.) > Definitely a Cython compiler error. Yes. Cython should not emit C with syntax error (if it can be avoided). From sturla at molden.no Mon Oct 19 06:37:30 2009 From: sturla at molden.no (Sturla Molden) Date: Mon, 19 Oct 2009 06:37:30 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <7841d7fb7e3d7e210bf16172c84ef453.squirrel@webmail.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADA0711.2010101@student.matnat.uio.no> <4ADA3D9B.4090607@molden.no> <4ADA490F.3080701@molden.no> <4ADA53B3.5080707@molden.no> <4ADA66D1.701@molden.no> <4ADB5826.3060600@molden.no> <7841d7fb7e3d7e210bf16172c84ef453.squirrel@webmail.uio.no> Message-ID: <4ADBED0A.5080506@molden.no> Dag Sverre Seljebotn skrev: > > Definitely a Cython compiler error. If you get to the end of your todolist > and still have time, the place to check such things is in IndexNode in > ExprNode.py...in analyse(), I think. (And the code in there is not pretty, > but just add another hack...) I think I am near the end of the todo list now... For now, the error is trapped by the C compiler (not Cython) if a readonly buffer is written to. Otherwise I am done. That's as far as I got. I've sent modifications of Cython 0.11.3 to Dag Sverre. He can do with it what he wants. :-) Now we can write: np.ndarray[double, ndim=1, mode="c", restrict=True] array # uses "double *restrict" to access array elements np.ndarray[double, ndim=1, mode="c", readonly=True] array # uses "double const *" to access array elements or both, or just double*. The C code is generated without lvalue casts, looks ok, compiles with GCC, and I haven't made it segfault yet. Restrict does not depend on C99: there are macros to use __restrict__ (GNU) or __restrict (Intel, MS) if available. That's it. If anyone else wants it, just drop me a line... Regards, Sturla Molden From dagss at student.matnat.uio.no Mon Oct 19 08:38:45 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Mon, 19 Oct 2009 08:38:45 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4AD9C774.4000803@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> Message-ID: <4ADC0975.2000106@student.matnat.uio.no> Sturla Molden wrote: > > There is another potential problem with the machine code. We cannot > generate code like > > *((double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + i0) = rvalue; > > and expect this to work (or even be accepted by the C compiler), because > that's an lvalue cast. Since I don't get pesky compiler warnings, it > either means Cython is doing "the right thing", or it means my GCC is > not pedantic enough. > > The "right thing" would be to put ((double *)((char*)buf + i0*s0 + i1*s1 > + ... + im*sm) + i0) into a local variable, and pray that an aggressive > compiler will be able to move the first part of tmp out of the local > scope... > > { > double *tmp = (double *)((char*)buf + i0*s0 + i1*s1 + ... + im*sm) > + i0; > *tmp = rvalue; > } Are you sure about this? I'm no C language lawyer, but when I think of lvalue casts I think of stuff like (*double)ptr = malloc(...); i.e. where the value to be transferred is casted. In the example above, though, you have *((*double)expr) = value i.e. *expr = value Which I'd think would be legal regardless of how the pointer which is the result of expr is acquired -- * basically turns an rvalue to an lvalue (?). At least, "gcc -ansi -pedantic" supports this view and compiles this without any warning: #include int main() { int a; void* p = &a; *((int*)p) = 33; printf("%d\n", a); return 0; } -- Dag Sverre From sturla at molden.no Mon Oct 19 15:48:03 2009 From: sturla at molden.no (Sturla Molden) Date: Mon, 19 Oct 2009 15:48:03 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ADC0975.2000106@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADC0975.2000106@student.matnat.uio.no> Message-ID: <4ADC6E13.9060606@molden.no> Dag Sverre Seljebotn skrev: > i.e. where the value to be transferred is casted. In the example above, > though, you have > > *((*double)expr) = value > > i.e. > > *expr = value > > Which I'd think would be legal regardless of how the pointer which is > the result of expr is acquired -- * basically turns an rvalue to an > lvalue (?). > I think you are right. This is from "C in a nutshell": array[1] (L) &array[1] (R) ptr (L) *ptr (L) ptr + 1 (R) *ptr + 1 (R) So ((char*)buf + i0*s0 + i1*s1 + ... + im*sm) + i0) is like the second last pattern, which is an rvalue. Ok. I stand corrected. Sturla From dalcinl at gmail.com Mon Oct 19 16:28:09 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Mon, 19 Oct 2009 12:28:09 -0200 Subject: [Cython] Unprefixed single character strings fail to compare to integers In-Reply-To: <10B7EF25-8750-4C8B-85B6-55ACAD8D4C72@math.washington.edu> References: <4AD97A11.3080301@behnel.de> <10B7EF25-8750-4C8B-85B6-55ACAD8D4C72@math.washington.edu> Message-ID: On Sat, Oct 17, 2009 at 6:26 AM, Robert Bradshaw wrote: > On Oct 17, 2009, at 1:02 AM, Stefan Behnel wrote: >> >> Personally, I would prefer either 1) or 3), the latter likely being >> more >> convenient but potentially introducing new pitfalls elsewhere (to be >> seen). >> >> Comments? > > I'm for (2) or (3), with a preference for (2). Option (1) will break > code (which I'm strongly against) and (3) seems prone to pitfalls as > you mention. > Yes, I also prefer (2). Anyway, I'm not going to implement it ;-) ... Robert, I also hate to break code. But I also hate to ask developer's to spend its time on supporting features related to ambiguities... IMHO, this is a case where "In the face of ambiguity, refuse the temptation to guess." applies. So I would say that (1) is out for backward compatibility reasons, then choose from (2) or (3) the easiest one to implement, and emit warnings about using unprefixed 1-string literals in char contexts. Hopefully, the warnings will be annoying enough to "force" users to update their code. Then I would not care too much about the possible pitfalls of (3), in case of (3) being the way to follow because it is the easiest to implement. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sturla at molden.no Mon Oct 19 16:35:59 2009 From: sturla at molden.no (Sturla Molden) Date: Mon, 19 Oct 2009 16:35:59 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ADC0975.2000106@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADC0975.2000106@student.matnat.uio.no> Message-ID: <4ADC794F.6000909@molden.no> Dag Sverre Seljebotn skrev > i.e. where the value to be transferred is casted. In the example above, > though, you have > > *((*double)expr) = value How would you use "restrict" and "const" with this expression? ((double *)((char*)buf + i*s) + i0) Like this? ((const double *)((const char*)buf + i*s) + i0) ((double *restrict)((char *restrict)buf + i*s) + i0) GCC accepts this with -Wall and -pedantic. I am worried that a cast to dtype*restrict will not work as intended. If the compiler sees these expressions ((double *restrict)((char *restrict)buf + i*s) + i01) ((double *restrict)((char *restrict)buf + i*s) + i02) as tmp + i01 tmp + i02 with double *restrict tmp = ((double *)((char *)buf + i*s); then it will work. If it sees the expressions as double *restrict tmp1 = tmp + i01; double *restrict tmp2 = tmp + i02; then it might not work. What worries me is that with i01 == i02, tmp1 is aliased with tmp2. And it does not just apply to simultaneous values of i01 and i02. Also note that from the C standard, the compiler is free to ignore restrict. It could also think expressions like those above are too difficult to analyze, and drop the modifier. It could very well be that it just honours restrict on declared variables, not expressions. I don't know... With the comma operator(as I used in my code), we know there is one restricted pointer declared and associated with each buffer. Thus it cannot fail. But which is more efficient? Possibly they work the same. But I think we need to do benchmarking. :-) Sturla From stefan_ml at behnel.de Mon Oct 19 16:47:03 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 19 Oct 2009 16:47:03 +0200 Subject: [Cython] Unprefixed single character strings fail to compare to integers In-Reply-To: References: <4AD97A11.3080301@behnel.de> <10B7EF25-8750-4C8B-85B6-55ACAD8D4C72@math.washington.edu> Message-ID: <4ADC7BE7.9050606@behnel.de> Lisandro Dalcin wrote: > On Sat, Oct 17, 2009 at 6:26 AM, Robert Bradshaw wrote: >> On Oct 17, 2009, at 1:02 AM, Stefan Behnel wrote: >>> Personally, I would prefer either 1) or 3), the latter likely being >>> more >>> convenient but potentially introducing new pitfalls elsewhere (to be >>> seen). >>> >>> Comments? >> I'm for (2) or (3), with a preference for (2). Option (1) will break >> code (which I'm strongly against) and (3) seems prone to pitfalls as >> you mention. > > Yes, I also prefer (2). Anyway, I'm not going to implement it ;-) ... Oh, I forgot to mention: (2) is mostly implemented now, with a few remaining quirks where the relaxed code became a bit too lax. http://hg.cython.org/cython-devel/rev/8d8cc4c9b91b http://hg.cython.org/cython-devel/rev/b0bb4d405755 Stefan From dagss at student.matnat.uio.no Mon Oct 19 17:06:04 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Mon, 19 Oct 2009 17:06:04 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ADC794F.6000909@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADC0975.2000106@student.matnat.uio.no> <4ADC794F.6000909@molden.no> Message-ID: <4ADC805C.3070209@student.matnat.uio.no> Sturla Molden wrote: > Dag Sverre Seljebotn skrev >> i.e. where the value to be transferred is casted. In the example above, >> though, you have >> >> *((*double)expr) = value > > How would you use "restrict" and "const" with this expression? > > ((double *)((char*)buf + i*s) + i0) > > Like this? > > ((const double *)((const char*)buf + i*s) + i0) > ((double *restrict)((char *restrict)buf + i*s) + i0) > > GCC accepts this with -Wall and -pedantic. > > I am worried that a cast to dtype*restrict will not work as intended. > > If the compiler sees these expressions > > ((double *restrict)((char *restrict)buf + i*s) + i01) > ((double *restrict)((char *restrict)buf + i*s) + i02) > > as > > tmp + i01 > tmp + i02 > > with > > double *restrict tmp > = ((double *)((char *)buf + i*s); > > then it will work. > > If it sees the expressions as > > double *restrict tmp1 = tmp + i01; > double *restrict tmp2 = tmp + i02; > > then it might not work. What worries me is that with i01 == i02, tmp1 is aliased with tmp2. And it does not just apply to simultaneous values of i01 and i02. Also note that from the C standard, the compiler is free to ignore restrict. It could also think expressions like those above are too difficult to analyze, and drop the modifier. It could very well be that it just honours restrict on declared variables, not expressions. I don't know... > > With the comma operator(as I used in my code), we know there is one restricted pointer declared and associated with each buffer. Thus it cannot fail. > > But which is more efficient? Possibly they work the same. But I think we need to do benchmarking. :-) Indeed. Do you have anything readily available where this could make a difference? Thanks for the changes; I'll merge them once I feel confident the right approach is taken for the issue above. There's a real chance it'll end up in 0.12. -- Dag Sverre From dalcinl at gmail.com Mon Oct 19 17:14:20 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Mon, 19 Oct 2009 13:14:20 -0200 Subject: [Cython] Unprefixed single character strings fail to compare to integers In-Reply-To: <4ADC7BE7.9050606@behnel.de> References: <4AD97A11.3080301@behnel.de> <10B7EF25-8750-4C8B-85B6-55ACAD8D4C72@math.washington.edu> <4ADC7BE7.9050606@behnel.de> Message-ID: On Mon, Oct 19, 2009 at 12:47 PM, Stefan Behnel wrote: > > Lisandro Dalcin wrote: >> On Sat, Oct 17, 2009 at 6:26 AM, Robert Bradshaw wrote: >>> On Oct 17, 2009, at 1:02 AM, Stefan Behnel wrote: >>>> Personally, I would prefer either 1) or 3), the latter likely being >>>> more >>>> convenient but potentially introducing new pitfalls elsewhere (to be >>>> seen). >>>> >>>> Comments? >>> I'm for (2) or (3), with a preference for (2). Option (1) will break >>> code (which I'm strongly against) and (3) seems prone to pitfalls as >>> you mention. >> >> Yes, I also prefer (2). Anyway, I'm not going to implement it ;-) ... > > Oh, I forgot to mention: (2) is mostly implemented now, with a few > remaining quirks where the relaxed code became a bit too lax. > > http://hg.cython.org/cython-devel/rev/8d8cc4c9b91b > http://hg.cython.org/cython-devel/rev/b0bb4d405755 > You see, I wasted my time trying to save your time ;-) Many Thanks! -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Mon Oct 19 17:28:32 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Mon, 19 Oct 2009 13:28:32 -0200 Subject: [Cython] Compiler run crashes CPython 3.1.1/3.2 In-Reply-To: <4ADB2E8A.9010503@behnel.de> References: <4ADB2E8A.9010503@behnel.de> Message-ID: On Sun, Oct 18, 2009 at 1:04 PM, Stefan Behnel wrote: > Hi, > > while working on the Py3 exception code, I discovered that something in the > tree transformation or tree assertion code makes the Python interpreter > crash during the test suite run. As I routinely test from 2.3 to 3.2 with debug Python builds (and UCS2, just because I always forget to use UCS4), I got these two: <...> Running tests against Cython 0.11.3 Python 3.1.1 (r311:74480, Sep 9 2009, 10:27:39) [GCC 4.4.1 20090725 (Red Hat 4.4.1-2)] compiling (c) first_assignment ... HIER1 python3.1: Objects/unicodeobject.c:839: PyUnicodeUCS2_FromFormatV: Assertion `obj' failed. Aborted <...> Running tests against Cython 0.11.3 Python 3.2a0 (py3k:75400, Oct 14 2009, 11:53:23) [GCC 4.4.1 20090725 (Red Hat 4.4.1-2)] compiling (c) first_assignment ... HIER1 python3.2: Objects/unicodeobject.c:839: PyUnicodeUCS2_FromFormatV: Assertion `obj' failed. Aborted So it it seems that PyUnicode_FromFormat (perhaps from PyErr_Format()) is called with %R format and a NULL PyObject*. > > This will run a single compile test and crashes reliably for me during the > tree-assertions phase. You may have to re-run step 2) as the first run will > 2to3-ify the source and then run the test without crashing. Only the > subsequent runs will crash reliably. > > Thanks, > > Stefan > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sturla at molden.no Mon Oct 19 18:03:31 2009 From: sturla at molden.no (Sturla Molden) Date: Mon, 19 Oct 2009 18:03:31 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ADC805C.3070209@student.matnat.uio.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADC0975.2000106@student.matnat.uio.no> <4ADC794F.6000909@molden.no> <4ADC805C.3070209@student.matnat.uio.no> Message-ID: <4ADC8DD3.7020902@molden.no> Dag Sverre Seljebotn skrev: > > Indeed. Do you have anything readily available where this could make a > difference? > I have not gotten to that yet. We need a benchmarking suite for Cython. I was thinking about porting Scimark 2.0 or Debian's "Computer Language Benchmarks Game" to Cython. Pros and cons: * Debian's suite is already ported to Python, which means less coding. * Scimark is oriented towards serious scientific computing. I feel its numbers are more relevant to my work. * Debian's suite is more cited, and the one to use for bragging about Cython. * Scimark is (to my knowledge) only available for ANSI C and Java. We don't get the pleasure of kicking C++ and Fortran's butt. :-) > Thanks for the changes; I'll merge them once I feel confident the right > approach is taken for the issue above. There's a real chance it'll end > up in 0.12 For others who would like to test, it is here: http://folk.uio.no/sturlamo/python/cython-mod.zip Just install Cython 0.11.3 and replace the files. Regards Sturla Molden From sturla at molden.no Mon Oct 19 19:44:21 2009 From: sturla at molden.no (Sturla Molden) Date: Mon, 19 Oct 2009 19:44:21 +0200 Subject: [Cython] Issues with numerical programming with Cython In-Reply-To: <4ADC8DD3.7020902@molden.no> References: <3337827751.1469432@smtp.netcom.no> <4ACDCFF0.7060705@molden.no> <4ACDF767.7020901@molden.no> <4ACF5BDC.1040506@molden.no> <4ACF6A5C.7040102@student.matnat.uio.no> <4AD88A2E.2080901@molden.no> <4AD893BB.2020904@student.matnat.uio.no> <4AD8DC88.7030109@molden.no> <4AD964EE.60606@student.matnat.uio.no> <4AD9C774.4000803@molden.no> <4ADC0975.2000106@student.matnat.uio.no> <4ADC794F.6000909@molden.no> <4ADC805C.3070209@student.matnat.uio.no> <4ADC8DD3.7020902@molden.no> Message-ID: <4ADCA575.7000802@molden.no> Sturla Molden skrev: > * Debian's suite is already ported to Python, which means less coding. > > * Scimark is oriented towards serious scientific computing. I feel its > numbers are more relevant to my work. > Looking at the codes, I am going for a port of SciMark 2.0. Debian's game is not fit to test the numerical performance of Cython with ndarrays. S.M. From robertwb at math.washington.edu Mon Oct 19 20:07:02 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 19 Oct 2009 11:07:02 -0700 Subject: [Cython] Unprefixed single character strings fail to compare to integers In-Reply-To: References: <4AD97A11.3080301@behnel.de> <10B7EF25-8750-4C8B-85B6-55ACAD8D4C72@math.washington.edu> Message-ID: <42155131-C5EB-441B-9130-C19B661E2B11@math.washington.edu> On Oct 19, 2009, at 7:28 AM, Lisandro Dalcin wrote: > On Sat, Oct 17, 2009 at 6:26 AM, Robert Bradshaw > wrote: >> On Oct 17, 2009, at 1:02 AM, Stefan Behnel wrote: >>> >>> Personally, I would prefer either 1) or 3), the latter likely being >>> more >>> convenient but potentially introducing new pitfalls elsewhere (to be >>> seen). >>> >>> Comments? >> >> I'm for (2) or (3), with a preference for (2). Option (1) will break >> code (which I'm strongly against) and (3) seems prone to pitfalls as >> you mention. >> > > Yes, I also prefer (2). Anyway, I'm not going to implement it ;-) ... > > Robert, I also hate to break code. But I also hate to ask developer's > to spend its time on supporting features related to ambiguities... > IMHO, this is a case where "In the face of ambiguity, refuse the > temptation to guess." applies. > > So I would say that (1) is out for backward compatibility reasons, > then choose from (2) or (3) the easiest one to implement, and emit > warnings about using unprefixed 1-string literals in char contexts. > Hopefully, the warnings will be annoying enough to "force" users to > update their code. Then I would not care too much about the possible > pitfalls of (3), in case of (3) being the way to follow because it is > the easiest to implement. You are assuming requiring the c prefix is a good thing--I think it's very useful to be able to omit it, and it certainly shouldn't have a warning. I bet most people haven't even heard of the c prefix... - Robert From dalcinl at gmail.com Mon Oct 19 20:24:40 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Mon, 19 Oct 2009 16:24:40 -0200 Subject: [Cython] Unprefixed single character strings fail to compare to integers In-Reply-To: <42155131-C5EB-441B-9130-C19B661E2B11@math.washington.edu> References: <4AD97A11.3080301@behnel.de> <10B7EF25-8750-4C8B-85B6-55ACAD8D4C72@math.washington.edu> <42155131-C5EB-441B-9130-C19B661E2B11@math.washington.edu> Message-ID: On Mon, Oct 19, 2009 at 4:07 PM, Robert Bradshaw wrote: > > You are assuming requiring the c prefix is a good thing-- > Not at all... I hate the 'c' prefix as much as you, but I also hate ambiguities, because supporting them could be a lot of work. Anyway, it seems Stefan has already made the heavy work. BTW, Are unicode characters supported by this machinery? > I think it's very useful to be able to omit it, Useful? Where is the usefulness? Perhaps it is convenient, as you save some (well, just one) keystrokes. > > I bet most people haven't even heard of the c prefix... > Here you are definitely right... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Mon Oct 19 20:31:26 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Mon, 19 Oct 2009 16:31:26 -0200 Subject: [Cython] Unprefixed single character strings fail to compare to integers In-Reply-To: <4AD97EB3.3040700@behnel.de> References: <4AD97A11.3080301@behnel.de> <4AD97EB3.3040700@behnel.de> Message-ID: On Sat, Oct 17, 2009 at 6:22 AM, Stefan Behnel wrote: > > ? ?cdef char* s = 'x' > ? ?print s == 'x' > Nice corner case... > > What is this code even supposed to mean? > I have no (clear) idea... I mean, it is really ambiguous, right? > It currently prints 'True', but that's only obvious when you know some > magic internals about Cython's string handling. > Indeed. BTW... So this would be 'True' even in Python 3, right? -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From robertwb at math.washington.edu Mon Oct 19 20:36:18 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 19 Oct 2009 11:36:18 -0700 Subject: [Cython] Unprefixed single character strings fail to compare to integers In-Reply-To: References: <4AD97A11.3080301@behnel.de> <10B7EF25-8750-4C8B-85B6-55ACAD8D4C72@math.washington.edu> <42155131-C5EB-441B-9130-C19B661E2B11@math.washington.edu> Message-ID: <1A8F18E5-E406-4CB4-9A7B-AA01B2942F37@math.washington.edu> On Oct 19, 2009, at 11:24 AM, Lisandro Dalcin wrote: > On Mon, Oct 19, 2009 at 4:07 PM, Robert Bradshaw > wrote: >> >> You are assuming requiring the c prefix is a good thing-- >> > > Not at all... I hate the 'c' prefix as much as you, but I also hate > ambiguities, because supporting them could be a lot of work. Anyway, > it seems Stefan has already made the heavy work. That's what was there before, it's just the change to the way strings worked broke it. (Thanks for fixing it Stefan, and it looks like even better than before.) > BTW, Are unicode characters supported by this machinery? I'm not sure... >> I think it's very useful to be able to omit it, > > Useful? Where is the usefulness? Perhaps it is convenient, as you save > some (well, just one) keystrokes. OK, convenient is probably a better word. It's more about remembering (or learning) that one keystroke than the time spent typing it :) - Robert From dalcinl at gmail.com Mon Oct 19 23:18:53 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Mon, 19 Oct 2009 19:18:53 -0200 Subject: [Cython] bitten again by typetesting and None In-Reply-To: <6DA6CB19-5F9E-452F-B607-190A221283FC@math.washington.edu> References: <9746E7A9-DE3C-4394-BDFD-87227BCA991D@math.washington.edu> <4AD8197B.3060307@behnel.de> <4AD88C0B.80006@behnel.de> <6DA6CB19-5F9E-452F-B607-190A221283FC@math.washington.edu> Message-ID: On Fri, Oct 16, 2009 at 3:33 PM, Robert Bradshaw wrote: > On Oct 16, 2009, at 8:15 AM, Lisandro Dalcin wrote: > >> On Fri, Oct 16, 2009 at 12:06 PM, Stefan Behnel >> wrote: >>> >>> Lisandro Dalcin wrote: >>>> On Fri, Oct 16, 2009 at 3:58 AM, Stefan Behnel wrote: >>>>>> cdef MyClass x = foo() >>>>> I agree that extension type casts should be exact and tested ones >>>>> should >>>>> fail for None. >>>> >>>> What did you meant with "exact" ? Subclasses should pass the >>>> typetest, right? >>> >>> Sorry, sure, "anything that qualifies as a true instance of the >>> checked >>> class", including subclasses. >>> >> >> BTW, that would be also the case for builtin types? IIUC, currently we >> check for *exactly* the type. > > No, I think that behavior should remain as is (for reasons previously > documented). > Now I think that the CURRENT behavior should remain the same, because of the usual concern of backward compatibility. If we start making exact checks that fail for None, then chances are that we could actually break code... A possible backward way could be to introduce (slightly) new syntax, something like , i.e using two '?' to indicate a "stronger" type check disallowing None... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From greg.ewing at canterbury.ac.nz Tue Oct 20 01:57:53 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 20 Oct 2009 12:57:53 +1300 Subject: [Cython] __richcmp__ and inheritance In-Reply-To: <4AD83BB5.5050209@creativetrax.com> References: <4AD83BB5.5050209@creativetrax.com> Message-ID: <4ADCFD01.305@canterbury.ac.nz> jason-sage at creativetrax.com wrote: > Also, unlike most other special methods, I noticed that if I defined > __richcmp__ as below (removing the type declaration for self): > > def __richcmp__(self, A other, int op): > print "using op: ",op > if op == 2: # == > return self.a == other.a > > then self can't access the cdef'd "a" attribute. See: http://docs.cython.org/docs/special_methods.html particularly the section "Arithmetic Methods". It could perhaps be made more clear that this applies to the __richcmp__ method as well. -- Greg From greg.ewing at canterbury.ac.nz Tue Oct 20 02:03:12 2009 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 20 Oct 2009 13:03:12 +1300 Subject: [Cython] __richcmp__ and inheritance In-Reply-To: <4AD83BB5.5050209@creativetrax.com> References: <4AD83BB5.5050209@creativetrax.com> Message-ID: <4ADCFE40.6070007@canterbury.ac.nz> jason-sage at creativetrax.com wrote: > def __richcmp__(self, A other, int op): > print "using op: ",op > if op == 2: # == > return self.a == other.a It's also not really a good idea to put type declarations into the parameter list when defining operator methods. That's because it will result in a TypeError when called with mismatched types, whereas the correct thing to do is to *return* (not raise) NotImplemented, so that the interpreter will try other ways of handling the operation. It's better to do something like this: def __richcmp__(self, other, int op): if isinstance(self, A) and isinstance(other, A): # handle these types of operands else: return NotImplemented -- Greg From ndbecker2 at gmail.com Tue Oct 20 02:09:16 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 19 Oct 2009 20:09:16 -0400 Subject: [Cython] bitten again by typetesting and None References: <9746E7A9-DE3C-4394-BDFD-87227BCA991D@math.washington.edu> <4AD8197B.3060307@behnel.de> <4AD88C0B.80006@behnel.de> <6DA6CB19-5F9E-452F-B607-190A221283FC@math.washington.edu> Message-ID: Lisandro Dalcin wrote: ... > A possible backward way could be to introduce (slightly) new syntax, > something like , i.e using two '?' to indicate a > "stronger" type check disallowing None... That would be spelled :) From robertwb at math.washington.edu Tue Oct 20 02:37:42 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 19 Oct 2009 17:37:42 -0700 Subject: [Cython] bitten again by typetesting and None In-Reply-To: References: <9746E7A9-DE3C-4394-BDFD-87227BCA991D@math.washington.edu> <4AD8197B.3060307@behnel.de> <4AD88C0B.80006@behnel.de> <6DA6CB19-5F9E-452F-B607-190A221283FC@math.washington.edu> Message-ID: <5C965459-BE9C-45AE-B124-992C8896BAC6@math.washington.edu> On Oct 19, 2009, at 5:09 PM, Neal Becker wrote: > Lisandro Dalcin wrote: > > ... >> A possible backward way could be to introduce (slightly) new syntax, >> something like , i.e using two '?' to indicate a >> "stronger" type check disallowing None... > > That would be spelled > :) Well, or one could use the nonecheck directive. I'd like to avoid adding more syntax for a problem that'll go away with a smarter compiler. - Robert From stefan_ml at behnel.de Tue Oct 20 08:22:56 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 20 Oct 2009 08:22:56 +0200 Subject: [Cython] Unprefixed single character strings fail to compare to integers In-Reply-To: References: <4AD97A11.3080301@behnel.de> <10B7EF25-8750-4C8B-85B6-55ACAD8D4C72@math.washington.edu> <42155131-C5EB-441B-9130-C19B661E2B11@math.washington.edu> Message-ID: <4ADD5740.1020206@behnel.de> Lisandro Dalcin wrote: > On Mon, Oct 19, 2009 at 4:07 PM, Robert Bradshaw wrote: >> You are assuming requiring the c prefix is a good thing-- > > Not at all... I hate the 'c' prefix as much as you, but I also hate > ambiguities, because supporting them could be a lot of work. I tried to make these things more generic, but allowed a couple of invalid comparisons doing so. I'll fix that ASAP. > BTW, Are unicode characters supported by this machinery? No, only characters that map to a single byte representation (i.e. I simply checks if the byte string has length 1). Stefan From stefan_ml at behnel.de Tue Oct 20 08:26:57 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 20 Oct 2009 08:26:57 +0200 Subject: [Cython] Unprefixed single character strings fail to compare to integers In-Reply-To: References: <4AD97A11.3080301@behnel.de> <4AD97EB3.3040700@behnel.de> Message-ID: <4ADD5831.80101@behnel.de> Lisandro Dalcin wrote: > On Sat, Oct 17, 2009 at 6:22 AM, Stefan Behnel wrote: >> cdef char* s = 'x' >> print s == 'x' > > Nice corner case... > >> What is this code even supposed to mean? > > I have no (clear) idea... I mean, it is really ambiguous, right? > >> It currently prints 'True', but that's only obvious when you know some >> magic internals about Cython's string handling. > > Indeed. > > BTW... So this would be 'True' even in Python 3, right? No, it's False there, because it's evaluated in Python space. I already forbid comparisons between bytes/unicode and str, so this must be disallowed, too. Stefan From dagss at student.matnat.uio.no Tue Oct 20 10:31:15 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Tue, 20 Oct 2009 10:31:15 +0200 Subject: [Cython] On external complex typedefs Message-ID: <4ADD7553.7010308@student.matnat.uio.no> I disallowed them for now (compiler error), since we know they don't work properly anyway. (I did this while fixing a bug with conjugate() on non-external typedefs.) http://hg.cython.org/cython-devel/rev/d5b4a406cdf2 -- Dag Sverre From stefan_ml at behnel.de Tue Oct 20 10:50:28 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 20 Oct 2009 10:50:28 +0200 Subject: [Cython] bitten again by typetesting and None In-Reply-To: <5C965459-BE9C-45AE-B124-992C8896BAC6@math.washington.edu> References: <9746E7A9-DE3C-4394-BDFD-87227BCA991D@math.washington.edu> <4AD8197B.3060307@behnel.de> <4AD88C0B.80006@behnel.de> <6DA6CB19-5F9E-452F-B607-190A221283FC@math.washington.edu> <5C965459-BE9C-45AE-B124-992C8896BAC6@math.washington.edu> Message-ID: <4ADD79D4.8030604@behnel.de> Robert Bradshaw wrote: > On Oct 19, 2009, at 5:09 PM, Neal Becker wrote: > >> Lisandro Dalcin wrote: >> >> ... >>> A possible backward way could be to introduce (slightly) new syntax, >>> something like , i.e using two '?' to indicate a >>> "stronger" type check disallowing None... >> That would be spelled >> :) > > Well, or one could use the nonecheck directive. I'd like to avoid > adding more syntax for a problem that'll go away with a smarter > compiler. +1 I also think that the chance of breaking code with this change is rather small. I can't imagine that many use cases where I would cast a value to a specific extension type other than accessing its C attributes or methods, which would clearly lead to a crash for None values. So however people used this feature before, I expect a None check to be very close in the code. Stefan From stefan_ml at behnel.de Tue Oct 20 10:52:44 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 20 Oct 2009 10:52:44 +0200 Subject: [Cython] Compiler run crashes CPython 3.1.1/3.2 In-Reply-To: References: <4ADB2E8A.9010503@behnel.de> Message-ID: <4ADD7A5C.404@behnel.de> Lisandro Dalcin wrote: > On Sun, Oct 18, 2009 at 1:04 PM, Stefan Behnel wrote: >> while working on the Py3 exception code, I discovered that something in the >> tree transformation or tree assertion code makes the Python interpreter >> crash during the test suite run. > > As I routinely test from 2.3 to 3.2 with debug Python builds (and > UCS2, just because I always forget to use UCS4), I got these two: > > <...> > Running tests against Cython 0.11.3 > Python 3.1.1 (r311:74480, Sep 9 2009, 10:27:39) > [GCC 4.4.1 20090725 (Red Hat 4.4.1-2)] > > compiling (c) first_assignment ... HIER1 > python3.1: Objects/unicodeobject.c:839: PyUnicodeUCS2_FromFormatV: > Assertion `obj' failed. > Aborted > > <...> > Running tests against Cython 0.11.3 > Python 3.2a0 (py3k:75400, Oct 14 2009, 11:53:23) > [GCC 4.4.1 20090725 (Red Hat 4.4.1-2)] > > compiling (c) first_assignment ... HIER1 > python3.2: Objects/unicodeobject.c:839: PyUnicodeUCS2_FromFormatV: > Assertion `obj' failed. > Aborted > > So it it seems that PyUnicode_FromFormat (perhaps from PyErr_Format()) > is called with %R format and a NULL PyObject*. Yep, that's when it's trying to print the corrupted sys.exc_info(). I'll file a bug report over at CPython. Stefan From sjparry88 at hotmail.co.uk Tue Oct 20 11:15:27 2009 From: sjparry88 at hotmail.co.uk (Sam Parry) Date: Tue, 20 Oct 2009 09:15:27 +0000 Subject: [Cython] vcvarsall.bat In-Reply-To: References: Message-ID: Hi Lisandro, I have just edited the Cython Wiki as you asked. I am sorry that it is late and also that I have been unable to test the patch that you kindly suggested to me. As I now get over 20 emails a day from this mailing list I am going to remove myself. I just wanted to say thank you for the help! I am sure I will return to Cython in a few years when I have matured as a programmer! If you wish to get in contact about any developments with vcvarsall.bat or my editing of the wiki, please email me on my personal address: sjparry88 at hotmail.co.uk. Thanks again, Sam > Date: Fri, 25 Sep 2009 10:40:16 -0300 > From: dalcinl at gmail.com > To: cython-dev at codespeak.net > Subject: Re: [Cython] vcvarsall.bat > > On Fri, Sep 25, 2009 at 8:38 AM, Sam Parry wrote: > > Thanks again for your reply Lisandro. > > > > > >> About how to find the location to put the per-user pydistutils.cfg > >> file, you forgot to "import os"!!! . In short, you have to enter a > >> Python promp and do this (here doing it in Linux): > >> > >> >>> import os > >> >>> os.path.expanduser('~') > >> '/u/dalcinl' > > > > Hahahaha, oooops! > > > > > >> If you can help me to test the patch below, then I'll start a new > >> thread to ask the other Cython developers to push this fix. > >> > >> diff -r 7fbe931e5ab7 pyximport/pyxbuild.py > >> --- a/pyximport/pyxbuild.py Wed Sep 16 15:50:00 2009 +0200 > >> +++ b/pyximport/pyxbuild.py Fri Sep 18 12:39:51 2009 -0300 > >> @@ -55,6 +55,11 @@ > >> build = dist.get_command_obj('build') > >> build.build_base = pyxbuild_dir > >> > >> + config_files = dist.find_config_files() > >> + try: config_files.remove('setup.cfg') > >> + except ValueError: pass > >> + dist.parse_config_files(config_files) > >> + > >> try: > >> ok = dist.parse_command_line() > >> except DistutilsArgError: > >> > > > > Would you please be specific about how to apply the patch (I have never done > > anything like this before!)? > > > > Just open the file pyximport/pyxbuild.py and add these four lines > (marked with "+") at the appropriate place. > > > You may have to wait a little while for any testing on my end because I > > finish my project today (I am only doing this as a summer project for > > someone) and so will be starting back at university soon... I will however > > pass this information on to my successor and I may be able to do some work > > on it if I have some spare time! I will try and put this info in the wiki > > though, probably sometime next week. > > > > BTW, I've already pushed that change to cython-devel. If you hit this link: > > http://hg.cython.org/cython-devel/archive/tip.zip > > you will be able to download a zip file with the current state of the > cython-devel repo, with BTW is already in beta stage (release 0.11.3 > to appear very soon, likely in the weekend) > > > >> On Fri, Sep 18, 2009 at 11:46 AM, Sam Parry > >> wrote: > >> > Hi guys, > >> > > >> > Thanks for the prompt reply. > >> > > >> > > >> >> Date: Tue, 15 Sep 2009 13:52:18 -0300 > >> >> From: dalcinl at gmail.com > >> >> To: cython-dev at codespeak.net > >> >> Subject: Re: [Cython] vcvarsall.bat > >> >> > >> >> IIRC, there are some patches in http://trac.cython.org/cython_trac/ to > >> >> make pyximport MinGW aware... Unfortunately, I did not have any chance > >> >> to review this, and Windows is always low in my priorities... You > >> >> know... the Windows OS has a lot of users, fans, and strong defenders > >> >> (we already had some of these "fights" here in this list!!!)... but > >> >> very few of them make any useful code contribution/testing/review for > >> >> their platform... > >> > > >> > I have not had a look at the patches yet but thought I would just > >> > comment on > >> > the other things you suggested. I dual boot Windows and Linux but, > >> > unfortunately, I am running the program on a Windows machine at work. > >> > > >> > > >> >> A fast workaround for your issue if to add a file named > >> >> "distutils.cfg" in C:\Python2.6\Lib\distutils (DISCLAIMER: do not > >> >> remember right now if this is the actual full path of distutils!) with > >> >> the contents below: > >> >> [build_ext] > >> >> compiler=mingw32 > >> > > >> > As far as the disutils.cfg, I had already done that to no avail. It was > >> > in > >> > the correct place too. I just created the file using notepad and copied > >> > in > >> > the same text as you have writen (but from one of the install help > >> > documents > >> > on the cython website). As I have had this in from the start it doesn't > >> > seem > >> > to help (me anyway)! > >> > > >> > > >> >> Alternatively, you can add a "pydistutils.cfg" file with the same > >> >> contents in %HOME% or %UserProfile% or watever your "home" directory > >> >> is in your Windows system (tip: use os.path.expanduser('~') in a > >> >> Python prompt to figure out the right place) > >> > > >> > Thanks for your detailed directions in finding the home directory. > >> > However, > >> > when I type this into the command line python interpreter, I get a > >> > NameError: 'os' is not defined. This seems a bit weird to me... As such > >> > I am > >> > unsure as to where to put the pydisutils.cfg file. > >> > > >> > > >> >> BTW, If you can elaborate a bit more on this and contribute all this > >> >> stuff to the Cython wiki, it would be great.... > >> > > >> > I wouldn't mind putting this stuff in the wiki in brief if I find a > >> > solution. It would probably be mostly copy and pasted from this > >> > conversation > >> > though, especially as I have no real experience at this kind of thing... > >> > > >> > > >> > Thanks again for the info, > >> > > >> > Sam > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> > > >> >> On Tue, Sep 15, 2009 at 11:14 AM, Sam Parry > >> >> wrote: > >> >> > Hi guys, > >> >> > > >> >> > Not sure if I'm emailing to the correct place so apologies if I am > >> >> > spamming > >> >> > you... > >> >> > > >> >> > I am having problems with Cython compiling. I am following the > >> >> > tutorial > >> >> > on > >> >> > the main website (from the Users Guide) and when I type "python > >> >> > setup.py > >> >> > build_ext --inplace" I get an error saying "unable to find > >> >> > vcvarsall.bat". I > >> >> > am using MinGW as my compiler and running on windows XP. I have > >> >> > managed > >> >> > to > >> >> > find a way around this: typing "python setup.py build_ext > >> >> > --compiler=mingw32 > >> >> > --inplace" works for the first 'hello world' tutorial part. However, > >> >> > I > >> >> > get > >> >> > the vcvarsall error when trying the pyximport method. Adding the > >> >> > "--compiler=mingw32" does not work for any of the examples using any > >> >> > form of > >> >> > numpy import. > >> >> > > >> >> > I would be grateful for any insights provided that could help me run > >> >> > cython! > >> >> > I am new to using the command line, c and cython (and not all that > >> >> > experienced with python either!) so forgive me if I need more detail > >> >> > than > >> >> > the average user! > >> >> > > >> >> > Thanks, > >> >> > > >> >> > Sam > >> >> > ________________________________ > >> >> > Use Hotmail to send and receive mail from your different email > >> >> > accounts. > >> >> > Find out how. > >> >> > _______________________________________________ > >> >> > Cython-dev mailing list > >> >> > Cython-dev at codespeak.net > >> >> > http://codespeak.net/mailman/listinfo/cython-dev > >> >> > > >> >> > > >> >> > >> >> > >> >> > >> >> -- > >> >> Lisandro Dalc?n > >> >> --------------- > >> >> Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) > >> >> Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) > >> >> Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) > >> >> PTLC - G?emes 3450, (3000) Santa Fe, Argentina > >> >> Tel/Fax: +54-(0)342-451.1594 > >> >> _______________________________________________ > >> >> Cython-dev mailing list > >> >> Cython-dev at codespeak.net > >> >> http://codespeak.net/mailman/listinfo/cython-dev > >> > > >> > > >> > ________________________________ > >> > View your Twitter and Flickr updates from one place - Learn more! > >> > _______________________________________________ > >> > Cython-dev mailing list > >> > Cython-dev at codespeak.net > >> > http://codespeak.net/mailman/listinfo/cython-dev > >> > > >> > > >> > >> > >> > >> -- > >> Lisandro Dalc?n > >> --------------- > >> Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) > >> Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) > >> Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) > >> PTLC - G?emes 3450, (3000) Santa Fe, Argentina > >> Tel/Fax: +54-(0)342-451.1594 > >> _______________________________________________ > >> Cython-dev mailing list > >> Cython-dev at codespeak.net > >> http://codespeak.net/mailman/listinfo/cython-dev > > > > > > ________________________________ > > View your Twitter and Flickr updates from one place ? Learn more! > > _______________________________________________ > > Cython-dev mailing list > > Cython-dev at codespeak.net > > http://codespeak.net/mailman/listinfo/cython-dev > > > > > > > > -- > Lisandro Dalc?n > --------------- > Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) > Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) > Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) > PTLC - G?emes 3450, (3000) Santa Fe, Argentina > Tel/Fax: +54-(0)342-451.1594 > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev _________________________________________________________________ Download Messenger onto your mobile for free http://clk.atdmt.com/UKM/go/174426567/direct/01/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20091020/496ea3c1/attachment.htm From stefan_ml at behnel.de Tue Oct 20 11:42:22 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 20 Oct 2009 11:42:22 +0200 Subject: [Cython] Compiler run crashes CPython 3.1.1/3.2 In-Reply-To: <4ADD7A5C.404@behnel.de> References: <4ADB2E8A.9010503@behnel.de> <4ADD7A5C.404@behnel.de> Message-ID: <4ADD85FE.40408@behnel.de> Stefan Behnel wrote: > I'll file a bug report over at CPython. http://bugs.python.org/issue7173 Stefan From sturla at molden.no Tue Oct 20 16:48:29 2009 From: sturla at molden.no (Sturla Molden) Date: Tue, 20 Oct 2009 16:48:29 +0200 Subject: [Cython] restrict and readonly Message-ID: <4ADDCDBD.7070700@molden.no> I did some testing of read-only and restrict Py_buffer access with simple matrix multiplication. I consistantly find that it does not help on large arrays, but does help for small. However, multiplying small matrices is so fast that speed does not matter anyway. Relative speed measurements for matrix multiplication average of 100 trials matrix ranks: (100 x 100) and (100 x 100) NumPy, np.matrix 1.00 x Cython, plain buffer 0.25 x Cython, readonly buffer 0.25 x Cython, restrict buffer 0.24 x Cython, restrict and readonly buffer 0.25 x Relative speed measurements for matrix multiplication average of 1000 trials matrix ranks: (10 x 10) and (10 x 10) NumPy, np.matrix 1.00 x Cython, plain buffer 2.35 x Cython, readonly buffer 2.65 x Cython, restrict buffer 2.75 x Cython, restrict and readonly buffer 2.70 x I also find that gcc autovectorizer does not like the way we work with Py_buffers: D:\benchmark\matmul>gcc -c -std=gnu99 -O3 -fpeel-loops -funroll-loops -ftree-loo p-linear -ffast-math -ftree-vectorizer-verbose=5 -march=core2 -Ic:/Python 26/include -Ic:/Python26/Lib/site-packages/numpy/core/include matmul_test.c [...] matmul_test.c:1171: note: not vectorized: data ref analysis failed D.9077_530 = *D.9076_529; matmul_test.c:854: note: vectorized 0 loops in function. I think it is the way we access arrays that confuses GCC's autovectorizer. After some searching, I found out that it only works with power-of-two strides, and "data ref analysis failed" is the error we would get when it is confued. Sturla Molden From dagss at student.matnat.uio.no Tue Oct 20 17:18:00 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: 20 Oct 2009 17:18:00 +0200 Subject: [Cython] restrict and readonly Message-ID: <3338903910.245321@smtp.netcom.no> When I tried this, I wasn't even able to vectorize a sum-reduce-style loop written in pure C. It seemed to me then that the auto-vectorizer only tackles parallel arithmetic and not reductions... (Not with cython-generated code though). BTW I tried with Intel C and it seems Cython code isn't vectorizeable then either. While I'm happy for any patches towards ato-vectorization, I don't think it is that important as a concept -- SIMD instructions in Cython would allow going directly, rather than "serialize vector op to loop, then parse loop s vector op". (the strides/power of 2 shouldn't matter if it is declared "c" ?) Dag Sverre Seljebotn -----Original Message----- From: Sturla Molden Date: Tuesday, Oct 20, 2009 4:49 pm Subject: [Cython] restrict and readonly To: cython-dev at codespeak.netReply-To: cython-dev at codespeak.net >I did some testing of read-only and restrict Py_buffer access with >simple matrix multiplication. I consistantly find that it does not help >on large arrays, but does help for small. > >However, multiplying small matrices is so fast that speed does not >matter anyway. > > >Relative speed measurements for matrix multiplication >average of 100 trials >matrix ranks: (100 x 100) and (100 x 100) > >NumPy, np.matrix 1.00 x >Cython, plain buffer 0.25 x >Cython, readonly buffer 0.25 x >Cython, restrict buffer 0.24 x >Cython, restrict and readonly buffer 0.25 x > > > >Relative speed measurements for matrix multiplication >average of 1000 trials >matrix ranks: (10 x 10) and (10 x 10) > >NumPy, np.matrix 1.00 x >Cython, plain buffer 2.35 x >Cython, readonly buffer 2.65 x >Cython, restrict buffer 2.75 x >Cython, restrict and readonly buffer 2.70 x > > > >I also find that gcc autovectorizer does not like the way we work with >Py_buffers: > >D:\benchmark\matmul>gcc -c -std=gnu99 -O3 -fpeel-loops -funroll-loops >-ftree-loo >p-linear -ffast-math -ftree-vectorizer-verbose=5 -march=core2 -Ic:/Python >26/include -Ic:/Python26/Lib/site-packages/numpy/core/include matmul_test.c > >[...] > >matmul_test.c:1171: note: not vectorized: data ref analysis failed >D.9077_530 = >*D.9076_529; > >matmul_test.c:854: note: vectorized 0 loops in function. > > >I think it is the way we access arrays that confuses GCC's >autovectorizer. After some searching, I found out that it only works >with power-of-two strides, and "data ref analysis failed" is the error >we would get when it is confued. > > >Sturla Molden >_______________________________________________ >Cython-dev mailing list >Cython-dev at codespeak.net >http://codespeak.net/mailman/listinfo/cython-dev > From sturla at molden.no Tue Oct 20 20:54:30 2009 From: sturla at molden.no (Sturla Molden) Date: Tue, 20 Oct 2009 20:54:30 +0200 Subject: [Cython] restrict and readonly In-Reply-To: <3338903910.245321@smtp.netcom.no> References: <3338903910.245321@smtp.netcom.no> Message-ID: <4ADE0766.8090607@molden.no> Dag Sverre Seljebotn skrev: >It seemed to me then that the auto-vectorizer only tackles parallel arithmetic >and not reductions... >(the strides/power of 2 shouldn't matter if it is declared "c" ?) I know... with mode "c" or "fortran", the last or first stride is known at compile time. Still the message from the vectorizer seem to indicate that this is the problem. I tried this with hand-written C as well. The inner loop is not vectorized, so you are probably right about reductions I did not get "data ref analysis failed" message from the auto-vectorizer. I only get this message with Cython-generated C. Sturla From dagss at student.matnat.uio.no Wed Oct 21 10:56:06 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 21 Oct 2009 10:56:06 +0200 Subject: [Cython] Preliminary SCons support Message-ID: <4ADECCA6.4000104@student.matnat.uio.no> OK, as requested I've uploaded the scons scripts I use. They're mostly taken from David Cournapeau's numscons, but works with normal scons. I'll start with a small user guide and then go to the TODO-list: 1) Copy Tools/site_scons to your project dir (sits in cython-devel hg trunk) 2) Make SConstruct (not the nicest example, but...): env = Environment(PYEXT_USE_DISTUTILS=True) # The above flag makes Python extensions look up compiler flags and include paths etc. from distutils) env.Tool("pyext") env.Tool("cython") env.Append(PYEXTINCPATH=[numpy.get_include()]) # Override location of Cython and set some flags env.Replace(CYTHON="python /uio/arkimedes/s07/dagss/cython/devel/cython.py", CYTHONFLAGS=['-a', '-I/uio/arkimedes/s07/dagss/cmb/cmblib']) # Specify an extension to be compiled env.PythonExtension('mapdatautils', ['mapdatautils.pyx']) # A more complicated example linking in Fortran code and libraries using ifort. # ifort must then be used to finally link the extension... env2 = env.Environment(F90="ifort") # Also omit -O2 and add Cython refnanny. This is hacky, see TODO. env2.Replace(PYEXTCFLAGS=['-fno-strict-aliasing', '-DNDEBUG', '-Wall', '-fwrapv', '-g', '-Wstrict-prototypes', '-DCYTHON_REFNANNY'], objs += env2.SharedObject(['comp_normalised_Plm.f90']) objs += env2.PythonObject(['healpix.pyx']) # note the use of PythonObject env2.PythonExtension('healpix', objs, LIBS=['healpix', 'cfitsio'], PYEXTLINKFLAGS=['-shared', '-openmp'], PYEXTLINK='$F90') OK, on to the TODO-list: - Currently the choice for extension module compilation is between PYEXT_USE_DISTUTILS and a set of sensible defaults. Instead I think one should be given the choice of a PYTHON to use, and then launch that PYTHON executable to fetch distutils information. - It should be possible to avoid the replacement of PYEXTCFLAGS above, perhaps by seperating between optional (-O2) and non-optional (-fno-strict-aliasing) flags and put them in seperate vars? - The support for C++-generated Cython code is too weak (one has to specify it in two seperate vars...not shown above) - Dependency tracking (none at all for pyx files currently) - I'm uncertain about having to specify PYEXT_USE_DISTUTILS (or, in time, PYTHON) prior to loading the pyext tool...is this normal? Or should the distutils settings be looked up at compilation time rather than configuration time? (But then one wouldn't be able to dynamically modify e.g. PYEXTCFLAGS, only "leave it unset to be filled in"...). Help and input appreciated, I know way too little scons to pull this off the right way! But it does what I needed to for, and is already a lot better than jumping between my shell scripts, makefiles and setup.py's... Dag Sverre From ndbecker2 at gmail.com Wed Oct 21 14:13:17 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 21 Oct 2009 08:13:17 -0400 Subject: [Cython] Preliminary SCons support References: <4ADECCA6.4000104@student.matnat.uio.no> Message-ID: Dag Sverre Seljebotn wrote: > OK, as requested I've uploaded the scons scripts I use. Where? From dagss at student.matnat.uio.no Wed Oct 21 14:43:31 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 21 Oct 2009 14:43:31 +0200 Subject: [Cython] Preliminary SCons support In-Reply-To: References: <4ADECCA6.4000104@student.matnat.uio.no> Message-ID: <4ADF01F3.8060002@student.matnat.uio.no> Neal Becker wrote: > Dag Sverre Seljebotn wrote: > > >> OK, as requested I've uploaded the scons scripts I use. >> > Where? > Sorry..: http://hg.cython.org/cython-devel/file/a63bc0404ffd/Tools/site_scons/site_tools Dag Sverre From ozanhaci at gmail.com Wed Oct 21 15:37:30 2009 From: ozanhaci at gmail.com (=?UTF-8?B?b3phbiBoYWPEsWJla2lyb8SfbHU=?=) Date: Wed, 21 Oct 2009 16:37:30 +0300 Subject: [Cython] vcvarsall.bat In-Reply-To: References: Message-ID: <8963e8e30910210637x5cce560foc3937bd8e6ea81a9@mail.gmail.com> I am new to python (almost 4 months) and Cython (1 week). I use Vista and previous week I tried to use Cython and I had the same problem about "vcvarsall.bat". By trial and error Now I can compile scripts with Cython. What I did is, I first installed Microsoft Virtual C++ 2008 Express Edition (VC++) There is a "vcvarsall.bat" file under the installation directory of VC++ I copied the "vcvarsall.bat" file under "C:\Python26\Scripts" (not required, you can include it with, sys.path.append("path-to-the-file")) Then everything worked great :) Then, since I am a curious guy, I tried the use ".h" files of VC++ under include folder (C:\Program Files\Microsoft Visual Studio 9.0\VC\include) I followed the instructions on the wiki page of Cython and Now I can use those very easily. (with, cdef extern from "math.h", etc) It is a really good practice to use Cython and see everything works perfectly for me, who is just a beginner. Ozan http://pypsoft.sourceforge.net On Tue, Sep 15, 2009 at 5:14 PM, Sam Parry wrote: > Hi guys, > > Not sure if I'm emailing to the correct place so apologies if I am spamming > you... > > I am having problems with Cython compiling. I am following the tutorial on > the main website (from the Users Guide) and when I type "python setup.py > build_ext --inplace" I get an error saying "unable to find vcvarsall.bat". I > am using MinGW as my compiler and running on windows XP. I have managed to > find a way around this: typing "python setup.py build_ext --compiler=mingw32 > --inplace" works for the first 'hello world' tutorial part. However, I get > the vcvarsall error when trying the pyximport method. Adding the > "--compiler=mingw32" does not work for any of the examples using any form of > numpy import. > > I would be grateful for any insights provided that could help me run > cython! I am new to using the command line, c and cython (and not all that > experienced with python either!) so forgive me if I need more detail than > the average user! > > Thanks, > > Sam > ------------------------------ > Use Hotmail to send and receive mail from your different email accounts. Find > out how. > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > > -- Ozan HACIBEK?RO?LU -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20091021/41dee6ae/attachment.htm From dalcinl at gmail.com Wed Oct 21 18:56:23 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 21 Oct 2009 14:56:23 -0200 Subject: [Cython] bitten again by typetesting and None In-Reply-To: <4ADD79D4.8030604@behnel.de> References: <4AD8197B.3060307@behnel.de> <4AD88C0B.80006@behnel.de> <6DA6CB19-5F9E-452F-B607-190A221283FC@math.washington.edu> <5C965459-BE9C-45AE-B124-992C8896BAC6@math.washington.edu> <4ADD79D4.8030604@behnel.de> Message-ID: On Tue, Oct 20, 2009 at 6:50 AM, Stefan Behnel wrote: > > Robert Bradshaw wrote: >> On Oct 19, 2009, at 5:09 PM, Neal Becker wrote: >> >>> Lisandro Dalcin wrote: >>> >>> ... >>>> A possible backward way could be to ?introduce (slightly) new syntax, >>>> something like , i.e using two '?' to indicate a >>>> "stronger" type check disallowing None... >>> That would be spelled >>> :) >> >> Well, or one could use the nonecheck directive. I'd like to avoid >> adding more syntax for a problem that'll go away with a smarter >> compiler. > > +1 > > I also think that the chance of breaking code with this change is rather > small. I can't imagine that many use cases where I would cast a value to a > specific extension type other than accessing its C attributes or methods, > which would clearly lead to a crash for None values. So however people used > this feature before, I expect a None check to be very close in the code. > OK, patch uploaded: http://trac.cython.org/cython_trac/attachment/ticket/417/typetest.diff Please review, and let me know if it is good enough for pushing... BTW, there is one usage of PyTypeTestNode at Cython/Compiler/Optimize.py ... Should we pass notnone=True there? -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sturla at molden.no Wed Oct 21 19:32:45 2009 From: sturla at molden.no (Sturla Molden) Date: Wed, 21 Oct 2009 19:32:45 +0200 Subject: [Cython] bug in const trick? Message-ID: <4ADF45BD.8040709@molden.no> Why is the type declaration there? Even "typedef int const int" would be bogus. That I am using volatile should not matter. Never typedef native C types to something else. Sturla Molden ctypedef int vint "volatile int" cdef class giltest: cdef vint tag, stop, start, missed, switched cdef int num_threads, trials Is compiled to: /* Type declarations */ typedef int volatile int; /* "D:\giltest.pyx":8 * * * cdef class giltest: # <<<<<<<<<<<<<< * * cdef vint tag, stop, start, missed, switched */ struct __pyx_obj_7giltest_giltest { PyObject_HEAD volatile int tag; volatile int stop; volatile int start; volatile int missed; volatile int switched; int num_threads; int trials; }; From dagss at student.matnat.uio.no Wed Oct 21 20:09:55 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 21 Oct 2009 20:09:55 +0200 Subject: [Cython] bug in const trick? In-Reply-To: <4ADF45BD.8040709@molden.no> References: <4ADF45BD.8040709@molden.no> Message-ID: <4ADF4E73.60403@student.matnat.uio.no> Sturla Molden wrote: > Why is the type declaration there? Even "typedef int const int" would > be bogus. That I am using volatile should not matter. Never typedef > native C types to something else. I think you want to do cdef extern from *: ctypedef int vint "volatile int" What you said is: typedef "int" as "vint" Cython-side and "volatile int" C-side. What you want to say is: Use an already defined typedef which is named "volatile int" C-side. Dag Sverre > > Sturla Molden > > > > ctypedef int vint "volatile int" > > cdef class giltest: > > cdef vint tag, stop, start, missed, switched > cdef int num_threads, trials > > > Is compiled to: > > > /* Type declarations */ > > typedef int volatile int; > > /* "D:\giltest.pyx":8 > * > * > * cdef class giltest: # <<<<<<<<<<<<<< > * > * cdef vint tag, stop, start, missed, switched > */ > > struct __pyx_obj_7giltest_giltest { > PyObject_HEAD > volatile int tag; > volatile int stop; > volatile int start; > volatile int missed; > volatile int switched; > int num_threads; > int trials; > }; > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev -- Dag Sverre From sturla at molden.no Wed Oct 21 21:00:11 2009 From: sturla at molden.no (Sturla Molden) Date: Wed, 21 Oct 2009 21:00:11 +0200 Subject: [Cython] bug in const trick? In-Reply-To: <4ADF4E73.60403@student.matnat.uio.no> References: <4ADF45BD.8040709@molden.no> <4ADF4E73.60403@student.matnat.uio.no> Message-ID: <4ADF5A3B.1020103@molden.no> Dag Sverre Seljebotn skrev: > cdef extern from *: > ctypedef int vint "volatile int" > > What you said is: typedef "int" as "vint" Cython-side and "volatile int" > C-side. > > Right... I see that it works :-) Hm... that remids me: should we add a "volatile" keyword to the buffer constructor as well? It would work like "readonly", except that the content of the buffer is declared volatile. Volatile is useful if the buffer is filled with data from some hardware interrupt. Volatile is also be useful when multiple threads are reading and writing to the same buffer. I have use for this when reading 16 bit data from an array of 32 ADCs, sampling at 48 kHz: cdef np.ndarray[np.int16_t, ndim=2, mode="c", volatile=True] adc_buffer adc_buffer = np.zeros((48000,32), dtype=np.int16) # filled from hardware interrupt # once every second Sturla Molden From dagss at student.matnat.uio.no Wed Oct 21 21:05:53 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 21 Oct 2009 21:05:53 +0200 Subject: [Cython] bug in const trick? In-Reply-To: <4ADF5A3B.1020103@molden.no> References: <4ADF45BD.8040709@molden.no> <4ADF4E73.60403@student.matnat.uio.no> <4ADF5A3B.1020103@molden.no> Message-ID: <4ADF5B91.7020403@student.matnat.uio.no> Sturla Molden wrote: > Dag Sverre Seljebotn skrev: >> cdef extern from *: >> ctypedef int vint "volatile int" >> >> What you said is: typedef "int" as "vint" Cython-side and "volatile int" >> C-side. >> >> > > Right... I see that it works :-) > > Hm... that remids me: should we add a "volatile" keyword to the buffer > constructor as well? It would work like "readonly", except that the > content of the buffer is declared volatile. > > Volatile is useful if the buffer is filled with data from some hardware > interrupt. Volatile is also be useful when multiple threads are reading > and writing to the same buffer. > > I have use for this when reading 16 bit data from an array of 32 ADCs, > sampling at 48 kHz: > > cdef np.ndarray[np.int16_t, ndim=2, mode="c", volatile=True] adc_buffer > > adc_buffer = np.zeros((48000,32), dtype=np.int16) # filled from > hardware interrupt > # once every second If you a real usecase for it (as it seems that you do), I'll accept a patch. -- Dag Sverre From vic.kelson at gmail.com Wed Oct 21 21:50:01 2009 From: vic.kelson at gmail.com (Vic Kelson) Date: Wed, 21 Oct 2009 15:50:01 -0400 Subject: [Cython] Please help with complex numbers Message-ID: <78C51995-FF68-40F2-9D0C-48AE326DE253@gmail.com> Hello all, A few months ago, I got some code working (with the help of a poster here -- thanks!) that used the gcc double complex type. Recently, I recall a discussion on here that suggested that a simpler built-in syntax is now in place for using 'cdef' complex types in C functions and methods. Is that true? I can't find details in the docs. At any rate, my old code doesn't work with python2.5 and cython 0.11.3. sigh. Thanks for the help! --v From dagss at student.matnat.uio.no Wed Oct 21 22:13:29 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 21 Oct 2009 22:13:29 +0200 Subject: [Cython] Please help with complex numbers In-Reply-To: <78C51995-FF68-40F2-9D0C-48AE326DE253@gmail.com> References: <78C51995-FF68-40F2-9D0C-48AE326DE253@gmail.com> Message-ID: <4ADF6B69.5060505@student.matnat.uio.no> Vic Kelson wrote: > Hello all, > > A few months ago, I got some code working (with the help of a poster > here -- thanks!) that used the gcc double complex type. Recently, I > recall a discussion on here that suggested that a simpler built-in > syntax is now in place for using 'cdef' complex types in C functions > and methods. Is that true? Yep. cdef double complex z = 3 + 1.3j print z.imag # -1.3 If you include any C header files which uses the gcc (that is, C99) complex type, then this will automatically use C99 complex. Dag Sverre From matthew.brett at gmail.com Thu Oct 22 03:15:33 2009 From: matthew.brett at gmail.com (Matthew Brett) Date: Wed, 21 Oct 2009 20:15:33 -0500 Subject: [Cython] Returning nested python objects Message-ID: <1e2af89e0910211815y4aa9a66ci83492d3b92442a92@mail.gmail.com> Hello, Please forgive my ignorance, but I am running into a problem that reveals my ignorance of reference counting and Cython in general. I am running code that creates a dictionary, fills it with lists of tuples created from C integers, and returns the dictionary, like this: def afunc(): cdef int i=1 cdef int j=2 cdef int k=3 cdef int m=4 cdef int n=5 d = {} val1 = (i, j) val2 = (k, m) d[m] = [val1, val2] return d The code above does indeed return the dictionary I was expecting: {5: [(1, 2), (3, 4)]} however, in a more complex routine, I am doing a similar thing, but returning many thousands of lists of tuples, and the routine grinds to a halt. If I only return lists of integers, as in: d[m] = [i, j] The code runs at good speed and returns the expected result. Looking at the generated C code, I wonder if I am running into a reference counting problem, because the tuple I'm creating seems to be decref'ed. I've tried adding Py_INCREFs to the list, tuple, and python copies of the integers, but this made no difference to the larger routine. I realize I'm not understanding on-the-fly python object creation / destruction in Cython, and was wondering where I should go to look to understand it better. Is there anything obvious I have missed that would explain my problem? Thanks a lot, Matthew From robertwb at math.washington.edu Thu Oct 22 06:14:25 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 21 Oct 2009 21:14:25 -0700 Subject: [Cython] Returning nested python objects In-Reply-To: <1e2af89e0910211815y4aa9a66ci83492d3b92442a92@mail.gmail.com> References: <1e2af89e0910211815y4aa9a66ci83492d3b92442a92@mail.gmail.com> Message-ID: On Oct 21, 2009, at 6:15 PM, Matthew Brett wrote: > Hello, > > Please forgive my ignorance, but I am running into a problem that > reveals my ignorance of reference counting and Cython in general. > > I am running code that creates a dictionary, fills it with lists of > tuples created from C integers, and returns the dictionary, like this: > > def afunc(): > cdef int i=1 > cdef int j=2 > cdef int k=3 > cdef int m=4 > cdef int n=5 > > d = {} > val1 = (i, j) > val2 = (k, m) > d[m] = [val1, val2] > return d > > > The code above does indeed return the dictionary I was expecting: > > {5: [(1, 2), (3, 4)]} > > however, in a more complex routine, I am doing a similar thing, but > returning many thousands of lists of tuples, and the routine grinds to > a halt. Meaning it doesn't terminate, runs out of memory, or segfaults? > If I only return lists of integers, as in: > > d[m] = [i, j] > > The code runs at good speed and returns the expected result. > > Looking at the generated C code, I wonder if I am running into a > reference counting problem, because the tuple I'm creating seems to be > decref'ed. > > I've tried adding Py_INCREFs to the list, tuple, and python copies of > the integers, but this made no difference to the larger routine. > > I realize I'm not understanding on-the-fly python object creation / > destruction in Cython, and was wondering where I should go to look to > understand it better. Is there anything obvious I have missed that > would explain my problem? Well, it's hard to say without seeing the code. I would try running it with the reference nanny turned on and see if that turns up anything suspicious. Also, try to whittle down your issue as small as possible of an example that still fails and post it. - Robert From robertwb at math.washington.edu Thu Oct 22 06:15:58 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 21 Oct 2009 21:15:58 -0700 Subject: [Cython] Please help with complex numbers In-Reply-To: <78C51995-FF68-40F2-9D0C-48AE326DE253@gmail.com> References: <78C51995-FF68-40F2-9D0C-48AE326DE253@gmail.com> Message-ID: <481FCD0A-C569-4C7B-84B8-91C5E4ADEB82@math.washington.edu> On Oct 21, 2009, at 12:50 PM, Vic Kelson wrote: > Hello all, > > A few months ago, I got some code working (with the help of a poster > here -- thanks!) that used the gcc double complex type. Recently, I > recall a discussion on here that suggested that a simpler built-in > syntax is now in place for using 'cdef' complex types in C functions > and methods. Is that true? As mentioned, yep. > I can't find details in the docs. At any rate, my old code doesn't > work with python2.5 and cython 0.11.3. sigh. > > Thanks for the help! Hopefully you'll be able to just change your typedefs and it should work. If not, could you please post a minimal example that's broken? (We try hard not to introduce any regressions...) - Robert From robertwb at math.washington.edu Thu Oct 22 06:27:33 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 21 Oct 2009 21:27:33 -0700 Subject: [Cython] [Pyrex] intern(str) fails if string is not a C string In-Reply-To: <4ADF6ACD.7000500@arbash-meinel.com> References: <4ADF6ACD.7000500@arbash-meinel.com> Message-ID: On Oct 21, 2009, at 1:10 PM, John Arbash Meinel wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > This bug seems to affect both cython and pyrex. > > Namely, I'm parsing a string that has NULL characters in it (known > width), which is also likely to be redundant within the data stream. > > I'm doing something like: > > mystr = PyString_FromStringAndSize(NULL, count+other_count) > memcpy(mystr, some_bytes, count) > memcpy(mystr+count, more_bytes, other_count) > > mystr = intern(mystr) > > This fails because pyrex and cython both effectively translate this > code > into: > > char *temp; > temp = PyString_AsString(mystr); > mystr = PyString_InternFromString(temp); > > With, of course, appropriate error checking and incref/decref > handling. > > I would, of course, like to use PyString_InternInPlace(PyObject **), > however that fails for other reasons. "taking address of a non l- > value" > if you try to do: > > cdef extern from "Python.h": > ctypedef struct PyObject: > pass > void PyString_InternInPlace(PyObject **) > > > st = 'my string' > PyString_InternInPlace(&st) > > > Now I can probably do some trickery with > > cdef PyObject *as_ptr > > as_ptr = st > PyString_InternInPlace(&as_ptr) > st = as_ptr > > However, because InternInPlace may destroy 'st', and that final > assignment will be doing a DECREF on the 'st' object, I'm pretty > sure it > will blow up. > > It feels like the only thing left to do is define a macro in a header > with something like: > > #define INTERN_STRING(obj) (PyString_InternInPlace(&(obj)))) > > and then > > cdef extern from "myheader.h": > INTERN_STRING(object) > > Is this true? > > John Good catch. I've disabled optimizing the intern builtin in Cython for now. We could re-enable it for char* only if someone finds interning strings to be a bottleneck. - Robert From robertwb at math.washington.edu Thu Oct 22 06:32:12 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 21 Oct 2009 21:32:12 -0700 Subject: [Cython] bitten again by typetesting and None In-Reply-To: References: <4AD8197B.3060307@behnel.de> <4AD88C0B.80006@behnel.de> <6DA6CB19-5F9E-452F-B607-190A221283FC@math.washington.edu> <5C965459-BE9C-45AE-B124-992C8896BAC6@math.washington.edu> <4ADD79D4.8030604@behnel.de> Message-ID: On Oct 21, 2009, at 9:56 AM, Lisandro Dalcin wrote: > On Tue, Oct 20, 2009 at 6:50 AM, Stefan Behnel > wrote: >> >> Robert Bradshaw wrote: >>> On Oct 19, 2009, at 5:09 PM, Neal Becker wrote: >>> >>>> Lisandro Dalcin wrote: >>>> >>>> ... >>>>> A possible backward way could be to introduce (slightly) new >>>>> syntax, >>>>> something like , i.e using two '?' to indicate a >>>>> "stronger" type check disallowing None... >>>> That would be spelled >>>> :) >>> >>> Well, or one could use the nonecheck directive. I'd like to avoid >>> adding more syntax for a problem that'll go away with a smarter >>> compiler. >> >> +1 >> >> I also think that the chance of breaking code with this change is >> rather >> small. I can't imagine that many use cases where I would cast a >> value to a >> specific extension type other than accessing its C attributes or >> methods, >> which would clearly lead to a crash for None values. So however >> people used >> this feature before, I expect a None check to be very close in the >> code. >> > > OK, patch uploaded: > http://trac.cython.org/cython_trac/attachment/ticket/417/typetest.diff > > Please review, and let me know if it is good enough for pushing... I'd either make the function inline or split it up into two functions so that the none_allowed argument (and possibly check for none) can be eliminated at compile time. > BTW, there is one usage of PyTypeTestNode at > Cython/Compiler/Optimize.py ... Should we pass notnone=True there? Probably not to be safe, but Stefan wrote this code, so he'd know better than I. - Robert From robertwb at math.washington.edu Thu Oct 22 06:36:57 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 21 Oct 2009 21:36:57 -0700 Subject: [Cython] vcvarsall.bat In-Reply-To: <8963e8e30910210637x5cce560foc3937bd8e6ea81a9@mail.gmail.com> References: <8963e8e30910210637x5cce560foc3937bd8e6ea81a9@mail.gmail.com> Message-ID: <6C80DC5F-11D3-4345-BB55-7A7450338C2D@math.washington.edu> On Oct 21, 2009, at 6:37 AM, ozan hac?bekiro?lu wrote: > I am new to python (almost 4 months) and Cython (1 week). I use > Vista and previous week I tried to use Cython and I had the same > problem about "vcvarsall.bat". By trial and error Now I can compile > scripts with Cython. Great. I'm not seeing anything about vcvarsall.bat on the Cython wiki, what exactly is the issue with it? > What I did is, > > I first installed Microsoft Virtual C++ 2008 Express Edition (VC++) > > There is a "vcvarsall.bat" file under the installation directory of > VC++ > > I copied the "vcvarsall.bat" file under "C:\Python26\Scripts" (not > required, you can include it with, sys.path.append("path-to-the- > file")) > > Then everything worked great :) > > Then, since I am a curious guy, I tried the use ".h" files of VC++ > under include folder (C:\Program Files\Microsoft Visual Studio 9.0\VC > \include) > > I followed the instructions on the wiki page of Cython and Now I can > use those very easily. (with, cdef extern from "math.h", etc) > > It is a really good practice to use Cython and see everything works > perfectly for me, who is just a beginner. > > > Ozan > http://pypsoft.sourceforge.net > > > > On Tue, Sep 15, 2009 at 5:14 PM, Sam Parry > wrote: > Hi guys, > > Not sure if I'm emailing to the correct place so apologies if I am > spamming you... > > I am having problems with Cython compiling. I am following the > tutorial on the main website (from the Users Guide) and when I type > "python setup.py build_ext --inplace" I get an error saying "unable > to find vcvarsall.bat". I am using MinGW as my compiler and running > on windows XP. I have managed to find a way around this: typing > "python setup.py build_ext --compiler=mingw32 --inplace" works for > the first 'hello world' tutorial part. However, I get the vcvarsall > error when trying the pyximport method. Adding the "-- > compiler=mingw32" does not work for any of the examples using any > form of numpy import. > > I would be grateful for any insights provided that could help me run > cython! I am new to using the command line, c and cython (and not > all that experienced with python either!) so forgive me if I need > more detail than the average user! > > Thanks, > > Sam > Use Hotmail to send and receive mail from your different email > accounts. Find out how. > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > > > > > -- > Ozan HACIBEK?RO?LU > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev From stefan_ml at behnel.de Thu Oct 22 08:29:33 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 22 Oct 2009 08:29:33 +0200 Subject: [Cython] Returning nested python objects In-Reply-To: <1e2af89e0910211815y4aa9a66ci83492d3b92442a92@mail.gmail.com> References: <1e2af89e0910211815y4aa9a66ci83492d3b92442a92@mail.gmail.com> Message-ID: <4ADFFBCD.90604@behnel.de> Matthew Brett wrote: > I am running code that creates a dictionary, fills it with lists of > tuples created from C integers, and returns the dictionary, like this: > > def afunc(): > cdef int i=1 > cdef int j=2 > cdef int k=3 > cdef int m=4 > cdef int n=5 > > d = {} > val1 = (i, j) > val2 = (k, m) > d[m] = [val1, val2] > return d > > > The code above does indeed return the dictionary I was expecting: > > {5: [(1, 2), (3, 4)]} > > however, in a more complex routine, I am doing a similar thing, but > returning many thousands of lists of tuples, and the routine grinds to > a halt. Did you check that your machine has enough memory? Depending on how "many thousands" we are talking about, it may start swapping when its memory fills up. Also, make sure you are not creating reference cycles somewhere in your structure that may require cyclic garbage collection. > Looking at the generated C code, I wonder if I am running into a > reference counting problem That's rather unlikely (although you didn't state which version of Cython you are using). > because the tuple I'm creating seems to be decref'ed. Don't worry, that's normal. When Cython creates them, they get stored in temporary variables that hold the reference. Adding them to the dict will let the dict add another reference, and when the temporary reference is taken out of scope, Cython must DECREF it. > I've tried adding Py_INCREFs to the list, tuple, and python copies of > the integers, but this made no difference to the larger routine. Please don't do that. That will cause your code to leak memory (which in turn will lead to higher memory consumption and more likely swapping). > I realize I'm not understanding on-the-fly python object creation / > destruction in Cython, and was wondering where I should go to look to > understand it better. It works more or less as in CPython, just with a sequence of C calls instead of a lengthy interpreter eval loop. Stefan From stefan_ml at behnel.de Thu Oct 22 10:08:06 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 22 Oct 2009 10:08:06 +0200 Subject: [Cython] bitten again by typetesting and None In-Reply-To: References: <4AD8197B.3060307@behnel.de> <4AD88C0B.80006@behnel.de> <6DA6CB19-5F9E-452F-B607-190A221283FC@math.washington.edu> <5C965459-BE9C-45AE-B124-992C8896BAC6@math.washington.edu> <4ADD79D4.8030604@behnel.de> Message-ID: <4AE012E6.8080609@behnel.de> Lisandro Dalcin wrote: > On Tue, Oct 20, 2009 at 6:50 AM, Stefan Behnel wrote: >> Robert Bradshaw wrote: >>> On Oct 19, 2009, at 5:09 PM, Neal Becker wrote: >>> >>>> Lisandro Dalcin wrote: >>>> >>>> ... >>>>> A possible backward way could be to introduce (slightly) new syntax, >>>>> something like , i.e using two '?' to indicate a >>>>> "stronger" type check disallowing None... >>>> That would be spelled >>>> :) >>> Well, or one could use the nonecheck directive. I'd like to avoid >>> adding more syntax for a problem that'll go away with a smarter >>> compiler. >> +1 >> >> I also think that the chance of breaking code with this change is rather >> small. I can't imagine that many use cases where I would cast a value to a >> specific extension type other than accessing its C attributes or methods, >> which would clearly lead to a crash for None values. So however people used >> this feature before, I expect a None check to be very close in the code. > > OK, patch uploaded: > http://trac.cython.org/cython_trac/attachment/ticket/417/typetest.diff According to the test case, this passes, also at runtime: cdef Foo x = None but this fails at runtime: cdef Foo x = None Looks a bit funny at first sight, but becomes a feature when you think about it. > Please review, and let me know if it is good enough for pushing... Regarding the naming, you called the flag "notnone", but used it as "not notnone" or "none_allowed" in most places. Why not call it "none_allowed" everywhere instead? Regarding likely() and '||' tests, I usually prefer duplicating the likely() around each subexpression. I'm not sure what the C compiler will make from the or-ed expression if you use only one likely(), but each subexpression is always evaluated by itself, and in almost all cases, it is also likely true by itself. I noticed that you added %.200s for type name formatting. Good catch. If you could fix the two remarks above, I'm fine with pushing it. > BTW, there is one usage of PyTypeTestNode at > Cython/Compiler/Optimize.py ... Should we pass notnone=True there? Yes. The optimisations there require exact type tests. Stefan From stefan_ml at behnel.de Thu Oct 22 10:22:55 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 22 Oct 2009 10:22:55 +0200 Subject: [Cython] bitten again by typetesting and None In-Reply-To: References: <4AD8197B.3060307@behnel.de> <4AD88C0B.80006@behnel.de> <6DA6CB19-5F9E-452F-B607-190A221283FC@math.washington.edu> <5C965459-BE9C-45AE-B124-992C8896BAC6@math.washington.edu> <4ADD79D4.8030604@behnel.de> Message-ID: <4AE0165F.90405@behnel.de> Robert Bradshaw wrote: > On Oct 21, 2009, at 9:56 AM, Lisandro Dalcin wrote: >> OK, patch uploaded: >> http://trac.cython.org/cython_trac/attachment/ticket/417/typetest.diff >> >> Please review, and let me know if it is good enough for pushing... > > I'd either make the function inline or split it up into two functions > so that the none_allowed argument (and possibly check for none) can be > eliminated at compile time. +1 for an inline utility function, although splitting it might still be a good idea. I'd also keep the "== Py_None" test first then, as this is something the C compiler can either know or that the CPU can quickly execute, faster than the following type check which requires at least an indirection, or even a function call (so the C compiler can't reverse the two tests due to potential side effects). Stefan From dalcinl at gmail.com Thu Oct 22 13:20:12 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Thu, 22 Oct 2009 08:20:12 -0300 Subject: [Cython] bitten again by typetesting and None In-Reply-To: <4AE0165F.90405@behnel.de> References: <6DA6CB19-5F9E-452F-B607-190A221283FC@math.washington.edu> <5C965459-BE9C-45AE-B124-992C8896BAC6@math.washington.edu> <4ADD79D4.8030604@behnel.de> <4AE0165F.90405@behnel.de> Message-ID: On Thu, Oct 22, 2009 at 5:22 AM, Stefan Behnel wrote: > > Robert Bradshaw wrote: >> On Oct 21, 2009, at 9:56 AM, Lisandro Dalcin wrote: >>> OK, patch uploaded: >>> http://trac.cython.org/cython_trac/attachment/ticket/417/typetest.diff >>> >>> Please review, and let me know if it is good enough for pushing... >> >> I'd either make the function inline or split it up into two functions >> so that the none_allowed argument (and possibly check for none) can be >> eliminated at compile time. > > +1 for an inline utility function, although splitting it might still be a > good idea. > > I'd also keep the "== Py_None" test first then, as this is something the C > compiler can either know or that the CPU can quickly execute, faster than > the following type check which requires at least an indirection, or even a > function call (so the C compiler can't reverse the two tests due to > potential side effects). > OK, many thanks for your input... I acknowledge the code in my patch is a crap, but I've just followed naming and implementation conventions for the argument type test code (just to not break the rules). BTW, I think the arg type test should also be improved, or perhaps even merged with this one we are talking about. I'll rework the patch. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From robertwb at math.washington.edu Fri Oct 23 06:57:49 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 22 Oct 2009 21:57:49 -0700 Subject: [Cython] Cython 0.12 Message-ID: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> As mentioned earlier, it's about time to release Cython 0.12. What I see that needs to happen is 1) Get Sage working with the new Cython. I've gotten Sage to compile and nearly all doctests passing (I think I'm down to one bug, somewhere in exception handling, but I haven't been able to look at it much yet). I'd assume lxml and other developer projects are building with the current head. 2) We should go onto the trac server (link below) and either resolve/ bump any tickets that are not going happen in the next week or two. Also, if there are any other blockers that need to be put in this list, please do so. To all: if there's something you're really like to see get into the next release, please speak up now. (No promises, but at the very least it'll help assign priorities.) 3) Widespread testing. Shortly we should put out an alpha and some release candidates. It would probably be good to have a feature freeze and push bug fixes only (for this branch). There's a lot of new stuff in this release (all of -unstable) so I'd like to pound it hard, including Windows building and projects that don't normally compile with the -devel branch. Lets aim for a serious alpha, or hopefully even a release candidate, by the end of the month. - Robert [1] http://trac.cython.org/cython_trac/query?status=assigned&status=new&status=reopened&milestone=0.12 From stefan_ml at behnel.de Fri Oct 23 10:31:42 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Oct 2009 10:31:42 +0200 Subject: [Cython] [Pyrex] intern(str) fails if string is not a C string In-Reply-To: References: <4ADF6ACD.7000500@arbash-meinel.com> Message-ID: <4AE169EE.6090108@behnel.de> Robert Bradshaw wrote: > On Oct 21, 2009, at 1:10 PM, John Arbash Meinel wrote: >> I'm doing something like: >> >> mystr = PyString_FromStringAndSize(NULL, count+other_count) >> memcpy(mystr, some_bytes, count) >> memcpy(mystr+count, more_bytes, other_count) >> >> mystr = intern(mystr) > > Good catch. I've disabled optimizing the intern builtin in Cython for > now. We could re-enable it for char* only if someone finds interning > strings to be a bottleneck. I've reimplemented it for byte strings now (in Cython), so using a char* will lead to a coercion and work in Py2. However, note that the intern() builtin was removed in Py3, so using it in your code may not be portable. Also, if we choose to implement it somehow,it will necessarily return a unicode string in Py3, which may not be what you want, given the above code fragment. I recommend using a dedicated dict instead, and put your byte strings there. This will not change the performance in any way, given that intern() on a char* has always been creating a Python byte string before interning (and possibly dropping) it. But it will make it clearer in the code what is actually happening. Stefan From stefan_ml at behnel.de Fri Oct 23 11:10:12 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Oct 2009 11:10:12 +0200 Subject: [Cython] Cython 0.12 In-Reply-To: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> Message-ID: <4AE172F4.2090306@behnel.de> Robert Bradshaw wrote: > As mentioned earlier, it's about time to release Cython 0.12. Totally. > What I see that needs to happen is > > 1) Get Sage working with the new Cython. I've gotten Sage to compile > and nearly all doctests passing You can switch the cascaded assignment work-around back to the original code, I fixed #409. > I think I'm down to one bug, > somewhere in exception handling, but I haven't been able to look at it > much yet Any more hints on this? I might be able to help out. > I'd assume lxml and other developer projects are building > with the current head. lxml tests fine, but it's certainly worth removing some C-isms from its code once I start depending Cython 0.12. If all those new optimisations had been in Cython two years ago, the code would look a lot cleaner today. > 2) We should go onto the trac server (link below) and either resolve/ > bump any tickets that are not going happen in the next week or two. I'll see that I get the tickets closed that I'm still working on. Most of the currently tickets do not look like the need fixing right now, but we should at least get all tests working on the supported platforms. > 3) Widespread testing. Oh, yes, please! :) It seems from the reports we had on the list that many users have already been running cython-devel recently. But it would be good to get some feedback especially from Windows/Mac users, as I expect most developers to be on Linux nowadays. > Shortly we should put out an alpha and some > release candidates. It would probably be good to have a feature freeze > and push bug fixes only (for this branch). +1 > There's a lot of new stuff > in this release (all of -unstable) so I'd like to pound it hard, > including Windows building and projects that don't normally compile > with the -devel branch. Given the amount of changes, I'd also expect at least two release candidates, and I really hope that people will exercise them. It's definitely worth switching from 0.11. Remember: *before* a new major release is the best time to get your bugs fixed, not afterwards. > Lets aim for a serious alpha, or hopefully even a release candidate, > by the end of the month. Sounds like a plan. Stefan From dagss at student.matnat.uio.no Fri Oct 23 11:40:05 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 23 Oct 2009 11:40:05 +0200 Subject: [Cython] Cython 0.12 In-Reply-To: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> Message-ID: <4AE179F5.4060307@student.matnat.uio.no> Robert Bradshaw wrote: > As mentioned earlier, it's about time to release Cython 0.12. What I > see that needs to happen is > > 1) Get Sage working with the new Cython. I've gotten Sage to compile > and nearly all doctests passing (I think I'm down to one bug, > somewhere in exception handling, but I haven't been able to look at it > much yet). I'd assume lxml and other developer projects are building > with the current head. > > 2) We should go onto the trac server (link below) and either resolve/ > bump any tickets that are not going happen in the next week or two. > Also, if there are any other blockers that need to be put in this > list, please do so. To all: if there's something you're really like to > see get into the next release, please speak up now. (No promises, but > at the very least it'll help assign priorities.) > > 3) Widespread testing. Shortly we should put out an alpha and some > release candidates. It would probably be good to have a feature freeze > and push bug fixes only (for this branch). There's a lot of new stuff > in this release (all of -unstable) so I'd like to pound it hard, > including Windows building and projects that don't normally compile > with the -devel branch. > Also, let's get as many as possible to test with the refnanny turned on (and let's make it easy, say, let's include the code to stick in ones setup.py in the RC release notes). Dag Sverre From stefan_ml at behnel.de Fri Oct 23 12:01:12 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Oct 2009 12:01:12 +0200 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE179F5.4060307@student.matnat.uio.no> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE179F5.4060307@student.matnat.uio.no> Message-ID: <4AE17EE8.1070303@behnel.de> Dag Sverre Seljebotn wrote: > let's get as many as possible to test with the refnanny turned on > (and let's make it easy, say, let's include the code to stick in ones > setup.py in the RC release notes). Would there be a way to enable that automatically for an alpha release? I know, this requires the external refnanny module, but wouldn't it be possible to enable it by default, and then add a fallback dead-nanny into the generated code that would just ignore calls and would be used if the refnanny itself isn't found? That would eat some performance but would allow users to enable the refnanny by simply having it lying around in their PYTHONPATH, instead of requiring a separate build option. Although I admit that there should be enough of an incentive to enable a little option in your setup.py. It's never been so easy to make sure that some out-of-your-control generated code is memory leak free... Stefan From dagss at student.matnat.uio.no Fri Oct 23 12:56:53 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 23 Oct 2009 12:56:53 +0200 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE17EE8.1070303@behnel.de> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE179F5.4060307@student.matnat.uio.no> <4AE17EE8.1070303@behnel.de> Message-ID: <4AE18BF5.4010004@student.matnat.uio.no> Stefan Behnel wrote: > Dag Sverre Seljebotn wrote: > >> let's get as many as possible to test with the refnanny turned on >> (and let's make it easy, say, let's include the code to stick in ones >> setup.py in the RC release notes). >> > > Would there be a way to enable that automatically for an alpha release? I > know, this requires the external refnanny module, but wouldn't it be > possible to enable it by default, and then add a fallback dead-nanny into > the generated code that would just ignore calls and would be used if the > refnanny itself isn't found? That would eat some performance but would > allow users to enable the refnanny by simply having it lying around in > their PYTHONPATH, instead of requiring a separate build option. > A basic "setup.py install" also installs the refnanny (in Cython.Runtime.refnanny), so in many circumstances it would be there. It would be possible to generate C sources so that CYTHON_REFNANNY=1 by default as well, and has to be set to =0. I'm -1 on a transparent fallback if the refnanny module is not there though, too much that starts clouding the "exactly what went on" which is so important when getting email reports. Also having actual behaviour differ in RC and final release like this makes me uneasy (what if people reports performance regressions?...i.e. one must be aware of it). All in all, +0 on CYTHON_REFANNAY default to 1 and -1 on fallback module from me. Dag Sverre From dalcinl at gmail.com Fri Oct 23 15:18:28 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 23 Oct 2009 11:18:28 -0200 Subject: [Cython] bitten again by typetesting and None In-Reply-To: References: <6DA6CB19-5F9E-452F-B607-190A221283FC@math.washington.edu> <5C965459-BE9C-45AE-B124-992C8896BAC6@math.washington.edu> <4ADD79D4.8030604@behnel.de> <4AE0165F.90405@behnel.de> Message-ID: On Thu, Oct 22, 2009 at 9:20 AM, Lisandro Dalcin wrote: > On Thu, Oct 22, 2009 at 5:22 AM, Stefan Behnel wrote: >> >> Robert Bradshaw wrote: >>> On Oct 21, 2009, at 9:56 AM, Lisandro Dalcin wrote: >>>> OK, patch uploaded: >>>> http://trac.cython.org/cython_trac/attachment/ticket/417/typetest.diff >>>> >>>> Please review, and let me know if it is good enough for pushing... >>> >>> I'd either make the function inline or split it up into two functions >>> so that the none_allowed argument (and possibly check for none) can be >>> eliminated at compile time. >> >> +1 for an inline utility function, although splitting it might still be a >> good idea. >> >> I'd also keep the "== Py_None" test first then, as this is something the C >> compiler can either know or that the CPU can quickly execute, faster than >> the following type check which requires at least an indirection, or even a >> function call (so the C compiler can't reverse the two tests due to >> potential side effects). >> > > OK, many thanks for your input... I acknowledge the code in my patch > is a crap, but I've just followed naming and implementation > conventions for the argument type test code (just to not break the > rules). BTW, I think the arg type test should also be improved, or > perhaps even merged with this one we are talking about. I'll rework > the patch. > Patch updated: http://trac.cython.org/cython_trac/attachment/ticket/417/typetest.diff -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From stefan_ml at behnel.de Fri Oct 23 15:25:13 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Oct 2009 15:25:13 +0200 Subject: [Cython] bitten again by typetesting and None In-Reply-To: References: <6DA6CB19-5F9E-452F-B607-190A221283FC@math.washington.edu> <5C965459-BE9C-45AE-B124-992C8896BAC6@math.washington.edu> <4ADD79D4.8030604@behnel.de> <4AE0165F.90405@behnel.de> Message-ID: <4AE1AEB9.9080408@behnel.de> Lisandro Dalcin wrote: > Patch updated: http://trac.cython.org/cython_trac/attachment/ticket/417/typetest.diff Ah, yes, that's a smart way of doing it. Just one thing: are there cases where this may lead to multiple evaluation of the tested expression? I doubt it, since Python values tend to live in temp variables, but I'm not sure how this interacts with C function calls, for example. Stefan From dalcinl at gmail.com Fri Oct 23 16:44:01 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 23 Oct 2009 12:44:01 -0200 Subject: [Cython] bitten again by typetesting and None In-Reply-To: <4AE1AEB9.9080408@behnel.de> References: <5C965459-BE9C-45AE-B124-992C8896BAC6@math.washington.edu> <4ADD79D4.8030604@behnel.de> <4AE0165F.90405@behnel.de> <4AE1AEB9.9080408@behnel.de> Message-ID: On Fri, Oct 23, 2009 at 11:25 AM, Stefan Behnel wrote: > > Lisandro Dalcin wrote: >> Patch updated: http://trac.cython.org/cython_trac/attachment/ticket/417/typetest.diff > > Ah, yes, that's a smart way of doing it. > > Just one thing: are there cases where this may lead to multiple evaluation > of the tested expression? I doubt it, since Python values tend to live in > temp variables, but I'm not sure how this interacts with C function calls, > for example. > Can you provide a bit code about what you are talking? (then i could integrate such cases in the test) -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sccolbert at gmail.com Fri Oct 23 17:28:43 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Fri, 23 Oct 2009 17:28:43 +0200 Subject: [Cython] bug in numpy.pxd Message-ID: <7f014ea60910230828h2d7b770cme6969e5836f4077f@mail.gmail.com> line 317 in numpy.pxd for Cython 11.3 bint PyArray_ISISCONTIGUOUS(ndarray m) double "IS" in that definition. Cheers, Chris From stefan_ml at behnel.de Fri Oct 23 18:25:01 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Oct 2009 18:25:01 +0200 Subject: [Cython] [Pyrex] intern(str) fails if string is not a C string In-Reply-To: <4AE1BE2E.5060506@arbash-meinel.com> References: <4ADF6ACD.7000500@arbash-meinel.com> <4AE169EE.6090108@behnel.de> <4AE1BE2E.5060506@arbash-meinel.com> Message-ID: <4AE1D8DD.2000303@behnel.de> John Arbash Meinel wrote: >> I recommend using a dedicated dict instead, and put your byte strings >> there. This will not change the performance in any way, given that intern() >> on a char* has always been creating a Python byte string before interning >> (and possibly dropping) it. But it will make it clearer in the code what is >> actually happening. > > So I can't intern() a char* because it has NULLs in the array. You have to use PyString_FromStringAndSize() to build a Python byte string manually, which then supports being interned in Python 2 (and that will be fixed in Cython 0.12). > I don't want to use a dedicated dict, because then the strings become > immortal. Except that a dedicated dict allows you to control if the strings /really/ become immortal or not. Once a string is interned in CPython, there is no way to get it out of the dict of interned strings. Your own dict is under your control. > I do understand that interning in python is really meant for internal > use. Because attributes, etc are all managed via py strings (becoming > Unicode in Py3), and thus lookups in dicts, etc are better if you intern > everything. Interning is not required. Any dict will work just fine, as long as you make sure that the strings you use come from that dict. > However, there is no way to implement de-duping without immortality in > python Unless you have a way of keeping track of the usage of a value. Depending on your use case, it might work to just clear (and maybe rebuild) the whole dict when it reaches a given size or after the 1000000-th insertion, or when memory gets tight, or whatever. > other than something like weakrefs (which strings and tuples > don't support, and really exacerbates the memory problems w/ interning, Plus, weakrefs are pretty slow. I did a little benchmarking in lxml lately to find out if a cached object reference (that I had added for performance reasons, but that introduced a cyclic reference) could be replaced by a weak reference. It turned out that it was actually faster to just recreate the object than to keep a weak reference to a life object. So I just dropped the cached reference and with it all sorts of memory issues that were due to requiring a GC cleanup run. Stefan From stefan_ml at behnel.de Fri Oct 23 19:22:22 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Oct 2009 19:22:22 +0200 Subject: [Cython] bitten again by typetesting and None In-Reply-To: References: <5C965459-BE9C-45AE-B124-992C8896BAC6@math.washington.edu> <4ADD79D4.8030604@behnel.de> <4AE0165F.90405@behnel.de> <4AE1AEB9.9080408@behnel.de> Message-ID: <4AE1E64E.3050509@behnel.de> Lisandro Dalcin wrote: > On Fri, Oct 23, 2009 at 11:25 AM, Stefan Behnel wrote: >> Lisandro Dalcin wrote: >>> Patch updated: http://trac.cython.org/cython_trac/attachment/ticket/417/typetest.diff >> Ah, yes, that's a smart way of doing it. >> >> Just one thing: are there cases where this may lead to multiple evaluation >> of the tested expression? I doubt it, since Python values tend to live in >> temp variables, but I'm not sure how this interacts with C function calls, >> for example. >> > > Can you provide a bit code about what you are talking? (then i could > integrate such cases in the test) I was thinking of ticket 404 that Robert fixed. http://trac.cython.org/cython_trac/ticket/404 It might be worth adding a test like this: cdef int count = 0 cdef object getFoo() global count count += 1 return Foo() def test_getFoo(): cdef int old_count = count cdef Foo x = getFoo() return count - old_count def test_getFooCast(): cdef int old_count = count cdef Foo x = getFoo() return count - old_count >>> test_getFoo() 1 >>> test_getFooCast() 1 Just add that and I'll happily await your commit. Stefan From robertwb at math.washington.edu Fri Oct 23 19:32:00 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Fri, 23 Oct 2009 10:32:00 -0700 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE172F4.2090306@behnel.de> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE172F4.2090306@behnel.de> Message-ID: On Oct 23, 2009, at 2:10 AM, Stefan Behnel wrote: > Robert Bradshaw wrote: >> As mentioned earlier, it's about time to release Cython 0.12. > > Totally. > >> What I see that needs to happen is >> >> 1) Get Sage working with the new Cython. I've gotten Sage to compile >> and nearly all doctests passing > > You can switch the cascaded assignment work-around back to the > original > code, I fixed #409. Thanks. >> I think I'm down to one bug, >> somewhere in exception handling, but I haven't been able to look at >> it >> much yet > > Any more hints on this? I might be able to help out. Sure. I get SystemError: NULL result without error in PyObject_Call I haven't tried to pull it out into an isolated failure yet. http://trac.sagemath.org/sage_trac/ticket/7272 the file in question is http://hg.sagemath.org/sage-main/file/5bf36a37cd0c/sage/modular/modsym/heilbronn.pyx#l400 >> I'd assume lxml and other developer projects are building >> with the current head. > > lxml tests fine, but it's certainly worth removing some C-isms from > its > code once I start depending Cython 0.12. If all those new > optimisations had > been in Cython two years ago, the code would look a lot cleaner today. Same for Sage. >> 2) We should go onto the trac server (link below) and either resolve/ >> bump any tickets that are not going happen in the next week or two. > > I'll see that I get the tickets closed that I'm still working on. > Most of > the currently tickets do not look like the need fixing right now, > but we > should at least get all tests working on the supported platforms. > > >> 3) Widespread testing. > > Oh, yes, please! :) > > It seems from the reports we had on the list that many users have > already > been running cython-devel recently. But it would be good to get some > feedback especially from Windows/Mac users, as I expect most > developers to > be on Linux nowadays. I actually mostly use a Mac (10.5) but 10.4 and 10.6 testing, as well as Windows, would be good. > Given the amount of changes, I'd also expect at least two release > candidates, and I really hope that people will exercise them. It's > definitely worth switching from 0.11. Remember: *before* a new major > release is the best time to get your bugs fixed, not afterwards. Agreed. And we should make sure to test things like --embed too (perhaps this should be part of runtests, introducing a make test target in the demo). - Robert From robertwb at math.washington.edu Fri Oct 23 19:36:51 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Fri, 23 Oct 2009 10:36:51 -0700 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE17EE8.1070303@behnel.de> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE179F5.4060307@student.matnat.uio.no> <4AE17EE8.1070303@behnel.de> Message-ID: <9F55E5F1-FD2D-43AB-92A9-74C92B42EFAD@math.washington.edu> On Oct 23, 2009, at 3:01 AM, Stefan Behnel wrote: > Dag Sverre Seljebotn wrote: >> let's get as many as possible to test with the refnanny turned on >> (and let's make it easy, say, let's include the code to stick in ones >> setup.py in the RC release notes). > > Would there be a way to enable that automatically for an alpha > release? I > know, this requires the external refnanny module, but wouldn't it be > possible to enable it by default, and then add a fallback dead-nanny > into > the generated code that would just ignore calls and would be used if > the > refnanny itself isn't found? That would eat some performance but would > allow users to enable the refnanny by simply having it lying around in > their PYTHONPATH, instead of requiring a separate build option. I'm not so sure about the silent fallback, but +1 to enabling it for alphas (or even releasing an alpha and alpha-refnanny). > Although I admit that there should be enough of an incentive to > enable a > little option in your setup.py. It's never been so easy to make sure > that > some out-of-your-control generated code is memory leak free... You can add -DCYTHON_REFANNAY to your cflags, though that needs to be done extension by extension, so I agree there should be a better way. - Robert From stefan_ml at behnel.de Fri Oct 23 19:48:27 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Oct 2009 19:48:27 +0200 Subject: [Cython] Cython 0.12 In-Reply-To: References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE172F4.2090306@behnel.de> Message-ID: <4AE1EC6B.2060604@behnel.de> Robert Bradshaw wrote: > On Oct 23, 2009, at 2:10 AM, Stefan Behnel wrote: >> Robert Bradshaw wrote: >>> I think I'm down to one bug, >>> somewhere in exception handling, but I haven't been able to look at >>> it much yet >> Any more hints on this? I might be able to help out. > > I get > SystemError: NULL result without error in PyObject_Call > I haven't tried to pull it out into an isolated failure yet. http://trac.sagemath.org/sage_trac/ticket/7272 > the file in question is > http://hg.sagemath.org/sage-main/file/5bf36a37cd0c/sage/modular/modsym/heilbronn.pyx#l400 Hmm, not much I can do without seeing the generated C code. At least, it doesn't look exception related. Might also be a stray NULL return value, maybe __pyx_r wasn't set up in the _initialize_list() method for whatever reason. > Agreed. And we should make sure to test things like --embed too Yes, that's absolutely worth testing. Stefan From stefan_ml at behnel.de Fri Oct 23 21:45:12 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Oct 2009 21:45:12 +0200 Subject: [Cython] bug in numpy.pxd In-Reply-To: <7f014ea60910230828h2d7b770cme6969e5836f4077f@mail.gmail.com> References: <7f014ea60910230828h2d7b770cme6969e5836f4077f@mail.gmail.com> Message-ID: <4AE207C8.8000001@behnel.de> Chris Colbert wrote: > line 317 in numpy.pxd for Cython 11.3 > > bint PyArray_ISISCONTIGUOUS(ndarray m) > > double "IS" in that definition. Thanks, I applied the two fixes from the bug tracker (#419/#420). Stefan From stefan_ml at behnel.de Fri Oct 23 21:54:16 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Oct 2009 21:54:16 +0200 Subject: [Cython] Cython 0.12 In-Reply-To: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> Message-ID: <4AE209E8.5050504@behnel.de> Robert Bradshaw wrote: > 2) We should go onto the trac server (link below) and either resolve/ > bump any tickets that are not going happen in the next week or two. This looks ok to me: http://trac.cython.org/cython_trac/attachment/ticket/405/0001-prevent-warnings-when-compiling-with-gcc-Wextra.patch It's certainly a minor issue, but I wouldn't mind applying it. Any objections? Lisandro? Stefan From stefan_ml at behnel.de Fri Oct 23 22:02:03 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Oct 2009 22:02:03 +0200 Subject: [Cython] Cython 0.12 In-Reply-To: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> Message-ID: <4AE20BBB.9040104@behnel.de> Hi, what about this one: http://trac.cython.org/cython_trac/ticket/314 "[patch] array.pxd - fast Cython access for Python's builtin array.array" Does anyone remember what the status of this was? Has anyone reviewed it? Stefan From dalcinl at gmail.com Fri Oct 23 22:02:26 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 23 Oct 2009 18:02:26 -0200 Subject: [Cython] bitten again by typetesting and None In-Reply-To: <4AE1E64E.3050509@behnel.de> References: <4ADD79D4.8030604@behnel.de> <4AE0165F.90405@behnel.de> <4AE1AEB9.9080408@behnel.de> <4AE1E64E.3050509@behnel.de> Message-ID: On Fri, Oct 23, 2009 at 3:22 PM, Stefan Behnel wrote: > > Lisandro Dalcin wrote: >> On Fri, Oct 23, 2009 at 11:25 AM, Stefan Behnel wrote: >>> Lisandro Dalcin wrote: >>>> Patch updated: http://trac.cython.org/cython_trac/attachment/ticket/417/typetest.diff >>> Ah, yes, that's a smart way of doing it. >>> >>> Just one thing: are there cases where this may lead to multiple evaluation >>> of the tested expression? I doubt it, since Python values tend to live in >>> temp variables, but I'm not sure how this interacts with C function calls, >>> for example. >>> >> >> Can you provide a bit code about what you are talking? (then i could >> integrate such cases in the test) > > I was thinking of ticket 404 that Robert fixed. > > http://trac.cython.org/cython_trac/ticket/404 > > It might be worth adding a test like this: > > ?cdef int count = 0 > > ?cdef object getFoo() > ? ? ?global count > ? ? ?count += 1 > ? ? ?return Foo() > > ?def test_getFoo(): > ? ? ?cdef int old_count = count > ? ? ?cdef Foo x = getFoo() > ? ? ?return count - old_count > > ?def test_getFooCast(): > ? ? ?cdef int old_count = count > ? ? ?cdef Foo x = getFoo() > ? ? ?return count - old_count > > ?>>> test_getFoo() > ?1 > ?>>> test_getFooCast() > ?1 > > Just add that and I'll happily await your commit. > http://hg.cython.org/cython-devel/rev/9f4f888a2b4e http://hg.cython.org/cython-devel/rev/294a197230dd -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From matthew.brett at gmail.com Fri Oct 23 22:05:41 2009 From: matthew.brett at gmail.com (Matthew Brett) Date: Fri, 23 Oct 2009 13:05:41 -0700 Subject: [Cython] Returning nested python objects In-Reply-To: <4ADFFBCD.90604@behnel.de> References: <1e2af89e0910211815y4aa9a66ci83492d3b92442a92@mail.gmail.com> <4ADFFBCD.90604@behnel.de> Message-ID: <1e2af89e0910231305nd6c7621k3224327f1e6493a3@mail.gmail.com> Hi, Thanks for your merciful replies. Short version ------------------- As you guessed this was not a cython problem, but inherent slowness in python object creation when the system was getting close to its limits. Long version ------------------ Of course I had not investigated the problem enough, and lacking understanding, wondered if it may be Cython. It turned out, when I did investigate properly, the routine was just taking a very long time (10 times longer appending a tuple with two scalars to a list, compared to appending a scalar to a list). The kind of thing I was doing was this: def func(long n1, long n2): d = {} cdef long i, j cdef int a, b for i in range(n1): a = i+1 b = i+2 d[i] = [] for j in range(n2): val = (a, b) # the slow: fast "val = a" d[i].append(val) return d where n1 was around 30K and n2 around 50. Now I reduced the problem, and timed it, python and cython take 10 times longer for the tuple case ("val = (a, b)") than the scalar case ("val = a") - just as for my larger routine. > Don't worry, that's normal. When Cython creates them, they get stored in > temporary variables that hold the reference. Adding them to the dict will > let the dict add another reference, and when the temporary reference is > taken out of scope, Cython must DECREF it. Thank you - that was indeed the source of my confusion. Best, Matthew From stefan_ml at behnel.de Fri Oct 23 22:12:00 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 23 Oct 2009 22:12:00 +0200 Subject: [Cython] bitten again by typetesting and None In-Reply-To: References: <4ADD79D4.8030604@behnel.de> <4AE0165F.90405@behnel.de> <4AE1AEB9.9080408@behnel.de> <4AE1E64E.3050509@behnel.de> Message-ID: <4AE20E10.10708@behnel.de> Lisandro Dalcin wrote: > http://hg.cython.org/cython-devel/rev/9f4f888a2b4e > http://hg.cython.org/cython-devel/rev/294a197230dd Thanks! Stefan From dagss at student.matnat.uio.no Fri Oct 23 22:37:00 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: 23 Oct 2009 22:37:00 +0200 Subject: [Cython] Cython 0.12 Message-ID: <3339182268.272674@smtp.netcom.no> Unless there's been a recent change it needs a serious cleanup before being applied, let's bump it to 0.12.1 or wishlist (no trac access, sorry). (There is, in addition to the change we want, a hack to to treat an array.array as a 2D array which is much (much much) better suited for a subclass..) Dag Sverre Seljebotn -----Original Message----- From: Stefan Behnel Date: Friday, Oct 23, 2009 10:02 pm Subject: Re: [Cython] Cython 0.12 To: cython-dev at codespeak.netReply-To: cython-dev at codespeak.net Hi, > >what about this one: > >http://trac.cython.org/cython_trac/ticket/314 > >"[patch] array.pxd - fast Cython access for Python's builtin array.array" > >Does anyone remember what the status of this was? Has anyone reviewed it? > >Stefan >________ From dagss at student.matnat.uio.no Fri Oct 23 22:44:00 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: 23 Oct 2009 22:44:00 +0200 Subject: [Cython] Cython 0.12 Message-ID: <3339182656.311396@smtp.netcom.no> No trac access atm, but I'll try to get Sturla's recent buffer patches reviewed on Monday or Tuesday, I hope they can go in for 0.12. Dag Sverre Seljebotn -----Original Message----- From: Robert Bradshaw Date: Friday, Oct 23, 2009 6:55 am Subject: [Cython] Cython 0.12 To: Cython-dev Reply-To: cython-dev at codespeak.net As mentioned earlier, it's about time to release Cython 0.12. What I >see that needs to happen is > >1) Get Sage working with the new Cython. I've gotten Sage to compile >and nearly all doctests passing (I think I'm down to one bug, >somewhere in exception handling, but I haven't been able to look at it >much yet). I'd assume lxml and other developer projects are building >with the current head. > >2) We should go onto the trac server (link below) and either resolve/ >bump any tickets that are not going happen in the next week or two. >Also, if there are any other blockers that need to be put in this >list, please do so. To all: if there's something you're really like to >see get into the next release, please speak up now. (No promises, but >at the very least it'll help assign priorities.) > >3) Widespread testing. Shortly we should put out an alpha and some >release candidates. It would probably be good to have a feature freeze >and push bug fixes only (for this branch). There's a lot of new stuff >in this release (all of -unstable) so I'd like to pound it hard, >including Windows building and projects that don't normally compile >with the -devel branch. > >Lets aim for a serious alpha, or hopefully even a release candidate, >by the end of the month. > >- Robert > >[1] http://trac.cython.org/cython_trac/query?status=assigned&status=new&status=reopened&milestone=0.12 > >_______________________________________________ >Cython-dev mailing list >Cython-dev at codespeak.net >http://codespeak.net/mailman/listinfo/cython-dev > From dalcinl at gmail.com Fri Oct 23 23:05:27 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 23 Oct 2009 19:05:27 -0200 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE20BBB.9040104@behnel.de> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE20BBB.9040104@behnel.de> Message-ID: On Fri, Oct 23, 2009 at 6:02 PM, Stefan Behnel wrote: > Hi, > > what about this one: > > http://trac.cython.org/cython_trac/ticket/314 > > "[patch] array.pxd - fast Cython access for Python's builtin array.array" > > Does anyone remember what the status of this was? Has anyone reviewed it? > I have some cute enhancements to propose to this (I have this code more or les ready in a notebook at home), 1) I've implemented a rather trivial hackey to access from C land the internal table of descriptors stored in Modules/arraymodule.c 2) I've extended the beast to make it possible creating arrays for datatypes that are not currently supported (for example, long long int, complex numbers)... However, I would like to discuss this with Robert Kern, and eventually improve the features. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Fri Oct 23 23:08:31 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 23 Oct 2009 19:08:31 -0200 Subject: [Cython] Cython 0.12 In-Reply-To: <3339182268.272674@smtp.netcom.no> References: <3339182268.272674@smtp.netcom.no> Message-ID: On Fri, Oct 23, 2009 at 6:37 PM, Dag Sverre Seljebotn wrote: > Unless there's been a recent change it needs a serious cleanup before being applied, let's bump it to 0.12.1 or wishlist (no trac access, sorry). > > (There is, in addition to the change we want, a hack to to treat an array.array as a 2D array which is much (much much) better suited for a subclass..) > I'm not sure if I understood you, but from my side I do not like the idea of playing games with the traditional 1D array.array type to make it appears as 2D... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From robert.kern at gmail.com Fri Oct 23 23:52:55 2009 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 23 Oct 2009 16:52:55 -0500 Subject: [Cython] Cython 0.12 In-Reply-To: References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE20BBB.9040104@behnel.de> Message-ID: On 2009-10-23 16:05 PM, Lisandro Dalcin wrote: > However, I would like to discuss this with Robert Kern, and eventually > improve the features. I am not the author of that patch. I don't use "rk" as a username. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From dalcinl at gmail.com Sat Oct 24 00:04:49 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 23 Oct 2009 20:04:49 -0200 Subject: [Cython] Cython 0.12 In-Reply-To: References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE20BBB.9040104@behnel.de> Message-ID: On Fri, Oct 23, 2009 at 7:52 PM, Robert Kern wrote: > On 2009-10-23 16:05 PM, Lisandro Dalcin wrote: > >> However, I would like to discuss this with Robert Kern, and eventually >> improve the features. > > I am not the author of that patch. I don't use "rk" as a username. > Ups! Sorry... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From lodatom at gmail.com Sat Oct 24 03:00:29 2009 From: lodatom at gmail.com (Mark Lodato) Date: Fri, 23 Oct 2009 21:00:29 -0400 Subject: [Cython] Cython 0.12 In-Reply-To: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> Message-ID: On Fri, Oct 23, 2009 at 12:57 AM, Robert Bradshaw wrote: > To all: if there's something you're really like to > see get into the next release, please speak up now. (No promises, but > at the very least it'll help assign priorities.) I have two patch series that I posted to trac: http://trac.cython.org/cython_trac/ticket/402 This is a bunch of updates for cython_freeze. It does not touch anything else, so it should not create any bugs in the rest of Cython. It works in my testing, and the cython_freeze that shipped with 11.3 doesn't work anyway, so I think there should be no harm in including it in 12.0. If you would prefer these patches in a different format (another tarball, a single squashed patch, anything else) let me know. http://trac.cython.org/cython_trac/ticket/405 Cython-generated code emits a ton of warnings when compiling with gcc -Wextra, and this patch fixes it. I haven't tested it much, and I don't know much about Cython internals, so this certainly needs a few set of knowledgeable eyes to look over it. It would be nice as a part of 12.0, but I don't know if it's ready (or a good idea). Thanks, Mark From stefan_ml at behnel.de Sat Oct 24 07:36:21 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 24 Oct 2009 07:36:21 +0200 Subject: [Cython] Cython 0.12 In-Reply-To: References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE209E8.5050504@behnel.de> Message-ID: <4AE29255.3080102@behnel.de> Lisandro Dalcin wrote: > On Fri, Oct 23, 2009 at 5:54 PM, Stefan Behnel wrote: >> Robert Bradshaw wrote: >>> 2) We should go onto the trac server (link below) and either resolve/ >>> bump any tickets that are not going happen in the next week or two. >> This looks ok to me: >> >> http://trac.cython.org/cython_trac/attachment/ticket/405/0001-prevent-warnings-when-compiling-with-gcc-Wextra.patch >> >> It's certainly a minor issue, but I wouldn't mind applying it. Any >> objections? Lisandro? > > Sorry for the delay... definitely +1. Applied and closed. Stefan From stefan_ml at behnel.de Sat Oct 24 07:42:28 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 24 Oct 2009 07:42:28 +0200 Subject: [Cython] Cython 0.12 In-Reply-To: References: <3339182268.272674@smtp.netcom.no> Message-ID: <4AE293C4.80904@behnel.de> Lisandro Dalcin wrote: > On Fri, Oct 23, 2009 at 6:37 PM, Dag Sverre Seljebotn wrote: >> Unless there's been a recent change it needs a serious cleanup before >> being applied, let's bump it to 0.12.1 or wishlist (no trac access, >> sorry). >> >> (There is, in addition to the change we want, a hack to to treat an >> array.array as a 2D array which is much (much much) better suited for >> a subclass..) > > I'm not sure if I understood you, but from my side I do not like the > idea of playing games with the traditional 1D array.array type to make > it appears as 2D... I assume that Dag meant that there's 2D support integrated into the patch, and that it would be better to refactor that into a separate subclass. I agree with that. Most people won't use it and it's much better to have simpler code for the normal use cases. Stefan From stefan_ml at behnel.de Sat Oct 24 07:47:55 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 24 Oct 2009 07:47:55 +0200 Subject: [Cython] Cython 0.12 In-Reply-To: References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> Message-ID: <4AE2950B.9020405@behnel.de> Mark Lodato wrote: > I have two patch series that I posted to trac: > > http://trac.cython.org/cython_trac/ticket/402 > > This is a bunch of updates for cython_freeze. It does not touch > anything else, so it should not create any bugs in the rest of Cython. > It works in my testing, and the cython_freeze that shipped with 11.3 > doesn't work anyway, so I think there should be no harm in including > it in 12.0. If you would prefer these patches in a different format > (another tarball, a single squashed patch, anything else) let me know. Robert has that one assigned. Robert? There's also #434 about --embed not working in Py3. Mark, did you test your patch under Py3.1? > http://trac.cython.org/cython_trac/ticket/405 > > Cython-generated code emits a ton of warnings when compiling with gcc > -Wextra, and this patch fixes it. I haven't tested it much, and I > don't know much about Cython internals, so this certainly needs a few > set of knowledgeable eyes to look over it. It would be nice as a part > of 12.0, but I don't know if it's ready (or a good idea). It has just been applied. Stefan From lodatom at gmail.com Sat Oct 24 17:49:43 2009 From: lodatom at gmail.com (Mark Lodato) Date: Sat, 24 Oct 2009 11:49:43 -0400 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE2950B.9020405@behnel.de> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> Message-ID: On Sat, Oct 24, 2009 at 1:47 AM, Stefan Behnel wrote: > Mark Lodato wrote: >> I have two patch series that I posted to trac: >> >> http://trac.cython.org/cython_trac/ticket/402 >> >> This is a bunch of updates for cython_freeze. ?It does not touch >> anything else, so it should not create any bugs in the rest of Cython. >> ?It works in my testing, and the cython_freeze that shipped with 11.3 >> doesn't work anyway, so I think there should be no harm in including >> it in 12.0. ?If you would prefer these patches in a different format >> (another tarball, a single squashed patch, anything else) let me know. > > Robert has that one assigned. Robert? > > There's also #434 about --embed not working in Py3. Mark, did you test your > patch under Py3.1? I saw that bug, and cython_freeze has the exact same problems as --embed. I'm working on a fix now. Mark From lodatom at gmail.com Sat Oct 24 18:28:41 2009 From: lodatom at gmail.com (Mark Lodato) Date: Sat, 24 Oct 2009 12:28:41 -0400 Subject: [Cython] Building in-place fails Message-ID: I just updated to the latest cython-devel and now `make' fails with: python setup.py build_ext --inplace Compiling module Cython.Compiler.Parsing ... ERROR: 'ModuleNode' object has no attribute 'directive_comments' Extension module compilation failed, using plain Python implementation running build_ext It appears that this was caused by: http://hg.cython.org/cython-devel/rev/014a3ca7e197e9314f6ee60dcf9dc42aefac0b11 naming references changed from 'option' to 'directive' Thu Oct 15 03:47:42 2009 -0400 (9 days ago) Is this a known problem? Any ideas on how I can use Cython in the meantime? Thanks, Mark From lodatom at gmail.com Sat Oct 24 18:35:47 2009 From: lodatom at gmail.com (Mark Lodato) Date: Sat, 24 Oct 2009 12:35:47 -0400 Subject: [Cython] Building in-place fails In-Reply-To: References: Message-ID: On Sat, Oct 24, 2009 at 12:28 PM, Mark Lodato wrote: > I just updated to the latest cython-devel and now `make' fails with: > > python setup.py build_ext --inplace > Compiling module Cython.Compiler.Parsing ... > ERROR: 'ModuleNode' object has no attribute 'directive_comments' > Extension module compilation failed, using plain Python implementation > running build_ext > > > It appears that this was caused by: > > http://hg.cython.org/cython-devel/rev/014a3ca7e197e9314f6ee60dcf9dc42aefac0b11 > naming references changed from 'option' to 'directive' > Thu Oct 15 03:47:42 2009 -0400 (9 days ago) On further investigation, this is a problem not just when compiling with Cython, but also using plain Python implementation: Traceback (most recent call last): File "../../bin/cython", line 8, in main(command_line = 1) File "/home/mark/cython/cython/Cython/Compiler/Main.py", line 760, in main result = compile(sources, options) File "/home/mark/cython/cython/Cython/Compiler/Main.py", line 737, in compile return compile_multiple(source, options) File "/home/mark/cython/cython/Cython/Compiler/Main.py", line 707, in compile_multiple result = run_pipeline(source, options) File "/home/mark/cython/cython/Cython/Compiler/Main.py", line 568, in run_pipeline err, enddata = context.run_pipeline(pipeline, source) File "/home/mark/cython/cython/Cython/Compiler/Main.py", line 219, in run_pipeline data = phase(data) File "Visitor.py", line 265, in Cython.Compiler.Visitor.CythonTransform.__call__ (/home/mark/cython/cython/Cython/Compiler/Visitor.c:4520) File "Visitor.py", line 248, in Cython.Compiler.Visitor.VisitorTransform.__call__ (/home/mark/cython/cython/Cython/Compiler/Visitor.c:4280) File "Visitor.py", line 46, in Cython.Compiler.Visitor.BasicVisitor.visit (/home/mark/cython/cython/Cython/Compiler/Visitor.c:1383) File "/home/mark/cython/cython/Cython/Compiler/ParseTreeTransforms.py", line 352, in visit_ModuleNode for key, value in node.directive_comments.iteritems(): AttributeError: 'ModuleNode' object has no attribute 'directive_comments' From robertwb at math.washington.edu Sat Oct 24 18:56:08 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 24 Oct 2009 09:56:08 -0700 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE209E8.5050504@behnel.de> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE209E8.5050504@behnel.de> Message-ID: <6FBDA0B8-451B-4855-8E76-A810AFA0F805@math.washington.edu> On Oct 23, 2009, at 12:54 PM, Stefan Behnel wrote: > > Robert Bradshaw wrote: >> 2) We should go onto the trac server (link below) and either resolve/ >> bump any tickets that are not going happen in the next week or two. > > This looks ok to me: > > http://trac.cython.org/cython_trac/attachment/ticket/405/0001-prevent-warnings-when-compiling-with-gcc-Wextra.patch > > It's certainly a minor issue, but I wouldn't mind applying it. Any > objections? Lisandro? Looks good to me--has anyone verified that the const temp variable actually gets optimized away? - Robert From dagss at student.matnat.uio.no Sat Oct 24 18:53:35 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sat, 24 Oct 2009 18:53:35 +0200 Subject: [Cython] Building in-place fails In-Reply-To: References: Message-ID: <0cfa0f09841a8223e39ce22979874db9.squirrel@webmail.uio.no> > On Sat, Oct 24, 2009 at 12:28 PM, Mark Lodato wrote: >> I just updated to the latest cython-devel and now `make' fails with: >> >> python setup.py build_ext --inplace >> Compiling module Cython.Compiler.Parsing ... >> ERROR: 'ModuleNode' object has no attribute 'directive_comments' >> Extension module compilation failed, using plain Python implementation >> running build_ext >> >> >> It appears that this was caused by: >> >> http://hg.cython.org/cython-devel/rev/014a3ca7e197e9314f6ee60dcf9dc42aefac0b11 >> naming references changed from 'option' to 'directive' >> Thu Oct 15 03:47:42 2009 -0400 (9 days ago) It is strange that this wasn't discovered during my test runs etc... anyway, this is just an issue of renaming variables, and in ModuleNode there's an attribute option_comments that should be renamed directive_comments. (I'm on the run so no commit from me, sorry.) Dag Sverre From robertwb at math.washington.edu Sat Oct 24 19:09:54 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 24 Oct 2009 10:09:54 -0700 Subject: [Cython] Cython 0.12 In-Reply-To: References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> Message-ID: On Oct 24, 2009, at 8:49 AM, Mark Lodato wrote: > On Sat, Oct 24, 2009 at 1:47 AM, Stefan Behnel > wrote: >> Mark Lodato wrote: >>> I have two patch series that I posted to trac: >>> >>> http://trac.cython.org/cython_trac/ticket/402 >>> >>> This is a bunch of updates for cython_freeze. It does not touch >>> anything else, so it should not create any bugs in the rest of >>> Cython. >>> It works in my testing, and the cython_freeze that shipped with >>> 11.3 >>> doesn't work anyway, so I think there should be no harm in including >>> it in 12.0. If you would prefer these patches in a different format >>> (another tarball, a single squashed patch, anything else) let me >>> know. >> >> Robert has that one assigned. Robert? Yep, I've taken a look and pushed them in. The easiest way is to export a large series of change is "hg bundle" which makes an .hg file that's the entire commit history between two points of the tree. (Either that or publishing a repository that others can pull from.) >> There's also #434 about --embed not working in Py3. Mark, did you >> test your >> patch under Py3.1? > > I saw that bug, and cython_freeze has the exact same problems as > --embed. I'm working on a fix now. Thanks. - Robert From robertwb at math.washington.edu Sat Oct 24 19:18:08 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 24 Oct 2009 10:18:08 -0700 Subject: [Cython] Building in-place fails In-Reply-To: References: Message-ID: On Oct 24, 2009, at 9:28 AM, Mark Lodato wrote: > I just updated to the latest cython-devel and now `make' fails with: > > python setup.py build_ext --inplace > Compiling module Cython.Compiler.Parsing ... > ERROR: 'ModuleNode' object has no attribute 'directive_comments' > Extension module compilation failed, using plain Python implementation > running build_ext Hmm... I'm unable to reproduce this. I just made a fresh clone and python setup.py build_ext --inplace worked just fine. I wonder if its conflicting with an older version of Cython it's finding somewhere. > It appears that this was caused by: > > http://hg.cython.org/cython-devel/rev/014a3ca7e197e9314f6ee60dcf9dc42aefac0b11 > naming references changed from 'option' to 'directive' > Thu Oct 15 03:47:42 2009 -0400 (9 days ago) > > > Is this a known problem? Any ideas on how I can use Cython in the > meantime? Perhaps you can remove the old Cython from your library and reinstall from scratch? I'm not sure, but I'd like to get to the bottom of this. Does anyone else see anything similar? - Robert From dalcinl at gmail.com Sat Oct 24 21:07:17 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sat, 24 Oct 2009 16:07:17 -0300 Subject: [Cython] Cython 0.12 In-Reply-To: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> Message-ID: On Fri, Oct 23, 2009 at 1:57 AM, Robert Bradshaw wrote: > > 3) Widespread testing. ... > ... > including Windows building > This fails in C++ with MSVC... * z.real = a # <<<<<<<<<<<<<< __Pyx_CREAL(__pyx_v_z) = __pyx_t_1; Anyway, this change would be required for C++ std:0x ... Hey, Dag! Any chance you can take this (little?) task? -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From lodatom at gmail.com Sat Oct 24 21:23:46 2009 From: lodatom at gmail.com (Mark Lodato) Date: Sat, 24 Oct 2009 15:23:46 -0400 Subject: [Cython] Building in-place fails In-Reply-To: References: Message-ID: On Sat, Oct 24, 2009 at 1:18 PM, Robert Bradshaw wrote: > On Oct 24, 2009, at 9:28 AM, Mark Lodato wrote: > >> I just updated to the latest cython-devel and now `make' fails with: >> >> python setup.py build_ext --inplace >> Compiling module Cython.Compiler.Parsing ... >> ERROR: 'ModuleNode' object has no attribute 'directive_comments' >> Extension module compilation failed, using plain Python implementation >> running build_ext > > Hmm... I'm unable to reproduce this. I just made a fresh clone and > > python setup.py build_ext --inplace > > worked just fine. I wonder if its conflicting with an older version of > Cython it's finding somewhere. The problem was that `make clean' does not remove Cython/Compiler/Parsing.c, .so, etc, so I was using an old version of these. I believe GNU make does not interpret the curly brackets, so it is trying to remove "Cython/Compiler/Parsing.{c,so,pyd}", which does not exist. Here's a patch to fix it: --- 8< --- diff --git i/Makefile w/Makefile index 6fdb6f9..7bc9674 100644 --- i/Makefile +++ w/Makefile @@ -11,11 +11,21 @@ clean: @rm -f *.pyc */*.pyc */*/*.pyc @rm -f *~ */*~ */*/*~ @rm -f core */core - @rm -f Cython/Compiler/Parsing.{c,so,pyd} - @rm -f Cython/Compiler/Scanning.{c,so,pyd} - @rm -f Cython/Compiler/Visitor.{c,so,pyd} - @rm -f Cython/Runtime/refnanny.{c,so,pyd} - @rm -f Cython/Plex/Scanners.{c,so,pyd} + @rm -f Cython/Compiler/Parsing.c + @rm -f Cython/Compiler/Parsing.so + @rm -f Cython/Compiler/Parsing.pyd + @rm -f Cython/Compiler/Scanning.c + @rm -f Cython/Compiler/Scanning.so + @rm -f Cython/Compiler/Scanning.pyd + @rm -f Cython/Compiler/Visitor.c + @rm -f Cython/Compiler/Visitor.so + @rm -f Cython/Compiler/Visitor.pyd + @rm -f Cython/Runtime/refnanny.c + @rm -f Cython/Runtime/refnanny.so + @rm -f Cython/Runtime/refnanny.pyd + @rm -f Cython/Plex/Scanners.c + @rm -f Cython/Plex/Scanners.so + @rm -f Cython/Plex/Scanners.pyd @(cd Demos; $(MAKE) clean) testclean: --- >8 --- From dalcinl at gmail.com Sat Oct 24 21:24:39 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sat, 24 Oct 2009 16:24:39 -0300 Subject: [Cython] Win32 with MSVC and refnanny+profile Message-ID: Just tested in Win32 with MSVC, a few warnings here and there, mosty related to loss of precision on numeric conversions (eg. int <-> float) However, two things to point out: 1) tests\compile\cstructreturn.pyx is clearly wrong code, and the compiler warned about uninitialized return. This makes me think that perhaps Cython should at least emit a warning if in a cdef function with explicit return type you never "return something"... Should I fix the test to silent the warning? 2) refnany + profile code fails to compile, because the refnnany setup code in functions should be emmited BEFORE the trace call (in order to do not mix variable declarations and code)... If any of you have a few minutes to fix this, It would be great. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From robertwb at math.washington.edu Sat Oct 24 22:33:40 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 24 Oct 2009 13:33:40 -0700 Subject: [Cython] Win32 with MSVC and refnanny+profile In-Reply-To: References: Message-ID: On Oct 24, 2009, at 12:24 PM, Lisandro Dalcin wrote: > Just tested in Win32 with MSVC, a few warnings here and there, mosty > related to loss of precision on numeric conversions (eg. int <-> > float) > > However, two things to point out: > > 1) tests\compile\cstructreturn.pyx is clearly wrong code, and the > compiler warned about uninitialized return. This makes me think that > perhaps Cython should at least emit a warning if in a cdef function > with explicit return type you never "return something"... Until we have correct control flow, I don't think we can even accurately detect this. > Should I fix the test to silent the warning? Yes, please do. That test is obviously wrong. > 2) refnany + profile code fails to compile, because the refnnany setup > code in functions should be emmited BEFORE the trace call (in order to > do not mix variable declarations and code)... If any of you have a few > minutes to fix this, It would be great. The profile (may) declare some variable as well... Perhaps we need to split it up into two macros. - Robert From robertwb at math.washington.edu Sat Oct 24 22:46:47 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 24 Oct 2009 13:46:47 -0700 Subject: [Cython] Building in-place fails In-Reply-To: References: Message-ID: <3B7D9272-7405-4571-B633-F39D75320304@math.washington.edu> On Oct 24, 2009, at 12:23 PM, Mark Lodato wrote: > On Sat, Oct 24, 2009 at 1:18 PM, Robert Bradshaw > wrote: >> On Oct 24, 2009, at 9:28 AM, Mark Lodato wrote: >> >>> I just updated to the latest cython-devel and now `make' fails with: >>> >>> python setup.py build_ext --inplace >>> Compiling module Cython.Compiler.Parsing ... >>> ERROR: 'ModuleNode' object has no attribute 'directive_comments' >>> Extension module compilation failed, using plain Python >>> implementation >>> running build_ext >> >> Hmm... I'm unable to reproduce this. I just made a fresh clone and >> >> python setup.py build_ext --inplace >> >> worked just fine. I wonder if its conflicting with an older version >> of >> Cython it's finding somewhere. > > > The problem was that `make clean' does not remove > Cython/Compiler/Parsing.c, .so, etc, so I was using an old version of > these. Ah, that would do it. > I believe GNU make does not interpret the curly brackets, so > it is trying to remove "Cython/Compiler/Parsing.{c,so,pyd}", which > does not exist. I've pushed http://hg.cython.org/cython-devel/rev/6aa7679a6740 - Robert From sturla at molden.no Sun Oct 25 09:58:39 2009 From: sturla at molden.no (Sturla Molden) Date: Sun, 25 Oct 2009 09:58:39 +0100 Subject: [Cython] bug in buffer syntax Message-ID: <4AE4133F.90401@molden.no> If we have np.ndarray[double, ndim=2] array then &(array[row,0]) and &(array[0,column]) is a trick to get a pointer to a row or a column. Strangely, the expression is only allowed in cdef functions. In Python callable functions, it produces the error message "Cannot take address of Python variable". However, the type of &(a[row,column]) is double *, which is not the address of a Python variable. Sturla Molden From stefan_ml at behnel.de Sun Oct 25 10:03:00 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 25 Oct 2009 10:03:00 +0100 Subject: [Cython] bug in buffer syntax In-Reply-To: <4AE4133F.90401@molden.no> References: <4AE4133F.90401@molden.no> Message-ID: <4AE41444.10901@behnel.de> Sturla Molden, 25.10.2009 09:58: > If we have > > np.ndarray[double, ndim=2] array > > then &(array[row,0]) and &(array[0,column]) is a trick to get a pointer > to a row or a column. > > Strangely, the expression is only allowed in cdef functions. In Python > callable functions, it produces the error message "Cannot take address > of Python variable". However, the type of &(a[row,column]) is double *, > which is not the address of a Python variable. Could you provide complete code examples for the two functions you use? Thanks, Stefan From sturla at molden.no Sun Oct 25 10:13:10 2009 From: sturla at molden.no (Sturla Molden) Date: Sun, 25 Oct 2009 10:13:10 +0100 Subject: [Cython] Relaxed run-time checks on buffer contiguity? Message-ID: <4AE416A6.1090201@molden.no> Buffers/ndarrays declared with mode="c" or mode="fortran" will only accept C or Fortran contiguous buffers. But the generated C code does not assume more than contiguity in the fastest varying dimension. With a = np.zeros((10,10)) b = a[::2, :] the code generated for np.ndarray[double, ndim=2, mode="c"] would work for both a and b. That is, >>> import numpy as np >>> np.zeros((10,10))[:,:].strides (80, 8) >>> np.zeros((10,10))[::2,:].strides (160, 8) But: >>> np.zeros((10,10))[::2,:].flags C_CONTIGUOUS : False <<<<< Not C contiguous!!! F_CONTIGUOUS : False OWNDATA : False WRITEABLE : True ALIGNED : True UPDATEIFCOPY : False Should the run-time type-check instead just check for the stride of the fastest varying dimension? I.e. just assert that b.strides[1] == sizeof(double)? S.M. From sturla at molden.no Sun Oct 25 10:27:25 2009 From: sturla at molden.no (Sturla Molden) Date: Sun, 25 Oct 2009 10:27:25 +0100 Subject: [Cython] bug in buffer syntax In-Reply-To: <4AE41444.10901@behnel.de> References: <4AE4133F.90401@molden.no> <4AE41444.10901@behnel.de> Message-ID: <4AE419FD.2070908@molden.no> Stefan Behnel skrev: > Could you provide complete code examples for the two functions you use? > > Sure... I was fiddling with an experimental re-write (or clean-up) of SciPy's ckdtree. Here it is. Sturla -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: ckdtree.pyx Url: http://codespeak.net/pipermail/cython-dev/attachments/20091025/24830987/attachment-0001.diff From sturla at molden.no Sun Oct 25 10:37:30 2009 From: sturla at molden.no (Sturla Molden) Date: Sun, 25 Oct 2009 10:37:30 +0100 Subject: [Cython] bug in buffer syntax In-Reply-To: <4AE41444.10901@behnel.de> References: <4AE4133F.90401@molden.no> <4AE41444.10901@behnel.de> Message-ID: <4AE41C5A.6070307@molden.no> Stefan Behnel skrev: >> np.ndarray[double, ndim=2] array >> >> then &(array[row,0]) and &(array[0,column]) is a trick to get a pointer >> to a row or a column. >> >> Strangely, the expression is only allowed in cdef functions. In Python >> callable functions, it produces the error message "Cannot take address >> of Python variable". However, the type of &(a[row,column]) is double *, >> which is not the address of a Python variable. >> > > Could you provide complete code examples for the two functions you use? > Forget it! My fault... It seems I forgot to declare a C variable. :-) S.M. From stefan_ml at behnel.de Sun Oct 25 15:33:45 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 25 Oct 2009 15:33:45 +0100 Subject: [Cython] C array support redux Message-ID: <4AE461C9.2060809@behnel.de> Hi all, the wiki has an enhancement page on better C array support. http://wiki.cython.org/enhancements/arraytypes Note that this is not about SIMD operations and whatnot, just about plain int[] x The page mentions things like dynamic memory allocation happening automatically behind the scenes, so that cdef int a[runtime_size] would locally allocate memory, as would subsequent slicing, I guess. I wonder if that's not too much magic, and if a much simpler thing wouldn't get us far enough already. Since we already agreed to get a full-featured SIMD type, what do you think about dropping the dynamic memory handling part for plain C arrays, and instead just supporting slicing operations on any C pointer type, and letting them return a Python list? (or a byte string in the special case of a char*) This would be a rather straight forward thing to support: cdef char* s = ... py_s = s[:30] It would translate directly to a call to PyString_FromStringAndSize(), which is a rather often requested feature IMO. All other base types would return a runtime-constructed list instead: cdef int* x = ... py_int_list = x[4:20:-1] This would generate a loop that creates Python int values from the slice and put them into a list, so it's basically a short form for this: py_int_list = [ int(x[i]) for i from 20 >= i > 4 by -1 ] I suggest returning a list and not a tuple here, as a list can be modified later on, which is a likely thing to happen. Having to manually copy a tuple into a new list just to be able to modify it, is a rather inefficient requirement. Using this in a loop context would also be easy to optimise, i.e. cdef int* x = ... cdef Py_ssize_t length = ... cdef int i for i in x[:length]: ... would be implemented as a C for loop from 0 to length-1, and pointer index access to get a value for i in each step (or maybe a running pointer variable, not sure what's better in C code). There are a couple of requirements for this. One is that this only works for Python compatible base types, so e.g. arrays of pointers wouldn't be supported (unless we coerce them to PyCObject/PyCapsule, but I doubt that there's a use case for that). Another bit is that we might (not sure yet) need to know the step size at compile time. I'm also not sure yet how this fits with the future SIMD type. Anyway, what do you think about this? Stefan From dalcinl at gmail.com Sun Oct 25 17:04:04 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sun, 25 Oct 2009 13:04:04 -0300 Subject: [Cython] C array support redux In-Reply-To: <4AE461C9.2060809@behnel.de> References: <4AE461C9.2060809@behnel.de> Message-ID: On Sun, Oct 25, 2009 at 11:33 AM, Stefan Behnel wrote: > Hi all, > > the wiki has an enhancement page on better C array support. > > http://wiki.cython.org/enhancements/arraytypes > > Note that this is not about SIMD operations and whatnot, just about plain > > ? ? ? ?int[] x > > The page mentions things like dynamic memory allocation happening > automatically behind the scenes, so that > > ? ? ? ?cdef int a[runtime_size] > > would locally allocate memory, as would subsequent slicing, I guess. I > wonder if that's not too much magic, and if a much simpler thing wouldn't > get us far enough already. > Stefan, I think you are missing a point here... Some of as do need automatic allocation of plain C arrays, because we want them for passing to a C function for fill-in data, or because we want to use it as temporary for intermediate computation. > > Since we already agreed to get a full-featured SIMD type, what do you think > about dropping the dynamic memory handling part for plain C arrays, > Well, I still think that automatic memory allocation for C arrays would be a REALLY nice feature... > and > instead just supporting slicing operations on any C pointer type, and > letting them return a Python list? (or a byte string in the special case of > a char*) > I'm definitely +1 about all this. But I insist: Memory allocation and fancy slicing operations for coercion to PyObject are IMO to different beasts... So you could support the "lhs = rhs[slice]" when lhs is a pyobject, but generate a Cython compile error if lhs is a C pointer/array type (perhaps making exceptions for the case of char[]/char*) until auto mem alloc is implemented. Am I missing something here? > This would be a rather straight forward thing to support: > > ? ? ? ?cdef char* s = ... > ? ? ? ?py_s = s[:30] > > It would translate directly to a call to PyString_FromStringAndSize(), > which is a rather often requested feature IMO. All other base types would > return a runtime-constructed list instead: > > ? ? ? ?cdef int* x = ... > ? ? ? ?py_int_list = x[4:20:-1] > > This would generate a loop that creates Python int values from the slice > and put them into a list, so it's basically a short form for this: > > ? ? ? ?py_int_list = [ int(x[i]) for i from 20 >= i > 4 by -1 ] > > I suggest returning a list and not a tuple here, as a list can be modified > later on, which is a likely thing to happen. Having to manually copy a > tuple into a new list just to be able to modify it, is a rather inefficient > requirement. > > Using this in a loop context would also be easy to optimise, i.e. > > ? ? ? ?cdef int* x = ... > ? ? ? ?cdef Py_ssize_t length = ... > ? ? ? ?cdef int i > > ? ? ? ?for i in x[:length]: > ? ? ? ? ? ?... > > would be implemented as a C for loop from 0 to length-1, and pointer index > access to get a value for i in each step (or maybe a running pointer > variable, not sure what's better in C code). > > There are a couple of requirements for this. One is that this only works > for Python compatible base types, so e.g. arrays of pointers wouldn't be > supported (unless we coerce them to PyCObject/PyCapsule, but I doubt that > there's a use case for that). Another bit is that we might (not sure yet) > need to know the step size at compile time. I'm also not sure yet how this > fits with the future SIMD type. > > Anyway, what do you think about this? > > Stefan > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sturla at molden.no Sun Oct 25 17:10:33 2009 From: sturla at molden.no (Sturla Molden) Date: Sun, 25 Oct 2009 17:10:33 +0100 Subject: [Cython] C array support redux In-Reply-To: <4AE461C9.2060809@behnel.de> References: <4AE461C9.2060809@behnel.de> Message-ID: <4AE47879.4020305@molden.no> Stefan Behnel skrev: > The page mentions things like dynamic memory allocation happening > automatically behind the scenes, so that > > cdef int a[runtime_size] > > would locally allocate memory, as would subsequent slicing, I guess. This by the way, can be deferred to the C or C++ compiler: C99: int a[runtime_size]; C++: std::vector dummy(runtime_size); int *const a = &dummy[0]; For ANSI C one can use the alloca function available for most compilers: C89: int *const a = (int*)alloca(runtime_size*sizeof(int)); > Since we already agreed to get a full-featured SIMD type, what do you think > about dropping the dynamic memory handling part for plain C arrays, and > instead just supporting slicing operations on any C pointer type, and > letting them return a Python list? (or a byte string in the special case of > a char*) > I have programmed a lot in Fortran 95, where this kind of slicing is available. I think slicing a pointer (if it can be done fast without Python overhead) has its merits. But I think returning Python lists are generally too expensive. I'd rather have a pointer slicing return a Py_buffer struct referencing the memory. If it is assigned to a list variable, then you get a list contructed. But if it is assigned to another sliced pointer or buffer, it should not be more expensive than a memcpy. It all depends on a full featured SIMD type. Sturla Molden From stefan_ml at behnel.de Sun Oct 25 17:29:03 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 25 Oct 2009 17:29:03 +0100 Subject: [Cython] C array support redux In-Reply-To: References: <4AE461C9.2060809@behnel.de> Message-ID: <4AE47CCF.6040901@behnel.de> Lisandro Dalcin, 25.10.2009 17:04: > So you could support the "lhs = rhs[slice]" when lhs is a > pyobject, but generate a Cython compile error if lhs is a C > pointer/array type (perhaps making exceptions for the case of > char[]/char*) until auto mem alloc is implemented. Yes, that occurred to me, too, after sending the e-mail. So it's actually a special case that should be easier to implement for the beginning, without preventing the general feature from becoming available later on. (preferably after implementing the SIMD type, so that we can see what's actually left to add). I really like how the slicing syntax fixes the "C string potentially containing \0 -> Py string" conversion, BTW. We could even support this efficiently then: cdef char* s = "some encoded C string" unicode_string = s[:1531].decode('UTF-8') That would become a straight call to PyUnicode_DecodeUTF8(s,1531,NULL). Stefan From sturla at molden.no Sun Oct 25 18:39:57 2009 From: sturla at molden.no (Sturla Molden) Date: Sun, 25 Oct 2009 18:39:57 +0100 Subject: [Cython] optimizing list.pop Message-ID: <4AE48D6D.3080503@molden.no> I just realized the Python does not provide a fast way of popping an item from a list, just append. I.e. there is a PyList_Append, but no PyList_Pop. And in Python's code for _listobject.c, the function listpop is declared static. When using a list as a stack (a common case for Python lists), a fast pop is just as important as a fast append. Since the function listpop is static, the fastest way to pop a list is to grab the method named "pop" from the PyTypeObject. This might not be obvious to everyone, so I think it is an optimization that Cython should do. Sturla Molden cdef extern from "Python.h": ctypedef object (*PyCFunction)(object self, object args) ctypedef struct PyMethodDef: char *ml_name PyCFunction ml_meth ctypedef struct PyTypeObject: PyMethodDef *tp_methods PyTypeObject PyList_Type cdef PyCFunction __listpop = NULL cpdef listpop(list self, Py_ssize_t n=-1): global __listpop cdef PyMethodDef *ptr cdef int ok = 0 if not __listpop: ptr = PyList_Type.tp_methods; while ptr: if str(ptr[0].ml_name) == "pop": __listpop = ptr.ml_meth ok = 1 break ptr += 1 if not ok: raise ValueError, \ 'Could not find method "pop" in list type object' return __listpop(self, (int(n),)) From dalcinl at gmail.com Sun Oct 25 19:53:30 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sun, 25 Oct 2009 15:53:30 -0300 Subject: [Cython] optimizing list.pop In-Reply-To: <4AE48D6D.3080503@molden.no> References: <4AE48D6D.3080503@molden.no> Message-ID: On Sun, Oct 25, 2009 at 2:39 PM, Sturla Molden wrote: > I just realized the Python does not provide a fast way of popping an > item from a list, just append. I.e. there is a PyList_Append, but no > PyList_Pop. And in Python's code for _listobject.c, the function listpop > is declared static. When using a list as a stack (a common case for > Python lists), a fast pop is just as important as a fast append. > Indeed. +1 for the idea, but... > Since the function listpop is static, the fastest way to pop a list is > to grab the method named "pop" from the PyTypeObject. This might not be > obvious to everyone, so I think it is an optimization that Cython should do. > -0.5 for the implementation... The hack is cute, but still have to make a listpop(self,args), were you need to create a tuple to make the call... I think Cython could generate a custom, inline function implementing l.pop([n]) and fast dispatch to it if the object is exactly a list ... > > > cdef extern from "Python.h": > > ? ?ctypedef object (*PyCFunction)(object self, object args) > > ? ?ctypedef struct PyMethodDef: > ? ? ? ?char *ml_name > ? ? ? ?PyCFunction ml_meth > > ? ?ctypedef struct PyTypeObject: > ? ? ? ?PyMethodDef *tp_methods > > ? ?PyTypeObject PyList_Type > > > cdef PyCFunction __listpop = NULL > > > cpdef listpop(list self, Py_ssize_t n=-1): > > ? ?global __listpop > > ? ?cdef PyMethodDef *ptr > ? ?cdef int ok = 0 > > ? ?if not __listpop: > ? ? ? ?ptr = PyList_Type.tp_methods; > ? ? ? ?while ptr: > ? ? ? ? ? ?if str(ptr[0].ml_name) == "pop": > ? ? ? ? ? ? ? __listpop = ptr.ml_meth > ? ? ? ? ? ? ? ok = 1 > ? ? ? ? ? ? ? break > ? ? ? ? ? ?ptr += 1 > ? ? ? ?if not ok: > ? ? ? ? ? ?raise ValueError, \ > ? ? ? ? ? ? ?'Could not find method "pop" in list type object' > ? ?return __listpop(self, (int(n),)) > > > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dagss at student.matnat.uio.no Sun Oct 25 20:52:38 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sun, 25 Oct 2009 20:52:38 +0100 Subject: [Cython] Relaxed run-time checks on buffer contiguity? In-Reply-To: <4AE416A6.1090201@molden.no> References: <4AE416A6.1090201@molden.no> Message-ID: <5fb064915b51e4bfe45336db0f7a4261.squirrel@webmail.uio.no> Sturla Molden wrote: > > Buffers/ndarrays declared with mode="c" or mode="fortran" will only > accept C or Fortran contiguous buffers. But the generated C code does > not assume more than contiguity in the fastest varying dimension. > > With > > a = np.zeros((10,10)) > b = a[::2, :] > > the code generated for np.ndarray[double, ndim=2, mode="c"] would work > for both a and b. That is, > > >>> import numpy as np > >>> np.zeros((10,10))[:,:].strides > (80, 8) > >>> np.zeros((10,10))[::2,:].strides > (160, 8) > > But: > > >>> np.zeros((10,10))[::2,:].flags > C_CONTIGUOUS : False <<<<< Not C contiguous!!! > F_CONTIGUOUS : False > OWNDATA : False > WRITEABLE : True > ALIGNED : True > UPDATEIFCOPY : False > > Should the run-time type-check instead just check for the stride of the > fastest varying dimension? I.e. just assert that b.strides[1] == > sizeof(double)? This could be exploited in some code to make sure a buffer is contiguous before handing it off to C or Fortran code. In that way it would break backwards compatability. Therefore I'm -1. The memoryviews (in gsoc-kurt branch) supports efficient access to buffers like np.zeros((10,10))[::2,:], so I'd rather push this question off until that is merged. Dag Sverre From dagss at student.matnat.uio.no Sun Oct 25 21:13:29 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sun, 25 Oct 2009 21:13:29 +0100 Subject: [Cython] C array support redux In-Reply-To: <4AE461C9.2060809@behnel.de> References: <4AE461C9.2060809@behnel.de> Message-ID: <607c2a95f63d3077bcc34880d2b9c62f.squirrel@webmail.uio.no> Stefan Behnel wrote: > Hi all, > > the wiki has an enhancement page on better C array support. > > http://wiki.cython.org/enhancements/arraytypes > > Note that this is not about SIMD operations and whatnot, just about plain > > int[] x > > The page mentions things like dynamic memory allocation happening > automatically behind the scenes, so that > > cdef int a[runtime_size] > > would locally allocate memory, as would subsequent slicing, I guess. I > wonder if that's not too much magic, and if a much simpler thing wouldn't > get us far enough already. > > Since we already agreed to get a full-featured SIMD type, what do you > think > about dropping the dynamic memory handling part for plain C arrays, and > instead just supporting slicing operations on any C pointer type, and > letting them return a Python list? (or a byte string in the special case > of > a char*) > > This would be a rather straight forward thing to support: > > cdef char* s = ... > py_s = s[:30] > > It would translate directly to a call to PyString_FromStringAndSize(), > which is a rather often requested feature IMO. All other base types would > return a runtime-constructed list instead: > > cdef int* x = ... > py_int_list = x[4:20:-1] > > This would generate a loop that creates Python int values from the slice > and put them into a list, so it's basically a short form for this: > > py_int_list = [ int(x[i]) for i from 20 >= i > 4 by -1 ] Hmm. Interesting idea. My initial feeling as well is that I'd expect x[2:40] to: a) Return an object which directly indexes C integers instead of doing object conversions b) Perhaps: Refer to the original memory? The two are orthogonal, and b) is certainly due to me mixing NumPy-ness and Pythonicness -- copying on slicing is more Pythonic, after all. At any rate, it should be possible to do for my_typed_var in x[:10]: ... without object conversions, and the cleanest way of going about that seems to be a). For instance one could make a copy of the data and put it in an array.array. As far as the Cython memoryview type goes (which over the summer became the name for the "Cython numerical array type"... since it is so close to Python's memoryview: Slices returns new views, not copies): I think it would feel natural to have myptr[0:54,0:10] simply turn the pointer into a memoryview. However I'm not at all going to fight over this corner of the syntax for numerical use -- for numerical use an explicit function like cython.memoryview(myptr, (54, 10), owned=False) works just as well I think. Dag Sverre From dagss at student.matnat.uio.no Sun Oct 25 21:26:56 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Sun, 25 Oct 2009 21:26:56 +0100 Subject: [Cython] C array support redux In-Reply-To: <4AE461C9.2060809@behnel.de> References: <4AE461C9.2060809@behnel.de> Message-ID: Stefan Behnel wrote: > This would be a rather straight forward thing to support: > > cdef char* s = ... > py_s = s[:30] > > It would translate directly to a call to PyString_FromStringAndSize(), > which is a rather often requested feature IMO. All other base types would > return a runtime-constructed list instead: > > cdef int* x = ... > py_int_list = x[4:20:-1] > > This would generate a loop that creates Python int values from the slice > and put them into a list, so it's basically a short form for this: > > py_int_list = [ int(x[i]) for i from 20 >= i > 4 by -1 ] After a little more thinking here's another perspective: a) I support turning charptr[:length] into bytes w/ explicit length, because I feel that's something Cython should be able to handle more gracefully. b) However I'm really doubting the extension to other types than char*. It's going to be a different case (bytes and a list or array or memoryview are very different types), and: Python is not Perl!! That is: The Python philosophy has always been that a few characters extra to express something is preferable to having too many concepts to learn in the language. I feel intptr[a:b:c] contradict this: It is a feature which it probably takes longer to learn about than to write the perfectly good list comprehension manually, and Python is well known to not add syntax candy in such cases. Therefore I don't think Cython should either. Dag Sverre From stefan_ml at behnel.de Sun Oct 25 21:38:49 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 25 Oct 2009 21:38:49 +0100 Subject: [Cython] C array support redux In-Reply-To: References: <4AE461C9.2060809@behnel.de> Message-ID: <4AE4B759.2030202@behnel.de> Dag Sverre Seljebotn, 25.10.2009 21:26: > Stefan Behnel wrote: >> This would be a rather straight forward thing to support: >> >> cdef char* s = ... >> py_s = s[:30] >> >> It would translate directly to a call to PyString_FromStringAndSize(), >> which is a rather often requested feature IMO. All other base types would >> return a runtime-constructed list instead: >> >> cdef int* x = ... >> py_int_list = x[4:20:-1] >> >> This would generate a loop that creates Python int values from the slice >> and put them into a list, so it's basically a short form for this: >> >> py_int_list = [ int(x[i]) for i from 20 >= i > 4 by -1 ] > > After a little more thinking here's another perspective: > > a) I support turning charptr[:length] into bytes w/ explicit length, > because I feel that's something Cython should be able to handle more > gracefully. Here we go: http://trac.cython.org/cython_trac/ticket/436 http://hg.cython.org/cython-devel/rev/57fa28d3b2e2 Note that this only supports "char*.decode()" for now, the other cases can be added later, i.e. the mapping to PyString_FromStringAndSize(), and the for-in loop support (which should actually be independent of the base type). > b) However I'm really doubting the extension to other types than char*. > It's going to be a different case (bytes and a list or array or memoryview > are very different types), and: Python is not Perl!! That is: The Python > philosophy has always been that a few characters extra to express > something is preferable to having too many concepts to learn in the > language. > > I feel intptr[a:b:c] contradict this: It is a feature which it probably > takes longer to learn about than to write the perfectly good list > comprehension manually, and Python is well known to not add syntax candy > in such cases. Therefore I don't think Cython should either. I don't quite buy that argument. When coercing to a Python object, a list sounds perfectly reasonable to me. But let's rediscuss this later, when we have a SIMD type, and when we see if it makes sense to use it for this use case also, or if other means seem more appropriate. Stefan From stefan_ml at behnel.de Mon Oct 26 07:34:13 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 26 Oct 2009 07:34:13 +0100 Subject: [Cython] C array support redux In-Reply-To: <4AE4B759.2030202@behnel.de> References: <4AE461C9.2060809@behnel.de> <4AE4B759.2030202@behnel.de> Message-ID: <4AE542E5.7080302@behnel.de> Stefan Behnel, 25.10.2009 21:38: > Dag Sverre Seljebotn, 25.10.2009 21:26: >> a) I support turning charptr[:length] into bytes w/ explicit length, >> because I feel that's something Cython should be able to handle more >> gracefully. > > Note that this only supports "char*.decode()" for now, the other cases can > be added later, i.e. the mapping to PyString_FromStringAndSize() [...] Oh well, I should have checked before posting. That part is already there, and seeing the code, I even remembered that Robert implemented that at the time. Ok, nothing to see here, keep moving ... Stefan From stefan_ml at behnel.de Mon Oct 26 09:07:46 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 26 Oct 2009 09:07:46 +0100 Subject: [Cython] C array support redux In-Reply-To: <4AE47879.4020305@molden.no> References: <4AE461C9.2060809@behnel.de> <4AE47879.4020305@molden.no> Message-ID: <4AE558D2.9020601@behnel.de> Sturla Molden, 25.10.2009 17:10: > Stefan Behnel skrev: >> The page mentions things like dynamic memory allocation happening >> automatically behind the scenes, so that >> >> cdef int a[runtime_size] >> >> would locally allocate memory, as would subsequent slicing, I guess. > This by the way, can be deferred to the C or C++ compiler: > > C99: int a[runtime_size]; > > C++: std::vector dummy(runtime_size); > int *const a = &dummy[0]; > > For ANSI C one can use the alloca function available for most compilers: > > C89: int *const a = (int*)alloca(runtime_size*sizeof(int)); Yes, there are two types of arrays: those that only live inside of a function, and those that leave the function context in one way or another. The above would be nice for the first, whereas the wiki page refers more to a ref-counted array type. That's why I said that the SIMD type would eliminate most of that requirement. >> Since we already agreed to get a full-featured SIMD type, what do you think >> about dropping the dynamic memory handling part for plain C arrays, and >> instead just supporting slicing operations on any C pointer type, and >> letting them return a Python list? (or a byte string in the special case of >> a char*) >> > I have programmed a lot in Fortran 95, where this kind of slicing is > available. I think slicing a pointer (if it can be done fast without > Python overhead) has its merits. But I think returning Python lists are > generally too expensive. I'd rather have a pointer slicing return a > Py_buffer struct referencing the memory. ... which would, in turn, require some kind of memory management for the Py_buffer, so that's not any better than the SIMD type. > If it is assigned to a list > variable, then you get a list contructed. That would require a typed list variable, though. There should also be a default way of coercing a C array to a Python object. I find a list the least surprising here, although a view object would certainly be more efficient, with the obvious drawback of requiring the array to stay alive at least as long as the view. Stefan From vinjvinj at gmail.com Mon Oct 26 16:26:25 2009 From: vinjvinj at gmail.com (Vineet Jain) Date: Mon, 26 Oct 2009 11:26:25 -0400 Subject: [Cython] Are there any plans to support yield? Message-ID: <003b01ca5650$afc89110$0f59b330$@com> I've been wanting to migrate my code to cython, however, there is no support for yield. Are there any plans to support the yield statement. If so, any idea on approximately when (3 months, 6 months, 12 months)? Thanks, Vineet -------------- next part -------------- An HTML attachment was scrubbed... URL: http://codespeak.net/pipermail/cython-dev/attachments/20091026/ecad363c/attachment.htm From stefan_ml at behnel.de Mon Oct 26 17:03:57 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Mon, 26 Oct 2009 17:03:57 +0100 Subject: [Cython] Are there any plans to support yield? In-Reply-To: <003b01ca5650$afc89110$0f59b330$@com> References: <003b01ca5650$afc89110$0f59b330$@com> Message-ID: <4AE5C86D.7060209@behnel.de> Vineet Jain, 26.10.2009 16:26: > I've been wanting to migrate my code to cython, however, there is no support > for yield. Are there any plans to support the yield statement. Absolutely. http://trac.cython.org/cython_trac/ticket/83 > If so, any idea on approximately when (3 months, 6 months, 12 months)? The support for closures and inner functions is still relatively new and hasn't been in a mainline version yet. Adding yield support on top of that isn't exactly trivial, but it's mostly clear how to do it. Any schedule depends on how much work we put into it and how much help we get. Any contribution is appreciated. Stefan From robertwb at math.washington.edu Mon Oct 26 19:09:38 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 26 Oct 2009 11:09:38 -0700 Subject: [Cython] C array support redux In-Reply-To: <4AE461C9.2060809@behnel.de> References: <4AE461C9.2060809@behnel.de> Message-ID: On Oct 25, 2009, at 7:33 AM, Stefan Behnel wrote: > Hi all, > > the wiki has an enhancement page on better C array support. > > http://wiki.cython.org/enhancements/arraytypes > > Note that this is not about SIMD operations and whatnot, just about > plain > > int[] x > > The page mentions things like dynamic memory allocation happening > automatically behind the scenes, so that > > cdef int a[runtime_size] > > would locally allocate memory, as would subsequent slicing, I guess. I > wonder if that's not too much magic, and if a much simpler thing > wouldn't > get us far enough already. I think dynamic memory allocation is the primary advantage of such a type, though the proposed SIMD type would meet these needs as well. > Since we already agreed to get a full-featured SIMD type, what do > you think > about dropping the dynamic memory handling part for plain C arrays, > and > instead just supporting slicing operations on any C pointer type, and > letting them return a Python list? (or a byte string in the special > case of > a char*) > > This would be a rather straight forward thing to support: > > cdef char* s = ... > py_s = s[:30] > > It would translate directly to a call to PyString_FromStringAndSize(), > which is a rather often requested feature IMO. All other base types > would > return a runtime-constructed list instead: > > cdef int* x = ... > py_int_list = x[4:20:-1] > > This would generate a loop that creates Python int values from the > slice > and put them into a list, so it's basically a short form for this: > > py_int_list = [ int(x[i]) for i from 20 >= i > 4 by -1 ] > > I suggest returning a list and not a tuple here, as a list can be > modified > later on, which is a likely thing to happen. Having to manually copy a > tuple into a new list just to be able to modify it, is a rather > inefficient > requirement. While turning them into a list may be useful, we should consider if this will be backwards incompatible with conversion to a SIMD/memory type. What could be more safely (and explicitly) done is cdef int* x py_int_list = list(x[4:20:-1]) or py_int_list = tuple(x[4:20:-1]) with conversion to object still left for future debate. > Using this in a loop context would also be easy to optimise, i.e. > > cdef int* x = ... > cdef Py_ssize_t length = ... > cdef int i > > for i in x[:length]: > ... > > would be implemented as a C for loop from 0 to length-1, and pointer > index > access to get a value for i in each step (or maybe a running pointer > variable, not sure what's better in C code). I see no reason why we couldn't already optimize such a loop, even for non-python compatible types i. I'd like to note that stack-allocated memory is a very non-pythonic thing, and I've seen a lot of Cython users tripped up by it, so I'm not sure how much we should encourage it/make it easy (though optimizing it when we know it's safe could be valuable to do). - Robert From dagss at student.matnat.uio.no Mon Oct 26 19:59:24 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Mon, 26 Oct 2009 19:59:24 +0100 Subject: [Cython] C array support redux In-Reply-To: References: <4AE461C9.2060809@behnel.de> Message-ID: <4AE5F18C.3030702@student.matnat.uio.no> Robert Bradshaw wrote: > On Oct 25, 2009, at 7:33 AM, Stefan Behnel wrote: > >> Hi all, >> >> the wiki has an enhancement page on better C array support. >> >> http://wiki.cython.org/enhancements/arraytypes >> >> Note that this is not about SIMD operations and whatnot, just about >> plain >> >> int[] x >> >> The page mentions things like dynamic memory allocation happening >> automatically behind the scenes, so that >> >> cdef int a[runtime_size] >> >> would locally allocate memory, as would subsequent slicing, I guess. I >> wonder if that's not too much magic, and if a much simpler thing >> wouldn't >> get us far enough already. > > I think dynamic memory allocation is the primary advantage of such a > type, though the proposed SIMD type would meet these needs as well. Just a few notes on terminology (and feel free to protest if you think this is wrong): a) Me and Kurt decided to use the name "memoryview" everywhere in the code written in summer. The essential feature of the proposed Cython type described in enhancements/array is a) a view to a reference-counted PEP 3118 buffer, b) slices returns new sub-views. This is exactly what the Python memoryview type does. Cython adds static typing to this, but we decided to also name the Cython concept memoryview. b) There was a recent discussion on numpy-discuss where people reacted on using the term SIMD for anything but CPU SIMD (i.e. many people understand "Instruction" in SIMD to refer exclusively to CPU instructions). Some voiced opposition to this view as well, but to avoid any ambiguity I suppose "vectorized operation" is the most neutral (and that's got nothing to do with the vectors of linear algebra! As I've said in other places, some of my vectors are sometimes stored as 2D arrays and some of my matrices in 1D arrays...) If I don't get a response to this I'll update the wiki accordingly. -- Dag Sverre From robertwb at math.washington.edu Tue Oct 27 01:49:33 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Mon, 26 Oct 2009 17:49:33 -0700 Subject: [Cython] C array support redux In-Reply-To: <4AE5F18C.3030702@student.matnat.uio.no> References: <4AE461C9.2060809@behnel.de> <4AE5F18C.3030702@student.matnat.uio.no> Message-ID: <181B196D-7252-450F-8C20-26665C357447@math.washington.edu> On Oct 26, 2009, at 11:59 AM, Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: >> On Oct 25, 2009, at 7:33 AM, Stefan Behnel wrote: >> >>> Hi all, >>> >>> the wiki has an enhancement page on better C array support. >>> >>> http://wiki.cython.org/enhancements/arraytypes >>> >>> Note that this is not about SIMD operations and whatnot, just about >>> plain >>> >>> int[] x >>> >>> The page mentions things like dynamic memory allocation happening >>> automatically behind the scenes, so that >>> >>> cdef int a[runtime_size] >>> >>> would locally allocate memory, as would subsequent slicing, I >>> guess. I >>> wonder if that's not too much magic, and if a much simpler thing >>> wouldn't >>> get us far enough already. >> >> I think dynamic memory allocation is the primary advantage of such a >> type, though the proposed SIMD type would meet these needs as well. > > Just a few notes on terminology (and feel free to protest if you think > this is wrong): > > a) Me and Kurt decided to use the name "memoryview" everywhere in the > code written in summer. The essential feature of the proposed Cython > type described in enhancements/array is a) a view to a reference- > counted > PEP 3118 buffer, b) slices returns new sub-views. This is exactly what > the Python memoryview type does. Cython adds static typing to this, > but > we decided to also name the Cython concept memoryview. > > b) There was a recent discussion on numpy-discuss where people > reacted > on using the term SIMD for anything but CPU SIMD (i.e. many people > understand "Instruction" in SIMD to refer exclusively to CPU > instructions). Some voiced opposition to this view as well, but to > avoid > any ambiguity I suppose "vectorized operation" is the most neutral > (and > that's got nothing to do with the vectors of linear algebra! As I've > said in other places, some of my vectors are sometimes stored as 2D > arrays and some of my matrices in 1D arrays...) > > If I don't get a response to this I'll update the wiki accordingly. I'm fine with either name--I just would like to have something fast and simple that doesn't require any dependancies. - Robert From vel.accel at gmail.com Tue Oct 27 07:43:36 2009 From: vel.accel at gmail.com (Peter Alexander) Date: Tue, 27 Oct 2009 02:43:36 -0400 Subject: [Cython] Docs Message-ID: <1e52e0880910262343q485cb41dtff82b6d142fadb6f@mail.gmail.com> Hi all. The last couple of weeks have been tough ones for me which is why I haven't been visible. My responsibilities here have increased and put additional pressure on my time. So I'm sorry to say that I can't put more effort into the Cython docs at this time. I sincerely apologize for that because I feel that they are an important issue that I really wanted to contribute to. I think Cython is a very worthy project and I have great respect for you who are contributing to it. In the future, when I can I'd like to help out more. I did get some work done on the docs that is substantial, but by no means complete and is publicly available for download [1]. I hope that someone else, who uses Cython, will pick up the batton and run with it. I say this because I feel Cython is very important to the entire Python community. Peter Alexander [1] http://bitbucket.org/travlr/cython-docs/ From stefan_ml at behnel.de Tue Oct 27 08:20:02 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Oct 2009 08:20:02 +0100 Subject: [Cython] C array support redux In-Reply-To: References: <4AE461C9.2060809@behnel.de> Message-ID: <4AE69F22.20904@behnel.de> Robert Bradshaw, 26.10.2009 19:09: > On Oct 25, 2009, at 7:33 AM, Stefan Behnel wrote: >> cdef int* x = ... >> py_int_list = x[4:20:-1] >> >> basically a short form for this: >> >> py_int_list = [ int(x[i]) for i from 20 >= i > 4 by -1 ] > > While turning them into a list may be useful, we should consider if > this will be backwards incompatible with conversion to a SIMD/memory > type. What could be more safely (and explicitly) done is > > cdef int* x > py_int_list = list(x[4:20:-1]) > > or > > py_int_list = tuple(x[4:20:-1]) Makes sense to me. We optimise many similar calls already, so IMO that's the perfect way of spelling it. > with conversion to object still left for future debate. ACK. That's easy to defer, given that it currently fails at compile time. >> Using this in a loop context would also be easy to optimise, i.e. >> >> cdef int* x = ... >> cdef Py_ssize_t length = ... >> cdef int i >> >> for i in x[:length]: >> ... >> >> would be implemented as a C for loop from 0 to length-1, and pointer >> index >> access to get a value for i in each step (or maybe a running pointer >> variable, not sure what's better in C code). > > I see no reason why we couldn't already optimize such a loop, even for > non-python compatible types i. Well, I have working code to make this efficient: cdef char* s = "...." for c in s[:100]: print c and, for example, this also runs as a C loop: cdef char* s = "...." for i,c in enumerate(s[:100]): print i,c However, both are cases where it already works, but for which it currently creates a Python byte string first to iterate over that. It doesn't currently work for types like int[], because the ForInLoopNode already tries to coerce the iterable to a Python object before we even get to optimise it. Removing that restriction for C arrays would mean to duplicate the decision if this can be optimised or not into both the loop node and the optimisation transformation. Not exactly beautiful. Plus, preventing "enumerate(int_array[:100])" from failing during type analysis is a very non-local change. The only two solutions I see here are 1) to somehow do the optimisations between analysing and coercing the iterable subtree type or 2) to exclude some subtree types from coercion and handle them entirely in the optimisation phase (or a later error detection phase etc). The latter is certainly hard to keep in tolerable bounds. 1) sounds cleaner but may mean moving the loop optimisations from the current transformation back into the type analysis phase, and use special NextNode/IteratorNode classes for the special cases. Not exactly something for a happy hour of coding. Since none of this is actually trivial (and entirely safe), I guess this is a candidate for at least 0.12.1 or 0.13, not 0.12. Any objections to add at least the char* optimisation above for 0.12? The only thing it adds is that this: cdef char* s = "...." cdef int c for c in s[:100]: print c will now print the byte values of each char in s (which IMO makes sense), whereas it failed before as the loop iterable was a Python string. > I'd like to note that stack-allocated memory is a very non-pythonic > thing, and I've seen a lot of Cython users tripped up by it, so I'm > not sure how much we should encourage it/make it easy (though > optimizing it when we know it's safe could be valuable to do). At least, it's been a source for vulnerable programs for ages, so I agree that encouraging it isn't really the right thing to do. Stefan From stefan_ml at behnel.de Tue Oct 27 08:37:33 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Oct 2009 08:37:33 +0100 Subject: [Cython] C array support redux In-Reply-To: <4AE5F18C.3030702@student.matnat.uio.no> References: <4AE461C9.2060809@behnel.de> <4AE5F18C.3030702@student.matnat.uio.no> Message-ID: <4AE6A33D.70201@behnel.de> Dag Sverre Seljebotn, 26.10.2009 19:59: > a) Me and Kurt decided to use the name "memoryview" everywhere in the > code written in summer. The essential feature of the proposed Cython > type described in enhancements/array is a) a view to a reference-counted > PEP 3118 buffer, b) slices returns new sub-views. This is exactly what > the Python memoryview type does. Cython adds static typing to this, but > we decided to also name the Cython concept memoryview. Is it just the "concept", or also the type itself? I just want to make sure people can cdef memoryview m to use the Python memoryview type without having it fail or do something unexpected, just like they use cdef list l > b) There was a recent discussion on numpy-discuss where people reacted > on using the term SIMD for anything but CPU SIMD (i.e. many people > understand "Instruction" in SIMD to refer exclusively to CPU > instructions). Some voiced opposition to this view as well, but to avoid > any ambiguity I suppose "vectorized operation" is the most neutral Fine with me. Stefan From dagss at student.matnat.uio.no Tue Oct 27 11:50:48 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Tue, 27 Oct 2009 11:50:48 +0100 Subject: [Cython] C array support redux In-Reply-To: <4AE6A33D.70201@behnel.de> References: <4AE461C9.2060809@behnel.de> <4AE5F18C.3030702@student.matnat.uio.no> <4AE6A33D.70201@behnel.de> Message-ID: <4AE6D088.2010901@student.matnat.uio.no> Stefan Behnel wrote: > Dag Sverre Seljebotn, 26.10.2009 19:59: >> a) Me and Kurt decided to use the name "memoryview" everywhere in the >> code written in summer. The essential feature of the proposed Cython >> type described in enhancements/array is a) a view to a reference-counted >> PEP 3118 buffer, b) slices returns new sub-views. This is exactly what >> the Python memoryview type does. Cython adds static typing to this, but >> we decided to also name the Cython concept memoryview. > > Is it just the "concept", or also the type itself? > > I just want to make sure people can > > cdef memoryview m > > to use the Python memoryview type without having it fail or do something > unexpected, just like they use > > cdef list l Sure, that will still work (if memoryview is added as a builtin type), we don't plan to interfer at all there. -- Dag Sverre From stefan_ml at behnel.de Tue Oct 27 12:58:39 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Tue, 27 Oct 2009 12:58:39 +0100 Subject: [Cython] C array support redux In-Reply-To: <4AE69F22.20904@behnel.de> References: <4AE461C9.2060809@behnel.de> <4AE69F22.20904@behnel.de> Message-ID: <4AE6E06F.2080109@behnel.de> Stefan Behnel, 27.10.2009 08:20: > I have working code to make this efficient: > > cdef char* s = "...." > for c in s[:100]: > print c > > and, for example, this also runs as a C loop: > > cdef char* s = "...." > for i,c in enumerate(s[:100]): > print i,c > > [...] > Any objections to add at least the char* optimisation above for 0.12? http://trac.cython.org/cython_trac/ticket/437 http://hg.cython.org/cython-devel/rev/1c46918cef48 Stefan From stefan at sun.ac.za Tue Oct 27 14:15:16 2009 From: stefan at sun.ac.za (=?ISO-8859-1?Q?St=E9fan_van_der_Walt?=) Date: Tue, 27 Oct 2009 15:15:16 +0200 Subject: [Cython] npy_intp in numpy.pxd Message-ID: <9457e7c80910270615i285106dfrabbc2b4c88e41bf6@mail.gmail.com> Hi all, The numpy.pxd included with Cython currently defines npy_intp, so that we can use it as cimport numpy as np np.npy_intp However, all the other types are defined as np.type_t, e.g., np.int_t. Would you mind adding np.intp_t and np.uintp_t (while keeping np.npy_intp for backwards compatibility)? As a side note, it may be safer to use the definitions of npy_intp and npy_uintp from the numpy header, rather than Py_ssize_t and Py_size_t. In some earlier versions of Python (e.g., 2.4), these were not the same. Then, I also have a quick question: why is a person allowed to do cdef extern from something: ctypedef int Py_ssize_t when Py_ssize_t is not an int? Is this a Cython-specific idea? Thanks! St?fan From dagss at student.matnat.uio.no Tue Oct 27 14:55:02 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Tue, 27 Oct 2009 14:55:02 +0100 Subject: [Cython] npy_intp in numpy.pxd In-Reply-To: <9457e7c80910270615i285106dfrabbc2b4c88e41bf6@mail.gmail.com> References: <9457e7c80910270615i285106dfrabbc2b4c88e41bf6@mail.gmail.com> Message-ID: <4AE6FBB6.9010103@student.matnat.uio.no> St?fan van der Walt wrote: > Hi all, > > The numpy.pxd included with Cython currently defines npy_intp, so that > we can use it as > > cimport numpy as np > np.npy_intp > > However, all the other types are defined as np.type_t, e.g., np.int_t. > Would you mind adding np.intp_t and np.uintp_t (while keeping > np.npy_intp for backwards compatibility)? Hmm. Yes. Basically the idea is that a) npy_X corresponds directly to the C API b) X_t corresponds to the runtime dtype t So, there's intp_t and uintp_t lacking for b). Can't push right now so keep nagging me if I don't. > As a side note, it may be safer to use the definitions of npy_intp and > npy_uintp from the numpy header, rather than Py_ssize_t and Py_size_t. > In some earlier versions of Python (e.g., 2.4), these were not the > same. Yep, ctypedef npy_intp intp_t and so on. > > Then, I also have a quick question: why is a person allowed to do > > cdef extern from something: > ctypedef int Py_ssize_t > > when Py_ssize_t is not an int? Is this a Cython-specific idea? Cython makes few assumptions about the size of external typedef types. Basically "Py_ssize_t" is carried through to C verbatim.... So the idea is that Cython should not rely on the size of external typedefs to be properly specified. This is what makes int32_t and friends work at all. However this is a somewhat inconsistent idea which is not followed everywhere in Cython, and every attempt to resolve it properly has been aborted. So that kind of code will fail e.g. on integer division :-( So this is something that must still be resolved but "mostly works OK" :-( (BTW Py_ssize_t is now a builtin type in Cython, but I'm discussing the idea in general.) -- Dag Sverre From dagss at student.matnat.uio.no Tue Oct 27 20:18:57 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Tue, 27 Oct 2009 20:18:57 +0100 Subject: [Cython] npy_intp in numpy.pxd In-Reply-To: <4AE6FBB6.9010103@student.matnat.uio.no> References: <9457e7c80910270615i285106dfrabbc2b4c88e41bf6@mail.gmail.com> <4AE6FBB6.9010103@student.matnat.uio.no> Message-ID: <4AE747A1.7020101@student.matnat.uio.no> Dag Sverre Seljebotn wrote: > St?fan van der Walt wrote: > >> Hi all, >> >> The numpy.pxd included with Cython currently defines npy_intp, so that >> we can use it as >> >> cimport numpy as np >> np.npy_intp >> >> However, all the other types are defined as np.type_t, e.g., np.int_t. >> Would you mind adding np.intp_t and np.uintp_t (while keeping >> np.npy_intp for backwards compatibility)? >> > > Hmm. Yes. > > Basically the idea is that > a) npy_X corresponds directly to the C API > b) X_t corresponds to the runtime dtype t > > So, there's intp_t and uintp_t lacking for b). Can't push right now so > keep nagging me if I don't. > Done! Dag Sverre > >> As a side note, it may be safer to use the definitions of npy_intp and >> npy_uintp from the numpy header, rather than Py_ssize_t and Py_size_t. >> In some earlier versions of Python (e.g., 2.4), these were not the >> same. >> > > Yep, > > ctypedef npy_intp intp_t > > and so on. > > >> Then, I also have a quick question: why is a person allowed to do >> >> cdef extern from something: >> ctypedef int Py_ssize_t >> >> when Py_ssize_t is not an int? Is this a Cython-specific idea? >> > > Cython makes few assumptions about the size of external typedef types. > Basically "Py_ssize_t" is carried through to C verbatim.... So the idea > is that Cython should not rely on the size of external typedefs to be > properly specified. This is what makes int32_t and friends work at all. > > However this is a somewhat inconsistent idea which is not followed > everywhere in Cython, and every attempt to resolve it properly has been > aborted. So that kind of code will fail e.g. on integer division :-( > > So this is something that must still be resolved but "mostly works OK" :-( > > (BTW Py_ssize_t is now a builtin type in Cython, but I'm discussing the > idea in general.) > > From sturla at molden.no Tue Oct 27 22:16:07 2009 From: sturla at molden.no (Sturla Molden) Date: Tue, 27 Oct 2009 22:16:07 +0100 Subject: [Cython] npy_intp in numpy.pxd In-Reply-To: <9457e7c80910270615i285106dfrabbc2b4c88e41bf6@mail.gmail.com> References: <9457e7c80910270615i285106dfrabbc2b4c88e41bf6@mail.gmail.com> Message-ID: <4AE76317.1030601@molden.no> St?fan van der Walt skrev: > > As a side note, it may be safer to use the definitions of npy_intp and > npy_uintp from the numpy header, rather than Py_ssize_t and Py_size_t. > In some earlier versions of Python (e.g., 2.4), these were not the > same. > No. You should use Py_ssize_t for indexing. The reason is that the C standard does not guarantee that sizeof(void*) == sizeof(size_t), and there are platforms where this evaluates to false. That is why Python core uses Py_ssize_t instead of Py_intptr_t for indexing sequence types (cf. PEP 353). The Py_intptr_t/npy_intp is long enough to hold a void*; the indexer should have the same size as size_t, thus Py_ssize_t. The use of npy_intp as indexer in NumPy is a C coding error. It accidentally works on computers with flat memory space, e.g. 32 bit x86 and x64. Although platforms with flat memory are common, it should not be encouraged. > Then, I also have a quick question: why is a person allowed to do > > cdef extern from something: > ctypedef int Py_ssize_t > > when Py_ssize_t is not an int? Is this a Cython-specific idea? > Because it "behaves like an int", the only difference being the size. But sizeof() is evaluated by the C compiler, which knows the true size of int and Py_ssize_t. Sturla Molden From sturla at molden.no Tue Oct 27 22:46:08 2009 From: sturla at molden.no (Sturla Molden) Date: Tue, 27 Oct 2009 22:46:08 +0100 Subject: [Cython] Syntax highlighting for Cython and NumPy Message-ID: <4AE76A20.2060405@molden.no> Here is an XML for Cython syntax highlighting in katepart (e.g. KATE and KDevelop). I made this because KATE is my faviourite text edior (feel free to call me a heretic for not using emacs). Unfortunately, the Python highlighting for KDE contains several bugs. And the Pyrex/Cython version that circulates on the web builds on this and introduces a couple more. I have tried to clean it up. Note that this will also highlight numpy.* or np.*, if * is a type or function you get from "cimport numpy" or "import numpy". This works on Windows as well, if you have installed KDE for Windows. Just copy the XML to: ~/.kde/share/apps/katepart/syntax/ C:\kde\share\apps\katepart\syntax (or whereever you have KDE installed) and "Cython with NumPy" shows up under Sources. Anyway, this is the syntax high-lighter I use to write Cython. Feel free to use it as you wish. P.S. I am also cleaning up Python high-lighting for KDE. Not done yet, but I will post a "Python with NumPy" highlighter later on if this is interesting. P.P.S. This also covers Pyrex, but add in some Cython stuff. Sturla Molden -------------- next part -------------- A non-text attachment was scrubbed... Name: cython.xml Type: text/xml Size: 34481 bytes Desc: not available Url : http://codespeak.net/pipermail/cython-dev/attachments/20091027/fe8112cf/attachment-0001.bin From sturla at molden.no Tue Oct 27 23:31:55 2009 From: sturla at molden.no (Sturla Molden) Date: Tue, 27 Oct 2009 23:31:55 +0100 Subject: [Cython] Syntax highlighting for Cython and NumPy In-Reply-To: <4AE76A20.2060405@molden.no> References: <4AE76A20.2060405@molden.no> Message-ID: <4AE774DB.4020209@molden.no> Sturla Molden skrev: > > and "Cython with NumPy" shows up under Sources. Anyway, this is the > syntax high-lighter I use to write Cython. It seems I posted the wrong file. :-( S.M. -------------- next part -------------- A non-text attachment was scrubbed... Name: cython.xml Type: text/xml Size: 34521 bytes Desc: not available Url : http://codespeak.net/pipermail/cython-dev/attachments/20091027/9a1e5c83/attachment.bin From dalcinl at gmail.com Wed Oct 28 00:14:36 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Tue, 27 Oct 2009 20:14:36 -0300 Subject: [Cython] Syntax highlighting for Cython and NumPy In-Reply-To: <4AE774DB.4020209@molden.no> References: <4AE76A20.2060405@molden.no> <4AE774DB.4020209@molden.no> Message-ID: Is there any specific naming convention for these XML files to work with KATE? Would it be fine to call it 'cython-mode-kate.xml' to push it to the repo? Will it still work (I mean, with that name) when placed appropriately in KATE config dirs or whatever? ... Just concerned that 'cython.xml' is a bit too generic filename... On Tue, Oct 27, 2009 at 7:31 PM, Sturla Molden wrote: > Sturla Molden skrev: >> >> and "Cython with NumPy" shows up under Sources. Anyway, this is the syntax >> high-lighter I use to write Cython. > > It seems I posted the wrong file. :-( > > S.M. > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > > -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sturla at molden.no Wed Oct 28 00:25:36 2009 From: sturla at molden.no (Sturla Molden) Date: Wed, 28 Oct 2009 00:25:36 +0100 Subject: [Cython] Syntax highlighting for Cython and NumPy In-Reply-To: References: <4AE76A20.2060405@molden.no> <4AE774DB.4020209@molden.no> Message-ID: <4AE78170.4040601@molden.no> Lisandro Dalcin skrev: > Is there any specific naming convention for these XML files to work > with KATE? Would it be fine to call it 'cython-mode-kate.xml' to push > it to the repo? Will it still work (I mean, with that name) when > placed appropriately in KATE config dirs or whatever? ... Just > concerned that 'cython.xml' is a bit too generic filename... > > You can name it anything you want. The file has an entry like this: References: <4AE76A20.2060405@molden.no> <4AE774DB.4020209@molden.no> Message-ID: <9A30BEDC-C958-4DCB-8E66-2D8012FC4980@math.washington.edu> Thanks! This has been a much requested feature. Could we include this in the cython repo? (Maybe in the tools directory?) - Robert On Oct 27, 2009, at 3:31 PM, Sturla Molden wrote: > Sturla Molden skrev: >> >> and "Cython with NumPy" shows up under Sources. Anyway, this is the >> syntax high-lighter I use to write Cython. > It seems I posted the wrong file. :-( > > S.M. > > > > > > > > > section="Sources" extensions="*.pyx;*.pxi;*.pxd" > mimetype="application/x-cython;text/x-cython" casesensitive="1" > author="Sturla Molden" license=""> > > > as > > > cimport > import > from > as > > > DEF > IF > ELIF > ELSE > include > > > class > cdef > cpdef > extern > ctypedef > def > del > global > lambda > struct > enum > property > readonly > public > nogil > gil > inline > > > and > assert > in > is > not > or > sizeof > > > > print > > > break > continue > elif > else > except > finally > for > if > pass > raise > return > try > while > with > > > > __import__ > abs > all > any > apply > basestring > buffer > callable > chr > classmethod > cmp > coerce > compile > delattr > dir > divmod > enumerate > eval > execfile > filter > getattr > > hasattr > hash > hex > id > input > intern > isinstance > issubclass > iter > len > > map > max > min > oct > open > ord > pow > > range > raw_input > reduce > reload > repr > reversed > round > setattr > sorted > staticmethod > sum > super > type > unichr > unicode > > xrange > zip > > > > unsigned > void > enum > double > long > short > char > Py_ssize_t > Py_intptr_t > Py_buffer > bint > > > > int > float > object > list > tuple > str > dict > set > frozenset > slice > bool > complex > file > > > > np > numpy > > > numpy > > > cython > > > dtype > flatiter > broadcast > ndarray > int8_t > int16_t > int32_t > int64_t > uint8_t > uint16_t > uint32_t > uint64_t > float32_t > float64_t > complex64_t > complex128_t > int_t > long_t > uint_t > ulong_t > float_t > double_t > longdouble_t > cfloat_t > cdouble_t > clongdouble_t > complex_t > npy_int8 > npy_int16 > npy_int32 > npy_int64 > npy_int96 > npy_int128 > npy_uint8 > npy_uint16 > npy_uint32 > npy_uint64 > npy_uint96 > npy_uint128 > npy_float32 > npy_float64 > npy_float80 > npy_float96 > npy_float128 > npy_complex64 > npy_complex128 > npy_complex120 > npy_complex192 > npy_complex256 > npy_cfloat > npy_cdouble > npy_clongdouble > npy_bool > npy_byte > npy_short > npy_int > npy_long > npy_longlong > npy_ubyte > npy_ushort > npy_uint > npy_ulong > npy_ulonglong > npy_float > npy_double > npy_longdouble > npy_intp > > > DataSource > MachAr > PackageLoader > RankWarning > Tester > abs > absolute > add > add_docstring > add_newdoc > alen > all > allclose > alltrue > alterdot > amax > amin > angle > any > append > apply_along_axis > apply_over_axes > arange > arccos > arccosh > arcsin > arcsinh > arctan > arctan2 > arctanh > argmax > argmin > argsort > argwhere > around > array > array2string > array_equal > array_equiv > array_repr > array_split > array_str > asanyarray > asarray > asarray_chkfinite > ascontiguousarray > asfarray > asfortranarray > asmatrix > asscalar > atleast_1d > atleast_2d > atleast_3d > average > bartlett > base_repr > bench > binary_repr > bincount > bitwise_and > bitwise_not > bitwise_or > bitwise_xor > blackman > bmat > bool > bool8 > bool_ > broadcast > broadcast_arrays > byte > byte_bounds > can_cast > cdouble > ceil > cfloat > character > chararray > choose > clip > clongdouble > clongfloat > column_stack > common_type > compare_chararrays > complex > complex128 > complex192 > complex64 > complex_ > complexfloating > compress > concatenate > conj > conjugate > convolve > copy > corrcoef > correlate > cos > cosh > cov > cross > csingle > cumprod > cumproduct > cumsum > deg2rad > degrees > delete > deprecate > deprecate_with_doc > diag > diagflat > diagonal > diff > digitize > disp > divide > dot > double > dsplit > dstack > dtype > ediff1d > empty > empty_like > equal > errstate > exp > exp2 > expand_dims > expm1 > extract > eye > fabs > fastCopyAndTranspose > find_common_type > finfo > fix > flatiter > flatnonzero > flexible > fliplr > flipud > float > float32 > float64 > float96 > float_ > floating > floor > floor_divide > fmax > fmin > fmod > frexp > frombuffer > fromfile > fromfunction > fromiter > frompyfunc > fromregex > fromstring > fv > generic > genfromtxt > get_array_wrap > get_include > get_numarray_include > get_numpy_include > get_printoptions > getbuffer > getbufsize > geterr > geterrcall > geterrobj > gradient > greater > greater_equal > hamming > hanning > histogram > histogram2d > histogramdd > hsplit > hstack > hypot > i0 > identity > imag > indices > inexact > info > inner > insert > int > int0 > int16 > int32 > int64 > int8 > int_ > int_asbuffer > intc > integer > interp > intersect1d > intersect1d_nu > intp > invert > ipmt > irr > iscomplex > iscomplexobj > isfinite > isfortran > isinf > isnan > isneginf > isposinf > isreal > isrealobj > isscalar > issctype > issubclass_ > issubdtype > issubsctype > iterable > ix_ > kaiser > kron > ldexp > left_shift > less > less_equal > lexsort > linspace > load > loads > loadtxt > log > log10 > log1p > log2 > logaddexp > logaddexp2 > logical_and > logical_not > logical_or > logical_xor > logspace > long > longcomplex > longdouble > longfloat > longlong > lookfor > mafromtxt > mat > matrix > max > maximum > maximum_sctype > may_share_memory > mean > median > memmap > meshgrid > min > minimum > mintypecode > mirr > mod > modf > msort > multiply > nan_to_num > nanargmax > nanargmin > nanmax > nanmin > nansum > ndarray > ndenumerate > ndfromtxt > ndim > ndindex > negative > newbuffer > nonzero > not_equal > nper > npv > number > obj2sctype > object > object0 > object_ > ones > ones_like > outer > packbits > piecewise > pkgload > place > pmt > poly > poly1d > polyadd > polyder > polydiv > polyfit > polyint > polymul > polysub > polyval > power > ppmt > prod > product > ptp > put > putmask > pv > rad2deg > radians > rank > rate > ravel > real > real_if_close > recarray > recfromcsv > recfromtxt > reciprocal > record > remainder > repeat > require > reshape > resize > restoredot > right_shift > rint > roll > rollaxis > roots > rot90 > round > round_ > row_stack > safe_eval > save > savetxt > savez > sctype2char > searchsorted > select > set_numeric_ops > set_printoptions > set_string_function > setbufsize > setdiff1d > seterr > seterrcall > seterrobj > setmember1d > setxor1d > shape > short > show_config > sign > signbit > signedinteger > sin > sinc > single > singlecomplex > sinh > size > sometrue > sort > sort_complex > source > split > sqrt > square > squeeze > std > str > str_ > string0 > string_ > subtract > sum > swapaxes > take > tan > tanh > tensordot > test > tile > trace > transpose > trapz > tri > tril > trim_zeros > triu > true_divide > trunc > typename > ubyte > ufunc > uint > uint0 > uint16 > uint32 > uint64 > uint8 > uintc > uintp > ulonglong > unicode > unicode0 > unicode_ > union1d > unique > unique1d > unpackbits > unravel_index > unsignedinteger > unwrap > ushort > vander > var > vdot > vectorize > void > void0 > vsplit > vstack > where > who > zeros > zeros_like > > > __name__ > __slots__ > __cythonbufferdefaults__ > None > self > True > False > NotImplemented > Ellipsis > NULL > > > > lineEndContext="#stay"> > > context="#stay"/> > context="#stay"/> > context="#stay"/> > > context="#stay"/> > context="#stay"/> > context="#stay"/> > context="#stay"/> > > String="pytypes" /> > > context="#stay"/> > context="#stay"/> > > > > > > > context="#stay"/> > > context="numpy"/> > > > > > > > context="Raw Tripple Q-string"/> > > > > > > > context="Tripple Q-comment" beginRegion="Tripple Q-region"/> > > > context="Tripple Q-string" beginRegion="Tripple Q-region"/> > > > > context="parenthesised" beginRegion="parenthesis"/> > endRegion="parenthesis"/> > > > context="#stay"/> > > > lineEndContext="#pop" noIndentationBasedFolding="True"> > > String="as" /> > > String="numpytypes" /> > String="numpyfuncs" /> > > > lineEndContext="#stay" noIndentationBasedFolding="True"> > > > lineEndContext="#stay" noIndentationBasedFolding="True"> > endRegion="Tripple A-region"/> > > lineEndContext="#stay" noIndentationBasedFolding="True"> > > context="#pop" endRegion="Tripple Q-region"/> > > lineEndContext="#stay" noIndentationBasedFolding="True"> > > > context="#stay"/> > endRegion="Tripple A-region"/> > > lineEndContext="#stay" noIndentationBasedFolding="True"> > > > context="#stay"/> > endRegion="Tripple A-region"/> > > lineEndContext="#stay" noIndentationBasedFolding="True"> > > > context="#stay"/> > context="#pop" endRegion="Tripple Q-region"/> > > lineEndContext="#stay" noIndentationBasedFolding="True"> > > > context="#stay"/> > context="#pop" endRegion="Tripple Q-region"/> > > lineEndContext="#stay"> > > > > lineEndContext="#stay"> > > > > lineEndContext="#stay"> > > > context="#stay"/> > > > lineEndContext="#stay"> > > > context="#stay"/> > > > lineEndContext="#stay"> > > > context="#stay"/> > > > lineEndContext="#stay"> > > > context="#stay"/> > > > > > > > defStyleNum="dsKeyword"/> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev From sturla at molden.no Wed Oct 28 01:06:22 2009 From: sturla at molden.no (Sturla Molden) Date: Wed, 28 Oct 2009 01:06:22 +0100 Subject: [Cython] Syntax highlighting for Cython and NumPy In-Reply-To: <9A30BEDC-C958-4DCB-8E66-2D8012FC4980@math.washington.edu> References: <4AE76A20.2060405@molden.no> <4AE774DB.4020209@molden.no> <9A30BEDC-C958-4DCB-8E66-2D8012FC4980@math.washington.edu> Message-ID: <4AE78AFE.9000300@molden.no> Robert Bradshaw skrev: > Thanks! This has been a much requested feature. Could we include this > in the cython repo? (Maybe in the tools directory?) > > - Robert > Sure, put it where you want, but beware of viral license... There is no license mentioned in the file, but it can be assumed LGPL v2. as it originates from KDE's Python syntax file. KDE does not mention a license in the Python syntax-file either, but KATE is LGPL v2, so we can assume that. Note that it still has couple of rough corners. It does not highlight class and function names like IDLE does. Also it highlights everything everywhere, so you can get names like readonly and public highlighted even when not used as a keyword. I'm still not sure how to fix this, as KDE's XML syntax is not nice to work with. Operators are highlighted like KDE's Python syntax highlight. But that can be commented out (I find it a bit annoying). S.M. From robertwb at math.washington.edu Wed Oct 28 01:16:52 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Tue, 27 Oct 2009 17:16:52 -0700 Subject: [Cython] Syntax highlighting for Cython and NumPy In-Reply-To: <4AE78AFE.9000300@molden.no> References: <4AE76A20.2060405@molden.no> <4AE774DB.4020209@molden.no> <9A30BEDC-C958-4DCB-8E66-2D8012FC4980@math.washington.edu> <4AE78AFE.9000300@molden.no> Message-ID: On Oct 27, 2009, at 5:06 PM, Sturla Molden wrote: > Robert Bradshaw skrev: >> Thanks! This has been a much requested feature. Could we include this >> in the cython repo? (Maybe in the tools directory?) >> >> - Robert >> > Sure, put it where you want, but beware of viral license... There is > no > license mentioned in the file, but it can be assumed LGPL v2. as it > originates from KDE's Python syntax file. KDE does not mention a > license > in the Python syntax-file either, but KATE is LGPL v2, so we can > assume > that. That's fine by me, but I would not have guessed. Could you put a GPL header on the top, acknowledging that it's a derivative work of the KATE Python file? > Note that it still has couple of rough corners. It does not highlight > class and function names like IDLE does. Also it highlights everything > everywhere, so you can get names like readonly and public highlighted > even when not used as a keyword. I'm still not sure how to fix this, > as > KDE's XML syntax is not nice to work with. I don't use KATE, but I bet it's still a nice step forward. - Robert From sturla at molden.no Wed Oct 28 01:30:59 2009 From: sturla at molden.no (Sturla Molden) Date: Wed, 28 Oct 2009 01:30:59 +0100 Subject: [Cython] Syntax highlighting for Cython and NumPy In-Reply-To: References: <4AE76A20.2060405@molden.no> <4AE774DB.4020209@molden.no> <9A30BEDC-C958-4DCB-8E66-2D8012FC4980@math.washington.edu> <4AE78AFE.9000300@molden.no> Message-ID: <4AE790C3.2050402@molden.no> Robert Bradshaw skrev: > That's fine by me, but I would not have guessed. Could you put a GPL > header on the top, acknowledging that it's a derivative work of the > KATE Python file? > Yes. It will only apply to this particular xml file anyway, not source code written using it to highlight syntax. I'll mention that so it don't get scary. >> Note that it still has couple of rough corners. It does not highlight >> class and function names like IDLE does. Also it highlights everything >> everywhere, so you can get names like readonly and public highlighted >> even when not used as a keyword. I'm still not sure how to fix this, >> as >> KDE's XML syntax is not nice to work with. >> > > I don't use KATE, but I bet it's still a nice step forward. > > It's a derivative work of "katepart", a common KDE component. Thus it applies to anything else in KDE that highlights syntax, including the much bigger KDevelop IDE. S.M. From sccolbert at gmail.com Wed Oct 28 01:55:03 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Wed, 28 Oct 2009 01:55:03 +0100 Subject: [Cython] npy_intp in numpy.pxd In-Reply-To: <4AE76317.1030601@molden.no> References: <9457e7c80910270615i285106dfrabbc2b4c88e41bf6@mail.gmail.com> <4AE76317.1030601@molden.no> Message-ID: <7f014ea60910271755w2b57db5cjfb8584c0c2e75a71@mail.gmail.com> On Tue, Oct 27, 2009 at 10:16 PM, Sturla Molden wrote: > St?fan van der Walt skrev: >> >> As a side note, it may be safer to use the definitions of npy_intp and >> npy_uintp from the numpy header, rather than Py_ssize_t and Py_size_t. >> ?In some earlier versions of Python (e.g., 2.4), these were not the >> same. >> > No. You should use Py_ssize_t for indexing. Where did Stefan mention anything about indexing? NumPy uses npy_intp* for defining array shapes, among other things.... > > The reason is that the C standard does not guarantee that sizeof(void*) > == sizeof(size_t), and there are platforms where this evaluates to > false. That is why Python core uses Py_ssize_t instead of Py_intptr_t > for indexing sequence types (cf. PEP 353). The Py_intptr_t/npy_intp is > long enough to hold a void*; the indexer should have the same size as > size_t, thus Py_ssize_t. > > The use of npy_intp as indexer in NumPy is a C coding error. It > accidentally works on computers with flat memory space, e.g. 32 bit x86 > and x64. Although platforms with flat memory are common, it should not > be encouraged. > >> Then, I also have a quick question: why is a person allowed to do >> >> cdef extern from something: >> ? ? ctypedef int Py_ssize_t >> >> when Py_ssize_t is not an int? ?Is this a Cython-specific idea? >> > Because it "behaves like an int", the only difference being the size. > But sizeof() is evaluated by the C compiler, which knows the true size > of int and Py_ssize_t. > > Sturla Molden > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > From sturla at molden.no Wed Oct 28 02:27:36 2009 From: sturla at molden.no (Sturla Molden) Date: Wed, 28 Oct 2009 02:27:36 +0100 Subject: [Cython] npy_intp in numpy.pxd In-Reply-To: <7f014ea60910271755w2b57db5cjfb8584c0c2e75a71@mail.gmail.com> References: <9457e7c80910270615i285106dfrabbc2b4c88e41bf6@mail.gmail.com> <4AE76317.1030601@molden.no> <7f014ea60910271755w2b57db5cjfb8584c0c2e75a71@mail.gmail.com> Message-ID: <4AE79E08.2010809@molden.no> Chris Colbert skrev: > Where did Stefan mention anything about indexing? > > NumPy uses npy_intp* for defining array shapes, among other things.... > > Yes, and that is a mistake. An array size is an offset to a pointer, it is not a pointer. Thus you need an integer long enough to hold an offset, not an integer long enough to hold a pointer. On segment-and-offset architectures, pointers and offsets don't have to be of the same length. S.M. From stefan_ml at behnel.de Wed Oct 28 08:13:49 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 28 Oct 2009 08:13:49 +0100 Subject: [Cython] repr(complex) has changed in Py3.1 Message-ID: <4AE7EF2D.9070903@behnel.de> Hi, most of the 'complex' tests currently fail in Py3.1 because complex.__repr__() became more correct. It now prints (-0-2j) for -(2j). Could someone who was involved in writing this code (Dag or Lisandro, I guess) please take a look and decide a) if this is worth testing for, and b) if it's enough to fix the test or if the support in Cython also needs adaptation to match what Py3.1 prints? That would allow us to close ticket #319. Thanks, Stefan From stefan_ml at behnel.de Wed Oct 28 08:21:15 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 28 Oct 2009 08:21:15 +0100 Subject: [Cython] Cython 0.12 In-Reply-To: References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> Message-ID: <4AE7F0EB.4020800@behnel.de> Hi, Mark Lodato, 24.10.2009 17:49: > On Sat, Oct 24, 2009 at 1:47 AM, Stefan Behnel wrote: >> There's also #434 about --embed not working in Py3. Mark, did you test your >> patch under Py3.1? > > I saw that bug, and cython_freeze has the exact same problems as > --embed. I'm working on a fix now. ... any news from this front? Stefan From sturla at molden.no Wed Oct 28 09:02:00 2009 From: sturla at molden.no (Sturla Molden) Date: Wed, 28 Oct 2009 09:02:00 +0100 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE7F0EB.4020800@behnel.de> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> <4AE7F0EB.4020800@behnel.de> Message-ID: <4AE7FA78.7090302@molden.no> Stefan Behnel skrev: > ... any news from this front? > > I'll be working on a testcase that Dag Sverre requested. Sturla From sturla at molden.no Wed Oct 28 10:15:43 2009 From: sturla at molden.no (Sturla Molden) Date: Wed, 28 Oct 2009 10:15:43 +0100 Subject: [Cython] Syntax highlighting for Cython and NumPy Message-ID: <4AE80BBF.7040205@molden.no> > Robert Bradshaw skrev: > >> That's fine by me, but I would not have guessed. Could you put a GPL >> header on the top, acknowledging that it's a derivative work of the >> KATE Python file? >> Here it is with the LGPL disclaimer. Yesterday night I gave it an overhaul as well. It seems to have improved from useful to fantastic :-) If there are keywords or things I have left out, please let me know. S.M. -------------- next part -------------- A non-text attachment was scrubbed... Name: cython-numpy.zip Type: application/x-zip-compressed Size: 6797 bytes Desc: not available Url : http://codespeak.net/pipermail/cython-dev/attachments/20091028/161423ed/attachment.bin From robertwb at math.washington.edu Wed Oct 28 10:45:32 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 28 Oct 2009 02:45:32 -0700 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE7F0EB.4020800@behnel.de> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> <4AE7F0EB.4020800@behnel.de> Message-ID: <63C4D4A6-135E-47AD-9AB1-1D97257445E6@math.washington.edu> On Oct 28, 2009, at 12:21 AM, Stefan Behnel wrote: > Hi, > > Mark Lodato, 24.10.2009 17:49: >> On Sat, Oct 24, 2009 at 1:47 AM, Stefan Behnel wrote: >>> There's also #434 about --embed not working in Py3. Mark, did you >>> test your >>> patch under Py3.1? >> >> I saw that bug, and cython_freeze has the exact same problems as >> --embed. I'm working on a fix now. > > ... any news from this front? Yes, see http://trac.cython.org/cython_trac/ticket/439 - Robert From robertwb at math.washington.edu Wed Oct 28 11:03:40 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 28 Oct 2009 03:03:40 -0700 Subject: [Cython] Syntax highlighting for Cython and NumPy In-Reply-To: <4AE80BBF.7040205@molden.no> References: <4AE80BBF.7040205@molden.no> Message-ID: <3D266C9E-A9E1-4038-BB27-0E14D51760E4@math.washington.edu> Cool. Merged. http://hg.cython.org/cython-devel/rev/92010f833bf6 On Oct 28, 2009, at 2:15 AM, Sturla Molden wrote: >> Robert Bradshaw skrev: >> >>> That's fine by me, but I would not have guessed. Could you put a >>> GPL header on the top, acknowledging that it's a derivative work >>> of the KATE Python file? >>> > Here it is with the LGPL disclaimer. > > Yesterday night I gave it an overhaul as well. It seems to have > improved from useful to fantastic :-) > > If there are keywords or things I have left out, please let me know. > > S.M. > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev From robertwb at math.washington.edu Wed Oct 28 11:09:39 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 28 Oct 2009 03:09:39 -0700 Subject: [Cython] C array support redux In-Reply-To: <4AE6E06F.2080109@behnel.de> References: <4AE461C9.2060809@behnel.de> <4AE69F22.20904@behnel.de> <4AE6E06F.2080109@behnel.de> Message-ID: <7E90592B-24B1-4B35-9582-1F8B7E82E586@math.washington.edu> On Oct 27, 2009, at 4:58 AM, Stefan Behnel wrote: > > Stefan Behnel, 27.10.2009 08:20: >> I have working code to make this efficient: >> >> cdef char* s = "...." >> for c in s[:100]: >> print c >> >> and, for example, this also runs as a C loop: >> >> cdef char* s = "...." >> for i,c in enumerate(s[:100]): >> print i,c >> >> [...] >> Any objections to add at least the char* optimisation above for 0.12? > > http://trac.cython.org/cython_trac/ticket/437 > http://hg.cython.org/cython-devel/rev/1c46918cef48 I'm not opposed to that. - Robert From robertwb at math.washington.edu Wed Oct 28 11:18:55 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 28 Oct 2009 03:18:55 -0700 Subject: [Cython] Docs In-Reply-To: <1e52e0880910262343q485cb41dtff82b6d142fadb6f@mail.gmail.com> References: <1e52e0880910262343q485cb41dtff82b6d142fadb6f@mail.gmail.com> Message-ID: <3B900815-CFBB-4265-A2A3-6ED6ED3029F4@math.washington.edu> On Oct 26, 2009, at 11:43 PM, Peter Alexander wrote: > Hi all. > > The last couple of weeks have been tough ones for me which is why I > haven't been visible. My responsibilities here have increased and put > additional pressure on my time. So I'm sorry to say that I can't put > more effort into the Cython docs at this time. I sincerely apologize > for that because I feel that they are an important issue that I really > wanted to contribute to. Don't worry, I *totally* understand :). We appreciate what you did get done. > I think Cython is a very worthy project and I have great respect for > you who are contributing to it. In the future, when I can I'd like to > help out more. > > I did get some work done on the docs that is substantial, but by no > means complete and is publicly available for download [1]. I hope that > someone else, who uses Cython, will pick up the batton and run with > it. I say this because I feel Cython is very important to the entire > Python community. I hope so too. I've put a rendered version of the docs up at [1] for people to look at. I think this is a superset of the information in the old manual. [1] http://sage.math.washington.edu/home/robertwb/cython/docs-new/ - Robert From ndbecker2 at gmail.com Wed Oct 28 15:00:10 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Wed, 28 Oct 2009 10:00:10 -0400 Subject: [Cython] C array support redux References: <4AE461C9.2060809@behnel.de> <4AE5F18C.3030702@student.matnat.uio.no> <4AE6A33D.70201@behnel.de> <4AE6D088.2010901@student.matnat.uio.no> Message-ID: Dag Sverre Seljebotn wrote: > Stefan Behnel wrote: >> Dag Sverre Seljebotn, 26.10.2009 19:59: >>> a) Me and Kurt decided to use the name "memoryview" everywhere in the >>> code written in summer. The essential feature of the proposed Cython >>> type described in enhancements/array is a) a view to a reference-counted >>> PEP 3118 buffer, b) slices returns new sub-views. This is exactly what >>> the Python memoryview type does. Cython adds static typing to this, but >>> we decided to also name the Cython concept memoryview. >> >> Is it just the "concept", or also the type itself? >> >> I just want to make sure people can >> >> cdef memoryview m >> >> to use the Python memoryview type without having it fail or do something >> unexpected, just like they use >> >> cdef list l > > Sure, that will still work (if memoryview is added as a builtin type), > we don't plan to interfer at all there. > Will this lead to better support of numpy slices? From dagss at student.matnat.uio.no Wed Oct 28 16:15:27 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 28 Oct 2009 16:15:27 +0100 Subject: [Cython] C array support redux In-Reply-To: References: <4AE461C9.2060809@behnel.de> <4AE5F18C.3030702@student.matnat.uio.no> <4AE6A33D.70201@behnel.de> <4AE6D088.2010901@student.matnat.uio.no> Message-ID: <4AE8600F.9070200@student.matnat.uio.no> Neal Becker wrote: > Dag Sverre Seljebotn wrote: > > >> Stefan Behnel wrote: >> >>> Dag Sverre Seljebotn, 26.10.2009 19:59: >>> >>>> a) Me and Kurt decided to use the name "memoryview" everywhere in the >>>> code written in summer. The essential feature of the proposed Cython >>>> type described in enhancements/array is a) a view to a reference-counted >>>> PEP 3118 buffer, b) slices returns new sub-views. This is exactly what >>>> the Python memoryview type does. Cython adds static typing to this, but >>>> we decided to also name the Cython concept memoryview. >>>> >>> Is it just the "concept", or also the type itself? >>> >>> I just want to make sure people can >>> >>> cdef memoryview m >>> >>> to use the Python memoryview type without having it fail or do something >>> unexpected, just like they use >>> >>> cdef list l >>> >> Sure, that will still work (if memoryview is added as a builtin type), >> we don't plan to interfer at all there. >> >> > > Will this lead to better support of numpy slices? > Yes, but not on "np.ndarray[np.int_t, ndim=2]", only on "np.int_t[:,:]". http://wiki.cython.org/enhancements/array Dag Sverre From stefan_ml at behnel.de Wed Oct 28 16:26:09 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Wed, 28 Oct 2009 16:26:09 +0100 Subject: [Cython] Cython 0.12 In-Reply-To: <63C4D4A6-135E-47AD-9AB1-1D97257445E6@math.washington.edu> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> <4AE7F0EB.4020800@behnel.de> <63C4D4A6-135E-47AD-9AB1-1D97257445E6@math.washington.edu> Message-ID: <4AE86291.4040104@behnel.de> Robert Bradshaw, 28.10.2009 10:45: > On Oct 28, 2009, at 12:21 AM, Stefan Behnel wrote: >> Mark Lodato, 24.10.2009 17:49: >>> On Sat, Oct 24, 2009 at 1:47 AM, Stefan Behnel wrote: >>>> There's also #434 about --embed not working in Py3. Mark, did you >>>> test your >>>> patch under Py3.1? >>> I saw that bug, and cython_freeze has the exact same problems as >>> --embed. I'm working on a fix now. >> ... any news from this front? > > Yes, see > > http://trac.cython.org/cython_trac/ticket/439 Mark, thanks a lot for doing that. I hope you copied the wchar_t adaptation part from somewhere, looks like a lot of work otherwise. One thing that strikes me, however, is the amount of code duplication. I think we should put cython_freeze into the Cython package (e.g. as Cython/Compiler/MainFunction.py), so that the compiler can use it to generate a main() function, and just add a __main__ execution body at the end that runs from the command line. Distutils could still install the module as a "cython_freeze" script in /usr/bin then, and the shipped bin/cython_freeze would simply import and run Cython/Compiler/MainFunction.py (so that you don't need to install Cython to get a runnable script). Another thing I noticed is the use of PyMem_Malloc() and friends. I'm not sure if it's safe to use those before initialising the Python interpreter. Anyway, I think that plain malloc() and free() make more sense here. Stefan From dagss at student.matnat.uio.no Wed Oct 28 16:30:18 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 28 Oct 2009 16:30:18 +0100 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE86291.4040104@behnel.de> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> <4AE7F0EB.4020800@behnel.de> <63C4D4A6-135E-47AD-9AB1-1D97257445E6@math.washington.edu> <4AE86291.4040104@behnel.de> Message-ID: <4AE8638A.4030403@student.matnat.uio.no> Stefan Behnel wrote: > Robert Bradshaw, 28.10.2009 10:45: > >> On Oct 28, 2009, at 12:21 AM, Stefan Behnel wrote: >> >>> Mark Lodato, 24.10.2009 17:49: >>> >>>> On Sat, Oct 24, 2009 at 1:47 AM, Stefan Behnel wrote: >>>> >>>>> There's also #434 about --embed not working in Py3. Mark, did you >>>>> test your >>>>> patch under Py3.1? >>>>> >>>> I saw that bug, and cython_freeze has the exact same problems as >>>> --embed. I'm working on a fix now. >>>> >>> ... any news from this front? >>> >> Yes, see >> >> http://trac.cython.org/cython_trac/ticket/439 >> > > Mark, thanks a lot for doing that. I hope you copied the wchar_t adaptation > part from somewhere, looks like a lot of work otherwise. > > One thing that strikes me, however, is the amount of code duplication. I > think we should put cython_freeze into the Cython package (e.g. as > Cython/Compiler/MainFunction.py), so that the compiler can use it to > generate a main() function, and just add a __main__ execution body at the > end that runs from the command line. Distutils could still install the > module as a "cython_freeze" script in /usr/bin then, and the shipped > bin/cython_freeze would simply import and run > Cython/Compiler/MainFunction.py (so that you don't need to install Cython > to get a runnable script). > > Another thing I noticed is the use of PyMem_Malloc() and friends. I'm not > sure if it's safe to use those before initialising the Python interpreter. > Anyway, I think that plain malloc() and free() make more sense here. > They require the GIL, last time I looked, so should probably be avoided. Dag Sverre From dagss at student.matnat.uio.no Wed Oct 28 16:39:04 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 28 Oct 2009 16:39:04 +0100 Subject: [Cython] More complex bugs Message-ID: <4AE86598.10204@student.matnat.uio.no> I just added http://trac.cython.org/cython_trac/ticket/441 Basically, ctypedef float myfloat; ... print some_myfloat * some_complex miscompiles as "some_myfloat" is coerced to "myfloat complex" (which, interestingly, is a type which can't be created or used in any other way!) Fixing this requires some thought. This probably broke because (in order to fix another bug) I stepped away from "the order something is needed in Cython decides output order in C". I believe that was a correct decision and don't want to step back. The proper solution is a DAG of all types and their dependencies. I believe that is a bit heavy/destabilizing for 0.12 though. Perhaps output all very simply typedefs (typedefs of ints and floats) first, then complex, then the rest? However there's another issue: Unlike what I originally thought, it is then possible to do e.g. cdef extern from "foo.h": ctypdef double mydouble # is size correct? print (some_mydouble * some_complex).imag This can fail spectacularily as we currently rely on determining __Pyx_c_prod vs. __Pyx_c_prodf and so on at Cythonization time. Lisandro, did you mention efforts in this direction? Dag Sverre From dagss at student.matnat.uio.no Wed Oct 28 16:46:07 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Wed, 28 Oct 2009 16:46:07 +0100 Subject: [Cython] Cast real to complex? Message-ID: <4AE8673F.5070205@student.matnat.uio.no> I just attempted (x) * z where x is float. (To work around a certain recently reported bug.) However conversion to complex this way is not supported. Is this a feature or a bug? Dag Sverre From sturla at molden.no Wed Oct 28 16:52:41 2009 From: sturla at molden.no (Sturla Molden) Date: Wed, 28 Oct 2009 16:52:41 +0100 Subject: [Cython] C array support redux In-Reply-To: References: <4AE461C9.2060809@behnel.de> <4AE5F18C.3030702@student.matnat.uio.no> <4AE6A33D.70201@behnel.de> <4AE6D088.2010901@student.matnat.uio.no> Message-ID: <4AE868C9.8030401@molden.no> Neal Becker skrev: > Will this lead to better support of numpy slices? > Yes, probably. Both ndarrays and memoryviews are PEP3118 buffers in Cython. The Cython compiler works directly on a Py_buffer struct, which is unboxed into the local scope. To the compiler, slicing a memoryview will not be different from slicing an ndarray. Slicing C pointers are a little different, though. I think both should be allowed and optimized. Slicing a pointer makes sence in Cython, because pointers are conceptually sequence types. S.M. From sturla at molden.no Wed Oct 28 16:57:33 2009 From: sturla at molden.no (Sturla Molden) Date: Wed, 28 Oct 2009 16:57:33 +0100 Subject: [Cython] C array support redux In-Reply-To: <4AE868C9.8030401@molden.no> References: <4AE461C9.2060809@behnel.de> <4AE5F18C.3030702@student.matnat.uio.no> <4AE6A33D.70201@behnel.de> <4AE6D088.2010901@student.matnat.uio.no> <4AE868C9.8030401@molden.no> Message-ID: <4AE869ED.7030404@molden.no> Sturla Molden skrev: > 0 > Yes, probably. Both ndarrays and memoryviews are PEP3118 buffers in > Cython. The Cython compiler works directly on a Py_buffer struct, which > is unboxed into the local scope. To the compiler, slicing a memoryview > will not be different from slicing an ndarray. Slicing C pointers are a > little different, though. I think both should be allowed and optimized. > Slicing a pointer makes sence in Cython, because pointers are > conceptually sequence types. > > Oops, it seems I was wrong. S.M. From robertwb at math.washington.edu Wed Oct 28 17:11:44 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Wed, 28 Oct 2009 09:11:44 -0700 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE86291.4040104@behnel.de> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> <4AE7F0EB.4020800@behnel.de> <63C4D4A6-135E-47AD-9AB1-1D97257445E6@math.washington.edu> <4AE86291.4040104@behnel.de> Message-ID: <3139D2F9-CE87-4309-9531-2EC229B85EF6@math.washington.edu> On Oct 28, 2009, at 8:26 AM, Stefan Behnel wrote: > Robert Bradshaw, 28.10.2009 10:45: >> On Oct 28, 2009, at 12:21 AM, Stefan Behnel wrote: >>> Mark Lodato, 24.10.2009 17:49: >>>> On Sat, Oct 24, 2009 at 1:47 AM, Stefan Behnel wrote: >>>>> There's also #434 about --embed not working in Py3. Mark, did you >>>>> test your >>>>> patch under Py3.1? >>>> I saw that bug, and cython_freeze has the exact same problems as >>>> --embed. I'm working on a fix now. >>> ... any news from this front? >> >> Yes, see >> >> http://trac.cython.org/cython_trac/ticket/439 > > Mark, thanks a lot for doing that. I hope you copied the wchar_t > adaptation > part from somewhere, looks like a lot of work otherwise. > > One thing that strikes me, however, is the amount of code > duplication. I > think we should put cython_freeze into the Cython package (e.g. as > Cython/Compiler/MainFunction.py), so that the compiler can use it to > generate a main() function, and just add a __main__ execution body > at the > end that runs from the command line. Distutils could still install the > module as a "cython_freeze" script in /usr/bin then, and the shipped > bin/cython_freeze would simply import and run > Cython/Compiler/MainFunction.py (so that you don't need to install > Cython > to get a runnable script). Yes, this has been mentioned before, and I agree. > Another thing I noticed is the use of PyMem_Malloc() and friends. > I'm not > sure if it's safe to use those before initialising the Python > interpreter. > Anyway, I think that plain malloc() and free() make more sense here. Good point. - Robert From dalcinl at gmail.com Wed Oct 28 19:44:55 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 28 Oct 2009 16:44:55 -0200 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE8638A.4030403@student.matnat.uio.no> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> <4AE7F0EB.4020800@behnel.de> <63C4D4A6-135E-47AD-9AB1-1D97257445E6@math.washington.edu> <4AE86291.4040104@behnel.de> <4AE8638A.4030403@student.matnat.uio.no> Message-ID: On Wed, Oct 28, 2009 at 1:30 PM, Dag Sverre Seljebotn wrote: > Stefan Behnel wrote: >> Robert Bradshaw, 28.10.2009 10:45: >> >>> On Oct 28, 2009, at 12:21 AM, Stefan Behnel wrote: >>> >>>> Mark Lodato, 24.10.2009 17:49: >>>> >>>>> On Sat, Oct 24, 2009 at 1:47 AM, Stefan Behnel wrote: >>>>> >>>>>> There's also #434 about --embed not working in Py3. Mark, did you >>>>>> test your >>>>>> patch under Py3.1? >>>>>> >>>>> I saw that bug, and cython_freeze has the exact same problems as >>>>> --embed. ?I'm working on a fix now. >>>>> >>>> ... any news from this front? >>>> >>> Yes, see >>> >>> http://trac.cython.org/cython_trac/ticket/439 >>> >> >> Mark, thanks a lot for doing that. I hope you copied the wchar_t adaptation >> part from somewhere, looks like a lot of work otherwise. >> >> One thing that strikes me, however, is the amount of code duplication. I >> think we should put cython_freeze into the Cython package (e.g. as >> Cython/Compiler/MainFunction.py), so that the compiler can use it to >> generate a main() function, and just add a __main__ execution body at the >> end that runs from the command line. Distutils could still install the >> module as a "cython_freeze" script in /usr/bin then, and the shipped >> bin/cython_freeze would simply import and run >> Cython/Compiler/MainFunction.py (so that you don't need to install Cython >> to get a runnable script). >> >> Another thing I noticed is the use of PyMem_Malloc() and friends. I'm not >> sure if it's safe to use those before initialising the Python interpreter. >> Anyway, I think that plain malloc() and free() make more sense here. >> > They require the GIL, last time I looked, so should probably be avoided. > No, I think you are wrong. PyMem_Malloc()/PyMem_Free() do not require the GIL (for non-debug builds, at least), as they are wrappers to system malloc() and free() (note: malloc(0) actually does malloc(1))... Anyway, I agree that for the freezing purpuses, it would be better to use system malloc()/free(), just take care of making matching calls, if not, problems could happen (remember about Windows, MSVC vs MinGW , incompatible CRT's) -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Wed Oct 28 20:13:10 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 28 Oct 2009 17:13:10 -0200 Subject: [Cython] More complex bugs In-Reply-To: <4AE86598.10204@student.matnat.uio.no> References: <4AE86598.10204@student.matnat.uio.no> Message-ID: On Wed, Oct 28, 2009 at 1:39 PM, Dag Sverre Seljebotn wrote: > I just added http://trac.cython.org/cython_trac/ticket/441 > > Basically, > > ctypedef float myfloat; > ... > print some_myfloat * some_complex > > miscompiles as "some_myfloat" is coerced to "myfloat complex" (which, > interestingly, is a type which can't be created or used in any other way!) > > Fixing this requires some thought. > > This probably broke because (in order to fix another bug) I stepped away > from "the order something is needed in Cython decides output order in > C". I believe that was a correct decision and don't want to step back. > The proper solution is a DAG of all types and their dependencies. I > believe that is a bit heavy/destabilizing for 0.12 though. Perhaps > output all very simply typedefs (typedefs of ints and floats) first, > then complex, then the rest? > > However there's another issue: Unlike what I originally thought, it is > then possible to do e.g. > > cdef extern from "foo.h": > ? ?ctypdef double mydouble # is size correct? > > print (some_mydouble * some_complex).imag > > This can fail spectacularily as we currently rely on determining > __Pyx_c_prod vs. __Pyx_c_prodf and so on at Cythonization time. > Lisandro, did you mention efforts in this direction? > I have not done anything in this direction, but I've already pointed out that this was likely broken... There are also issues with "z.real = r" in C++ with MSVC (liekly because complex::real() is not an lvalue), I've also posted about this, no one commented. Unfortunately, I do not think I can work on these issues for 0.12 if the release is going to happen this week or the next one... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sturla at molden.no Wed Oct 28 21:07:25 2009 From: sturla at molden.no (Sturla Molden) Date: Wed, 28 Oct 2009 21:07:25 +0100 Subject: [Cython] Cython 0.12 In-Reply-To: References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> <4AE7F0EB.4020800@behnel.de> <63C4D4A6-135E-47AD-9AB1-1D97257445E6@math.washington.edu> <4AE86291.4040104@behnel.de> <4AE8638A.4030403@student.matnat.uio.no> Message-ID: <4AE8A47D.4080504@molden.no> Lisandro Dalcin skrev: > No, I think you are wrong. PyMem_Malloc()/PyMem_Free() do not require > the GIL (for non-debug builds, at least), as they are wrappers to > system malloc() and free() (note: malloc(0) actually does > malloc(1))... > > I have always believed PyMem_Malloc call PyArena_Malloc with Python's heap as arena. PyArena_Malloc is a non-threadsafe reimplementation of malloc. I have a problem finding PyMem_Malloc in Python sources. Sturla Molden From sturla at molden.no Wed Oct 28 21:38:20 2009 From: sturla at molden.no (Sturla Molden) Date: Wed, 28 Oct 2009 21:38:20 +0100 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE8A47D.4080504@molden.no> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> <4AE7F0EB.4020800@behnel.de> <63C4D4A6-135E-47AD-9AB1-1D97257445E6@math.washington.edu> <4AE86291.4040104@behnel.de> <4AE8638A.4030403@student.matnat.uio.no> <4AE8A47D.4080504@molden.no> Message-ID: <4AE8ABBC.30602@molden.no> Sturla Molden skrev: > I have always believed PyMem_Malloc call PyArena_Malloc with Python's > heap as arena. PyArena_Malloc is a non-threadsafe reimplementation of > malloc. > > I have a problem finding PyMem_Malloc in Python sources. > > In normal mode we have a direct call to malloc, which don't require the GIL if libc is thread-safe: void * PyMem_Malloc(size_t nbytes) { return PyMem_MALLOC(nbytes); } #define PyMem_MALLOC(n) (((n) < 0 || (n) > PY_SSIZE_T_MAX) ? NULL \ : malloc((n) ? (n) : 1)) In debug mode, PyMem_Malloc finally becomes a call to PyObject_Malloc, which requires the GIL. S.M. From lodatom at gmail.com Thu Oct 29 02:19:11 2009 From: lodatom at gmail.com (Mark Lodato) Date: Wed, 28 Oct 2009 21:19:11 -0400 Subject: [Cython] Cython 0.12 In-Reply-To: <4AE86291.4040104@behnel.de> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> <4AE7F0EB.4020800@behnel.de> <63C4D4A6-135E-47AD-9AB1-1D97257445E6@math.washington.edu> <4AE86291.4040104@behnel.de> Message-ID: On Wed, Oct 28, 2009 at 11:26 AM, Stefan Behnel wrote: > Robert Bradshaw, 28.10.2009 10:45: >> >> http://trac.cython.org/cython_trac/ticket/439 > > Mark, thanks a lot for doing that. I hope you copied the wchar_t adaptation > part from somewhere, looks like a lot of work otherwise. > > [snip] > > Another thing I noticed is the use of PyMem_Malloc() and friends. I'm not > sure if it's safe to use those before initialising the Python interpreter. > Anyway, I think that plain malloc() and free() make more sense here. I copied this almost verbatim from Python 3.1.1's Modules/python.c. I assume using PyMem is fine since CPython does it, but I default to your judgment... > One thing that strikes me, however, is the amount of code duplication. I > think we should put cython_freeze into the Cython package (e.g. as > Cython/Compiler/MainFunction.py), so that the compiler can use it to > generate a main() function, and just add a __main__ execution body at the > end that runs from the command line. Distutils could still install the > module as a "cython_freeze" script in /usr/bin then, and the shipped > bin/cython_freeze would simply import and run > Cython/Compiler/MainFunction.py (so that you don't need to install Cython > to get a runnable script). Yes, I agree entirely. Once this gets tested and finalized, I think it would be great to merge cython_freeze into Cython as you suggest. Unfortunately, I don't know how to proceed... :) -- Mark From dalcinl at gmail.com Thu Oct 29 03:21:07 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Wed, 28 Oct 2009 23:21:07 -0300 Subject: [Cython] Cython 0.12 In-Reply-To: References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> <4AE7F0EB.4020800@behnel.de> <63C4D4A6-135E-47AD-9AB1-1D97257445E6@math.washington.edu> <4AE86291.4040104@behnel.de> Message-ID: On Wed, Oct 28, 2009 at 10:19 PM, Mark Lodato wrote: > On Wed, Oct 28, 2009 at 11:26 AM, Stefan Behnel wrote: >> Robert Bradshaw, 28.10.2009 10:45: >>> >>> http://trac.cython.org/cython_trac/ticket/439 >> >> Mark, thanks a lot for doing that. I hope you copied the wchar_t adaptation >> part from somewhere, looks like a lot of work otherwise. >> >> [snip] >> >> Another thing I noticed is the use of PyMem_Malloc() and friends. I'm not >> sure if it's safe to use those before initialising the Python interpreter. >> Anyway, I think that plain malloc() and free() make more sense here. > > I copied this almost verbatim from Python 3.1.1's Modules/python.c. ?I > assume using PyMem is fine since CPython does it, but I default to > your judgment... > IMHO, then changes to Modules/python.c in Python 3 are a mess... Perhaps I'm missing somenthing, but I fail to the point of using PyMem_XXX there... I'm not going to reject your implementation for using the PyMem_XXX functions, but I would prefer plain malloc()/free() being used.. I do this in mpi4py, tough this re-rubuilt interpreter is not usually required: http://code.google.com/p/mpi4py/source/browse/trunk/src/python.c >> One thing that strikes me, however, is the amount of code duplication. I >> think we should put cython_freeze into the Cython package (e.g. as >> Cython/Compiler/MainFunction.py), so that the compiler can use it to >> generate a main() function, and just add a __main__ execution body at the >> end that runs from the command line. Distutils could still install the >> module as a "cython_freeze" script in /usr/bin then, and the shipped >> bin/cython_freeze would simply import and run >> Cython/Compiler/MainFunction.py (so that you don't need to install Cython >> to get a runnable script). > > Yes, I agree entirely. ?Once this gets tested and finalized, I think > it would be great to merge cython_freeze into Cython as you suggest. > Unfortunately, I don't know how to proceed... :) > OK... I'm completely lost here... I'll need to actually review the beast to make more coments, sorry... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From robertwb at math.washington.edu Thu Oct 29 09:05:05 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 29 Oct 2009 01:05:05 -0700 Subject: [Cython] enumerate() optimization Message-ID: <9EABA1F9-A618-48EB-B59C-371DE50044AD@math.washington.edu> Stefan, While compiling Sage I found a curious bug in the enumerate() operation--it was casting PyObject* directly into typed targets (e.g. ints). http://trac.cython.org/cython_trac/ticket/442 For the moment I've disabled this optimization in this case, but it might be an easy fix. - Robert From robertwb at math.washington.edu Thu Oct 29 09:33:36 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 29 Oct 2009 01:33:36 -0700 Subject: [Cython] Cython 0.12 In-Reply-To: References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> <4AE7F0EB.4020800@behnel.de> <63C4D4A6-135E-47AD-9AB1-1D97257445E6@math.washington.edu> <4AE86291.4040104@behnel.de> Message-ID: On Oct 28, 2009, at 7:21 PM, Lisandro Dalcin wrote: > On Wed, Oct 28, 2009 at 10:19 PM, Mark Lodato > wrote: >> On Wed, Oct 28, 2009 at 11:26 AM, Stefan Behnel >> wrote: >>> Robert Bradshaw, 28.10.2009 10:45: >>>> >>>> http://trac.cython.org/cython_trac/ticket/439 >>> >>> Mark, thanks a lot for doing that. I hope you copied the wchar_t >>> adaptation >>> part from somewhere, looks like a lot of work otherwise. >>> >>> [snip] >>> >>> Another thing I noticed is the use of PyMem_Malloc() and friends. >>> I'm not >>> sure if it's safe to use those before initialising the Python >>> interpreter. >>> Anyway, I think that plain malloc() and free() make more sense here. >> >> I copied this almost verbatim from Python 3.1.1's Modules/ >> python.c. I >> assume using PyMem is fine since CPython does it, but I default to >> your judgment... >> > > IMHO, then changes to Modules/python.c in Python 3 are a mess... Yeah, I agree, they're pretty ugly. > Perhaps I'm missing somenthing, but I fail to the point of using > PyMem_XXX there... I'm not going to reject your implementation for > using the PyMem_XXX functions, but I would prefer plain > malloc()/free() being used.. I do this in mpi4py, tough this > re-rubuilt interpreter is not usually required: > http://code.google.com/p/mpi4py/source/browse/trunk/src/python.c > I've just changed them to plain old free/malloc. - Robert From robertwb at math.washington.edu Thu Oct 29 11:55:24 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 29 Oct 2009 03:55:24 -0700 Subject: [Cython] typedef reals in complex types Message-ID: <76E0E7E4-D517-48A2-B753-DA6A51750D96@math.washington.edu> http://hg.cython.org/cython-devel/diff/e71240c9ce4b/tests/run/complex_numbers_T305.pyx seems to have broken compiling the complex test cases on my computer, is anyone else seeing this? - Robert From robertwb at math.washington.edu Thu Oct 29 11:58:46 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 29 Oct 2009 03:58:46 -0700 Subject: [Cython] typedef reals in complex types In-Reply-To: <76E0E7E4-D517-48A2-B753-DA6A51750D96@math.washington.edu> References: <76E0E7E4-D517-48A2-B753-DA6A51750D96@math.washington.edu> Message-ID: Nevermind, see Dag's email. On Oct 29, 2009, at 3:55 AM, Robert Bradshaw wrote: > http://hg.cython.org/cython-devel/diff/e71240c9ce4b/tests/run/complex_numbers_T305.pyx > seems to have broken compiling the complex test cases on my > computer, is anyone else seeing this? > > - Robert > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev From robertwb at math.washington.edu Thu Oct 29 12:04:30 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 29 Oct 2009 04:04:30 -0700 Subject: [Cython] More complex bugs In-Reply-To: <4AE86598.10204@student.matnat.uio.no> References: <4AE86598.10204@student.matnat.uio.no> Message-ID: On Oct 28, 2009, at 8:39 AM, Dag Sverre Seljebotn wrote: > I just added http://trac.cython.org/cython_trac/ticket/441 > > Basically, > > ctypedef float myfloat; > ... > print some_myfloat * some_complex > > miscompiles as "some_myfloat" is coerced to "myfloat complex" (which, > interestingly, is a type which can't be created or used in any other > way!) > > Fixing this requires some thought. > > This probably broke because (in order to fix another bug) I stepped > away > from "the order something is needed in Cython decides output order in > C". I believe that was a correct decision and don't want to step back. > The proper solution is a DAG of all types and their dependencies. I > believe that is a bit heavy/destabilizing for 0.12 though. Perhaps > output all very simply typedefs (typedefs of ints and floats) first, > then complex, then the rest? Yep, I don't see the full DAG analysis happening in 0.12. I think any arbitrary order we come up with is potentially prone to errors. I'm OK with just disallowing that for 0.12, it's not a regression. - Robert From stefan_ml at behnel.de Thu Oct 29 13:02:14 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 29 Oct 2009 13:02:14 +0100 Subject: [Cython] enumerate() optimization In-Reply-To: <9EABA1F9-A618-48EB-B59C-371DE50044AD@math.washington.edu> References: <9EABA1F9-A618-48EB-B59C-371DE50044AD@math.washington.edu> Message-ID: <4AE98446.8040005@behnel.de> Robert Bradshaw, 29.10.2009 09:05: > Stefan, > > While compiling Sage I found a curious bug in the enumerate() > operation--it was casting PyObject* directly into typed targets (e.g. > ints). > > http://trac.cython.org/cython_trac/ticket/442 > > For the moment I've disabled this optimization in this case, but it > might be an easy fix. Yep: http://hg.cython.org/cython-devel/rev/56f98d6f0fc6 Stefan From stefan_ml at behnel.de Thu Oct 29 13:15:47 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Thu, 29 Oct 2009 13:15:47 +0100 Subject: [Cython] Cast real to complex? In-Reply-To: <4AE8673F.5070205@student.matnat.uio.no> References: <4AE8673F.5070205@student.matnat.uio.no> Message-ID: <4AE98773.8070900@behnel.de> Dag Sverre Seljebotn, 28.10.2009 16:46: > I just attempted > > (x) * z > > where x is float. (To work around a certain recently reported bug.) > However conversion to complex this way is not supported. Is this a > feature or a bug? IMHO, neither of the two, but I wouldn't mind supporting that. There is little ambiguity in the above cast. I assume the above would simply use a stack allocated complex temp variable to store the converted complex value, right? Stefan From sccolbert at gmail.com Thu Oct 29 13:32:09 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Thu, 29 Oct 2009 13:32:09 +0100 Subject: [Cython] modify docstrings at run or compile time Message-ID: <7f014ea60910290532y509d229cqd637f83d73ef26f3@mail.gmail.com> Hi, I didn't get a response on Cython-users, so i thought I might try here. I tried modifying the docstrings of cythonized "def" functions via a function decorator. While it passes cython compilation, I get a run-time error that says the docstring cannot be modified in place. Is there a special cython decorator that will allow me to do this, or a compile time option that will run my decorator, and generate the new docstring before compiling? Cheers! Chris From dagss at student.matnat.uio.no Thu Oct 29 13:54:09 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Thu, 29 Oct 2009 13:54:09 +0100 Subject: [Cython] Cast real to complex? In-Reply-To: <4AE98773.8070900@behnel.de> References: <4AE8673F.5070205@student.matnat.uio.no> <4AE98773.8070900@behnel.de> Message-ID: <4AE99071.9010903@student.matnat.uio.no> Stefan Behnel wrote: > Dag Sverre Seljebotn, 28.10.2009 16:46: > >> I just attempted >> >> (x) * z >> >> where x is float. (To work around a certain recently reported bug.) >> However conversion to complex this way is not supported. Is this a >> feature or a bug? >> > > IMHO, neither of the two, but I wouldn't mind supporting that. There is > little ambiguity in the above cast. I assume the above would simply use a > stack allocated complex temp variable to store the converted complex value, > right? > Yes. I forgot to say that erronoues C code is currently generated, so it's a bug no matter how one looks at it, just wondering in which direction it should be fixed... I'm not sure when I'll have time to fix all these complex issues but I'll keep them in mind. Dag Sverre From ndbecker2 at gmail.com Thu Oct 29 20:25:44 2009 From: ndbecker2 at gmail.com (Neal Becker) Date: Thu, 29 Oct 2009 15:25:44 -0400 Subject: [Cython] =?utf-8?b?ZXJyb3I6IOKAmF9fUHl4X1NhZmVSZWxlYXNlQnVmZmVy?= =?utf-8?q?=E2=80=99_was_not_declared_in_this_scope?= Message-ID: This code: ------------------- import numpy as np cimport numpy as np np.import_array() cdef inline int x_ (int k, int n): cdef int center = (n-1)/2 return k-center def lagrange (float x, int n): cdef np.ndarray[np.float64_t, ndim=1] ret # = np.empty (n, dtype=float) cdef int j, k cdef float prod, top, bot for j in range (n): prod = 1 for k in xrange (0, n): if (k != j): top = x - x_(k, n) bot = x_(j, n) - x_(k, n) prod *= top/bot ret[j] = prod return ret -------------- gives: _lagrange_coef.cpp: In function ?PyObject* __pyx_pf_14_lagrange_coef_lagrange(PyObject*, PyObject*, PyObject*)?: _lagrange_coef.cpp:941: error: ?__Pyx_SafeReleaseBuffer? was not declared in this scope _lagrange_coef.cpp:947: error: ?__Pyx_SafeReleaseBuffer? was not declared in this scope No error with the comment (np.empty) removed. Bug or user error? From seb.binet at gmail.com Thu Oct 29 20:31:37 2009 From: seb.binet at gmail.com (Sebastien Binet) Date: Thu, 29 Oct 2009 21:31:37 +0200 Subject: [Cython] "real" module support Message-ID: <200910292031.38904.binet@cern.ch> hi there, I have some freecycles these days and I was wondering if I couldn't dive a little bit more into cython's codebase. my pet peeve would be to add some more user friendly module support in cython, so one could write: # mymodule.pyx __all__ = [ 'fct1', 'fct2', 'cls1', 'obj', ] # definitions follow # EOF and be able to cimport those in various other cython modules, instead of having to create .pxd and .pyx files. so, where should I start ? cheers, sebastien. -- ######################################### # Dr. Sebastien Binet # Laboratoire de l'Accelerateur Lineaire # Universite Paris-Sud XI # Batiment 200 # 91898 Orsay ######################################### From dalcinl at gmail.com Fri Oct 30 00:22:30 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Thu, 29 Oct 2009 20:22:30 -0300 Subject: [Cython] repr(complex) has changed in Py3.1 In-Reply-To: <4AE7EF2D.9070903@behnel.de> References: <4AE7EF2D.9070903@behnel.de> Message-ID: Sorry for the late reply.. On Wed, Oct 28, 2009 at 4:13 AM, Stefan Behnel wrote: > Hi, > > most of the 'complex' tests currently fail in Py3.1 because > complex.__repr__() became more correct. It now prints (-0-2j) for -(2j). > Are you sure this is "more correct" ? What's the point of printing a "0" for the real part? I really do not know what's going on there... Enter your python prompt ant try to make it print a complex with a single "0" for the real part, I was not able to do so... > Could someone who was involved in writing this code (Dag or Lisandro, I > guess) please take a look It was Robert :-) > and decide a) if this is worth testing for, and > b) if it's enough to fix the test or if the support in Cython also needs > adaptation to match what Py3.1 prints? > > > That would allow us to close ticket #319. > Well, we have to resolve the external typedef stuff... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From robert.kern at gmail.com Fri Oct 30 00:35:11 2009 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 29 Oct 2009 18:35:11 -0500 Subject: [Cython] repr(complex) has changed in Py3.1 In-Reply-To: References: <4AE7EF2D.9070903@behnel.de> Message-ID: On 2009-10-29 18:22 PM, Lisandro Dalcin wrote: > Sorry for the late reply.. > > On Wed, Oct 28, 2009 at 4:13 AM, Stefan Behnel wrote: >> Hi, >> >> most of the 'complex' tests currently fail in Py3.1 because >> complex.__repr__() became more correct. It now prints (-0-2j) for -(2j). > > Are you sure this is "more correct" ? What's the point of printing a > "0" for the real part? I really do not know what's going on there... +0 and -0 are different in IEEE floating point representation. It is information that should be preserved particularly since signed zeros are more important with complex numbers than reals because of branch cuts. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From robertwb at math.washington.edu Fri Oct 30 00:41:14 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 29 Oct 2009 16:41:14 -0700 Subject: [Cython] repr(complex) has changed in Py3.1 In-Reply-To: References: <4AE7EF2D.9070903@behnel.de> Message-ID: On Oct 29, 2009, at 4:22 PM, Lisandro Dalcin wrote: > Sorry for the late reply.. > > On Wed, Oct 28, 2009 at 4:13 AM, Stefan Behnel > wrote: >> Hi, >> >> most of the 'complex' tests currently fail in Py3.1 because >> complex.__repr__() became more correct. It now prints (-0-2j) for - >> (2j). >> > > Are you sure this is "more correct" ? What's the point of printing a > "0" for the real part? I had the same thought. > I really do not know what's going on there... > Enter your python prompt ant try to make it print a complex with a > single "0" for the real part, I was not able to do so... I'm confused too Python 3.0 (r30:67503, Jan 23 2009, 04:39:45) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> str(-2j) '-2j' >>> repr(-2j) '-2j' Perhaps it's a 3.1+ thing. >> Could someone who was involved in writing this code (Dag or >> Lisandro, I >> guess) please take a look > > It was Robert :-) > >> and decide a) if this is worth testing for, and >> b) if it's enough to fix the test or if the support in Cython also >> needs >> adaptation to match what Py3.1 prints? When I write cdef double complex z = -2j print z it converts z into a Python complex object, then prints it. We don't do any string conversion ourselves. If they changed the was repr works, the only thing I see to do is change the doctest depending on the Python version. - Robert From robertwb at math.washington.edu Fri Oct 30 00:41:55 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 29 Oct 2009 16:41:55 -0700 Subject: [Cython] enumerate() optimization In-Reply-To: <4AE98446.8040005@behnel.de> References: <9EABA1F9-A618-48EB-B59C-371DE50044AD@math.washington.edu> <4AE98446.8040005@behnel.de> Message-ID: <950174D7-43AF-4FE0-95FE-0455351275E1@math.washington.edu> On Oct 29, 2009, at 5:02 AM, Stefan Behnel wrote: > Robert Bradshaw, 29.10.2009 09:05: >> Stefan, >> >> While compiling Sage I found a curious bug in the enumerate() >> operation--it was casting PyObject* directly into typed targets (e.g. >> ints). >> >> http://trac.cython.org/cython_trac/ticket/442 >> >> For the moment I've disabled this optimization in this case, but it >> might be an easy fix. > > Yep: > > http://hg.cython.org/cython-devel/rev/56f98d6f0fc6 Thanks. I was hoping it was that simple--I just figured better safe than sorry. - Robert From robertwb at math.washington.edu Fri Oct 30 00:44:01 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 29 Oct 2009 16:44:01 -0700 Subject: [Cython] repr(complex) has changed in Py3.1 In-Reply-To: References: <4AE7EF2D.9070903@behnel.de> Message-ID: <724452F6-4750-4217-9591-F9D89EC78811@math.washington.edu> On Oct 29, 2009, at 4:35 PM, Robert Kern wrote: > On 2009-10-29 18:22 PM, Lisandro Dalcin wrote: >> Sorry for the late reply.. >> >> On Wed, Oct 28, 2009 at 4:13 AM, Stefan >> Behnel wrote: >>> Hi, >>> >>> most of the 'complex' tests currently fail in Py3.1 because >>> complex.__repr__() became more correct. It now prints (-0-2j) for - >>> (2j). >> >> Are you sure this is "more correct" ? What's the point of printing a >> "0" for the real part? I really do not know what's going on there... > > +0 and -0 are different in IEEE floating point representation. It is > information > that should be preserved particularly since signed zeros are more > important with > complex numbers than reals because of branch cuts. That is a very good point that I never thought about. - Robert From wstein at gmail.com Fri Oct 30 00:56:37 2009 From: wstein at gmail.com (William Stein) Date: Thu, 29 Oct 2009 16:56:37 -0700 Subject: [Cython] repr(complex) has changed in Py3.1 In-Reply-To: References: <4AE7EF2D.9070903@behnel.de> Message-ID: <85e81ba30910291656g3f643b6xe7e8daa3511202a0@mail.gmail.com> On Thu, Oct 29, 2009 at 4:41 PM, Robert Bradshaw wrote: > On Oct 29, 2009, at 4:22 PM, Lisandro Dalcin wrote: > >> Sorry for the late reply.. >> >> On Wed, Oct 28, 2009 at 4:13 AM, Stefan Behnel >> wrote: >>> Hi, >>> >>> most of the 'complex' tests currently fail in Py3.1 because >>> complex.__repr__() became more correct. It now prints (-0-2j) for - >>> (2j). >>> >> >> Are you sure this is "more correct" ? What's the point of printing a >> "0" for the real part? > > I had the same thought. > >> I really do not know what's going on there... >> Enter your python prompt ant try to make it print a complex with a >> single "0" for the real part, I was not able to do so... > > I'm confused too > > Python 3.0 (r30:67503, Jan 23 2009, 04:39:45) > [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > ?>>> str(-2j) > '-2j' > ?>>> repr(-2j) > '-2j' > > Perhaps it's a 3.1+ thing. I installed python3.1.1 system-wide on sage.math.washington.edu just now: wstein at sage:~$ python3.1 Python 3.1.1 (r311:74480, Oct 29 2009, 16:43:33) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> repr(-2j) '-2j' >>> str(-2j) '-2j' > >>> Could someone who was involved in writing this code (Dag or >>> Lisandro, I >>> guess) please take a look >> >> It was Robert :-) >> >>> and decide a) if this is worth testing for, and >>> b) if it's enough to fix the test or if the support in Cython also >>> needs >>> adaptation to match what Py3.1 prints? > > When I write > > cdef double complex z = -2j > print z > > it converts z into a Python complex object, then prints it. We don't > do any string conversion ourselves. If they changed the was repr > works, the only thing I see to do is change the doctest depending on > the Python version. > > - Robert > > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > -- William Stein Associate Professor of Mathematics University of Washington http://wstein.org From robertwb at math.washington.edu Fri Oct 30 01:07:34 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 29 Oct 2009 17:07:34 -0700 Subject: [Cython] repr(complex) has changed in Py3.1 In-Reply-To: <85e81ba30910291656g3f643b6xe7e8daa3511202a0@mail.gmail.com> References: <4AE7EF2D.9070903@behnel.de> <85e81ba30910291656g3f643b6xe7e8daa3511202a0@mail.gmail.com> Message-ID: On Oct 29, 2009, at 4:56 PM, William Stein wrote: > On Thu, Oct 29, 2009 at 4:41 PM, Robert Bradshaw > wrote: >> On Oct 29, 2009, at 4:22 PM, Lisandro Dalcin wrote: >> >>> Sorry for the late reply.. >>> >>> On Wed, Oct 28, 2009 at 4:13 AM, Stefan Behnel >>> wrote: >>>> Hi, >>>> >>>> most of the 'complex' tests currently fail in Py3.1 because >>>> complex.__repr__() became more correct. It now prints (-0-2j) for - >>>> (2j). >>>> >>> >>> Are you sure this is "more correct" ? What's the point of printing a >>> "0" for the real part? >> >> I had the same thought. >> >>> I really do not know what's going on there... >>> Enter your python prompt ant try to make it print a complex with a >>> single "0" for the real part, I was not able to do so... >> >> I'm confused too >> >> Python 3.0 (r30:67503, Jan 23 2009, 04:39:45) >> [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 >> Type "help", "copyright", "credits" or "license" for more >> information. >> >>> str(-2j) >> '-2j' >> >>> repr(-2j) >> '-2j' >> >> Perhaps it's a 3.1+ thing. > > I installed python3.1.1 system-wide on sage.math.washington.edu just > now: > > wstein at sage:~$ python3.1 > Python 3.1.1 (r311:74480, Oct 29 2009, 16:43:33) > [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu4)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> repr(-2j) > '-2j' >>>> str(-2j) > '-2j' Ah... Python 3.1.1 (r311:74480, Oct 29 2009, 16:43:33) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> repr(-(2j)) '(-0-2j)' - Robert From dalcinl at gmail.com Fri Oct 30 01:12:13 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Thu, 29 Oct 2009 21:12:13 -0300 Subject: [Cython] repr(complex) has changed in Py3.1 In-Reply-To: References: <4AE7EF2D.9070903@behnel.de> Message-ID: On Thu, Oct 29, 2009 at 8:35 PM, Robert Kern wrote: > On 2009-10-29 18:22 PM, Lisandro Dalcin wrote: >> Sorry for the late reply.. >> >> On Wed, Oct 28, 2009 at 4:13 AM, Stefan Behnel ?wrote: >>> Hi, >>> >>> most of the 'complex' tests currently fail in Py3.1 because >>> complex.__repr__() became more correct. It now prints (-0-2j) for -(2j). >> >> Are you sure this is "more correct" ? What's the point of printing a >> "0" for the real part? I really do not know what's going on there... > > +0 and -0 are different in IEEE floating point representation. It is information > that should be preserved particularly since signed zeros are more important with > complex numbers than reals because of branch cuts. > Of course!!! I just did not play attention that the "0" had a minus! Sorry for the noise... These "-0" make perfect sense... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From robertwb at math.washington.edu Fri Oct 30 07:26:10 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Thu, 29 Oct 2009 23:26:10 -0700 Subject: [Cython] Cython 0.12 In-Reply-To: <63C4D4A6-135E-47AD-9AB1-1D97257445E6@math.washington.edu> References: <39B44714-6629-4DC6-B336-37706D45E852@math.washington.edu> <4AE2950B.9020405@behnel.de> <4AE7F0EB.4020800@behnel.de> <63C4D4A6-135E-47AD-9AB1-1D97257445E6@math.washington.edu> Message-ID: <915B8CA5-BD57-4511-A6E7-D25779A730E3@math.washington.edu> On Oct 28, 2009, at 2:45 AM, Robert Bradshaw wrote: > On Oct 28, 2009, at 12:21 AM, Stefan Behnel wrote: > >> Hi, >> >> Mark Lodato, 24.10.2009 17:49: >>> On Sat, Oct 24, 2009 at 1:47 AM, Stefan Behnel wrote: >>>> There's also #434 about --embed not working in Py3. Mark, did you >>>> test your >>>> patch under Py3.1? >>> >>> I saw that bug, and cython_freeze has the exact same problems as >>> --embed. I'm working on a fix now. >> >> ... any news from this front? > > Yes, see > > http://trac.cython.org/cython_trac/ticket/439 FYI, this was due to memory corruption because of the enumerate bug. (That's how I found it.) There were a couple of minor changes for Sage 4.2, but it now builds fine and passes all doctests. - Robert From sccolbert at gmail.com Fri Oct 30 13:14:08 2009 From: sccolbert at gmail.com (Chris Colbert) Date: Fri, 30 Oct 2009 13:14:08 +0100 Subject: [Cython] modify docstrings at run or compile time In-Reply-To: <7f014ea60910290532y509d229cqd637f83d73ef26f3@mail.gmail.com> References: <7f014ea60910290532y509d229cqd637f83d73ef26f3@mail.gmail.com> Message-ID: <7f014ea60910300514h3f253681p71a37831b1929ffb@mail.gmail.com> Ok, it turns out this is possible using numpy.add_docstring() the caveat is that there must be no previous docstring in the object. Remember: this is only for adding docstrings to compiled extension module objects at runtime. Here is a small contrived example (untested): #--------------------- # decorator.py #--------------------- import numpy as np class DocDeco(object): def __init__(self, doc): self.doc = str(doc) def __call__(self, func): np.add_docstring(func, self.doc) return func docdeco = DocDeco #---------------------- # foo.py #---------------------- from decorator import docdeco @docdeco('''docstring goes here''') def bar(): pass On Thu, Oct 29, 2009 at 1:32 PM, Chris Colbert wrote: > Hi, > > I didn't get a response on Cython-users, so i thought I might try here. > > I tried modifying the docstrings of cythonized "def" functions via a > function decorator. > > While it passes cython compilation, I get a run-time error that says > the docstring cannot be modified in place. > > Is there a special cython decorator that will allow me to do this, or > a compile time option that will run my decorator, and generate the new > docstring before compiling? > > Cheers! > > Chris > From dagss at student.matnat.uio.no Fri Oct 30 14:40:44 2009 From: dagss at student.matnat.uio.no (Dag Sverre Seljebotn) Date: Fri, 30 Oct 2009 14:40:44 +0100 Subject: [Cython] modify docstrings at run or compile time In-Reply-To: <7f014ea60910300514h3f253681p71a37831b1929ffb@mail.gmail.com> References: <7f014ea60910290532y509d229cqd637f83d73ef26f3@mail.gmail.com> <7f014ea60910300514h3f253681p71a37831b1929ffb@mail.gmail.com> Message-ID: Chris Colbert wrote: > Ok, it turns out this is possible using numpy.add_docstring() > > the caveat is that there must be no previous docstring in the object. Could it be that add_docstring simply creates a wrapper object? I.e. if you don't worry about performance you could easily make this how you want it (including append/merge docstrings) if you do class Wrapper: def __init__(self, func, doc): self.__doc__ = doc self.func = func def __call__(self, *args, **kw): return self.func(*args, **kw) Dag Sverre > > Remember: this is only for adding docstrings to compiled extension > module objects at runtime. > > Here is a small contrived example (untested): > > #--------------------- > # decorator.py > #--------------------- > import numpy as np > > class DocDeco(object): > def __init__(self, doc): > self.doc = str(doc) > > def __call__(self, func): > np.add_docstring(func, self.doc) > return func > > docdeco = DocDeco > > > #---------------------- > # foo.py > #---------------------- > from decorator import docdeco > > @docdeco('''docstring goes here''') > def bar(): > pass > > > > > On Thu, Oct 29, 2009 at 1:32 PM, Chris Colbert > wrote: >> Hi, >> >> I didn't get a response on Cython-users, so i thought I might try here. >> >> I tried modifying the docstrings of cythonized "def" functions via a >> function decorator. >> >> While it passes cython compilation, I get a run-time error that says >> the docstring cannot be modified in place. >> >> Is there a special cython decorator that will allow me to do this, or >> a compile time option that will run my decorator, and generate the new >> docstring before compiling? >> >> Cheers! >> >> Chris >> > _______________________________________________ > Cython-dev mailing list > Cython-dev at codespeak.net > http://codespeak.net/mailman/listinfo/cython-dev > From dalcinl at gmail.com Fri Oct 30 14:50:27 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Fri, 30 Oct 2009 11:50:27 -0200 Subject: [Cython] modify docstrings at run or compile time In-Reply-To: References: <7f014ea60910290532y509d229cqd637f83d73ef26f3@mail.gmail.com> <7f014ea60910300514h3f253681p71a37831b1929ffb@mail.gmail.com> Message-ID: On Fri, Oct 30, 2009 at 11:40 AM, Dag Sverre Seljebotn wrote: > Chris Colbert wrote: >> Ok, it turns out this is possible using numpy.add_docstring() >> >> the caveat is that there must be no previous docstring in the object. > > Could it be that add_docstring simply creates a wrapper object? Not at all. 'add_docstring()' is a vile hack implemented in C land that set the char* ml_doc slot in PyMethodDef entries... Moreover, add_docstring() causes a reference leak of the string object. -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From sturla at molden.no Fri Oct 30 17:11:35 2009 From: sturla at molden.no (Sturla Molden) Date: Fri, 30 Oct 2009 17:11:35 +0100 Subject: [Cython] opengl def Message-ID: <4AEB1037.6000704@molden.no> I could not post attachments to the user group (reading from web), so here it is. Sturla -------------- next part -------------- A non-text attachment was scrubbed... Name: opengl.pxd.bz2 Type: application/octet-stream Size: 26131 bytes Desc: not available Url : http://codespeak.net/pipermail/cython-dev/attachments/20091030/6c34932e/attachment-0001.obj From stefan_ml at behnel.de Sat Oct 31 14:18:35 2009 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 31 Oct 2009 14:18:35 +0100 Subject: [Cython] getting rid of the PY_NEW() hack Message-ID: <4AEC392B.9080406@behnel.de> Hi, I noticed that Robert used the PY_NEW() hack in the Alioth shootout implementations, which got me into rethinking how to deal with this. I know that it's faster and all that, so there's a need to do this. However, I dislike the fact that one needs to write a header file and a cdef-external declaration just to get to this feature. To fix this, I pushed a change that optimises this cdef type some_type = ... obj = some_type.__new__(some_type) into a call to the tp_new slot. It requires that the name is used twice (just like it works in Python), and it also requires the object to be either declared as 'type' or be the name of an extension type. This is because Python does the type checking in the Python __new__() method, not in the slot function, so we have to make sure this optimisation doesn't lead to errors being ignored that would otherwise be caught by a real call to __new__(). I think this is safe, but I wanted to mention it here so that others can give it another bit of thought. I know that there are better ways to do this behind the scenes. If we know that an extension type (hierarchy) does not define __init__(), we can even optimise a simple type instantiation call into a tp_new() call. However, the above is an explicit way of doing it, it's the normal Python spelling, and it doesn't prevent further optimisations in the future. So I think it's worth it. Stefan From robertwb at math.washington.edu Sat Oct 31 21:14:45 2009 From: robertwb at math.washington.edu (Robert Bradshaw) Date: Sat, 31 Oct 2009 13:14:45 -0700 Subject: [Cython] getting rid of the PY_NEW() hack In-Reply-To: <4AEC392B.9080406@behnel.de> References: <4AEC392B.9080406@behnel.de> Message-ID: On Oct 31, 2009, at 6:18 AM, Stefan Behnel wrote: > Hi, > > I noticed that Robert used the PY_NEW() hack in the Alioth shootout > implementations, which got me into rethinking how to deal with this. > I know > that it's faster and all that, so there's a need to do this. > However, I > dislike the fact that one needs to write a header file and a cdef- > external > declaration just to get to this feature. Yep, it's always been considered a hack, though a very useful one. It comes from way back in the day when it was (perceived to be) easier to work around Pyrex than modify it. > To fix this, I pushed a change that optimises this > > cdef type some_type = ... > obj = some_type.__new__(some_type) > > into a call to the tp_new slot. It requires that the name is used > twice > (just like it works in Python), and it also requires the object to be > either declared as 'type' or be the name of an extension type. This is > because Python does the type checking in the Python __new__() > method, not > in the slot function, so we have to make sure this optimisation > doesn't > lead to errors being ignored that would otherwise be caught by a > real call > to __new__(). > > I think this is safe, but I wanted to mention it here so that others > can > give it another bit of thought. > > I know that there are better ways to do this behind the scenes. If > we know > that an extension type (hierarchy) does not define __init__(), we > can even > optimise a simple type instantiation call into a tp_new() call. > However, > the above is an explicit way of doing it, it's the normal Python > spelling, > and it doesn't prevent further optimisations in the future. So I > think it's > worth it. Very much so. Thanks! The implementation certainly seems safe to me. - Robert From dalcinl at gmail.com Sat Oct 31 21:43:05 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sat, 31 Oct 2009 17:43:05 -0300 Subject: [Cython] getting rid of the PY_NEW() hack In-Reply-To: <4AEC392B.9080406@behnel.de> References: <4AEC392B.9080406@behnel.de> Message-ID: On Sat, Oct 31, 2009 at 10:18 AM, Stefan Behnel wrote: > > I think this is safe, but I wanted to mention it here so that others can > give it another bit of thought. > Stefan, could you cythonize the line below: cdef str s = str.__new__(str) In the generated C code you will see a superfluous check "if(str is None): raise TypeError()" ... Can you figure out why this is happening? BTW, this piece of code if far from being what CPython actually does :-) ... 1064 elif type_arg.type_entry != obj.type_entry: 1065 # different types - do what CPython does at runtime 1066 error(type_arg.pos, "%s.__new__(%s) is not safe, use %s.__new__()" % 1067 (obj.type_entry.name, type_arg.type_entry.name, 1068 type_arg.type_entry.name)) 1069 return node -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594 From dalcinl at gmail.com Sat Oct 31 22:12:26 2009 From: dalcinl at gmail.com (Lisandro Dalcin) Date: Sat, 31 Oct 2009 18:12:26 -0300 Subject: [Cython] getting rid of the PY_NEW() hack In-Reply-To: <4AEC392B.9080406@behnel.de> References: <4AEC392B.9080406@behnel.de> Message-ID: On Sat, Oct 31, 2009 at 10:18 AM, Stefan Behnel wrote: > > To fix this, I pushed a change that optimises this > > ? ? ? ?cdef type some_type = ... > ? ? ? ?obj = some_type.__new__(some_type) > So it seems that the optimization only works if __new__ is called with just a single arg some_type... but your __new__ optimization will definitely call __cinit__. Do you think that optimizing a many-args __cinit__ is a nonsense? BTW, You did not taken into account __cinit__ special method in your testing... I've tried to add __cinit__ in your testcase with a "print" inside, but I do not know why the test hangs (this is a bit strange, isn't it?)... -- Lisandro Dalc?n --------------- Centro Internacional de M?todos Computacionales en Ingenier?a (CIMEC) Instituto de Desarrollo Tecnol?gico para la Industria Qu?mica (INTEC) Consejo Nacional de Investigaciones Cient?ficas y T?cnicas (CONICET) PTLC - G?emes 3450, (3000) Santa Fe, Argentina Tel/Fax: +54-(0)342-451.1594