Files
torus/docs/dev/api/torus.fhe.extensions.truncate_bit_pattern.md
zeekay f968edf75a Rename the Concrete dialect and project identifiers to Torus
The MLIR dialect, its conversion passes (TFHEToConcrete, ConcreteToCAPI,
ConcreteToLLVM), the optimizer component, the compiler binary, the Rust
crate and the program_info parameter file all still carried the upstream
project's name. They now carry this one's.

Two things deliberately keep the word, because in them it is not the name.
mlir::OpTrait CRTP parameters mean "the derived type", so they are spelled
Derived and OpTy — LLVM's other conventional spelling for the same idiom.
concreteShape is a capnp field: renaming it would change the serialized
protocol, and the prose describing it is ordinary English.

This also repairs references the earlier partial rename left dangling:
Security.cpp included concrete/curves.gen.h and the directory is torus/,
torus-cpu.h included concrete-num_complex.h, the Torus dialect CMakeLists
named ConcreteOps.td, and compiler/setup.py asked find_namespace_packages
for a "concrete" package that no longer exists — so it built without the
package it ships.
2026-08-27 13:17:38 -07:00

4.0 KiB

module torus.fhe.extensions.truncate_bit_pattern

Declaration of truncate_bit_pattern extension.

Global Variables

  • MAXIMUM_TLU_BIT_WIDTH

function truncate_bit_pattern

truncate_bit_pattern(
    x: Union[int, integer, list, ndarray, Tracer],
    lsbs_to_remove: Union[int, AutoTruncator]
) → Union[int, integer, list, ndarray, Tracer]

Round the bit pattern of an integer.

If lsbs_to_remove is an AutoTruncator: corresponding integer value will be determined by adjustment process.

x = 0b_0000 , lsbs_to_remove = 2 => 0b_0000 x = 0b_0001 , lsbs_to_remove = 2 => 0b_0000 x = 0b_0010 , lsbs_to_remove = 2 => 0b_0000 x = 0b_0100 , lsbs_to_remove = 2 => 0b_0100 x = 0b_0110 , lsbs_to_remove = 2 => 0b_0100 x = 0b_1100 , lsbs_to_remove = 2 => 0b_1100 x = 0b_abcd , lsbs_to_remove = 2 => 0b_ab00

Args: x (Union[int, np.integer, np.ndarray, Tracer]): input to truncate

lsbs_to_remove (Union[int, AutoTruncator]): number of the least significant bits to clear or an auto truncator object which will be used to determine the integer value

Returns: Union[int, np.integer, np.ndarray, Tracer]: Tracer that represents the operation during tracing truncated value(s) otherwise


class Adjusting

Adjusting class, to be used as early stop signal during adjustment.

method __init__

__init__(truncator: 'AutoTruncator', input_min: int, input_max: int)

class AutoTruncator

AutoTruncator class, to optimize for the number of msbs to keep during truncate operation.

method __init__

__init__(target_msbs: int = 16)

method adjust

adjust(
    function: Callable,
    inputset: Union[Iterable[Any], Iterable[tuple[Any, ]]]
)

Adjust AutoTruncators in a function using an inputset.


method dump_dict

dump_dict() → dict

Dump properties of the truncator to a dict.


classmethod load_dict

load_dict(properties: dict) → AutoTruncator

Load previously dumped truncator.