On Tue, Jul 13, 2010 at 10:59 PM, Sturla Molden <[email protected]> wrote: > Kurt Smith skrev: >> def array_func_to_speedup(array1, array2): >> # array1 & array2 are 2D numpy arrays >> # still figuring out the exact syntax, inspired by scipy.weave >> from fwrap import weave >> fsrc = '''\ >> integer i,j >> do j = 1, array1_d2 >> do i = 1, array1_d1 >> array1(i, j) = array2(i, j)**2 >> enddo >> enddo >> ''' >> weave.inline(fsrc, ['array1', 'array2'], <other necessary bits>) >> assert np.all(array1 == array2**2) >> >> The 1st-class array support in Fortran 90/95 is a really nice fit >> here, I think, and the syntax is fairly natural. >> >> > Actually, > > fsrc = "array1 = array2**2" > > would suffice :-) > > That just shows why Fortran 90 is less painful than C for the work > scientists often do.
I should have picked a less trivial example :) But you're right -- Fortran's 1st class arrays have some very nice features, kind of like a simpler-and-faster version of numpy arrays. Unfortunately, for some compilers I've used, array expressions like: array1 = array2 + array3**2 Are slower than the 'do' version with explicit indexing -- that is to say, slower than they should be. Apparently the compilers create temporary arrays, exactly analogous to how numpy does it (although many times faster and with more opportunities for optimization). Perhaps I was using an old compiler when I tested this, or didn't turn on the right compile flags. Perhaps you can correct me on this. Kurt > > > Sturla _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
