def test_accumulate_normals(): """Test efficient normal accumulation for surfaces.""" # set up comparison n_pts = int(1.6e5) # approx number in sample source space n_tris = int(3.2e5) # use all positive to make a worst-case for cumulative summation # (real "nn" vectors will have both positive and negative values) tris = (rng.rand(n_tris, 1) * (n_pts - 2)).astype(int) tris = np.c_[tris, tris + 1, tris + 2] tri_nn = rng.rand(n_tris, 3) this = dict(tris=tris, np=n_pts, ntri=n_tris, tri_nn=tri_nn) # cut-and-paste from original code in surface.py: # Find neighboring triangles and accumulate vertex normals this['nn'] = np.zeros((this['np'], 3)) for p in range(this['ntri']): # vertex normals verts = this['tris'][p] this['nn'][verts, :] += this['tri_nn'][p, :] nn = _accumulate_normals(this['tris'], this['tri_nn'], this['np']) # the moment of truth (or reckoning) assert_allclose(nn, this['nn'], rtol=1e-7, atol=1e-7)