Expand description
Plans for structural operations: take and drop, rotate and reverse, windows, transpose and catenate. A plan gives the result’s layout, and Steps that read the result’s items from the argument’s items in order. gather::walk copies a compact array by a plan, and basedpl copies its other arrays by the same plan. Each plan checks its arguments.
Structs§
- Count
- A count that an argument gives, such as a take’s or a diagonal’s offset: its sign and magnitude.
- Plan
- A structural result’s layout, and the steps that read its items from the argument. The steps’ lengths multiply to the result’s item count, outermost first. One entry can cover several result axes.
- Routes
- The selectors of a selection by written parts (
routes): one for each axis of the layout thatsourcesregroups the source into, with the source axes that each reads, and whether the selection reads one item, one position on every source axis in order. - Slide
- A fold along one or two axes of a copy whose axes walk windows of its source, run as sliding folds over the source’s rows without building the windows (
crate::reduce::slidingandcrate::reduce::sliding_2d).Walkclassifies the copy. Each folded axis is a window’s axis that moves one position at a time along its source axis. The copy’s other axes along that source axis move by 1, where the windows slide, or by whole windows, where they tile it, as pooling’s do. basedpl folds its pending copies of windows this way, and the Python API its views of windows. - Walk
- How a copy walks its source: one entry for each axis of the copy, the source axis that each entry walks, and the offset of the positions on source axes that no entry walks. Axes that walk one source axis together read windows, as
Windows::planlays them out. Every reader of windows fromStepsclassifies them here:Walk::readgives what the axes along one source axis read. - Window
Axis - One axis of windows: windows of
sizeitems, eachstepitems after the last. A padded axis has a window centred on everystepth position, and reads past its ends by its edge mode. - Windows
- Windows over the leading axes of an array of one shape: a
WindowAxisfor each, and the lengths thatwindowedgives, the frame that counts the windows along each axis followed by the shape of one window.
Enums§
- Edge
- How a position outside an axis maps to one inside it, as edge modes of padding do.
Fillgives no position, which reads the fill. - Edged
- The positions that
Edge::positionsgives: each item’s position on the axis, or floats where some item reads the fill, with NaN there. - Index
Part - Written index parts, before the selected axes and their lengths are known.
- Selector
- One independent axis selector. Positions are zero-based and already normalized; a range can walk backwards.
Allkeeps the whole axis, whatever its length. An index array replaces its axis by the axes of its layout. Its positions, aTable, lie within the axis or areSteps::FILL, which reads the caller’s fill. The code that builds an index array checks its positions, asindex_positionsandindex_tabledo.NewAxisinserts a length-one axis without consuming an input axis.
Constants§
- NOT_
WHOLE - The message of the Domain error for an index value that isn’t a whole number.
Functions§
- addressed
- The first axis of
layoutthat each selector addresses, given the name of each selector’s one named axis, where it has exactly one, and the number of axes it covers, where more axes than remain cover the rest, as a coordinate past the last axis does. A selector whose namelayouthas addresses the axis with that name, unless another selector has the same name. Selectors with the same name take free axes in order, as unnamed selectors and NumPy’s index arrays do. Each other selector takes the first free axes whose names don’t conflict with its name. Either way a selector claims every axis it covers. Two selectors that claim one axis, or a selector with no free axis, give an Index error. - addressed_
parts - Routes written parts to source axes without padding them with implicit selectors. Axis payloads give their name and consumed width; returned payloads identify the original part.
- catenate
- The layout of
leftandrightjoined alongaxis, with the lengths thatcatenatedgives. The joined axis has both sides’ keys, with no key where a side has none, and each other axis has either side’s keys. A name survives where both sides agree. - catenated
- The lengths of
leftandrightjoined alongaxis: their lengths along it added. They must have the same rank, and the same lengths on their other axes. - counted_
positions - The positions along an axis of length
sizethat signed positions give, aspositionsgives them, withSteps::FILLforNoneand for a position outside the axis. - diagonal
- A diagonal of two distinct axes, moved to the last result axis. Positive offsets start further along
axes[1]; negative ones alongaxes[0]. - diagonal_
span - Where diagonal
offsetof a matrix ofrowsbycolsstarts, as a row and a column, and its length. A positive offset starts further along the columns. A negative one starts further down the rows. - expand
- Undoes
repeatwith the same counts: one cell for each count. A positive count gives the first cell it made, and any other count a fill. One count must divide the number of cells. More counts must use every cell, unless the axis has one cell. - extended
- The plan that appends the keys in
added, a list for each axis, to the axes oflayout, asmissing_keysgives them. An axis without keys takes them after a position without a key for each of its items. The new positions readSteps::FILL, and the others read the items in place. - float_
position - The whole number that a float index value names: the one it equals within tolerance
t, the comparison tolerance, which only Mathish makes nonzero.Nonefor a NaN or a value that isn’t whole, which reads the fill. A whole number pasti64saturates, and so lies outside every axis. The one rule for float index values:positions,signed_positions,index_tableandEdge::positionsread floats through it. - index_
claims - Expands Rest once geometry is known, with one source claim per consuming part. Axis payloads identify the original written part.
- index_
table - A table that reads the index values in
valuesas positions along an axis of lengthsize, aspositionsreads them. Booleans and integers that all lie inside the axis read in place, each converted as it’s read: the one pass that checks them writes nothing, and also finds whether they give evenly spaced positions, so that a walk can read them as one stride. Floats, read within tolerancet, and values with any outside the axis become the list of positions thatpositionsgives, with the fill position for each value that names none. - key_
position - The position of key
nameonaxisoflayout, orSteps::FILLwhere the axis lacks it: a missing key reads the fill and writes nothing, as a position outside the axis does. BPL and both Python bindings read keys by this rule. - key_
selector - The selector that keys give on
axisoflayout, bykey_position: one key’s position, which removes the axis, wherewithinisNone, and otherwise an index array of the keys’ positions, laid out aswithin. - missing_
keys - For each axis of
layout, the keys thatwantednames on it and it lacks, each once, in order.wantedpairs an axis with the keys that one selector names on it. A write adds these keys before it plans (extended). - pad
- Pads every axis by
(before, after)positions, to the lengths thatpaddedgives. Each position past an end reads byedge: the item type’s fill, or a position on the axis. Existing axis keys remain on their positions. Padding a keyed axis by another mode thanEdge::Fillrepeats keyed positions, which is an error. An axis that pads by nothing keeps a plain walk. - pad_
steps - The steps that pad each source axis under its edge mode.
- padded
- The lengths of
shapewithwidthsadded before and after each axis. - plan_
parts - Plans a selection by written parts on
layout, as⌷and the Python frontends read brackets.claimsgive each part’s axis name and width, as foraddressed_parts, andexplicitits axes.decode(i, axis)gives the selector of written partiat sourceaxis, with whether it reads one position. Axes that no part reaches stay whole, and a part wider than one axis reads its axes as one. Also gives whether the selection reads one item: one position on every source axis, in order.broadcastpairs index arrays asselectdoes.errconverts this module’s errors to the caller’s. - plan_
routes - The plan of the selection that
routesgives onlayout, asplan_partsplans it. - position_
recipe - Position
ion an axis of lengthsize, where a negativeicounts back from the end. Addingsizeto a negative position without a branch keeps a loop over positions vectorised. A position outside the axis is then at leastsize. - positions
- The positions that index values give along an axis of length
size. A negative value counts back from the end. A value outside the axis, a float that isn’t a whole number within tolerancet(float_position), or a NaN gives the fill position (Steps::FILL), which reads the fill and writes nothing. Items that aren’t numbers are a Domain error. - regrouped
- A layout of
shapewhose axisicomes fromlayout’s axessources[i], as a transpose sends them. An axis with no sources is new, as a split or a merge makes it. A result axis keeps the keys its sources agree on when each source has its length. It keeps the name they agree on, unlessnames[i]gives one. - repeat
- Repeats each cell along
axisby its count: one count for every cell, or one for each cell. A negative count gives that many fills in place of its cell. Where the axis has one cell, every count repeats it. A fill has no key, and repeating a keyed position is an error, as it is for selection. - repeated
repeat’s items with no plan to walk:view, the items oflayout, with each cell alongaxiswritten as many times as its count, a run at a time (gather::repeat, orgather::positionsfor counts of 0 and 1).Nonewhere a count is negative oraxishas keys, whichrepeat’s plan serves.- rotate
- Rotates the items along
axis, or reverses them whencountsisNone.countsgives the counts’ shape and items: one count for every lane, or one for each lane in the shape oflayoutwithoutaxis. A lane starts at positioncountof the axis, counted modulo its length. Keys on the axis move with their items when every lane rotates alike, and are dropped otherwise. - rotate_
steps - The steps that rotate an axis by its count, or reverse it when no count is given.
- rotated
- The lengths of
shaperotated alongaxis, which are its own.frame, the shape of counts that give one count for each lane, must matchshapewithoutaxis, which is one of its axes. - routes
- The routes of a selection by written parts on
layout, asplan_partstakes them.claimsgive each part’s axis name and width, as foraddressed_parts, andexplicitits axes.decode(i, axis)gives the selector of written partiat sourceaxis, with whether it reads one position. Axes that no part reaches stay whole (Selector::All), and a part wider than one axis reads its axes as one. - select
- Selects with one selector for each leading axis of
layout, in order, keeping the axes that no selector mentions. A single position removes its axis, and a range keeps it in place. An index array’s axes replace its axis. An unnamed vector keeps the axis’s name and the keys at the positions it selects if none repeats, as a named vector without keys of its own keeps those keys, and an unnamed index array of another rank has plain axes. Index arrays pair, as arguments pair in arithmetic: all of them withbroadcast, as.[]reads them, and otherwise those that share an axis name, as⌷reads them. Paired index arrays put their axes where the first of them was. A range pairs with an index array that has its axis’s name. Positions that step evenly along each axis read as strides (strided), whether one index array gives them or paired arrays sum to them. One index array whose positions read a stretch of its axis past the ends, as edge modes and positions that count back from the end give them, reads as one padded or rotated entry. - select_
axis selectwithselectoronaxisand every other axis whole. ANewAxisgoes in beforeaxis.- signed_
positions - The signed position that each index value gives, before any axis applies: integers as they are, and floats as
float_positionreads them within tolerancet, withNonefor a NaN or a value that isn’t whole. Items that aren’t real numbers have no position.positionsreads the values and checks them against an axis in one pass. - sole_
name - The name of the one named axis of
layout, where it has exactly one. - take
- Takes
countitems alongaxisfor each(axis, count)incounts, at the lengths thattakengives, or drops them whentakeis false. A negative count works from the end. A take past an end reads fill there. A later count for the same axis replaces an earlier one. - take_
steps - The steps that read
countstaken fromshape, or dropped wheretakeis false, one entry for each axis (take). - taken
- The lengths of
shapeafter taking or droppingcounts, each along its axis: a take keeps|k|positions, and a drop keepsmax(0, n-|k|). A later count for the same axis replaces an earlier one. - transpose
- Sends axis
ioflayoutto result axisaxes[i], at the lengths thattransposedgives. A result axis keeps the keys and name its source axes agree on. - transpose_
steps - The steps that read
shapetransposed byaxes, one entry for each result axis (transpose). - transposed
- The lengths of
shapetransposed byaxes, which sends axisito result axisaxes[i]. Axes sent to the same result axis select their diagonal, at the shortest of their lengths. Every result axis from 0 to the largest destination needs a source. - walked_
source - The row-major shape of a source of
lenitems whose axes the entries oftablesstep along, for a copy ofshape, for a caller that holds a source’s storage without its shape, as a Python view does. It has one axis for each distinct stride, and each axis holds as many items as the next larger stride spans.Nonewhere a stride doesn’t divide the next, orlenisn’t a whole number of the largest. - window_
padding_ steps - Pads the positions that windows read, or returns None when no axis pads or there are no windows.
- window_
steps - The windows’ frame steps followed by the steps within each window.
- windowed
- The lengths of the windows of
shapethataxesgive along its leading axes: the number of windows along each of those axes, then a window’s lengths. Along an axis of lengthn,⌊(n-size)÷step⌋+1windows fit, or none wheresizeis longer. A padded window is centred on each position, which gives⌈(n-[size even])÷step⌉windows. Its size must be less than twice the length of an axis that isn’t empty.