oh and a related question -- been wondering about this for a while : if i put all this in a foo.spyx file, i usually do "load foo.spyx". It works, but compiles every time! how do you just load the compiled version? and what about import it like a module, using foo.function() ?
On 14 fév, 18:11, Pierre <[email protected]> wrote: > Hey, thanks for all the responses. I use Cython occasionally, but i > tend to restrict myself to basic C types and simple functions which do > not import anything -- it seems I can learn an awful lot by studying > your examples! > > Can i ask the following questions about Jason's code? > > ** why so you 'import' CDF while you 'cimport' ComplexDoubleElement? > what is the difference? > > ** and why do these imports anyway, are they necessary for "cdef > complex..." to work? > > ** I didn't know PY_NEW. What is the difference between res= > PY_NEW(Matrix2) and simply res= Matrix2(0,0,0,0) (say) ? and what > about using PY_NEW with a class that *requires* parameters to its > __init__? > > ** more generally, is there a Cython tutorial that would be (just) > sufficiently advanced to cover such an example? > > thanks! > Pierre > > On 13 fév, 20:13, William Stein <[email protected]> wrote: > > > > > > > > > On Mon, Feb 13, 2012 at 11:07 AM, Jason Grout > > > <[email protected]> wrote: > > > On 2/13/12 12:41 PM, William Stein wrote: > > > >> On Mon, Feb 13, 2012 at 10:29 AM, Robert Bradshaw > > >> <[email protected]> wrote: > > > >>> On Mon, Feb 13, 2012 at 10:06 AM, William Stein<[email protected]> > > >>> wrote: > > > >>>> On Mon, Feb 13, 2012 at 9:59 AM, Pierre<[email protected]> > > >>>> wrote: > > > >>>>> I see. Well I *do* have hundreds of 2x2 matrices to multiply out so > > >>>>> i'm better off storing them as numpy matrices throughout... thanks for > > >>>>> your explanations though. > > > >>>>> Pierre > > > >>>> You might consider using Cython and writing a custom 2x2 matrix class. > > >>>> It wouldn't be difficult... so I'll write one right now and respond > > >>>> with the benchmarks. > > > >> Here it is: http://480.sagenb.org/home/pub/97/ > > > >> I ended up using GSL's complex matrix data type and the BLAS level 3 > > >> routine to do the multiplication. I did not add any other > > >> convenience functions to the class, so some more will probably be > > >> needed for your application. > > > > I'm curious why you didn't just store the 4 complex numbers in C. > > > I was concerned about "numerical stability" and figured BLAS would > > deal with that. But maybe that doesn't matter. > > > Most importantly, I forgot about Cython's complex type, which I now > > remember Robert Bradshaw wrote for his thesis work. I wasn't looking > > forward to writing your line: > > > res.m00=self.m00*right.m00+self.m01*right.m10 > > > but against the gsl library. But using the cython type in complex, > > you get the above at C speed with easy notation, which is pretty > > awesome. > > > > I tried > > > it and got a much bigger speedup: 17x faster than numpy and 150x faster > > > than > > > Sage. Seehttp://sagenb.org/home/pub/4303/ > > > Nice. > > > > Thanks, > > > > Jason > > > > -- > > > To post to this group, send email to [email protected] > > > To unsubscribe from this group, send email to > > > [email protected] > > > For more options, visit this group at > > >http://groups.google.com/group/sage-support > > > URL:http://www.sagemath.org > > > -- > > William Stein > > Professor of Mathematics > > University of Washingtonhttp://wstein.org -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
