9#include <memory_resource>
10#include <nk/value/value.hpp>
21inline int rowLexCmp(
const double *p, std::size_t cols, std::size_t rows,
22 std::size_t a, std::size_t b)
24 for (std::size_t c = 0; c < cols; ++c) {
25 const double av = p[c * rows + a];
26 const double bv = p[c * rows + b];
27 const bool aNan = std::isnan(av);
28 const bool bNan = std::isnan(bv);
29 if (aNan && bNan)
continue;
32 if (av < bv)
return -1;
33 if (av > bv)
return 1;
44inline int rowLexCmpByCols(
const double *p, std::size_t totalCols,
45 std::size_t rows, std::size_t a, std::size_t b,
46 const int *cols1based, std::size_t nCols)
48 for (std::size_t k = 0; k < nCols; ++k) {
49 const int rawCol = cols1based[k];
50 const bool desc = rawCol < 0;
51 const std::size_t cIdx =
static_cast<std::size_t
>(desc ? -rawCol : rawCol) - 1;
53 const double av = p[cIdx * rows + a];
54 const double bv = p[cIdx * rows + b];
55 const bool aNan = std::isnan(av);
56 const bool bNan = std::isnan(bv);
57 if (aNan && bNan)
continue;
59 if (aNan)
return desc ? -1 : 1;
60 if (bNan)
return desc ? 1 : -1;
61 if (av < bv)
return desc ? 1 : -1;
62 if (av > bv)
return desc ? -1 : 1;
71inline Value collectRowsByIndex(std::pmr::memory_resource *mr,
const Value &x,
72 const std::size_t *origRows, std::size_t nRows)
74 const std::size_t rows = x.dims().rows();
75 const std::size_t cols = x.dims().cols();
76 auto r = Value::matrix(nRows, cols, ValueType::DOUBLE, mr);
77 const double *src = x.doubleData();
78 double *
dst = r.doubleDataMut();
79 for (std::size_t newRow = 0; newRow < nRows; ++newRow) {
80 const std::size_t srcRow = origRows[newRow];
81 for (std::size_t c = 0; c < cols; ++c)
82 dst[c * nRows + newRow] = src[c * rows + srcRow];
Value dst(const Value &x, std::pmr::memory_resource *mr=nullptr)
Type-II Discrete Sine Transform.