On 9/4/11 4:19 PM, Maarten Derickx wrote:
Hej Guilherme,

Here at http://www.sagenb.org/home/pub/3117/
there is a modified version of your worksheet wich uses fast_callable to
make your example way faster. It is not as fast as your fortran example,
but as the timings at the bottom show this in not very reasonable to
expect in pure python, since the time my version takes is comparable to
the time it takes to initialize a Numpy array from pure python!


Does that use fast_callable? I couldn't find a mention of fast_callable in the worksheet anywhere except in the descriptive text at the top.

I wrote a small fast_float vector class that seems like it would be useful here. See http://sagenb.org/home/pub/2851/ (search for ff_vector), or just use the code below:

class ff_vector:
    def __init__(self, vec, *args, **kwds):
        self.comp = []
        self.nice = []

        for expr in vec:
            self.nice.append(expr)
            self.comp.append(fast_float(expr, *args, **kwds))

    def __call__(self,*args):
        if len(args)==1:
            args = list(args[0])
        v = vector(RDF, [f(*args) for f in self.comp])
        return v

    def __repr__(self):
        return 'ff_vector: '+repr(self.nice)


It's even faster if we return a python list rather than an RDF vector. I've done this at http://www.sagenb.org/home/pub/3122/, and you can see that we get to within ~5x of the fortran (if we cut out the overhead of creating a single list of the arguments).

If you used Cython, my guess is that you could get closer to the fortran. My guess is that the fortran would be hard to impossible to beat, though.


I'm (not actively) working on patches for fast_callable that will polish lots of things in fast_callable and will also enable fast_callable vectors [1]. Anyone that would like to help with that is more than welcome to work on it!


Thanks,

Jason


[1] http://trac.sagemath.org/sage_trac/ticket/5572

--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to