11"""
22Plan layer: the rank-to-rank routing induced by a Selection on a Layout.
33
4- `` ExchangePlan` ` is a value object built once (no communication) from a
5- `` Selection`` and a `` Layout` `. It computes, for every routed element, its
4+ `ExchangePlan` is a value object built once (no communication) from a
5+ `Selection` and a `Layout`. It computes, for every routed element, its
66owner rank and owner-local offset, and arranges the result/value array as
7- `` (npoints, payload)` ` so packing and unpacking are single NumPy fancy-index
8- operations. The same plan drives `` get`` (pull) and `` put` ` (push).
7+ `(npoints, payload)` so packing and unpacking are single NumPy fancy-index
8+ operations. The same plan drives `get` (pull) and `put` (push).
99
1010Every axis falls in one of four quadrants and is handled uniformly:
1111
@@ -35,14 +35,14 @@ class ExchangePlan:
3535 """
3636 The rank-to-rank routing induced by a Selection on a Layout.
3737
38- A plan is built once, without communication, and then drives both `` get` `
39- (pull `` data[idx]`` ) and `` put`` (assign `` data[idx] = value` `). It maps
38+ A plan is built once, without communication, and then drives both `get`
39+ (pull `data[idx]`) and `put` (assign `data[idx] = value`). It maps
4040 every routed result element to its owner rank and owner-local offset, and
4141 splits the result axes into a "T" (transport) block over the distributed
4242 axes and a contiguous "payload" block over the replicated axes, so packing
4343 and unpacking are single NumPy fancy-index operations.
4444
45- Use `` build` ` to construct one; the constructor takes the already
45+ Use `build` to construct one; the constructor takes the already
4646 computed routing tables.
4747
4848 Parameters
@@ -52,15 +52,15 @@ class ExchangePlan:
5252 selection : Selection
5353 Normalized meaning of the index expression.
5454 perm : list of int
55- Permutation taking the result axes to `` (T-dims..., payload-dims...)` `.
55+ Permutation taking the result axes to `(T-dims..., payload-dims...)`.
5656 t_shape : tuple of int
5757 Shape of the transport block (the distributed result axes).
5858 payload_shape : tuple of int
5959 Shape of the payload block (the replicated result axes).
6060 owners : numpy.ndarray
61- Owner rank of each T row (``-1` ` when out of bounds).
61+ Owner rank of each T row (`-1 ` when out of bounds).
6262 peers : dict
63- Maps a peer rank to `` (rows, dist_lin)` `: the T rows it owns and their
63+ Maps a peer rank to `(rows, dist_lin)`: the T rows it owns and their
6464 owner-local linear offsets over the distributed axes.
6565 block_offsets : numpy.ndarray
6666 Offset of each payload element within the owner's replicated block.
@@ -91,7 +91,7 @@ def __init__(self, layout, selection, perm, t_shape, payload_shape, owners,
9191 @classmethod
9292 def build (cls , selection , layout ):
9393 """
94- Plan the exchange for `` data[idx]` `; the result serves both get and set.
94+ Plan the exchange for `data[idx]`; the result serves both get and set.
9595
9696 Parameters
9797 ----------
@@ -159,7 +159,7 @@ def payload_size(self):
159159 def _raise_on_error (self , check_dup ):
160160 """Reach consensus on local errors and raise consistently on all ranks.
161161
162- A single 1-bit `` Allreduce` ` gates the (rare) error path so that every
162+ A single 1-bit `Allreduce` gates the (rare) error path so that every
163163 rank raises together, avoiding a deadlock where one rank raises while the
164164 others enter the exchange. This is log-depth, not an all-to-all.
165165 """
@@ -187,7 +187,7 @@ def _owner_apply(self, moved, dist_lin, block_offsets):
187187
188188 def get (self , local ):
189189 """
190- Return `` data[idx]` ` as a NumPy array by pulling from the owner ranks.
190+ Return `data[idx]` as a NumPy array by pulling from the owner ranks.
191191
192192 Parameters
193193 ----------
@@ -197,7 +197,7 @@ def get(self, local):
197197 Returns
198198 -------
199199 numpy.ndarray
200- The indexed result, in `` selection.result_shape` `.
200+ The indexed result, in `selection.result_shape`.
201201 """
202202 self ._raise_on_error (check_dup = False )
203203 comm , ps = self .comm , self .payload_size
@@ -228,14 +228,14 @@ def get(self, local):
228228
229229 def put (self , local , value ):
230230 """
231- Assign `` data[idx] = value` ` by pushing to the owner ranks.
231+ Assign `data[idx] = value` by pushing to the owner ranks.
232232
233233 Parameters
234234 ----------
235235 local : numpy.ndarray
236236 The caller's rank-local array (written in place).
237237 value : array_like
238- The value to assign, broadcast to `` selection.result_shape` `.
238+ The value to assign, broadcast to `selection.result_shape`.
239239 """
240240 self ._raise_on_error (check_dup = True )
241241 rows_flat = self ._value_to_rows (value , local .dtype )
@@ -314,11 +314,11 @@ def _resolve_owners(selection, layout, gcoords):
314314 Returns
315315 -------
316316 owners : numpy.ndarray
317- Flat owner rank per T row (``-1` ` if out of bounds).
317+ Flat owner rank per T row (`-1 ` if out of bounds).
318318 local : numpy.ndarray
319- Per-axis owner-local offset per T row, shaped `` (naxes, nrows)` `.
319+ Per-axis owner-local offset per T row, shaped `(naxes, nrows)`.
320320 sub : numpy.ndarray
321- Per-axis owner sub-rank per T row, shaped `` (naxes, nrows)` `.
321+ Per-axis owner sub-rank per T row, shaped `(naxes, nrows)`.
322322 """
323323 axes = layout .distributed_axes
324324 nrows = len (next (iter (gcoords .values ()))) if gcoords else 0
@@ -386,7 +386,7 @@ def _group_peers(layout, owners, dist_local, sub, gcoords):
386386 Returns
387387 -------
388388 peers : dict
389- Maps a peer rank to `` (rows, dist_lin)` `: the T rows it owns and their
389+ Maps a peer rank to `(rows, dist_lin)`: the T rows it owns and their
390390 owner-local linear offsets over the distributed axes.
391391 oob_error : str or None
392392 Set when any row addresses an out-of-bounds global index.
@@ -425,12 +425,12 @@ def _group_peers(layout, owners, dist_local, sub, gcoords):
425425def nbx_push (comm , distributed_axes , repl_total , peers , block_offsets ,
426426 payload_size , rows_flat , local ):
427427 """
428- Route `` rows_flat` ` to the owner ranks (NBX) and scatter each received
429- payload into `` local` ` at its owner-local position.
428+ Route `rows_flat` to the owner ranks (NBX) and scatter each received
429+ payload into `local` at its owner-local position.
430430
431- This is the single push primitive behind both `` ExchangePlan.put` `
432- (advanced/replicated assignment, `` payload_size` ` >= 1) and the structured
433- redistribution layer (one value per point, `` payload_size` ` == 1).
431+ This is the single push primitive behind both `ExchangePlan.put`
432+ (advanced/replicated assignment, `payload_size` >= 1) and the structured
433+ redistribution layer (one value per point, `payload_size` == 1).
434434
435435 Parameters
436436 ----------
@@ -441,13 +441,13 @@ def nbx_push(comm, distributed_axes, repl_total, peers, block_offsets,
441441 repl_total : int
442442 Full replicated stride (1 when there is no replicated payload).
443443 peers : dict
444- Maps a peer rank to `` (rows, dist_lin)`` (see `` _group_peers` `).
444+ Maps a peer rank to `(rows, dist_lin)` (see `_group_peers`).
445445 block_offsets : numpy.ndarray
446446 Offset of each payload element within an owner's replicated block.
447447 payload_size : int
448448 Number of payload elements per point.
449449 rows_flat : numpy.ndarray
450- Values to push, shaped `` (nrows, payload_size)` ` in owner-grouped order.
450+ Values to push, shaped `(nrows, payload_size)` in owner-grouped order.
451451 local : numpy.ndarray
452452 The owner's rank-local array (written in place).
453453 """
@@ -469,12 +469,12 @@ def nbx_push(comm, distributed_axes, repl_total, peers, block_offsets,
469469
470470
471471def _encode (payload_size , block_offsets , dist_lin ):
472- """Pack a request header as `` [payload_size, *block_offsets, *dist_lin]` `."""
472+ """Pack a request header as `[payload_size, *block_offsets, *dist_lin]`."""
473473 return np .concatenate (([payload_size ], block_offsets , dist_lin )).astype (np .int64 )
474474
475475
476476def _decode (buf ):
477- """Unpack a request header into `` (block_offsets, dist_lin)` `."""
477+ """Unpack a request header into `(block_offsets, dist_lin)`."""
478478 payload_size = int (buf [0 ])
479479 block_offsets = buf [1 :1 + payload_size ]
480480 dist_lin = buf [1 + payload_size :]
0 commit comments