From b97a56f5f81a806d05d9c55146acad73af2a57bc Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Fri, 7 Oct 2011 16:59:35 -0400 Subject: 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. --- chroma/make.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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): """ -- cgit