[Numpy-discussion] Best way to handle "wrapped" array accesses?

Victor Putz vputz at nyx.net
Fri Oct 26 04:31:00 EDT 2007


I've seen a few references on this, but hadn't found a proper solution... 
I'm doing Lattice-Boltzmann simulations with periodic boundary conditions,
which always necessarily involve either padding the edges and doing 
additional steps, or making a "wrapped" array (for example, if I have an 
array that's N rows by M columns, and cells are moving right, I then make 
a "wrapped" array a la "D = hstack( A[:,0:-1], A[:,-1:] )" (creating a 
temporary) and adding them.

I'd like to avoid the temporary and still make the operation as fast as 
possible.  A really elegant solution would be a "wrapped array" subclass 
that would automatically handle the indexing (C = A[:,1:M+1] + B), but I'm 
not certain how friendly the array class is with subclassing.

What's the best way to handle this?  Am I pretty much stuck with 
temporaries or hacked functions ("add_wrapped(A, offset, B, C)")?

(It's probably a moot point in the long term, as once things get big I 
will have to use the cluster, which is probably not SciPy-friendly and 
it'll likely be a bit before I can convince the sys admin to let me play 
outside the "installed software" boundaries.  But now I just want to 
know).

Thanks,
-->VPutz




More information about the NumPy-Discussion mailing list