12#ifndef _FLAMES_SORT_HPP_
13#define _FLAMES_SORT_HPP_
15#ifndef _FLAMES_CORE_HPP_
23 constexpr size_t size =
V::size();
26 for (
int width = 1; width < size; width *= 2) {
31 if (i2 >= size) i2 = size;
32 if (i3 >= size) i3 = size;
34 for (
int i = 0; i < size; ++i) {
38 if (f2 == i3 || (f1 < i2 && t1 <= t2)) {
46 if (f1 == i2 && f2 == i3) {
50 if (i2 >= size) i2 = size;
51 if (i3 >= size) i3 = size;
56 for (
int i = 0; i < size; ++i) {
63template <
typename V1,
typename V2>
65 constexpr size_t size = V1::size();
66 static_assert(size == V2::size(),
"Sort in and out vectors/matrices should be of same size.");
67 typename V1::value_type temp[size];
69 for (
int width = 1; width < size; width *= 2) {
74 if (i2 >= size) i2 = size;
75 if (i3 >= size) i3 = size;
77 for (
int i = 0; i < size; ++i) {
79 typename V1::value_type t1 = in[f1];
81 typename V1::value_type t2 = (f2 == i3) ?
static_cast<typename V1::value_type
>(0) : in[f2];
82 if (f2 == i3 || (f1 < i2 && t1 <= t2)) {
90 if (f1 == i2 && f2 == i3) {
94 if (i2 >= size) i2 = size;
95 if (i3 >= size) i3 = size;
107template <
typename V1,
typename V2>
108static inline void sort(
const V1& in, V2& out) {
112template <
typename T,
typename I>
113static inline void argmax_4_2(T in1, T in2, T in3, T in4, I i_in1, I i_in2, I i_in3, I i_in4, T& out1, T& out2,
114 I& i_out1, I& i_out2,
bool sorted =
false) {
117 assert(in1 >= in2 && in3 >= in4 &&
"Should be sorted in flames::argmax_4_2 with sorted=true.");
123 }
else if (in3 < in2) {
128 }
else if (in1 < in3) {
140 T _in1, _in2, _in3, _in4;
141 I _i_in1, _i_in2, _i_in3, _i_in4;
171 }
else if (_in3 < _in2) {
176 }
else if (_in1 < _in3) {
Matrix.
Definition: core.hpp:565
static constexpr size_t size() noexcept
Get the matrix size of storage.
Definition: core.hpp:832
T value_type
Definition: core.hpp:593
Core Utilities for FLAMES.
#define FLAMES_PRAGMA(x)
Definition: core.hpp:50
#define FLAMES_MAT_COPY_UNROLL_FACTOR
Definition: core.hpp:85
Namespace for the FLAMES library.
Definition: core.hpp:166
static void mergeSort(V &vec)
Definition: sort.hpp:22
static void sort(V &vec)
Definition: sort.hpp:103
static void argmax_4_2(T in1, T in2, T in3, T in4, I i_in1, I i_in2, I i_in3, I i_in4, T &out1, T &out2, I &i_out1, I &i_out2, bool sorted=false)
Definition: sort.hpp:113