Expand description
Copying the items of a slice into a buffer by position: repeating each, keeping those a mask selects, taking them at indices, walking an n-dimensional pattern of offsets over them, and writing them at offsets. positions writes the positions that a mask selects. Each applies a conversion to each item it writes, so a caller can widen items as it gathers them. Most are generic and #[inline], so they compile in the caller, with the caller’s types and conversion. walk and scatter_walk instead compile their walk once for each item type, and run any other conversion as a separate contiguous pass. Their fixed-width loops move Units, which compile once for each size of item. Booleans and integers convert into f64 through fixed-width loops of their own as they write (Item::cells_from).
Structs§
- Same
- A
Convertfor a source and result of one type, which keeps each item as it is. A walk or scatter with it moves items straight between its source and result, with no conversion pass. - Table
- Explicit offsets along one axis, with
Steps::FILLwhere a fill goes: a list of offsets, or index values that each give one.startandlenchoose the offsets in use, so that slicing a table copies none of them.
Enums§
- Steps
- The source offsets of one result axis. Regular patterns need no position table; a missing offset reads fill.
- Writes
- Where a scatter writes: at flat offsets, or at the positions that
stepsreach frombase, in the orderwalkreads them. ASteps::FILLoffset, or a fill position, writes nothing. A walk writes without listing its positions.
Traits§
- Convert
- How
walkandscatter_walkturn a source item into a result item. EveryFn(S) -> Dconverts item by item.Samekeeps each item of a source and result of one type as it is. - Index
Source - Index values that a table reads as positions along an axis, converting each one as it reads it, so that the values aren’t first copied into a list of offsets.
Table::indicestakes them. - Index
Value - A value that names a position along an axis: a Boolean or an integer. A float index value names the whole number it equals within the comparison tolerance, which
crate::structure::float_positionreads before any table holds it. - Item
- An item type that
walkandscatter_walkmove as aUnitof its size and alignment: each element type of compact buffers. Their fixed-width loops then compile once for each size of item, whatever the item’s type or its conversion. A few conversions intof64write through fixed-width loops of their own instead (Item::cells_from). - Unit
- A type through which walks move items: an unsigned integer, or an array of two, with the size and alignment of the item types that use it.
Functions§
- counts_
up - Whether
xsis 0, 1, 2 and so on: offsets that read a source in order, or an axis order that a transpose leaves unchanged. - interleave
- Appends
rowsrows toout, each holding the next lane of each part in turn, as arrays joined along an axis lay out their lanes. Lanerof a part whose lanes holdnitems is its items fromr × nup to(r + 1) × n. Rows go straight intoout‘s spare capacity, so each result item is written once. Where two parts’ lanes hold one length of at mostRUNitems, each lane moves as one block of units. Other lanes copy item by item. - positions
- Appends
position(j)for each positionjwhose count inmaskis 1, in order. Every count is 0 or 1, andtotalof them are 1. Long runs cost little: a block of 64 counts that are all 0 is skipped, and one whose counts are all 1 is written in one loop. In a block that mixes both,selectedcomputes only the selected items. Each count is read by its low bit, which writes every slot whatever the counts hold. - repeat
- Appends
item(j)for eachjbelowlen, as many times as its count.countsholds one count for all the items, or one for each item. The counts are nonnegative and sum tototal. An item with a count of at most 4 writes four copies where its run starts. The items after it overwrite the copies beyond its count. A larger count fills its run. With a count for each item, a group of 4 items whose counts are all at most 4 writes its copies after one check for the whole group. With a check and a taken branch for each item, the loop’s cost varied by about a third with where its code was placed. - scatter
- Replaces the item of
outat each offset with the matching one ofitems, converted byconv, or with the only one whenitemsholds one. A later offset wins. An out-of-range offset, includingSteps::FILL, writes nothing. - scatter_
walk - Replaces the items of
outthatstepsreach frombase, in the order thatwalkreads them, with the matching ones ofitems, converted byconv, or with the only one whenitemsholds one.itemsholds one item for each position the steps reach, or one item. A fill position writes nothing. A conversion other thanSameconverts a block of items at a time, whole rows of the first axis up to aboutCHUNKitems, then writes that block while it’s still in cache. WhereDhas a fixed-width loop that converts fromS(Item::cells_from), short cells along a stride convert as they write instead, with no separate pass. The walk’s fixed-width loops then move items asUnits, so they compile once for each size of item, whatever the types and conversion. Rows longer thanRUNwrite along a slice each. Short cells write through one table of their offsets, aswalkreads them. Cells that a table of starts picks, each reaching items a stride apart, as columns’ do, must be disjoint or identical. They write in blocks of 8 cells, row by row, so each block’s writes share the lines they touch, aswalk’s reads do. A later identical cell wins. Other steps write inwalk’s order. - take
- Appends the items of
itemsatindices, each converted byf. Each index is in-n..nfornitems, and a negative index counts back from the end. - walk
- Appends the items of
sthatstepsreach frombase, each converted byconv: oneStepsfor each axis, with the last varying fastest. ANoneoffset givesfill, converted.convis anyFn(S) -> D, orSamefor a source and result of one type. The walk’s fixed-width loops move items asUnits, so they compile once for each size of item. WithSame, the walk appends straight ontoout, splitting across threads from [SPLIT] items. Any other conversion walksCHUNKitems at a time into a buffer of source items, which it converts ontooutwhile they’re still in cache.