feat(array): map_over maps over a tuple of dims, with mapper= choosing jax.vmap, a loop or any vmap-like callable

Open
#408 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
75/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
numpy, python
Domain
backend, data

Research direction

Start with pipekit_array/named/_map.py:map_over and inspect its current dimension mapping and loop fallback. Add tuple-of-dim support and the mapper option described in the issue, then compare results with nested map_over for DimArray and CField, including the NumPy loop case. Done means those checks pass and lint and type checks are green.

Written by the indexing model from the issue text.

Description

area:code type:feature

Problem / Request

Let pa.map_over(x, fn, dims, mapper=jax.vmap) take a tuple of dims and a mapper: jax.vmap (default on JAX data, as today), "loop", or any vmap-like callable such as a sharded map.

Motivation

Mapping over members and times today is two nested map_over calls. coordax's cmap takes the vmap as an argument (CP-D4). The prototype on a (member, time, y, x) = (4, 5, 32, 32) ensemble: one call over ("member", "time") equalled nesting to 0.0 with jax.vmap, and a loop equalled it to 2.2e-8; eagerly the vmap took 3.0 ms and the loop 10.3 ms, so the choice belongs to the caller.

Proposed API

# Shapes: (member, time, y, x) = (4, 5, 32, 32)

# today (pipekit-array)
# (member, time, y, x) → (member, time)
eta_bar = pa.map_over(eta, lambda m: pa.map_over(m, spatial_mean, "time"), "member")

# proposed (CP-D4)
# (member, time, y, x) → (member, time), mapped dims first in the order given
eta_bar = pa.map_over(eta, spatial_mean, ("member", "time"), mapper=jax.vmap)

A single dim as a string keeps working. Today's fallback to a loop for a fn that cannot be traced stays when mapper is not given.

Reuse

  • pipekit_array/named/_map.py:map_over.

References & Existing Code

  • Design: docs/design/coordax_carriers.md in jejjohnson/geostack (merged in jejjohnson/geostack#368), "Mapping over named dims" and pattern 3.
  • Prototype: q3_q7_rest.py, section Q3.

Implementation Steps

  • Accept dims: str | tuple[str, ...] and mapper; nest one level per dim.
  • Docstring with the nested equivalent.

Definition of Done

  • Equal to nested map_over with jax.vmap, to the bit, on DimArray and CField.
  • Equal to round-off with mapper="loop"; NumPy data with "loop" stays NumPy.
  • Lint, type check and tests green.

Relationships

  • Parent: jejjohnson/geostack#369
Dominant language
Python
Stars
0
Forks
0
Avg merge
3h 50m
Merged PRs (30d)
143

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jejjohnson/pipekit

All issues in jejjohnson/pipekit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.