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

Aperta
#408 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
75/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
numpy, python
Ambito
backend, data

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Python
Stelle
0
Fork
0
Merge medio
3h 50m
PR unite (30g)
143

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jejjohnson/pipekit

Tutte le issue di jejjohnson/pipekit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.