MCPcopy
hub / github.com/mne-tools/mne-python / _triangle_neighbors

Function _triangle_neighbors

mne/surface.py:408–423  ·  view source on GitHub ↗

Efficiently compute vertex neighboring triangles.

(tris, npts)

Source from the content-addressed store, hash-verified

406
407
408def _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()

Callers 4

test_triangle_neighborsFunction · 0.90
_make_morph_map_hemiFunction · 0.85
complete_surface_infoFunction · 0.85
_get_vertex_map_nnFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_triangle_neighborsFunction · 0.72