mirror of
https://github.com/zama-ai/tfhe-rs.git
synced 2026-01-06 21:34:05 -05:00
fix(integer): handle message mod 0 in num_blocks
This commit is contained in:
committed by
Nicolas Sarlin
parent
c083eb826d
commit
f17cd9bd37
@@ -25,6 +25,9 @@ impl DataKind {
|
||||
Self::Unsigned(n) | Self::Signed(n) => n.get(),
|
||||
Self::Boolean => 1,
|
||||
Self::String { n_chars, .. } => {
|
||||
if message_modulus.0 == 0 {
|
||||
return 0;
|
||||
}
|
||||
let blocks_per_char = 7u32.div_ceil(message_modulus.0.ilog2());
|
||||
(n_chars * blocks_per_char) as usize
|
||||
}
|
||||
@@ -95,3 +98,20 @@ impl Expandable for BooleanBlock {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_string_num_blocks() {
|
||||
let kind = DataKind::String {
|
||||
n_chars: 10,
|
||||
padded: true,
|
||||
};
|
||||
|
||||
let num_blocks = kind.num_blocks(MessageModulus(0));
|
||||
|
||||
assert_eq!(num_blocks, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user