Kwker

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

Rubygem install kwker (against the C package).
Kwker.sort!(a, descending: false, nans_first: false)

Sorts an array in place, smallest first, and returns it.

Arguments

Example

Rubygem install kwker (against the C package).
Kwker.sort!([3, 1, 2]) # => [1, 2, 3]

sort Page

Rubygem install kwker (against the C package).
Kwker.sort(a, descending: false, nans_first: false)

Returns a sorted copy of an array; the array itself is not changed.

Arguments

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

Rubygem install kwker (against the C package).
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

Example

Rubygem install kwker (against the C package).
Kwker.select!([50, 10, 40, 20, 30], 2)[2] # => 30

Notes

partial_sort! Page

Rubygem install kwker (against the C package).
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

Notes

argsort Page

Rubygem install kwker (against the C package).
Kwker.argsort(a, descending: false, nans_first: false)

Returns the indices that sort an array. Equal elements keep their input order.

Arguments

Returns

An Array of Integers (a Numo::Int64 for a Numo::NArray).

Example

Rubygem install kwker (against the C package).
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

Rubygem install kwker (against the C package).
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

Returns

[values, indices], sorted; equal elements go to the earlier index first.

Example

Rubygem install kwker (against the C package).
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

Rubygem install kwker (against the C package).
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

Rubygem install kwker (against the C package).
Kwker.version

The Kwker C library's version, for example "0.1.0" (defined by the C extension).