Skip to content

Add rescale to MatrixEntry/ArrayEntry and rename scale_array → rescale_array#104

Merged
cmutel merged 3 commits into
mainfrom
feature/scale-in-matrix-array-entry
Jun 4, 2026
Merged

Add rescale to MatrixEntry/ArrayEntry and rename scale_array → rescale_array#104
cmutel merged 3 commits into
mainfrom
feature/scale-in-matrix-array-entry

Conversation

@cmutel
Copy link
Copy Markdown
Member

@cmutel cmutel commented Jun 4, 2026

Summary

  • Extends the high-level entry-point API (MatrixEntry, ArrayEntry, add_entries, add_array_entries) to expose the rescale_array support added in Add scale_array support for per-exchange multiplicative rescaling #89.
  • Renames scale_arrayrescale_array throughout — parameters, helper method, resource kind, file suffix, local variables, docstrings, and tests — to eliminate the ambiguity with the stats_arrays distribution scale parameter (loc/scale/shape in UNCERTAINTY_DTYPE).

New fields:

  • MatrixEntry.rescale: float = 1.0 — per-exchange multiplicative factor; flows through dictionary_formatter and resolve_dict_iterator so it is sorted once alongside the other arrays, then stored as a kind="rescale" resource when any value ≠ 1.0.
  • ArrayEntry.rescale: Optional[np.ndarray] = None — same concept as an array; passed directly to add_persistent_array.

Unchanged: UNCERTAINTY_DTYPE["scale"], MatrixEntry.scale (distribution scale parameter), dictionary_formatter's row.get("scale").

Test plan

  • pytest tests/ — 247 passed, 1 skipped
  • Verify kind="rescale" resources are written and round-trip correctly through the Parquet path (covered by existing test_scale_array_parquet_roundtrip, now renamed test_rescale_array_parquet_roundtrip)
  • Verify MatrixEntry.rescale values are aligned with sorted indices/data (new test_rescale_sorted_with_data)

cmutel added 3 commits June 4, 2026 10:06
…gh to scale_array resources

Extends the high-level entry-point API to expose the scale_array support
added in #89.

- MatrixEntry gains `rescale: float = 1.0` (multiplicative factor, distinct
  from the existing `scale` distribution parameter).
- ArrayEntry gains `scale: Optional[np.ndarray] = None` with shape and
  float-coercion validation.
- dictionary_formatter and resolve_dict_iterator now carry a `rescale` field
  so the value is sorted exactly once alongside row/col/amount; scale_array
  (or None when all values are 1.0) is returned as a fifth element.
- add_persistent_vector_from_iterator forwards the extracted scale_array to
  add_persistent_vector, keeping add_entries a simple one-liner.
- add_array_entries passes scale_array=entry.scale to add_persistent_array.
… uncertainty scale

The stats_arrays `scale` parameter (standard deviation / distribution
scale) already owns the name in this codebase. Using the same word for
the per-exchange multiplicative factor caused silent ambiguity.

Renames everywhere — parameters, helper method, resource kind and file
suffix, local variables, docstrings, and tests:

- `scale_array` → `rescale_array` on all four `add_persistent/dynamic_*`
  methods, `add_persistent_vector_from_iterator`, and `_add_rescale_array_resource`
- Resource kind `"scale"` → `"rescale"`, file suffix `.scale` → `.rescale`
- `kind in ("flip", "scale", …)` guard in `write_modified` → `"rescale"`
- `ArrayEntry.scale` field → `ArrayEntry.rescale`
- `utils.py` local variable and returned tuple element
- All test assertions and variable names updated accordingly

Distribution-scale references (`UNCERTAINTY_DTYPE["scale"]`,
`MatrixEntry.scale`, `dictionary_formatter` `row.get("scale")`) are
intentionally left unchanged.
- Correct add_array_entries docstring: scale→rescale and kind="scale"→kind="rescale"
- Note in MatrixEntry.rescale docstring that the Python float is downcast to numpy.float32 on write
- Add test_rescale_resource_written_when_only_some_entries_rescaled covering the mixed case (one entry at default 1.0, one non-default)
@cmutel cmutel merged commit 4c1e465 into main Jun 4, 2026
6 checks passed
@cmutel cmutel deleted the feature/scale-in-matrix-array-entry branch June 4, 2026 08:26
@cmutel cmutel mentioned this pull request Jun 4, 2026
3 tasks
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