Function deepmd::buildPairExcludeTable

Function deepmd::buildPairExcludeTable#

Function Documentation#

inline std::vector<int> deepmd::buildPairExcludeTable(const int ntypes, const std::vector<std::pair<int, int>> &exclude_types)#

Build the flat (ntypes+1)^2 pair-type keep table.

Inference-path mirror of the Python PairExcludeMask constructor (deepmd/dpmodel/utils/exclude_mask.py). The table is row-major over [tj][ti] (flat index tj * (ntypes+1) + ti); an entry is 0 when the ordered pair (ti, tj) is excluded and 1 otherwise. Both (ti, tj) and (tj, ti) are inserted into the exclude set, so the table is symmetric. Type ntypes is the reserved virtual-atom row/column.

Returns an empty vector when exclude_types is empty, so callers can treat an empty table as “no exclusion” (identity) just like the Python pair_excl is None early-exit.

This lives in the backend-agnostic common.h (not commonPT.h) so both the libtorch apply-helpers (applyPairExclusion* in commonPT.h) and the torch-free TF-C-API DeepPotJAX ingestion seam share one canonical table builder.

Parameters:
  • ntypes – Number of real atom types.

  • exclude_types – List of excluded (ti, tj) type pairs.