Skip to content

Commit

Permalink
chore(hlapi): stabilize FheTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeul-zama committed Dec 13, 2024
1 parent 4388a3d commit b1ce34f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 60 deletions.
1 change: 1 addition & 0 deletions tfhe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ ron = "0.8"
tfhe-backward-compat-data = { git = "https://github.com/zama-ai/tfhe-backward-compat-data.git", branch = "v0.4", default-features = false, features = [
"load",
] }
strum = { version = "0.26", features = ["derive"] }

[build-dependencies]
cbindgen = { version = "0.26.0", optional = true }
Expand Down
71 changes: 41 additions & 30 deletions tfhe/src/c_api/high_level_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,36 @@ mod zk;
#[repr(C)]
#[allow(non_camel_case_types)]
pub enum FheTypes {
Type_FheBool,
Type_FheUint2,
Type_FheUint4,
Type_FheUint6,
Type_FheUint8,
Type_FheUint10,
Type_FheUint12,
Type_FheUint14,
Type_FheUint16,
Type_FheUint32,
Type_FheUint64,
Type_FheUint128,
Type_FheUint160,
Type_FheUint256,
Type_FheUint512,
Type_FheUint1024,
Type_FheUint2048,
Type_FheInt2,
Type_FheInt4,
Type_FheInt6,
Type_FheInt8,
Type_FheInt10,
Type_FheInt12,
Type_FheInt14,
Type_FheInt16,
Type_FheInt32,
Type_FheInt64,
Type_FheInt128,
Type_FheInt160,
Type_FheInt256,
Type_FheBool = 0,
Type_FheUint4 = 1,
Type_FheUint8 = 2,
Type_FheUint16 = 3,
Type_FheUint32 = 4,
Type_FheUint64 = 5,
Type_FheUint128 = 6,
Type_FheUint160 = 7,
Type_FheUint256 = 8,
Type_FheUint512 = 9,
Type_FheUint1024 = 10,
Type_FheUint2048 = 11,
Type_FheUint2 = 12,
Type_FheUint6 = 13,
Type_FheUint10 = 14,
Type_FheUint12 = 15,
Type_FheUint14 = 16,
Type_FheInt2 = 17,
Type_FheInt4 = 18,
Type_FheInt6 = 19,
Type_FheInt8 = 20,
Type_FheInt10 = 21,
Type_FheInt12 = 22,
Type_FheInt14 = 23,
Type_FheInt16 = 24,
Type_FheInt32 = 25,
Type_FheInt64 = 26,
Type_FheInt128 = 27,
Type_FheInt160 = 28,
Type_FheInt256 = 29,
}

impl From<crate::FheTypes> for FheTypes {
Expand Down Expand Up @@ -90,3 +90,14 @@ impl From<crate::FheTypes> for FheTypes {
}
}
}

#[test]
fn fhe_types_enum_to_int_compatible() {
use strum::IntoEnumIterator;

for rust_value in crate::FheTypes::iter() {
let c_value = FheTypes::from(rust_value);

assert_eq!(rust_value as i32, c_value as i32)
}
}
62 changes: 32 additions & 30 deletions tfhe/src/high_level_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,35 +129,37 @@ pub enum Device {
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[repr(i32)]
#[cfg_attr(test, derive(strum::EnumIter))]
pub enum FheTypes {
Bool,
Uint2,
Uint4,
Uint6,
Uint8,
Uint10,
Uint12,
Uint14,
Uint16,
Uint32,
Uint64,
Uint128,
Uint160,
Uint256,
Uint512,
Uint1024,
Uint2048,
Int2,
Int4,
Int6,
Int8,
Int10,
Int12,
Int14,
Int16,
Int32,
Int64,
Int128,
Int160,
Int256,
Bool = 0,
Uint4 = 1,
Uint8 = 2,
Uint16 = 3,
Uint32 = 4,
Uint64 = 5,
Uint128 = 6,
Uint160 = 7,
Uint256 = 8,
Uint512 = 9,
Uint1024 = 10,
Uint2048 = 11,
Uint2 = 12,
Uint6 = 13,
Uint10 = 14,
Uint12 = 15,
Uint14 = 16,
Int2 = 17,
Int4 = 18,
Int6 = 19,
Int8 = 20,
Int10 = 21,
Int12 = 22,
Int14 = 23,
Int16 = 24,
Int32 = 25,
Int64 = 26,
Int128 = 27,
Int160 = 28,
Int256 = 29,
}

0 comments on commit b1ce34f

Please sign in to comment.