Skip to content

Commit 1fe982e

Browse files
committed
Implement argsort helper function
1 parent a826c09 commit 1fe982e

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

source/pbat/common/ArgSort.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "ArgSort.h"

source/pbat/common/ArgSort.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef PBAT_COMMON_ARG_SORT_H
2+
#define PBAT_COMMON_ARG_SORT_H
3+
4+
#include <algorithm>
5+
#include <concepts>
6+
#include <iterator>
7+
#include <numeric>
8+
#include <vector>
9+
10+
namespace pbat {
11+
namespace common {
12+
13+
template <std::integral TIndex, class FLess>
14+
std::vector<TIndex> ArgSort(auto n, FLess less)
15+
{
16+
std::vector<TIndex> inds(n);
17+
std::iota(inds.begin(), inds.end(), TIndex(0));
18+
std::sort(inds.begin(), inds.end(), less);
19+
return inds;
20+
}
21+
22+
} // namespace common
23+
} // namespace pbat
24+
25+
#endif // PBAT_COMMON_ARG_SORT_H

source/pbat/common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ target_sources(PhysicsBasedAnimationToolkit_PhysicsBasedAnimationToolkit
22
PUBLIC
33
FILE_SET api
44
FILES
5+
"ArgSort.h"
56
"Common.h"
67
"Concepts.h"
78
"ConstexprFor.h"
@@ -13,6 +14,7 @@ target_sources(PhysicsBasedAnimationToolkit_PhysicsBasedAnimationToolkit
1314
)
1415
target_sources(PhysicsBasedAnimationToolkit_PhysicsBasedAnimationToolkit
1516
PRIVATE
17+
"ArgSort.cpp"
1618
"Eigen.cpp"
1719
"Indexing.cpp"
1820
"Queue.cpp"

source/pbat/common/Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef PBAT_COMMON_COMMON_H
22
#define PBAT_COMMON_COMMON_H
33

4+
#include "ArgSort.h"
45
#include "Concepts.h"
56
#include "ConstexprFor.h"
67
#include "Eigen.h"

0 commit comments

Comments
 (0)