123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- //
- // Academic License - for use in teaching, academic research, and meeting
- // course requirements at degree granting institutions only. Not for
- // government, commercial, or other organizational use.
- // File: sortIdx.cpp
- //
- // MATLAB Coder version : 5.3
- // C/C++ source code generated on : 27-Mar-2023 15:34:32
- //
- // Include Files
- #include "fun10_sortIdx.h"
- #include "rt_nonfinite.h"
- #include "coder_array.h"
- // Function Declarations
- namespace coder {
- namespace internal {
- static void merge(::coder::array<int, 2U> &idx, ::coder::array<double, 2U> &x,
- int offset, int np, int nq, ::coder::array<int, 1U> &iwork,
- ::coder::array<double, 1U> &xwork);
- }
- } // namespace coder
- // Function Definitions
- //
- // Arguments : ::coder::array<int, 2U> &idx
- // ::coder::array<double, 2U> &x
- // int offset
- // int np
- // int nq
- // ::coder::array<int, 1U> &iwork
- // ::coder::array<double, 1U> &xwork
- // Return Type : void
- //
- namespace coder {
- namespace internal {
- static void merge(::coder::array<int, 2U> &idx, ::coder::array<double, 2U> &x,
- int offset, int np, int nq, ::coder::array<int, 1U> &iwork,
- ::coder::array<double, 1U> &xwork)
- {
- if (nq != 0) {
- int iout;
- int j;
- int n_tmp;
- int p;
- int q;
- n_tmp = np + nq;
- for (j = 0; j < n_tmp; j++) {
- iout = offset + j;
- iwork[j] = idx[iout];
- xwork[j] = x[iout];
- }
- p = 0;
- q = np;
- iout = offset - 1;
- int exitg1;
- do {
- exitg1 = 0;
- iout++;
- if (xwork[p] <= xwork[q]) {
- idx[iout] = iwork[p];
- x[iout] = xwork[p];
- if (p + 1 < np) {
- p++;
- } else {
- exitg1 = 1;
- }
- } else {
- idx[iout] = iwork[q];
- x[iout] = xwork[q];
- if (q + 1 < n_tmp) {
- q++;
- } else {
- q = iout - p;
- for (j = p + 1; j <= np; j++) {
- iout = q + j;
- idx[iout] = iwork[j - 1];
- x[iout] = xwork[j - 1];
- }
- exitg1 = 1;
- }
- }
- } while (exitg1 == 0);
- }
- }
- //
- // Arguments : int idx[16]
- // double x[16]
- // int offset
- // int np
- // int nq
- // int iwork[16]
- // double xwork[16]
- // Return Type : void
- //
- void merge(int idx[16], double x[16], int offset, int np, int nq, int iwork[16],
- double xwork[16])
- {
- if (nq != 0) {
- int iout;
- int j;
- int n_tmp;
- int p;
- int q;
- n_tmp = np + nq;
- for (j = 0; j < n_tmp; j++) {
- iout = offset + j;
- iwork[j] = idx[iout];
- xwork[j] = x[iout];
- }
- p = 0;
- q = np;
- iout = offset - 1;
- int exitg1;
- do {
- exitg1 = 0;
- iout++;
- if (xwork[p] <= xwork[q]) {
- idx[iout] = iwork[p];
- x[iout] = xwork[p];
- if (p + 1 < np) {
- p++;
- } else {
- exitg1 = 1;
- }
- } else {
- idx[iout] = iwork[q];
- x[iout] = xwork[q];
- if (q + 1 < n_tmp) {
- q++;
- } else {
- q = iout - p;
- for (j = p + 1; j <= np; j++) {
- iout = q + j;
- idx[iout] = iwork[j - 1];
- x[iout] = xwork[j - 1];
- }
- exitg1 = 1;
- }
- }
- } while (exitg1 == 0);
- }
- }
- //
- // Arguments : ::coder::array<int, 2U> &idx
- // ::coder::array<double, 2U> &x
- // int offset
- // int n
- // int preSortLevel
- // ::coder::array<int, 1U> &iwork
- // ::coder::array<double, 1U> &xwork
- // Return Type : void
- //
- void merge_block(::coder::array<int, 2U> &idx, ::coder::array<double, 2U> &x,
- int offset, int n, int preSortLevel,
- ::coder::array<int, 1U> &iwork,
- ::coder::array<double, 1U> &xwork)
- {
- int bLen;
- int nPairs;
- nPairs = n >> preSortLevel;
- bLen = 1 << preSortLevel;
- while (nPairs > 1) {
- int nTail;
- int tailOffset;
- if ((nPairs & 1) != 0) {
- nPairs--;
- tailOffset = bLen * nPairs;
- nTail = n - tailOffset;
- if (nTail > bLen) {
- merge(idx, x, offset + tailOffset, bLen, nTail - bLen, iwork, xwork);
- }
- }
- tailOffset = bLen << 1;
- nPairs >>= 1;
- for (nTail = 0; nTail < nPairs; nTail++) {
- merge(idx, x, offset + nTail * tailOffset, bLen, bLen, iwork, xwork);
- }
- bLen = tailOffset;
- }
- if (n > bLen) {
- merge(idx, x, offset, bLen, n - bLen, iwork, xwork);
- }
- }
- } // namespace internal
- } // namespace coder
- //
- // File trailer for sortIdx.cpp
- //
- // [EOF]
- //
|