Skip to content

Refactor fhe math idiomatic rust#290

Merged
tlepoint merged 2 commits into
mainfrom
refactor-fhe-math-idiomatic-rust
Aug 24, 2025
Merged

Refactor fhe math idiomatic rust#290
tlepoint merged 2 commits into
mainfrom
refactor-fhe-math-idiomatic-rust

Conversation

@tlepoint

Copy link
Copy Markdown
Owner

This commit introduces several changes to the fhe-math crate to make the code more idiomatic, readable, and maintainable, without affecting performance.

The following changes were made in crates/fhe-math/src/rq/mod.rs:

  • Refactored Poly::change_representation to use a single match on a tuple of representations, which simplifies the control flow.
  • Simplified Poly::substitute by merging the Ntt and NttShoup match arms, reducing code duplication.
  • Refactored Poly::mod_switch_down_next to eliminate code duplication between constant-time and variable-time computation paths by using function pointers.
  • Improved error handling in Poly::small by using an early return for the invalid variance case.

google-labs-jules Bot and others added 2 commits August 24, 2025 17:39
This commit introduces several changes to the `fhe-math` crate to make the code more idiomatic, readable, and maintainable, without affecting performance.

The following changes were made in `crates/fhe-math/src/rq/mod.rs`:

- Removed redundant `AsRef<Poly>` and `AsMut<Poly>` implementations. The standard library provides blanket implementations for these traits.
- Refactored `Poly::change_representation` to use a single `match` on a tuple of representations, which simplifies the control flow.
- Simplified `Poly::substitute` by merging the `Ntt` and `NttShoup` match arms, reducing code duplication.
- Refactored `Poly::mod_switch_down_next` to eliminate code duplication between constant-time and variable-time computation paths by using function pointers.
- Improved error handling in `Poly::small` by using an early return for the invalid variance case.
@tlepoint tlepoint merged commit 32b0af3 into main Aug 24, 2025
6 checks passed
@tlepoint tlepoint deleted the refactor-fhe-math-idiomatic-rust branch August 24, 2025 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant