fhelium.backend.rns.moddown
Auxiliary-basis removal in coefficient and NTT representations.
divide_trailing_rows
function View source
def divide_trailing_rows(source: torch.Tensor, inverses: torch.Tensor, parameters: torch.Tensor, drop_count: int, *, half: torch.Tensor | None=None, row_order: torch.Tensor | None=None, rounding: str='nearest') -> torch.Tensor: ...Return floor((x+h)/D) after arranging the divisor rows last.
D is the product of the trailing drop_count moduli. half supplies (D-1)/2 in the ordered basis for nearest rounding. Input storage is read-only.
moddown_qp_to_q
function View source
def moddown_qp_to_q(source, tensors, attributes): ...Return floor((x + h)/P) mod Q, with h=0 or (P-1)/2.
rounding selects floor or nearest. Depth and CKKS scale are preserved.
moddown_ntt_qp_to_q
function View source
def moddown_ntt_qp_to_q(source: torch.Tensor, tensors: Mapping[str, torch.Tensor], attributes: Mapping[str, object], *, coefficient_c0: torch.Tensor | None=None) -> torch.Tensor: ...Return
source holds NTT/Montgomery residues over active QP. Inverting only the P rows determines the coefficient remainder coefficient_c0 is supplied, it is added to component zero's coefficient correction before the forward NTT, adding NTT(c0) without another transform. The input c0 remains unchanged.
NativeModDownImplementation
class View source
NativeModDownImplementation(name: str = 'native-key-switch-moddown', supports_in_place: bool = False, operation_types: tuple[type[Operation], ...] = (rns.ModDownQpToQOp, rns.ModDownNttQpToQOp, rns.ModDownAddRescaleOp, rns.RoundedTrailingQuotientOp))Divide RNS accumulators by auxiliary and depth-group products.
Attributes
| Name | Type | Default/value |
|---|---|---|
name | str | 'native-key-switch-moddown' |
supports_in_place | bool | False |
operation_types | tuple[type[Operation], ...] | (rns.ModDownQpToQOp, rns.ModDownNttQpToQOp, rns.ModDownAddRescaleOp, rns.RoundedTrailingQuotientOp) |
tensor_requirements
method
def tensor_requirements(operation, config): ...prepare_operation
method
def prepare_operation(operation): ...resource_requirements
method
def resource_requirements(invocation: OperationInvocation) -> tuple[ResourceRequirement, ...]: ...execute
method
def execute(invocation: OperationInvocation, values: tuple[torch.Tensor, ...], resources: tuple[BoundResource, ...], *, in_place: bool) -> tuple[torch.Tensor, ...]: ...moddown_add_rescale
function View source
def moddown_add_rescale(products: torch.Tensor, base: torch.Tensor, tensors: Mapping[str, torch.Tensor], attributes: Mapping[str, object]) -> torch.Tensor: ...Compute
Inputs are NTT/Montgomery bundles. The products' leading component extent selects the matching prefix of base components. Source storage and numerical operands are read-only. Output is coefficient/standard or NTT/Montgomery according to output_domain.