Skip to content

Commit

Permalink
style(global): fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
soonum committed Oct 3, 2024
1 parent c7f4de9 commit 212af17
Show file tree
Hide file tree
Showing 35 changed files with 87 additions and 86 deletions.
5 changes: 3 additions & 2 deletions _typos.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[default]
extend-ignore-identifiers-re = [
# Related to serialized object
"ser.*",
"ser",
"unser",
# Used when dumping tfhe-rs parameters set into Sage format
"ND.*",
# Related to FHE strings example handling "banana"
"ba",
".*_ba",
"enc_ba",
# Example with string replacing "hello" with "herlo"
"herlo",
# Example in trivium
Expand Down
2 changes: 1 addition & 1 deletion tfhe/docs/guides/data_versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ You will find below a list of breaking changes and how to upgrade them.

# 0.6 -> 0.7
- `tfhe::integer::ciphertext::CompactCiphertextList`:
in 0.6, these lists of ciphertext were statically typed and homogenous. Since 0.7, they are heterogeneous. The new version stores for each element an information about its type (Signed, Unsigned or Boolean). Since this information were not stored before, the list is set to be made of `Unsigned` integers by default. If that is not the case, you can set its type using the following snippet:
in 0.6, these lists of ciphertext were statically typed and homogeneous. Since 0.7, they are heterogeneous. The new version stores for each element an information about its type (Signed, Unsigned or Boolean). Since this information were not stored before, the list is set to be made of `Unsigned` integers by default. If that is not the case, you can set its type using the following snippet:

```rust
use std::io::Cursor;
Expand Down
10 changes: 5 additions & 5 deletions tfhe/examples/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ impl Default for Args {
}

impl Args {
fn from_arg_list(mut progam_args: std::env::Args) -> Self {
fn from_arg_list(mut program_args: std::env::Args) -> Self {
let mut args = Args::default();
let mut had_invalid = false;

progam_args.next().unwrap(); // This is argv[0], the program name/path
while let Some(arg) = progam_args.next() {
program_args.next().unwrap(); // This is argv[0], the program name/path
while let Some(arg) = program_args.next() {
if arg == "--parallel" {
args.parallel = true;
} else if arg == "--trivial" {
args.trivial = true;
} else if arg == "--device" {
let Some(value) = progam_args.next() else {
let Some(value) = program_args.next() else {
panic!("Expected value after --device");
};

Expand All @@ -161,7 +161,7 @@ impl Args {
_ => panic!("Unsupported device {value}"),
}
} else if arg == "--multibit" {
let Some(value) = progam_args.next() else {
let Some(value) = program_args.next() else {
panic!("Expected value after --multibit");
};

Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/c_api/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl From<Vec<u8>> for DynamicBuffer {
/// This function is safe to call if `dynamic_buffer` is not aliased to avoid double frees.
#[no_mangle]
pub unsafe extern "C" fn destroy_dynamic_buffer(dynamic_buffer: *mut DynamicBuffer) -> c_int {
// Mimicks C for calls of free on NULL, nothing occurs
// Mimics C for calls of free on NULL, nothing occurs
if dynamic_buffer.is_null() {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/c_api/core_crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::core_crypto::commons::math::random::DynamicDistribution as RustDynami
use crate::core_crypto::commons::numeric::UnsignedInteger;
use std::os::raw::c_int;

// f64 will be aligned as a u64, use the same alignement
// f64 will be aligned as a u64, use the same alignment
#[repr(u64)]
#[derive(Clone, Copy)]
pub enum DynamicDistributionTag {
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/c_api/high_level_api/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub unsafe extern "C" fn set_server_key(server_key: *const ServerKey) -> c_int {
/// Sets the cuda server key.
///
/// Once a cuda server key is set in a thread, all computations done in
/// that thread will actually happend on the Cuda GPU.
/// that thread will actually happen on the Cuda GPU.
///
/// Does not take ownership of the key
#[cfg(feature = "gpu")]
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/c_api/shortint/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub struct ShortintCompactPublicKeyEncryptionParameters {
pub modulus_power_of_2_exponent: usize,
// Normally the CompactPublicKeyEncryptionParameters has an additional field expansion_kind,
// but it's only used to manage different kind of parameters internally, for the C API
// these parameters will always require casting, as they alwasy require casting we add a field
// these parameters will always require casting, as they always require casting we add a field
// for the casting parameters here.
pub casting_parameters: ShortintCompactCiphertextListCastingParameters,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ fn random_noise_roundtrip<Scalar: UnsignedTorus + CastInto<usize>>(

let expected_variance = Variance(noise.gaussian_std_dev().get_variance());

let num_ouptuts = 100_000;
let num_outputs = 100_000;

let mut output: Vec<_> = vec![Scalar::ZERO; num_ouptuts];
let mut output: Vec<_> = vec![Scalar::ZERO; num_outputs];

encryption_rng.fill_slice_with_random_noise_from_distribution_custom_mod(
&mut output,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::*;

mod lwe_encryption_noise;
mod lwe_keyswitch_noise;
mod lwe_programmable_boostrapping_noise;
mod lwe_programmable_bootstrapping_noise;

#[allow(clippy::excessive_precision)]
pub const NOISE_TEST_PARAMS_4_BITS_NATIVE_U64_132_BITS_GAUSSIAN: ClassicTestParams<u64> =
Expand Down
2 changes: 1 addition & 1 deletion tfhe/src/core_crypto/commons/ciphertext_modulus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::fmt::Display;
use std::marker::PhantomData;

#[derive(Clone, Copy, PartialEq, Eq)]
/// Private enum to avoid end user mis-instantiating a CiphertextModulus
/// Private enum to avoid end user instantiating a bad CiphertextModulus
///
/// NonZeroU128 allows to always have a correct modulus and to have an enum that is no bigger than a
/// u128 with the 0 optimization as the tag then corresponds to the Native variant.
Expand Down
8 changes: 4 additions & 4 deletions tfhe/src/core_crypto/commons/math/random/gaussian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ where
distribution: Gaussian<f64>,
_modulus: Option<Self::CustomModulus>,
) -> f64 {
// Here the CustomModulus is a Torus and not f64 and is therefore not comaptible, so
// Here the CustomModulus is a Torus and not f64 and is therefore not compatible, so
// we cannot forward it, thankully the modulus does not impact gaussian generation success
<(f64, f64) as RandomGenerable<Gaussian<f64>>>::single_sample_success_probability(
distribution,
Expand All @@ -139,7 +139,7 @@ where
distribution: Gaussian<f64>,
_modulus: Option<Self::CustomModulus>,
) -> usize {
// Here the CustomModulus is a Torus and not f64 and is therefore not comaptible, so
// Here the CustomModulus is a Torus and not f64 and is therefore not compatible, so
// we cannot forward it, thankully the modulus does not impact gaussian generation success
<(f64, f64) as RandomGenerable<Gaussian<f64>>>::single_sample_required_random_byte_count(
distribution,
Expand Down Expand Up @@ -175,7 +175,7 @@ where
distribution: Gaussian<f64>,
_modulus: Option<Self::CustomModulus>,
) -> f64 {
// Here the CustomModulus is a Torus and not f64 and is therefore not comaptible, so
// Here the CustomModulus is a Torus and not f64 and is therefore not compatible, so
// we cannot forward it, thankully the modulus does not impact gaussian generation success
<(f64, f64) as RandomGenerable<Gaussian<f64>>>::single_sample_success_probability(
distribution,
Expand All @@ -187,7 +187,7 @@ where
distribution: Gaussian<f64>,
_modulus: Option<Self::CustomModulus>,
) -> usize {
// Here the CustomModulus is a Torus and not f64 and is therefore not comaptible, so
// Here the CustomModulus is a Torus and not f64 and is therefore not compatible, so
// we cannot forward it, thankully the modulus does not impact gaussian generation success
<(f64, f64) as RandomGenerable<Gaussian<f64>>>::single_sample_required_random_byte_count(
distribution,
Expand Down
26 changes: 13 additions & 13 deletions tfhe/src/core_crypto/commons/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,39 +311,39 @@ pub mod test_tools {
// q = 2^64
let q = CiphertextModulus::<u64>::new_native();
// Divide by 8 to get an exact division vs 10 or anything not a power of 2
let one_eigth = ((1u128 << 64) / 8) as u64;
let seven_eigth = 7 * one_eigth;
let one_eighth = ((1u128 << 64) / 8) as u64;
let seven_eighth = 7 * one_eighth;

let distance = torus_modular_diff(one_eigth, seven_eigth, q);
let distance = torus_modular_diff(one_eighth, seven_eighth, q);
assert_eq!(distance, 0.25);
let distance = torus_modular_diff(seven_eigth, one_eigth, q);
let distance = torus_modular_diff(seven_eighth, one_eighth, q);
assert_eq!(distance, -0.25);
}
{
// q = 2^63
let q = CiphertextModulus::<u64>::try_new_power_of_2(63).unwrap();
// Divide by 8 to get an exact division vs 10 or anything not a power of 2
let one_eigth = q.get_custom_modulus() as u64 / 8;
let seven_eigth = 7 * one_eigth;
let one_eighth = q.get_custom_modulus() as u64 / 8;
let seven_eighth = 7 * one_eighth;

let distance = torus_modular_diff(one_eigth, seven_eigth, q);
let distance = torus_modular_diff(one_eighth, seven_eighth, q);
assert_eq!(distance, 0.25);
let distance = torus_modular_diff(seven_eigth, one_eigth, q);
let distance = torus_modular_diff(seven_eighth, one_eighth, q);
assert_eq!(distance, -0.25);
}
{
// q = 2^64 - 2^32 + 1
let q = CiphertextModulus::<u64>::try_new((1 << 64) - (1 << 32) + 1).unwrap();
// Even though 8 does not divide q exactly, everything work ok for this example.
// This may not be the case for all moduli with enough LSBs set as then one_eigth would
// This may not be the case for all moduli with enough LSBs set as then one_eighth would
// be the floor and not the rounding of q / 8, here they happen to match and that's good
// enough
let one_eigth = q.get_custom_modulus() as u64 / 8;
let seven_eigth = 7 * one_eigth;
let one_eighth = q.get_custom_modulus() as u64 / 8;
let seven_eighth = 7 * one_eighth;

let distance = torus_modular_diff(one_eigth, seven_eigth, q);
let distance = torus_modular_diff(one_eighth, seven_eighth, q);
assert_eq!(distance, 0.25);
let distance = torus_modular_diff(seven_eigth, one_eigth, q);
let distance = torus_modular_diff(seven_eighth, one_eighth, q);
assert_eq!(distance, -0.25);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub const PRECISION_4_FAST_KS: FastKSParam<u64> = FastKSParam {
// AP:
// DP -> Fast KS -> PBS
// Fast KS =
// - convert LWE to GLWE witout packing called "sample insertion"
// - convert LWE to GLWE without packing called "sample insertion"
// - GLWE fast KS
// - sample extraction
// - finalize the keyswitch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub unsafe fn cuda_multi_bit_programmable_bootstrap_lwe_ciphertext_async<Scalar>
assert_eq!(
input.lwe_dimension(),
multi_bit_bsk.input_lwe_dimension(),
"Mimatched input LweDimension. LweCiphertext input LweDimension {:?}. \
"Mismatched input LweDimension. LweCiphertext input LweDimension {:?}. \
FourierLweMultiBitBootstrapKey input LweDimension {:?}.",
input.lwe_dimension(),
multi_bit_bsk.input_lwe_dimension(),
Expand All @@ -35,7 +35,7 @@ pub unsafe fn cuda_multi_bit_programmable_bootstrap_lwe_ciphertext_async<Scalar>
assert_eq!(
output.lwe_dimension(),
multi_bit_bsk.output_lwe_dimension(),
"Mimatched output LweDimension. LweCiphertext output LweDimension {:?}. \
"Mismatched output LweDimension. LweCiphertext output LweDimension {:?}. \
FourierLweMultiBitBootstrapKey output LweDimension {:?}.",
output.lwe_dimension(),
multi_bit_bsk.output_lwe_dimension(),
Expand All @@ -44,7 +44,7 @@ pub unsafe fn cuda_multi_bit_programmable_bootstrap_lwe_ciphertext_async<Scalar>
assert_eq!(
accumulator.glwe_dimension(),
multi_bit_bsk.glwe_dimension(),
"Mimatched GlweSize. Accumulator GlweSize {:?}. \
"Mismatched GlweSize. Accumulator GlweSize {:?}. \
FourierLweMultiBitBootstrapKey GlweSize {:?}.",
accumulator.glwe_dimension(),
multi_bit_bsk.glwe_dimension(),
Expand All @@ -53,7 +53,7 @@ pub unsafe fn cuda_multi_bit_programmable_bootstrap_lwe_ciphertext_async<Scalar>
assert_eq!(
accumulator.polynomial_size(),
multi_bit_bsk.polynomial_size(),
"Mimatched PolynomialSize. Accumulator PolynomialSize {:?}. \
"Mismatched PolynomialSize. Accumulator PolynomialSize {:?}. \
FourierLweMultiBitBootstrapKey PolynomialSize {:?}.",
accumulator.polynomial_size(),
multi_bit_bsk.polynomial_size(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub unsafe fn cuda_programmable_bootstrap_lwe_ciphertext_async<Scalar>(
assert_eq!(
input.lwe_dimension(),
bsk.input_lwe_dimension(),
"Mimatched input LweDimension. LweCiphertext input LweDimension {:?}. \
"Mismatched input LweDimension. LweCiphertext input LweDimension {:?}. \
FourierLweMultiBitBootstrapKey input LweDimension {:?}.",
input.lwe_dimension(),
bsk.input_lwe_dimension(),
Expand All @@ -36,7 +36,7 @@ pub unsafe fn cuda_programmable_bootstrap_lwe_ciphertext_async<Scalar>(
assert_eq!(
output.lwe_dimension(),
bsk.output_lwe_dimension(),
"Mimatched output LweDimension. LweCiphertext output LweDimension {:?}. \
"Mismatched output LweDimension. LweCiphertext output LweDimension {:?}. \
FourierLweMultiBitBootstrapKey output LweDimension {:?}.",
output.lwe_dimension(),
bsk.output_lwe_dimension(),
Expand All @@ -45,7 +45,7 @@ pub unsafe fn cuda_programmable_bootstrap_lwe_ciphertext_async<Scalar>(
assert_eq!(
accumulator.glwe_dimension(),
bsk.glwe_dimension(),
"Mimatched GlweSize. Accumulator GlweSize {:?}. \
"Mismatched GlweSize. Accumulator GlweSize {:?}. \
FourierLweMultiBitBootstrapKey GlweSize {:?}.",
accumulator.glwe_dimension(),
bsk.glwe_dimension(),
Expand All @@ -54,7 +54,7 @@ pub unsafe fn cuda_programmable_bootstrap_lwe_ciphertext_async<Scalar>(
assert_eq!(
accumulator.polynomial_size(),
bsk.polynomial_size(),
"Mimatched PolynomialSize. Accumulator PolynomialSize {:?}. \
"Mismatched PolynomialSize. Accumulator PolynomialSize {:?}. \
FourierLweMultiBitBootstrapKey PolynomialSize {:?}.",
accumulator.polynomial_size(),
bsk.polynomial_size(),
Expand Down
8 changes: 4 additions & 4 deletions tfhe/src/high_level_api/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ macro_rules! declare_concrete_array_types {
) => {
::paste::paste!{
$(
// Instanciate Array Types for dyn backend
// Instantiate Array Types for dyn backend
pub type [<FheUint $num_bits Array>] = FheUintArray<crate::[<FheUint $num_bits Id>]>;
pub type [<FheUint $num_bits Slice>]<'a> = FheUintSlice<'a, crate::[<FheUint $num_bits Id>]>;
pub type [<FheUint $num_bits SliceMut>]<'a> = FheUintSliceMut<'a, crate::[<FheUint $num_bits Id>]>;

// Instanciate Array Types for Cpu backend
// Instantiate Array Types for Cpu backend
pub type [<CpuFheUint $num_bits Array>] = CpuFheUintArray<crate::[<FheUint $num_bits Id>]>;
pub type [<CpuFheUint $num_bits Slice>]<'a> = CpuFheUintSlice<'a, crate::[<FheUint $num_bits Id>]>;
pub type [<CpuFheUint $num_bits SliceMut>]<'a> = CpuFheUintSliceMut<'a, crate::[<FheUint $num_bits Id>]>;
Expand All @@ -296,12 +296,12 @@ macro_rules! declare_concrete_array_types {
) => {
::paste::paste!{
$(
// Instanciate Array Types for dyn backend
// Instantiate Array Types for dyn backend
pub type [<FheInt $num_bits Array>] = FheIntArray<crate::[<FheInt $num_bits Id>]>;
pub type [<FheInt $num_bits Slice>]<'a> = FheIntSlice<'a, crate::[<FheInt $num_bits Id>]>;
pub type [<FheInt $num_bits SliceMut>]<'a> = FheIntSliceMut<'a, crate::[<FheInt $num_bits Id>]>;

// Instanciate Array Types for Cpu backend
// Instantiate Array Types for Cpu backend
pub type [<CpuFheInt $num_bits Array>] = CpuFheIntArray<crate::[<FheInt $num_bits Id>]>;
pub type [<CpuFheInt $num_bits Slice>]<'a> = CpuFheIntSlice<'a, crate::[<FheInt $num_bits Id>]>;
pub type [<CpuFheInt $num_bits SliceMut>]<'a> = CpuFheIntSliceMut<'a, crate::[<FheInt $num_bits Id>]>;
Expand Down
16 changes: 8 additions & 8 deletions tfhe/src/high_level_api/array/stride.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,15 @@ where
}
}

pub struct OffsetedStridedIterMut<'a, T> {
pub struct OffsettedStridedIterMut<'a, T> {
flat_offset: usize,
index_producer: StridedIndexProducer,
current_count: usize,
max_count: usize,
inner: ::std::slice::IterMut<'a, T>,
}

impl<'a, T> Iterator for OffsetedStridedIterMut<'a, T> {
impl<'a, T> Iterator for OffsettedStridedIterMut<'a, T> {
type Item = &'a mut T;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -407,7 +407,7 @@ impl<'a, T> Iterator for OffsetedStridedIterMut<'a, T> {
}
}

impl<'a, T> DoubleEndedIterator for OffsetedStridedIterMut<'a, T> {
impl<'a, T> DoubleEndedIterator for OffsettedStridedIterMut<'a, T> {
fn next_back(&mut self) -> Option<Self::Item> {
if self.current_count == 0 {
None
Expand All @@ -427,21 +427,21 @@ impl<'a, T> DoubleEndedIterator for OffsetedStridedIterMut<'a, T> {
}
}

impl<'a, T> ExactSizeIterator for OffsetedStridedIterMut<'a, T> {
impl<'a, T> ExactSizeIterator for OffsettedStridedIterMut<'a, T> {
fn len(&self) -> usize {
ExactSizeIterator::len(&self.index_producer)
}
}

pub struct ParStridedIterMut<'a, T> {
inner: OffsetedStridedIterMut<'a, T>,
inner: OffsettedStridedIterMut<'a, T>,
}

impl<'a, T> ParStridedIterMut<'a, T> {
pub fn new(slice: &'a mut [T], dims: DynDimensions) -> Self {
let max_count = dims.flattened_len();
Self {
inner: OffsetedStridedIterMut {
inner: OffsettedStridedIterMut {
flat_offset: 0,
index_producer: StridedIndexProducer::new(dims),
current_count: 0,
Expand Down Expand Up @@ -503,10 +503,10 @@ where
T: Send,
{
type Item = &'a mut T;
type IntoIter = OffsetedStridedIterMut<'a, T>;
type IntoIter = OffsettedStridedIterMut<'a, T>;

fn into_iter(self) -> Self::IntoIter {
OffsetedStridedIterMut {
OffsettedStridedIterMut {
flat_offset: self.flat_offset,
index_producer: self.index_producer,
current_count: self.current_count,
Expand Down
Loading

0 comments on commit 212af17

Please sign in to comment.