fhelium/rns_tables.h
#include <fhelium/rns_tables.h> · namespace fhelium::rns
Construction of the RNS constant tables consumed by fhelium::rns, fhelium::ntt, and fhelium::ckks functions.
Every function computes its entries on the host from a list of odd moduli and returns new CPU Tensors; move them to the execution device before use. dtype is the residue dtype, int32 or int64, and selects the Montgomery radix
| Function | Devices | Summary |
|---|---|---|
parameter_table | Any device | Returns the rns_params Tensor of shape [RNS_PARAMETER_COUNT, limb] for moduli, whose rows follow fhelium/rns_parameters.h. |
integer_scalar_table | Any device | Returns scalar (an optional leading minus sign and digits) and every modulus moduli, the row residues of an integer-scalar product in Montgomery form, as a dtype Tensor of shape [moduli] on device. |
product_residues | Any device | Returns |
half_product_residues | Any device | Returns factors is odd. The result has shape [target]. |
half_product_digits | Any device | Returns the mixed-radix digits factors, so that |
quotient_offset_residues | Any device | Returns the residues of the rounding offset p_nearest is true and d_nearest is true, and 0 otherwise. |
mixed_radix_tables | Any device | Returns the Garner tables for a source basis destination. |
crt_basis_extension_tables | Any device | Returns the CRT basis-extension tables from source into target. |
crt_quotient_tables | Any device | Returns the centered CRT tables whose lift from source into target yields the negated quotient correction of an approximate division. |
trailing_quotient_inverses | Any device | Returns the inverses for removing the last drop_count moduli one at a time. |
rescale_inverse_matrix | Any device | Returns the shape [moduli, moduli] matrix whose entry |
joint_rescale_table_set | Any device | Named tables of the ModDown quotient fused with rescaling (JointRescaleTables, slots prefixed joint_). |
rescale_table_set | Any device | Named RescaleTables of the rational rescale from the source rows to the target rows; ntt_input adds |
basis_extension_table_set | Any device | Named BasisExtensionTables from the source rows of one parameter table to the target rows of another. |
crt_table_set | Any device | Named CrtTables of the approximate basis conversion from the source rows to the target rows; normalized selects the centered quotient form. |
centered_quotient_table_set | Any device | Named CrtTables of the centered quotient by the source rows evaluated on the target rows, scaled by the inverse of the divisor rows' product. |
parameter_table
function View source
at::Tensor fhelium::rns::parameter_table(
at::IntArrayRef moduli,
int64_t log_n,
double default_scale,
at::ScalarType dtype);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.parameter_table
fhelium_rns_ops::parameter_table(int[] moduli, int log_n, float default_scale, ScalarType dtype) -> TensorReturns the rns_params Tensor of shape [RNS_PARAMETER_COUNT, limb] for moduli, whose rows follow fhelium/rns_parameters.h.
The ring dimension is default_scale rounded to the nearest integer, ties to even.
integer_scalar_table
function View source
at::Tensor fhelium::rns::integer_scalar_table(
at::IntArrayRef moduli,
std::string_view scalar,
at::ScalarType dtype,
c10::Device device);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.integer_scalar_table
fhelium_rns_ops::integer_scalar_table(int[] moduli, str scalar, ScalarType dtype, Device device) -> TensorReturns scalar (an optional leading minus sign and digits) and every modulus moduli, the row residues of an integer-scalar product in Montgomery form, as a dtype Tensor of shape [moduli] on device.
product_residues
function View source
at::Tensor fhelium::rns::product_residues(
at::IntArrayRef factors,
at::IntArrayRef targets,
int64_t exponent,
bool montgomery,
at::ScalarType dtype);2
3
4
5
6
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.product_residues
fhelium_rns_ops::product_residues(int[] factors, int[] targets, int exponent, bool montgomery, ScalarType dtype) -> TensorReturns
exponent, either 1 or -1, and montgomery is true and 0 otherwise. The result has shape [target].
half_product_residues
function View source
at::Tensor fhelium::rns::half_product_residues(
at::IntArrayRef factors,
at::IntArrayRef targets,
at::ScalarType dtype);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.half_product_residues
fhelium_rns_ops::half_product_residues(int[] factors, int[] targets, ScalarType dtype) -> TensorReturns factors is odd. The result has shape [target].
half_product_digits
function View source
at::Tensor fhelium::rns::half_product_digits(
at::IntArrayRef factors,
at::ScalarType dtype);2
3
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.half_product_digits
fhelium_rns_ops::half_product_digits(int[] factors, ScalarType dtype) -> TensorReturns the mixed-radix digits factors, so that
The result has shape [factor].
quotient_offset_residues
function View source
at::Tensor fhelium::rns::quotient_offset_residues(
at::IntArrayRef p_moduli,
at::IntArrayRef d_moduli,
bool p_nearest,
bool d_nearest,
at::IntArrayRef targets,
at::ScalarType dtype);2
3
4
5
6
7
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.quotient_offset_residues
fhelium_rns_ops::quotient_offset_residues(int[] p_moduli, int[] d_moduli, bool p_nearest, bool d_nearest, int[] targets, ScalarType dtype) -> TensorReturns the residues of the rounding offset p_nearest is true and d_nearest is true, and 0 otherwise.
The result has shape [target] and holds
mixed_radix_tables
function View source
std::tuple<at::Tensor, at::Tensor, at::Tensor> fhelium::rns::mixed_radix_tables(
at::IntArrayRef source,
at::IntArrayRef destination,
at::ScalarType dtype);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.mixed_radix_tables
fhelium_rns_ops::mixed_radix_tables(int[] source, int[] destination, ScalarType dtype) -> (Tensor, Tensor, Tensor)Returns the Garner tables for a source basis destination.
With prefix products
normalizersof shape[w - 1]: ;propagationof shape[w - 1, w]: for and zero otherwise;extensionof shape[w - 1, destination]: for every destination modulus .
crt_basis_extension_tables
function View source
std::tuple<at::Tensor, at::Tensor, at::Tensor, at::Tensor, at::Tensor> fhelium::rns::crt_basis_extension_tables(
at::IntArrayRef source,
at::IntArrayRef target,
bool normalized,
at::ScalarType dtype);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.crt_basis_extension_tables
fhelium_rns_ops::crt_basis_extension_tables(int[] source, int[] target, bool normalized, ScalarType dtype) -> (Tensor, Tensor, Tensor, Tensor, Tensor)Returns the CRT basis-extension tables from source into target.
For matrix of shape [source, target] holds normalized is true. target_reciprocals holds source_normalizers holds source_reciprocals holds target_offsets holds crt_basis_extend lift the centered residues
crt_quotient_tables
function View source
std::tuple<at::Tensor, at::Tensor, at::Tensor, at::Tensor, at::Tensor> fhelium::rns::crt_quotient_tables(
at::IntArrayRef source,
at::IntArrayRef target,
at::IntArrayRef divisor,
at::ScalarType dtype);2
3
4
5
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.crt_quotient_tables
fhelium_rns_ops::crt_quotient_tables(int[] source, int[] target, int[] divisor, ScalarType dtype) -> (Tensor, Tensor, Tensor, Tensor, Tensor)Returns the centered CRT tables whose lift from source into target yields the negated quotient correction of an approximate division.
With divisor is empty) and matrix holds target_offsets holds crt_basis_extension_tables. For source residues crt_basis_extend with these tables returns moddown_crt_*, joint_crt_*) consume.
trailing_quotient_inverses
function View source
at::Tensor fhelium::rns::trailing_quotient_inverses(
at::IntArrayRef moduli,
int64_t drop_count,
at::ScalarType dtype);2
3
4
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.trailing_quotient_inverses
fhelium_rns_ops::trailing_quotient_inverses(int[] moduli, int drop_count, ScalarType dtype) -> TensorReturns the inverses for removing the last drop_count moduli one at a time.
Row [drop_count, moduli - 1] result are zero.
rescale_inverse_matrix
function View source
at::Tensor fhelium::rns::rescale_inverse_matrix(
at::IntArrayRef moduli,
at::ScalarType dtype);2
3
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.rescale_inverse_matrix
fhelium_rns_ops::rescale_inverse_matrix(int[] moduli, ScalarType dtype) -> TensorReturns the shape [moduli, moduli] matrix whose entry
joint_rescale_table_set
function View source
std::tuple<std::vector<std::string>, std::vector<at::Tensor>> fhelium::rns::joint_rescale_table_set(
const at::Tensor& parameters,
c10::IntArrayRef moduli,
int64_t log_n,
c10::IntArrayRef q_prime_ids,
c10::IntArrayRef p_prime_ids,
c10::IntArrayRef drop_prime_ids,
c10::IntArrayRef target_prime_ids,
std::string_view moddown_rounding,
std::string_view rescale_rounding,
std::string_view basis_conversion);2
3
4
5
6
7
8
9
10
11
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.joint_rescale_table_set
fhelium_rns_ops::joint_rescale_table_set(Tensor parameters, int[] moduli, int log_n, int[] q_prime_ids, int[] p_prime_ids, int[] drop_prime_ids, int[] target_prime_ids, str moddown_rounding, str rescale_rounding, str basis_conversion) -> (str[], Tensor[])Named tables of the ModDown quotient fused with rescaling (JointRescaleTables, slots prefixed joint_).
parameters is the parameter table of the context primes moduli. Q and P list the ordered input rows, D the Q rows that rescaling drops, and target_prime_ids the output rows (empty selects Q without D). The result pairs the slot names of the defined fields with their Tensors.
rescale_table_set
function View source
std::tuple<std::vector<std::string>, std::vector<at::Tensor>> fhelium::rns::rescale_table_set(
const at::Tensor& parameters,
c10::IntArrayRef moduli,
int64_t log_n,
c10::IntArrayRef source_prime_ids,
c10::IntArrayRef target_prime_ids,
std::string_view rounding,
bool ntt_input);2
3
4
5
6
7
8
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.rescale_table_set
fhelium_rns_ops::rescale_table_set(Tensor parameters, int[] moduli, int log_n, int[] source_prime_ids, int[] target_prime_ids, str rounding, bool ntt_input) -> (str[], Tensor[])Named RescaleTables of the rational rescale from the source rows to the target rows; ntt_input adds
basis_extension_table_set
function View source
std::tuple<std::vector<std::string>, std::vector<at::Tensor>> fhelium::rns::basis_extension_table_set(
const at::Tensor& source_parameters,
c10::IntArrayRef source_moduli,
const at::Tensor& target_parameters,
c10::IntArrayRef target_moduli,
int64_t log_n,
c10::IntArrayRef source_prime_ids,
c10::IntArrayRef target_prime_ids);2
3
4
5
6
7
8
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.basis_extension_table_set
fhelium_rns_ops::basis_extension_table_set(Tensor source_parameters, int[] source_moduli, Tensor target_parameters, int[] target_moduli, int log_n, int[] source_prime_ids, int[] target_prime_ids) -> (str[], Tensor[])Named BasisExtensionTables from the source rows of one parameter table to the target rows of another.
crt_table_set
function View source
std::tuple<std::vector<std::string>, std::vector<at::Tensor>> fhelium::rns::crt_table_set(
const at::Tensor& parameters,
c10::IntArrayRef moduli,
int64_t log_n,
c10::IntArrayRef source_prime_ids,
c10::IntArrayRef target_prime_ids,
bool normalized);2
3
4
5
6
7
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.crt_table_set
fhelium_rns_ops::crt_table_set(Tensor parameters, int[] moduli, int log_n, int[] source_prime_ids, int[] target_prime_ids, bool normalized) -> (str[], Tensor[])Named CrtTables of the approximate basis conversion from the source rows to the target rows; normalized selects the centered quotient form.
centered_quotient_table_set
function View source
std::tuple<std::vector<std::string>, std::vector<at::Tensor>> fhelium::rns::centered_quotient_table_set(
const at::Tensor& parameters,
c10::IntArrayRef moduli,
int64_t log_n,
c10::IntArrayRef source_prime_ids,
c10::IntArrayRef target_prime_ids,
c10::IntArrayRef divisor_prime_ids);2
3
4
5
6
7
Devices: Any device
Torch operator: torch.ops.fhelium_rns_ops.centered_quotient_table_set
fhelium_rns_ops::centered_quotient_table_set(Tensor parameters, int[] moduli, int log_n, int[] source_prime_ids, int[] target_prime_ids, int[] divisor_prime_ids) -> (str[], Tensor[])Named CrtTables of the centered quotient by the source rows evaluated on the target rows, scaled by the inverse of the divisor rows' product.