Skip to content

fix: 馃悰 preserve input precision in apply and compress - #36

Merged
Panadestein merged 9 commits into
Algorithmiq:mainfrom
SimoneGasperini:fix-dtype-silent-promotion
Oct 6, 2026
Merged

Panadestein merged 9 commits into
Algorithmiq:mainfrom
SimoneGasperini:fix-dtype-silent-promotion

Conversation

@SimoneGasperini

Copy link
Copy Markdown
Contributor

Fix #13.

Description

apply and compress previously had default to float64 Gaussian random sketch, silently promoting float32 and complex64 inputs to double precision.

I implemented a simple utility function sketch_dtype to infer the default sketch dtype from the input arrays, preserving single precision where appropriate. Explicit dtype overrides remain supported.

I also added tests to cover all four primitives: MPS compression, MPO compression, MPO-MPS application, and MPO-MPO application. Each runs with float32, float64, complex64, and complex128 inputs, checking that the output retains the input dtype and reproduces the original tensor within the appropriate tolerance.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

馃煛 Changes recommended

Two test decorators require Ruff formatting to pass lint CI.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Preserves input precision by deriving random-sketch dtypes from tensor inputs.

Changes:

  • Adds sketch_dtype inference.
  • Updates apply and compress defaults and documentation.
  • Tests all four operations across real and complex precisions.
File Description
src/鈥媠rc_method/鈥媢tils/鈥媉backend.py Adds sketch dtype resolution.
src/鈥媠rc_method/鈥媋pply.py Infers sketch precision for applications.
src/鈥媠rc_method/鈥媍ompress.py Infers sketch precision for compression.
tests/鈥媡est_package.py Adds precision-preservation tests.

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/test_package.py
SimoneGasperini and others added 5 commits September 23, 2026 20:26
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Simone Gasperini <simone.gasperini4@unibo.it>
Port the sketch dtype resolution onto the stack kernel and draw complex
sketches from the complex Ginibre ensemble.

Assisted-by: pi:claude-sonnet-5.5

@Panadestein Panadestein left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @SimoneGasperini !

@Panadestein
Panadestein merged commit 1e63a21 into Algorithmiq:main Oct 6, 2026
10 checks passed
Panadestein added a commit that referenced this pull request Oct 7, 2026
Resolve the conflicts with stdlib logging (#52), input-precision
sketches (#36), validation (#38), ty enforcement (#37, #55) and the
Fumadocs site (#56):

- the sweep draws its sketches with gaussian_sketch and logs its plan,
  pass times and stalls at DEBUG with %-style arguments;
- the working dtype is promoted over every site, not just the first;
- docs/large-problems.md moves to features/large-problems.mdx and the
  out-of-core testing notes to contributing/testing.mdx;
- bench_large.py logs through the stdlib and gains --debug.

Type lazily read sites: the entry points accept any array-like with
shape, dtype, ndim and np.asarray support but were typed
Sequence[NDArray]. Add the SiteLike protocol and the Site alias, use
them from src/apply/compress down to the site source, and export
SiteLike. Also fix the other ty findings: the Tier list in the planner,
known_kind() for validated trains, padded_shape without a type: ignore,
cupyx as an allowed unresolved import, and typed fakes in the tests.

Assisted-by: pi:claude-opus-5.5
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.

Single-precision inputs are silently promoted to double precision

4 participants