Writers¶
LazyArray.write(values) and assignment through a view are implemented by
write_into, which writes through a transform using only basic integer/slice
assignment on the source. Independent affine selections become one basic
assignment. Other selections are scattered against the source's write grid:
each touched cell is read once, updated in memory, and written back, so
storage round trips are bounded by touched cells rather than selected
elements. NumPy sources receive one fancy assignment instead, and a source
that advertises no grid is written one element at a time without reading.
zarr_indexing.writer ¶
Synchronous writes through coordinate transforms using basic source assignment.
write_into ¶
write_into(
source: Any,
transform: IndexTransform,
values: Any,
write_grid: Sequence[DimensionGridLike] | None = None,
) -> None
Write broadcast values to precisely the cells addressed by transform.
The source must expose shape, a NumPy-compatible dtype, and basic
integer/slice assignment. Values are snapshotted and converted before the
first mutation, so source aliases and conversion failures are safe. Extra
leading singleton value axes are accepted, as in NumPy assignment. Repeated
source coordinates receive the last value in C order of the view.
Independent affine maps use one basic assignment. Other selections are
scattered in bulk: a NumPy source receives one fancy assignment, and a
readable source with a write_grid is written one grid cell at a time —
the cell's touched hull is read once, updated in memory, and written back
with one basic assignment, so storage round trips are bounded by touched
cells. Without a grid, or for the few transforms the planner cannot factor
(such as one input axis feeding two output maps), or for a source that
cannot be read, the fallback is one integer assignment per element, which
never reads. Backend assignment may itself read storage units as part of
updating them.
Source assignment failures propagate and may leave preceding writes applied; this operation is not transactional.
Source code in src/zarr_indexing/writer.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |