Expand description
Search and sort over slices of keys. A key is an item read as a whole number (Key), or an unsigned word whose order is the order you want (RadixKey). Float::order_key gives each float such a word, as wide as the float. Positions take 32 bits inside these functions, so a slice holds at most u32::MAX items. tolerant builds its searches over floats on these functions.
index_of and classes index the first position of each key; firsts marks first occurrences directly. index_of passes over x once for each item of y when y has at most SCANNED items. The index is a table when the keys span at most twice the slice’s length, or 1024, and a hash table otherwise. numbered numbers the classes in order of first position, with each one’s size. grouped_keys numbers them the same way from a table of keys, with each one’s positions, numbered_keys with each item’s number, and class_counts gives only their sizes. counts counts the items with each key in such a table. sort_rows sorts keys that span such a table by counting them. It sorts other keys with an LSD radix sort that skips any byte that is the same in every key. view_sort_along, view_partition_along and view_quantiles_along work on each item’s SortKey, which reads back to the item exactly. A sort counts, sorts a float lane through a bitonic network on vectors, or sorts the keys by comparison or by the same radix sort. With several threads, the radix sort splits each pass of more than RADIX_PIECE keys across them, and index_of splits its lookups.
Structs§
- Chains
- Positions grouped by a 64-bit key, such as a hash. A map gives the first and last position pushed with each key, and each position links to the next one pushed with the same key. Positions pushed in order give chains in order.
- Class
Numbers - Each item’s class number below
count, at any integer width: classes that a fold totals, or a scan runs, each on its own (Grouping). - Exact
- A cell compared exactly: an atom, which has no shape, or an array of compact Booleans, integers or characters, with its shape. Two cells are equal when their shapes and items are equal. Booleans and integers of any width compare as numbers, and characters only with characters. A hash leaves out the shape, which equality compares. Cells order as BPL grades them: an atom before an array, arrays by rank, then item by item with numbers before characters (
crate::characters::order_of_kinds), then by length and shape. - Grouped
- The classes of a slice, numbered from 0 in order of their first positions, with the positions of each.
- Groups
- Positions group by group, ascending within each group, with the number in each group. Each buffer holds whole groups. The two classes of a slice of two keys take a buffer each, which
into_buffershands over without a copy. Other groups share one buffer. Positions areu32s. - Links
- The positions in one or two of
Chains’ chains, each in the order they were pushed. Keepnextthis small: the search loops that call it rely on it inlining. - Numbered
- The classes that
classesgives, numbered from 0 in order of their first positions, with the number of items in each. - Ranges
- One range of positions for each group, in any order, as each one’s start and length: a segmented array’s vector items as their entries in its leaf. Each range folds by
Reduction::sliceand scans byReduction::scan. An empty range folds toR::unit().
Enums§
- Set
- Set operations retain first-occurrence order, matching as classification and membership do.
Constants§
- SCANNED
- The number of items of
yup to whichindex_ofandtolerant::index_ofpass overxonce for each, in place of building an index.
Traits§
- Grouping
- A grouping of a vector’s items that a fold totals, or a scan runs, each on its own: classes by number (
ClassNumbers), or ranges of positions (Ranges), as a segmented array’s items are ranges of its leaf. - Key
- An item as a whole number: a Boolean’s 0 or 1, an integer, a character’s code point, or an order key. Two items match exactly when their keys are equal. A 64-bit unsigned key wraps to a negative number, which keeps keys distinct.
- Radix
Key - An unsigned key that
sort_rowssorts one byte at a time.
Functions§
- bins
- For each of
values, the number ofboundariesat or below it, as BQN’s dyadic⍋and NumPy’ssearchsortedwithside='right'give it.boundariesmust be in ascending order. When they are, and they span few enough keys for a table, a table of the count of boundaries at or below each key answers each value with one read. Otherwise each value takes a binary search, which halves its range with a select in place of a branch, so mispredicted comparisons don’t stall it. Sixteen values search together, level by level, because every search ofboundarieshalves the same lengths. Their loads at each level are then independent. - class_
counts - The number of items in each class of
x, in order of the classes’ first positions, asnumberedcounts them. Keys that span a table takecounts, then a pass for first positions that stops once it has found every keyxholds, with nothing written for each item. - classes
- The first position of each item’s key in
x, which represents the item’s class. - counts
- The least key of
x, and the number of items with each key from it to the greatest (counts_into), whentableallows that range. - counts_
into - Writes the number of items of
xwith each key intocounts, whose entries are zero and stand for the keys fromminon, covering every key ofx. Up to 4 keys, each count but the first takes a pass that vectorizes. With fewer than 64 keys, runs of one key are common, and each count would wait for the previous one to be stored. So the items then go to four tables in turn, which are summed at the end. On the Mac, four tables made 2 keys 3 times as fast as one table, and 64 keys or more no faster. - dense_
offsets - Whether
offsetsare dense enough to use a table over thesizepositions they fall below. - find_
with - Marks where
pattern_shapefits withinshapeand every pattern item matches. Shapes describe compact row-major buffers;samecompares their flat positions. A lower-rank pattern has leading axes of length one. - first_
classes - The first position of each item’s
keyinx, from one pass that records and reads each key together. Two items’ keys are equal exactly when the items match. - first_
matches - For each item of
y, the position of the first equal item ofx, or the length ofxwhere none is equal, from a hash map.index_oftakes it for keys that span too much for a table. - firsts
- Whether each item is the first with its key. Narrow key ranges mark first positions in a table; wider keys use a hash set.
- grouped
- The positions of
groupsin order of group, keeping their order within each group, with the number in each of thengroups. - grouped_
by - The positions of
itemsgrouped by the group thatgroupgives each item, keeping their order within each group, with the number in each of thengroups.groupedis the version for groups given as numbers. - grouped_
keys - The classes of
xasGroupedgives them, orNonewhen its keys span too many values for a table. Each class’s positions come from one pass overx. - index_
of - For each item of
y, the first position of its key inx, or the length ofxwhen it has none. A slice here holds at mostu32::MAXitems, so positions areu32s. - inverse_
permutation - Inverts a permutation: each position’s rank in
order, as aTsuch as a grade’su32or an axis order’susize. Every position must occur exactly once. - member_
layout - The layout of the major cells of an array laid out by
layout, when a query laid out byquerycan match one of them: its shape equals theirs, and its axis names and keys agree with theirs (Layout::matches).Nonewhen it can’t. A Rank error for a rank-0 array, which isn’t a container. - numbered
- Numbers the classes in
classes, which gives each item the first position of its class, asclassesandtolerant::classesdo, and counts each class. - numbered_
keys - The classes of
xasNumberedgives them, numbered asgrouped_keysnumbers them, orNonewhen its keys span too many values for a table. A fold of each class reads these numbers in one pass, where each class’s positions would take a pass to build and a gather to read. A pass that numbers each key as it first meets it, in place ofnumbered_table, measured slower: it stores to a table entry for every item, and repeated keys then wait on those stores. Each class’s count comes from one count of the class numbers (ClassNumbers::counts). - occurrences
- For each offset, how many preceding offsets equal it, and the largest occurrence count.
Nonewhen none repeats. Every offset must be belowsize. - quantiles
- Linear-interpolated quantiles of
x. Selection keeps the input width; f16 interpolation computes in f32. Empty inputs give NaN. A probability outside[0, 1], or NaN, gives a Domain error. - select
- Places each of the sorted, distinct
ranksat its sorted position, leaving the runs between them unordered. Ranks must be belowx.len(). Selecting the middle requested rank first partitions disjoint runs for the remaining ranks; one rank takes linear time. - sort_
rows - The rows of an
n-row table in ascending order, comparing entries column by column from the first. Rows that compare equal keep their order of position.columnsholds each column’snkeys, whose unsigned order is the order you want. A caller fills them from its items in a pass that vectorizes. Fewer than 256 rows take a comparison sort. One column whose keystabledallows takes a counting sort. Other tables take the radix sort once for each column, from the last. Positions areu32s, as a slice holds at mostu32::MAXitems. - view_
argextremes - The first minimum or maximum position of each lane, without gathering lanes or allocating a result per lane. Comparisons use sorting’s NaN-last order.
- view_
argpartition - Positions partitioned around
rank. Equal values need not keep their original order. - view_
bins - For each item of
values, the number ofboundariesat or below it, asbinscounts them: for Booleans, integers or characters of one kind, with integers of different widths read asi64, and for floats of one width by their order keys.Nonefor other pairs. - view_
bins_ below - For each item of
values, the number ofboundariesbelow it, for views of one dtype other than complex:binsof the complemented order keys, withboundariesreversed.Nonefor other views. - view_
class_ counts - The size of each class of
x, in order of first position, asview_classesmatches them. Booleans, integers and characters that span a table count from it, asclass_countsdoes.Nonefor complex numbers. - view_
classes - The class of each item of
x, as the first position of an item that matches it: exactly for Booleans, integers and characters, throughclasses, and withintfor floats, throughtolerant::classes, which checks for an interrupt as it goes.Nonefor complex numbers. - view_
contains - Whether one of
cellsconsecutive cells ofxmatchesy. The caller checks cell shapes and aligns keys before searching, asview_memberdoes. - view_
find - Marks occurrences of a compact pattern in a compact target, with the shapes and geometry of
find_with. Booleans, integers and characters of one kind match exactly, and floats of any widths match withint, including NaN with NaN.Nonefor other dtype pairs. - view_
firsts - Whether each item of
xis the first of its class, asview_classesmatches them.Nonefor complex numbers. - view_
grade - Stable positions that order a vector. Equal items keep their original positions, including signed zeros and NaNs.
- view_
grouped - The classes of
x, asview_classesmatches them, numbered in order of first position, with the positions of each. Booleans, integers and characters that span a table group straight from it, asgrouped_keysdoes.Nonefor complex numbers. - view_
index_ of - For each item of
y, the first position inxof an item that matches it, or the length ofxwhere none does: exactly for Booleans, integers or characters of one kind, with integers of different widths read asi64, and withintfor floats of one width, checking for an interrupt as it goes. An integer haystack also takesf64needles when every needle is an integer thattolerant::integer_ofaccepts.Nonefor other pairs. - view_
lexgrade - Stable lexicographic order of
nrows, with columns in primary-first order. Each column is a compact view, its first key’s offset and the step between keys. Columns can have different dtypes; radix keys keep each column’s item width.Nonefor complex keys. - view_
lexgrade_ along - Stable positions that order each lane of
[outer, len, inner], asview_lexgradeorders rows, laid out as the lanes’ items are. Each column, in primary-first order, is a compact view, the offset of the first item’s key and the step between successive items’ keys:1where the view holds one key for every item, or a row’s width where each item is a row of a matrix.Nonefor complex keys. An interrupt stops a run of several lanes with the interrupt hook’s error. - view_
matches - Whether equal-length compact cells match. Booleans and integers match floats as
f64s withint.Nonewhen their kinds need the caller’s numeric conversion. - view_
member - Whether
querymatches one major cell ofx, as≡matches arrays, for compact items in row-major order. The query’s layout must match a cell’s (member_layout). Its items line up with the cell’s by key. Items compare at the two views’ common dtype, asview_matchescompares them, and characters never match numbers. It checks for an interrupt as the search goes. A Rank error for a rank-0x. - view_
numbered - The classes of
x, asview_classesmatches them, numbered in order of first position, with each item’s class number. Booleans, integers and characters that span a table number straight from it, asnumbered_keysdoes.Nonefor complex numbers. - view_
order_ keys - Each item’s order key, widened to 64 bits. Within one dtype, their unsigned order is the items’ order, with every NaN last.
Nonefor complex numbers. - view_
partition_ along - Partitions each lane around
rankin its output buffer, comparing its items’SortKeys, computed once. Value partitioning writes the items back from the keys, and index partitioning writes i64 positions.Nonefor complex numbers. An interrupt stops it with the interrupt hook’s error. - view_
quantiles_ along - Quantiles of each lane, with a leading probability axis. Integers select exactly before converting the selected values to f64; floats keep their width.
Nonefor complex numbers, which have no order. A probability outside[0, 1], or NaN, gives a Domain error, and an interrupt the interrupt hook’s error. - view_
selected - The positions of the items of
xwhose ranks in a stable grade, ascending or descending wheredown, fall inrange, in rank order. Positions break ties because taking from a stable grade observes them. A run nearer the end is found in the reversed order.Nonefor complex numbers. - view_
set - Unique values of a set operation on two views of one dtype. Shared searches do all matching; gathered output has no keys or names.
Nonefor unsupported pairs. - view_
sort - A sorted vector: one lane of
view_sort_along. - view_
sort_ along - Sorts each lane into its own output. A lane of 256 items or more whose values span a small table sorts by counting, and a float lane through
networkedwhere it takes the lane’s length. Other lanes sort their items’SortKeys, computed once, by an unstable comparison sort belowvalue_radix_fromand by the radix sort from there, then write the items back from the keys. Equal keys come from equal items, so the result doesn’t depend on how the sort orders them, and¯0comes before0. Lanes run through the shared stack scheduler, which reuses each thread’s buffers. A single lane runs on the calling thread, where the radix sort can split its passes across threads.Nonefor complex numbers. An interrupt stops a run of several lanes with the interrupt hook’s error.