diff --git a/tpy_r3d.py b/tpy_r3d.py index e1f2ff5..cbf49d4 100644 --- a/tpy_r3d.py +++ b/tpy_r3d.py @@ -70,14 +70,14 @@ def test_split_tets_thru_centroid(): # generate a random tet and clip plane ntets = 1 - opoly = [build_rand_tetrahedron() for _ in range(ntets)] - plane = plane_centroid(opoly[ntets//7]) + polys = [build_rand_tetrahedron() for _ in range(ntets)] + plane = plane_centroid(polys[ntets//7]) # split them all with the same plane - poly12 = [split(o, plane) for o in opoly] + poly12 = [split(p, plane) for p in polys] poly1, poly2 = zip(*poly12) - for orig, p1, p2 in zip(opoly, poly1, poly2): + for orig, p1, p2 in zip(polys, poly1, poly2): check_poly(orig) check_poly(p1) check_poly(p2) @@ -85,24 +85,24 @@ def test_split_tets_thru_centroid(): def time_split(): - NUM_TRIALS = 1000 + NUM_TRIALS = 100_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)] t0 = perf_counter() for t in range(NUM_TRIALS): # clip the first tet against the faces of the second - poly = polys[t] for face in facesets[t]: - _poly = clip(poly, face) - if (t+1) % 1000 == 0: + polys[t] = clip(polys[t], face) + if (t+1) % 10000 == 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}') + polys_bulk = [build_rand_tetrahedron() for _ in range(NUM_TRIALS)] bulk = { - 'vertices': numpy.vstack(p['vertices'] for p in polys), - 'neighbors': numpy.vstack(p['neighbors'] for p in polys) + numpy.arange(NUM_TRIALS).repeat(4)[:, None] * 4, + 'vertices': numpy.vstack(p['vertices'] for p in polys_bulk), + 'neighbors': numpy.vstack(p['neighbors'] for p in polys_bulk) + numpy.arange(NUM_TRIALS).repeat(4)[:, None] * 4, } t1 = perf_counter() poly = clip(bulk, facesets[0][0]) @@ -131,7 +131,7 @@ def test_tet_tet_timing(): # find the moments (up to quadratic order) of the clipped poly _om = get_moments(poly, POLY_ORDER) - if (t+1) % 1000 == 0: + if (t+1) % 10000 == 0: t_each = (perf_counter() - t0) / (t + 1) logger.info(f'time per split+get_moments for {t+1} iterations: {t_each}') logger.info(f'done timing, time per split+get_moments: {(perf_counter() - t0) / NUM_TRIALS}')