fhelium.backend.ntt
NTT numerical implementations, table preparation, and context-owned transforms.
NttContext provides policy-specific Tensor tables. NativeNttImplementation prepares operations over supplied Tensor operands and shares native calls with context transforms. Compile can select a schedule before preparing execution.
CompactPowerOfTwoRadixTables
class View source
CompactPowerOfTwoRadixTables(forward_outer_twiddles: torch.Tensor, inverse_outer_twiddles: torch.Tensor, forward_radix_root_powers: torch.Tensor, inverse_radix_root_powers: torch.Tensor)Packed outer twists and roots for strict fixed-radix digits.
Outer shapes are [limb, N - 1] and root shapes are [limb, radix] in QP row order. Conversion mutates each integral table from standard to Montgomery residues in place.
Attributes
| Name | Type | Default/value |
|---|---|---|
forward_outer_twiddles | torch.Tensor | |
inverse_outer_twiddles | torch.Tensor | |
forward_radix_root_powers | torch.Tensor | |
inverse_radix_root_powers | torch.Tensor |
convert_twiddles_to_montgomery_
method
def convert_twiddles_to_montgomery_(rns_params: torch.Tensor) -> None: ...CompactRadix2Tables
class View source
CompactRadix2Tables(forward_twiddles: torch.Tensor, inverse_twiddles: torch.Tensor)Dense [limb, N] twiddle rows for production kernels.
Rows align with QP parameter columns. Conversion mutates each integral table from standard to Montgomery residues in place.
Attributes
| Name | Type | Default/value |
|---|---|---|
forward_twiddles | torch.Tensor | |
inverse_twiddles | torch.Tensor |
convert_twiddles_to_montgomery_
method
def convert_twiddles_to_montgomery_(rns_params: torch.Tensor) -> None: ...IndexedRadix2Tables
class View source
IndexedRadix2Tables(forward_even_indices: torch.Tensor, forward_odd_indices: torch.Tensor, forward_twiddles: torch.Tensor, inverse_even_indices: torch.Tensor, inverse_odd_indices: torch.Tensor, inverse_twiddles: torch.Tensor)Schedules and stage-expanded twiddles for indexed execution.
Index tensors are torch.int32 on the backend device. Twiddle tensors are integral [limb, stage, butterfly] rows aligned with QP parameter columns; they begin in standard form and are converted in place to Montgomery form without changing shape, dtype, device, or storage.
Attributes
| Name | Type | Default/value |
|---|---|---|
forward_even_indices | torch.Tensor | |
forward_odd_indices | torch.Tensor | |
forward_twiddles | torch.Tensor | |
inverse_even_indices | torch.Tensor | |
inverse_odd_indices | torch.Tensor | |
inverse_twiddles | torch.Tensor |
convert_twiddles_to_montgomery_
method
def convert_twiddles_to_montgomery_(rns_params: torch.Tensor) -> None: ...NativeNttImplementation
class View source
NativeNttImplementation(name: str, required_backend_name: str | None, supports_in_place: bool = True, operation_types: tuple[type[Operation], ...] = _NTT_OPERATION_TYPES)Bases: _TensorOperandImplementation
Execute logical NTT operations through one named schedule executor.
Attributes
| Name | Type | Default/value |
|---|---|---|
name | str | |
required_backend_name | str | None | |
supports_in_place | bool | True |
operation_types | tuple[type[Operation], ...] | _NTT_OPERATION_TYPES |
select_ntt_schedule
method
def select_ntt_schedule(**facts): ...prepare_operation
method
def prepare_operation(operation: Operation): ...execute
method
def execute(invocation: OperationInvocation, values: tuple[torch.Tensor, ...], resources: tuple[BoundResource, ...], *, in_place: bool) -> tuple[torch.Tensor, ...]: ...NttContext
class View source
NttContext(rns_context: RnsContext, ntt_backend: str | None=None)Own one NTT policy and its tables, and use shared prepared transforms.
The context composes an RnsContext whose parameter tensor is passed unchanged to native NTT executors. Transform methods preserve prime rows and operand storage unless the method is the functional forward_to_montgomery variant.
tensor_operands
method
def tensor_operands(prime_ids: tuple[int, ...], *, inverse: bool) -> tuple[torch.Tensor, ...]: ...Return native table views for the selected rows and transform direction.
Parameter generation belongs to this context. The returned Tensors can be supplied directly or placed in a Program's external material table.
forward_montgomery_
method
def forward_montgomery_(a: torch.Tensor, *, include_p: bool=False, parameter_row_start: int | None=None) -> None: ...Apply the negacyclic forward NTT to Montgomery residues in place.
forward_to_montgomery_
method
def forward_to_montgomery_(a: torch.Tensor, *, include_p: bool=False, parameter_row_start: int | None=None) -> None: ...Apply forward NTT and standard-to-Montgomery conversion in place.
forward_to_montgomery
method
def forward_to_montgomery(a: torch.Tensor, *, include_p: bool=False, parameter_row_start: int | None=None) -> torch.Tensor: ...Return the non-aliasing forward NTT/Montgomery transition.
inverse_montgomery_
method
def inverse_montgomery_(a: torch.Tensor, *, include_p: bool=False, parameter_row_start: int | None=None) -> None: ...Apply normalized inverse NTT and keep Montgomery form.
inverse_to_standard_lazy_
method
def inverse_to_standard_lazy_(a: torch.Tensor, *, include_p: bool=False, parameter_row_start: int | None=None) -> None: ...Inverse NTT to coefficient/standard lazy residues in place.
inverse_to_standard_
method
def inverse_to_standard_(a: torch.Tensor, *, include_p: bool=False, parameter_row_start: int | None=None) -> None: ...Inverse NTT to coefficient/standard reduced residues in place.
inverse_to_centered_
method
def inverse_to_centered_(a: torch.Tensor, *, include_p: bool=False, parameter_row_start: int | None=None) -> None: ...Inverse NTT to centered coefficient/standard residues in place.
NttTables
data View source
NttTables = IndexedRadix2Tables | CompactRadix2Tables | CompactPowerOfTwoRadixTablesprepare_ntt_tables
function View source
def prepare_ntt_tables(policy: NttBackendPolicy, ckks_config: CkksConfig, *, materialize_parameter_rows: MaterializeParameterRows, device: torch.device, dtype: torch.dtype) -> NttTables: ...Build a plan and return separately allocated backend table tensors.
Prime rows follow the config's depth-zero QP order. Returned tensors use the selected execution dtype on device and remain in standard representation until RnsContext converts them in place.