Kwker

Fortran API reference

Every public function of the kwker Fortran module (an fpm package), with its parameters and results (Kwker 0.1.0).

Import path: use kwker

Kwker for Fortran: an ISO_C_BINDING module over the C library (libkwker_c): in-place sorting, selection and argsort of integer(int32 / int64) and real(real32 / real64) arrays (the engine - AVX-512, AVX2 or portable - chosen at run time). Floating point: -0.0 before 0.0, NaNs last (first with KWKER_NANS_FIRST). Indices are 1-based.

KWKER_ASCENDING, KWKER_DESCENDING, KWKER_NANS_FIRST Page

FortranCompile kwker.f90 with your program; link -lkwker_c.
integer, parameter, public :: KWKER_ASCENDING = 0, KWKER_DESCENDING = 1, KWKER_NANS_FIRST = 2

The order argument: KWKER_ASCENDING (the default) or KWKER_DESCENDING, plus KWKER_NANS_FIRST to put NaNs first

kwker_sort Page

FortranCompile kwker.f90 with your program; link -lkwker_c.
subroutine kwker_sort(a, order)
  integer(int32) | integer(int64) | real(real32) | real(real64), intent(inout), contiguous :: a(:)
  integer, intent(in), optional :: order
end subroutine

Sorts an array in place, smallest first.

Arguments

Example

FortranCompile kwker.f90 with your program; link -lkwker_c.
call kwker_sort(a)

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.

kwker_select Page

FortranCompile kwker.f90 with your program; link -lkwker_c.
subroutine kwker_select(a, k, order)
  integer(int32) | integer(int64) | real(real32) | real(real64), intent(inout), contiguous :: a(:)
  integer, intent(in) :: k
  integer, intent(in), optional :: order
end subroutine

Puts the value a full sort would put at a(k) there, smaller or equal values before it and larger or equal ones after it. With k = (size(a) + 1) / 2 that is the median.

Arguments

Notes

Remarks: Position k holds the key a full sort puts there; the keys before it are ordered before or equal to it, the keys after it after or equal (rule 7). Keys follow the key order: -0.0 before +0.0, every NaN in one block, last unless NaNs-first is asked for.

kwker_argsort Page

FortranCompile kwker.f90 with your program; link -lkwker_c.
function kwker_argsort(a, order) result(ix)
  integer(int32) | integer(int64) | real(real32) | real(real64), intent(in), contiguous :: a(:)
  integer, intent(in), optional :: order
  integer(int64), allocatable :: ix(:)
end function

Returns the positions (1-based) that sort an array: a(ix) is sorted. Equal values keep their input order.

Arguments

Example

FortranCompile kwker.f90 with your program; link -lkwker_c.
ix = kwker_argsort(a)

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.

kwker_isa Page

FortranCompile kwker.f90 with your program; link -lkwker_c.
function kwker_isa() result(s)
  character(:), allocatable :: s
end function

The engine in use, as the C library's kwker_isa() names it: "avx512", "avx2", "sse42", "neon" or "portable"

Remarks: The engine changes only the speed, never a result (rule 11).

kwker_version Page

FortranCompile kwker.f90 with your program; link -lkwker_c.
function kwker_version() result(s)
  character(:), allocatable :: s
end function

The library version