def compile_polynomial(
*,
window: int,
channels: int,
max_depth: int,
depths: tuple[int, ...] | None = None,
max_offset_span: int | None = None,
max_offset_support: int | None = None,
max_offset_multiplicity: int | None = None,
scaling: RawSignatureScale = "signature",
) -> PolynomialPlan:
"""Compile a raw scalar-polynomial coordinate dictionary once."""
for name, value in (("window", window), ("channels", channels)):
if not isinstance(value, int) or isinstance(value, bool) or value < 1:
raise ValueError(f"{name} must be a positive integer.")
restrictions = (
("max_offset_span", max_offset_span, 0),
("max_offset_support", max_offset_support, 1),
("max_offset_multiplicity", max_offset_multiplicity, 1),
)
for name, value, minimum in restrictions:
if value is not None and (
not isinstance(value, int) or isinstance(value, bool) or value < minimum
):
qualifier = "non-negative" if minimum == 0 else "positive"
raise ValueError(f"{name} must be a {qualifier} integer or None.")
if not isinstance(scaling, str) or scaling not in {"signature", "support"}:
raise ValueError("scaling must be 'signature' or 'support'.")
selected_depths = _depths(max_depth, depths)
dictionaries = tuple(
ScaledMonomialDictionary.raw_signature(
in_channels=channels,
kernel_size=window,
depth=depth,
max_offset_span=max_offset_span,
max_offset_support=max_offset_support,
max_offset_multiplicity=max_offset_multiplicity,
scale=scaling,
dtype=torch.float64,
)
for depth in selected_depths
)
return _compiled_plan(
PolynomialPlan,
window=window,
channels=channels,
max_depth=max(selected_depths),
depths=selected_depths,
max_offset_span=max_offset_span,
max_offset_support=max_offset_support,
max_offset_multiplicity=max_offset_multiplicity,
scaling=scaling,
_dictionaries=dictionaries,
)