simplex_parity#

iskra.topology.simplex_parity(faces: Tensor) → Tensor[SOURCE]#

Parity of each simplex’s vertex ordering relative to sorted order.

Treats the vertex indices of each simplex as a permutation of their sorted values and returns the parity of that permutation: \(0\) if even (same orientation as ascending index order), \(1\) if odd (opposite). Implemented by selection-sorting each simplex into ascending vertex order and counting swaps modulo \(2\). The number of transpositions is not unique, but its parity is.

Internally, we rely on the fact that the canonical order of vertices in a face is the sorted order. Therefore, the funciton performs a selection sort of the vertices within each face and counts how many swaps we have to do to arrive at a sorted list.

Tip

get_subfaces() maps this parity to the orientation signs \(\\{+1, -1\\}\) used in the face-subface hierarchy.

Caution

Vertex indices within each simplex are assumed distinct.

Parameters:

faces (Tensor[Int64, [Bs, F, FV]]) – Face-vertex indices. Any number of leading batch dimensions is allowed.

Returns:

​ (Tensor[Int64, [Bs, F]]) – \(0\) for even parity, \(1\) for odd parity.