function P1 = marginalize_potential(P1, onto)
% MARGINALIZE_POTENTIAL (Dispatch) Marginalize a generic potential.
% P1 = marginalize_potential(P1, onto)

switch P1.type
  case 'd',
    P1 = marginalize_table(P1, onto);
  case 'm',
    P1 = marginalize_max_table(P1, onto);
  case 'g',
    P1 = marginalize_gpot(P1, onto);
  case 'cg',
    P1 = marginalize_cgpot(P1, onto);
  otherwise
    error(['bad type ' P1.type]);
end
