Fastest code C/C++ to select the median in a set of 27 floating point values

后端 未结 15 1135
梦谈多话
梦谈多话 2020-12-07 09:24

This is the well know select algorithm. see http://en.wikipedia.org/wiki/Selection_algorithm.

I need it to find the median value of a set of 3x3x3 voxel values. Sinc

15条回答
  •  無奈伤痛
    2020-12-07 09:42

    My super fast algorithm for calculation of median of a 1-D data set does the job in three passes and doesn't need to sort (!!!) the data set.

    A very generic description is as follows:

    • Pass 1: Scans the 1-D data set and collects some statistical information of the data set
    • Pass 2: Uses the statistical information of the data set and applies some data mining to create an intermediate ( helper ) array
    • Pass 3: Scans the intermediate ( helper ) array in order to find the median

    The algorithm is designed for finding medians of extremely large 1-D data sets greater then 8GE ( giga elements ) of Single-Precision Floating Point values ( on a desktop system with 32GB of physical memory and 128GB of virtual memory ), or for finding medians of small data sets in a hard real-time environment.

    The algorithm is:

    • faster then the classical algorithm, based on Heap or Merge sorting algorithm, in ~60 - ~75 times
    • implemented in pure C language
    • doesn't use any Intel intrinsics functions
    • doesn't use any inline assembler instructions
    • absolutely portable between C/C++ compilers, like MS, Intel, MinGW, Borland, Turbo and Watcom
    • absolutely portable between platforms

    Best regards, Sergey Kostrov

提交回复
热议问题