Skip to content

WIP: Static size tools for MeasureBase - #12

Draft
oschulz wants to merge 5 commits into
mainfrom
measurebase
Draft

oschulz wants to merge 5 commits into
mainfrom
measurebase

Conversation

@oschulz

@oschulz oschulz commented Sep 21, 2026

Copy link
Copy Markdown
Owner

Written by Claude (Fable 5.1, high effort) on behalf of the maintainer.

Work in progress, companion to JuliaMath/MeasureBase.jl#182.

Static and dynamic size tools that MeasureBase's batched-first rewrite needs, moved here from MeasureBase's private helpers so that other packages can use them: size_dims, a type-level axes2size, constant-folding reductions over tuple types (static_reduce, static_mapreduce, static_all, static_any, folded pairwise so they infer as constants on Julia 1.10), a static-preserving leading-dimensions family (sum_leading_dims, drop_leading_dims, merge_leading_dims, all_leading_dims), and static-preserving vector splits and views (split_at, maybestatic_view).

One breaking change, hence 0.3.0: maybestatic_reshape keeps only StaticArray inputs static. It used to wrap any array, including device and traced arrays, into an SArray when the target size was static, which copies through the host. See NEWS.md.

https://claude.ai/code/session_01L5yPndh2K6u14z3CwF9YXf

`maybestatic_reshape` wrapped any array into an `SArray` for a static
size, which copies device arrays and traced arrays to the host. Only
`StaticArray` inputs stay or become static arrays now, other arrays are
reshaped with the non-static size.

Created by generative AI.
Tools that generic code needs to keep static sizes static, collected
from private helpers of MeasureBase:

- `size_dims`, the inverse of `canonical_size`, and a type-level
  `axes2size` for statically sized axes.
- `static_reduce`, `static_all` and `static_any`, pairwise folds over
  tuple types that infer as constants where `reduce`, `all` and `any`
  over tuples of values don't (Julia 1.10).
- `sum_leading_dims`, `drop_leading_dims`, `merge_leading_dims` and
  `all_leading_dims`, indexed by a static number of leading dimensions.
  Static arrays stay static, lazy broadcasts are reduced lazily where
  their style allows it.
- `maybestatic_view` and `split_at`, views and splits of vectors and
  tuples that stay static for static inputs and indices.

Created by generative AI.
Reducing dimension by dimension costs one kernel launch per dimension on
a device. Only StaticArrays needs it, `all` over several dimensions at
once is unsupported there.

Created by generative AI.
`static_reduce(op, f, T)` becomes `static_mapreduce(f, op, T)`, like
`mapreduce(f, op, itr)`, and `static_reduce(op, T)` stays the `identity`
case. Reducing an empty tuple type has no result and says so.

`maybestatic_view` also takes an index range, like `view`.

Created by generative AI.
Created by generative AI.
@codecov

codecov Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.64706% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.10%. Comparing base (674bd65) to head (0532402).

Files with missing lines Patch % Lines
src/tools.jl 92.64% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main      #12      +/-   ##
===========================================
- Coverage   100.00%   97.10%   -2.90%     
===========================================
  Files            1        1              
  Lines          110      173      +63     
===========================================
+ Hits           110      168      +58     
- Misses           0        5       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant