Skip to content

Extend NTTShoup handling to add, sub, and neg operations#352

Merged
tlepoint merged 6 commits into
mainfrom
ntt-shoup-ops-6421348099083632485
Jan 28, 2026
Merged

Extend NTTShoup handling to add, sub, and neg operations#352
tlepoint merged 6 commits into
mainfrom
ntt-shoup-ops-6421348099083632485

Conversation

@tlepoint

Copy link
Copy Markdown
Owner

Implemented handling for Representation::NttShoup in Add, Sub, and Neg traits in crates/fhe-math/src/rq/ops.rs. When performing these operations on an NttShoup polynomial, it is now automatically converted to Ntt representation (as linear operations invalidate Shoup precomputations or don't benefit from them). Also updated AddAssign and SubAssign to allow operations between Ntt and NttShoup representations. Added regression tests.


PR created automatically by Jules for task 6421348099083632485 started by @tlepoint

Implemented handling for Representation::NttShoup in Add, Sub, and Neg traits in crates/fhe-math/src/rq/ops.rs.
When performing these operations on an NttShoup polynomial, it is now automatically converted to Ntt representation.
Also updated AddAssign and SubAssign to allow operations between Ntt and NttShoup representations.
Added regression tests in crates/fhe-math/tests/ntt_shoup_ops.rs.

Co-authored-by: tlepoint <1345502+tlepoint@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38cf3d0850

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/fhe-math/src/rq/ops.rs Outdated
Comment on lines +58 to +62
impl Add<&Poly> for &Poly {
type Output = Poly;
fn add(self, p: &Poly) -> Poly {
let mut q = self.clone();
q += p;
q
match self.representation {
Representation::NttShoup => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Make owned Poly + Poly handle NttShoup RHS

This new conversion only runs in the &Poly + &Poly implementation. The owned impl Add for Poly still does p += &self, and AddAssign continues to forbid NttShoup on the LHS, so a + b will still panic when b is Representation::NttShoup even though &a + &b now works. That makes behavior depend on ownership and breaks the intended NttShoup support for owned additions; consider routing the owned Add through the borrowed implementation or converting the RHS when it is NttShoup.

Useful? React with 👍 / 👎.

google-labs-jules Bot and others added 5 commits January 28, 2026 00:50
Implemented handling for Representation::NttShoup in Add, Sub, and Neg traits in crates/fhe-math/src/rq/ops.rs.
When performing these operations on an NttShoup polynomial, it is now automatically converted to Ntt representation.
Also updated AddAssign and SubAssign to allow operations between Ntt and NttShoup representations.
Added regression tests in crates/fhe-math/tests/ntt_shoup_ops.rs.
Fixed clippy warnings regarding wildcard enum matches.

Co-authored-by: tlepoint <1345502+tlepoint@users.noreply.github.com>
Implemented handling for Representation::NttShoup in Add, Sub, and Neg traits in crates/fhe-math/src/rq/ops.rs.
When performing these operations on an NttShoup polynomial, it is now automatically converted to Ntt representation.
Updated AddAssign and SubAssign to handle NttShoup on LHS by converting to Ntt, which enables owned operations (p + q, p - q) to work correctly when RHS is NttShoup.
Implemented Sub for Poly to support owned subtraction.
Added regression tests in crates/fhe-math/tests/ntt_shoup_ops.rs covering borrowed and owned operations.
Fixed clippy warnings regarding wildcard enum matches.

Co-authored-by: tlepoint <1345502+tlepoint@users.noreply.github.com>
@tlepoint tlepoint merged commit 03cfe4e into main Jan 28, 2026
6 checks passed
@tlepoint tlepoint deleted the ntt-shoup-ops-6421348099083632485 branch January 28, 2026 04:04
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