From 1473633a11100eb4cf19606e3490612b37df9934 Mon Sep 17 00:00:00 2001 From: jan Date: Tue, 3 Apr 2018 15:43:11 -0700 Subject: [PATCH] minor fixes and optim --- chop/util.py | 14 ++++++-------- tpy_r3d.py | 6 +++--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/chop/util.py b/chop/util.py index 8b40377..c7c14b7 100644 --- a/chop/util.py +++ b/chop/util.py @@ -73,9 +73,6 @@ def find_faces(neighbors: numpy.ndarray) -> List[numpy.ndarray]: v_current = v_start.copy() v_next = neighbors[v_current, nxt_edge] - mask = v_start # dummy for loop init, could use numpy.array([True]) instead - remove = numpy.zeros_like(edge_id, dtype=bool) - ''' Choose a method for storing the face info based on expected runtime vs unnecessary memory allocation @@ -115,9 +112,10 @@ def find_faces(neighbors: numpy.ndarray) -> List[numpy.ndarray]: b) we reach the original vertex (stop, done with this path) ''' k = 1 - #init_mask = v_next > v_current - #v = numpy.vstack((edge_id, v_start, v_current, v_next))[:, init_mask] - v = numpy.vstack((edge_id, v_start, v_current, v_next)) + mask = v_next > v_current + v = numpy.vstack((edge_id, v_start, v_current, v_next))[:, mask] + remove = numpy.logical_not(mask) + while mask.any(): add_edges(v[0], v[3], k) @@ -182,12 +180,12 @@ def _get_maps(a, b): @profile def _get_maps_rows(a, b): ''' - Row-wise _get_map_2way + Row-wise _get_maps ''' dims = numpy.maximum(a.max(0), b.max(0)) + 1 a1d = numpy.ravel_multi_index(a.T, dims) b1d = numpy.ravel_multi_index(b.T, dims) - return _get_map(a1d, b1d) + return _get_maps(a1d, b1d) def _argsort_rows(a): diff --git a/tpy_r3d.py b/tpy_r3d.py index d3baa0f..e31d438 100644 --- a/tpy_r3d.py +++ b/tpy_r3d.py @@ -85,7 +85,7 @@ def test_split_tets_thru_centroid(): def time_split(): - NUM_TRIALS = 100_000 + NUM_TRIALS = 10_000 logger.info(f'Intersecting {NUM_TRIALS} pairs of tetrahedra.') polys = [build_rand_tetrahedron() for _ in range(NUM_TRIALS)] facesets = [planes_from_tetrahedron(rand_tetrahedron_vertices()) for _ in range(NUM_TRIALS)] @@ -94,7 +94,7 @@ def time_split(): # clip the first tet against the faces of the second for face in facesets[t]: polys[t] = clip(polys[t], face) - if (t+1) % 10000 == 0: + if (t+1) % (NUM_TRIALS // 10) == 0: t_each = (perf_counter() - t0) / (t + 1) logger.info(f'time per split for {t+1} splits: {t_each}') logger.info(f'done timing, time per split: {(perf_counter() - t0) / NUM_TRIALS}') @@ -224,7 +224,7 @@ def test_voxelization(): grid = voxelize(poly, edges, order=POLY_ORDER) print(f'voxel time: {perf_counter() - t0}') - visualize_voxels(grid) + #visualize_voxels(grid) voxsum = numpy.sum(grid, axis=(0, 1, 2))