[Numpy-discussion] Assignment from a list is slow in Numarray
Timo Korvola
tkorvola at e.math.helsinki.fi
Sun Sep 19 10:36:05 EDT 2004
Hello,
I am new to the list, sorry if you've been through this before.
I am trying to do some FEM computations using Petsc, to which I have
written Python bindings using Swig. That involves passing arrays
around, which I found delightfully simple with
NA_{Input,Output,Io}Array. Numeric seems more difficult for output
and bidirectional arrays.
My code for reading a triangulation from a file went roughly
like this:
coord = zeros( (n_vertices, 2), Float)
for v in n_vertices:
coord[ v, :] = [float( s) for s in file.readline().split()]
This was taking quite a bit of time with ~50000 vertices and ~100000
elements, for which three integers per element are read in a similar
manner. I found it was faster to loop explicitly:
coord = zeros( (n_vertices, 2), Float)
for v in n_vertices:
for j, c in enumerate( [float( s) for s in file.readline().split()]):
coord[ v, j] = c
Morally this uglier code with an explicit loop should not be faster
but it is with Numarray. With Numeric assignment from a list has
reasonable performance. How can it be improved for Numarray?
--
Timo Korvola <URL:http://www.iki.fi/tkorvola>
More information about the NumPy-Discussion
mailing list