Skip to content

OpenFHE emitter: support rank-0 tensor.from_elements - #3631

Draft
gauthamajoy wants to merge 1 commit into
google:mainfrom
gauthamajoy:fix-0d-from-elements
Draft

gauthamajoy wants to merge 1 commit into
google:mainfrom
gauthamajoy:fix-0d-from-elements

Conversation

@gauthamajoy

@gauthamajoy gauthamajoy commented Nov 11, 2026 •

Copy link
Copy Markdown

The printer rejected any non-rank-1 result with a bare failure(), so 0-d
results (e.g. from generated decrypt helpers) failed with a generic "Failed
to translate" error. Allow rank 0 (emitted as a size-1 vector, matching
extract/insert), and emit a diagnostic for rank >= 2.

Fixes #3624

Testing

  • Added a rank-0 from_elements case to emit_0d_tensor.mlir, and a new
    emit_2d_tensor_error.mlir checking the diagnostic for rank >= 2.
  • Both tests fail without the emitter change and pass with it.
  • The full emitter suite (bazel test //tests/Emitter/...:all) passed with
    the fix before I added the negative test. Tested on nightly-2026.11.06,
    then rebased onto current main without re-running.

Question
Since the emitter flattens all tensors to std::vector, should rank >= 2
from_elements just be allowed too (row-major elements match the
flattening)? I kept it rejected pending #1703, but happy to change it.

I'll join the next office hours.

I used AI to help edit and elaborate this PR description.

The printer rejected any non-rank-1 result with a bare failure(), so
0-d results (e.g. from generated decrypt helpers) failed with a generic
"Failed to translate" error. Allow rank 0 (emitted as a size-1 vector,
matching extract/insert), and emit a diagnostic for rank >= 2.

Fixes google#3624
@gauthamajoy

Copy link
Copy Markdown
Author

Closed by accident, reopening the PR.

@gauthamajoy

Copy link
Copy Markdown
Author

FYI: the cla/google check passing here isn't correct on our end. I'm getting it sorted and will mark this ready for review once it's resolved.

Comment on lines +1695 to +1696
// Only rank-0 and rank-1 tensor construction is currently supported.
// TODO(#1703): Support higher-rank tensors.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Technically true, but I don't think we will see many natural workflows that produce a from_elements that produces a rank-2+ tensor.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed, it’s unlikely to come up. The error is mainly so it fails clearly rather than emitting invalid code. Happy to drop the TODO (and #1703) if you’d rather not track it.

This branch has not been deployed

No deployments
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.

OpenFHE emitter: tensor.from_elements with a 0-d result fails to translate

2 participants