def _correct_auto_elements(surf, mat):
 pi2 = (2.0 * np.pi)
 tris_flat = surf['tris'].ravel()
 misses = (pi2 - mat.sum(axis=1))
 for (j, miss) in enumerate(misses):
  n_memb = len(surf['neighbor_tri'][j])
  mat[(j, j)] = (miss / 2.0)
  miss /= (4.0 * n_memb)
  members = np.where((j == tris_flat))[0]
  mods = (members % 3)
  offsets = np.array([[1, 2], [(-1), 1], [(-1), (-2)]])
  tri_1 = (members + offsets[(mods, 0)])
  tri_2 = (members + offsets[(mods, 1)])
  for (t1, t2) in zip(tri_1, tri_2):
   mat[(j, tris_flat[t1])] += miss
   mat[(j, tris_flat[t2])] += miss
 return

def _correct_auto_elements ( surf , mat ) : pi2 = ( 2.0 * np . pi ) tris_flat = surf [ 'tris' ] . ravel ( ) misses = ( pi2 - mat . sum ( axis = 1 ) ) for ( j , miss ) in enumerate ( misses ) : n_memb = len ( surf [ 'neighbor_tri' ] [ j ] ) mat [ ( j , j ) ] = ( miss / 2.0 ) miss /= ( 4.0 * n_memb ) members = np . where ( ( j == tris_flat ) ) [ 0 ] mods = ( members % 3 ) offsets = np . array ( [ [ 1 , 2 ] , [ ( - 1 ) , 1 ] , [ ( - 1 ) , ( - 2 ) ] ] ) tri_1 = ( members + offsets [ ( mods , 0 ) ] ) tri_2 = ( members + offsets [ ( mods , 1 ) ] ) for ( t1 , t2 ) in zip ( tri_1 , tri_2 ) : mat [ ( j , tris_flat [ t1 ] ) ] += miss mat [ ( j , tris_flat [ t2 ] ) ] += miss return
improve auto-element approximation .