Ruby API reference
Every public function of the kwker gem, for Ruby Arrays and Numo::NArray, with its parameters and results (Kwker 0.1.0).
sort! Page
Kwker.sort!(a, descending: false, nans_first: false)
Sorts an array in place, smallest first, and returns it.
Arguments
a: an Array of Integers (int64 range) or Floats, or a Numo::NArray.descending: true sorts largest first.nans_first: true puts NaNs first; by default they go last.
Example
Kwker.sort!([3, 1, 2]) # => [1, 2, 3]
sort Page
Kwker.sort(a, descending: false, nans_first: false)
Returns a sorted copy of an array; the array itself is not changed.
Arguments
a, descending, nans_first: as in sort!.
Remarks: Not stable (rule 5): keys that are equal but can be told apart (NaNs with different bits) may change places. Keys follow the key order: -0.0 before +0.0, every NaN in one block, last unless NaNs-first is asked for.
select! Page
Kwker.select!(a, k, descending: false, nans_first: false)
Puts the element a full sort would put at index k into a[k], smaller or equal ones before it and larger or equal ones after it. Returns the array.
Arguments
a: an Array of Integers or Floats, or a Numo::NArray.k: the index to fill, 0 <= k < a.size (ArgumentError otherwise).descending, nans_first: as in sort!.
Example
Kwker.select!([50, 10, 40, 20, 30], 2)[2] # => 30
Notes
- Only a[k] is in its sorted place; the elements on either side are in no particular order.
partial_sort! Page
Kwker.partial_sort!(a, k, descending: false, nans_first: false)
Puts the k smallest elements, sorted, at the front of the array and returns it.
Arguments
a: an Array of Integers or Floats, or a Numo::NArray.k: how many elements to sort; k >= a.size sorts them all.descending, nans_first: as in sort! (descending: the k largest).
Notes
- The elements after the first k are in no particular order.
argsort Page
Kwker.argsort(a, descending: false, nans_first: false)
Returns the indices that sort an array. Equal elements keep their input order.
Arguments
a: an Array of Integers or Floats, or a Numo::NArray; not changed.descending, nans_first: as in sort!.
Returns
An Array of Integers (a Numo::Int64 for a Numo::NArray).
Example
Kwker.argsort([30, 10, 20]) # => [1, 2, 0]
Remarks: Stable (rule 6): equal keys keep their input order, so the same input always gives the same positions. Keys follow the key order: -0.0 before +0.0, every NaN in one block, last unless NaNs-first is asked for.
top_k Page
Kwker.top_k(a, k, descending: false, nans_first: false)
Returns the k first elements in sorted order and their indices: the k smallest, or the k largest with descending: true.
Arguments
a: an Array of Integers or Floats, or a Numo::NArray; not changed.k: how many; more than a.size returns them all.descending, nans_first: as in sort!.
Returns
[values, indices], sorted; equal elements go to the earlier index first.
Example
Kwker.top_k([12, 7, 30, 18], 2, descending: true) # => [[30, 18], [2, 3]]
Remarks: The first k keys of the stable order and their positions; equal keys keep their input order (rule 9). Keys follow the key order: -0.0 before +0.0, every NaN in one block, last unless NaNs-first is asked for.
isa Page
Kwker.isa
The engine in use: "avx512", "avx2", "sse42", "neon", "sve" or "portable" (defined by the C extension).
Remarks: The engine changes only the speed, never a result (rule 11).
version Page
Kwker.version
The Kwker C library's version, for example "0.1.0" (defined by the C extension).