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?