[Numpy-discussion] Assignment from a list is slow in Numarray

Nadav Horesh nadavh at visionsense.com
Mon Sep 20 01:12:02 EDT 2004

Yo may try the aging module TableIO (http://php.iupui.edu/~mmiller3/python/). Just replace "import Numeric" by "import numarray as Numeric". It may give up to two-fold speed improvement. Since you have C skills, you might update the small C source to interact directly with numarray.


-----Original Message-----
From:	Timo Korvola [mailto:tkorvola at e.math.helsinki.fi]
Sent:	Sun 19-Sep-04 20:35
To:	numpy-discussion at lists.sourceforge.net
Subject:	[Numpy-discussion] Assignment from a list is slow in Numarray

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>

This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net

More information about the NumPy-Discussion mailing list