summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Seibert <stan@mtrr.org>2011-10-07 16:59:35 -0400
committerStan Seibert <stan@mtrr.org>2011-10-07 16:59:35 -0400
commitb97a56f5f81a806d05d9c55146acad73af2a57bc (patch)
tree92f1a62e7730cb0b72408fe9c17aff03ae94ab4b
parentc13c687cc1c3fed4484be2a19fc045cee7b3d310 (diff)
downloadchroma-b97a56f5f81a806d05d9c55146acad73af2a57bc.tar.gz
chroma-b97a56f5f81a806d05d9c55146acad73af2a57bc.tar.bz2
chroma-b97a56f5f81a806d05d9c55146acad73af2a57bc.zip
Rewrite mesh_grid to be less compact but 100x faster.
Most of the time required to build the LBNE geometry is spent on mesh_grid() for the highly segmented cylinder. (67 seconds!) The speed hit is caused by the use of zip to connect the vertices. The same task can be done in several lines with slice notation, and goes much faster.
-rw-r--r--chroma/make.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/chroma/make.py b/chroma/make.py
index 2c3155a..2f1d9a5 100644
--- a/chroma/make.py
+++ b/chroma/make.py
@@ -4,7 +4,20 @@ from chroma.transform import rotate
from chroma.itertoolset import *
def mesh_grid(grid):
- return np.vstack(zip(grid[:-1].flatten(),grid[1:].flatten(),np.roll(grid[1:],-1,1).flatten()) + zip(grid[:-1].flatten(),np.roll(grid[1:],-1,1).flatten(),np.roll(grid[:-1],-1,1).flatten()))
+ begin = grid[:-1].flatten()
+ end = grid[1:].flatten()
+ begin_roll = np.roll(grid[:-1],-1,1).flatten()
+ end_roll = np.roll(grid[1:],-1,1).flatten()
+
+ mesh = np.empty(shape=(2*len(begin),3), dtype=begin.dtype)
+ mesh[:len(begin),0] = begin
+ mesh[:len(begin),1] = end
+ mesh[:len(begin),2] = end_roll
+ mesh[len(begin):,0] = begin
+ mesh[len(begin):,1] = end_roll
+ mesh[len(begin):,2] = begin_roll
+
+ return mesh
def linear_extrude(x1, y1, height, x2=None, y2=None, center=None):
"""