Efficiently compute vertex neighboring triangles.
(tris, npts)
| 406 | |
| 407 | |
| 408 | def _triangle_neighbors(tris, npts): |
| 409 | """Efficiently compute vertex neighboring triangles.""" |
| 410 | # this code replaces the following, but is faster (vectorized): |
| 411 | # neighbor_tri = [list() for _ in range(npts)] |
| 412 | # for ti, tri in enumerate(tris): |
| 413 | # for t in tri: |
| 414 | # neighbor_tri[t].append(ti) |
| 415 | rows = tris.ravel() |
| 416 | cols = np.repeat(np.arange(len(tris)), 3) |
| 417 | data = np.ones(len(cols)) |
| 418 | csr = coo_array((data, (rows, cols)), shape=(npts, len(tris))).tocsr() |
| 419 | neighbor_tri = [ |
| 420 | csr.indices[start:stop] for start, stop in zip(csr.indptr[:-1], csr.indptr[1:]) |
| 421 | ] |
| 422 | assert len(neighbor_tri) == npts |
| 423 | return neighbor_tri |
| 424 | |
| 425 | |
| 426 | @jit() |
no outgoing calls