54 set_config(std::move(config));
78 static std::vector<size_t> gpu_order(
const std::vector<double>& scores);
86 const auto n = out.
data.regions.size();
88 if (n == 0 || cfg.keys.empty()) {
92 std::vector<double> scores(n);
93 for (
size_t i = 0; i < n; ++i) {
101 std::vector<size_t> order(n);
102 if (cfg.gpu_sort_threshold > 0 && n >= cfg.gpu_sort_threshold) {
105 std::iota(order.begin(), order.end(),
size_t { 0 });
106 std::ranges::stable_sort(order, [&](
size_t a,
size_t b) {
return scores[a] < scores[b]; });
109 std::vector<Kakshya::Region> reordered;
110 reordered.reserve(n);
111 for (
size_t idx : order) {
112 reordered.push_back(out.
data.regions[idx]);
114 out.
data.regions = std::move(reordered);
115 out.
data.current_region_index = 0;
116 out.
data.active_indices.clear();
123 config.direction = SortingDirection::ASCENDING;
125 return sorter.
order(scores);
Exact GPU sorting of numeric channels by a bitonic network over order keys.
#define MF_DESCRIBE(...)
Requests a generated member description for a struct at namespace scope.
Modern, digital-first sorting framework for Maya Flux.
std::vector< size_t > order(std::span< const double > values)
The indices that order one channel, computed on the GPU in the configured direction.
Sorts each numeric channel on the GPU, exactly, without fp64.
const Config & config() const
ConfigRefs stored_configs(Supports< Configs... >) const
RegionKeySorter(RegionKeySorterConfig config={})
Construct a region key sorter from its settings.
static std::vector< size_t > gpu_order(const std::vector< double > &scores)
Ascending order of the scores, computed exactly on the GPU.
Datum< Kakshya::RegionGroup > sort_implementation(const Datum< Kakshya::RegionGroup > &input) override
ConfigRefs configs() const override
The stored settings, or defaults when none were set.
Supports< RegionKeySorterConfig > supports
SortingType get_sorting_type() const override
Gets the sorting type category for this sorter.
Template-flexible sorter base with instance-defined I/O types.
@ ComputeMatrix
Compute operations (Yantra - algorithms, matrices, DSP).
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
SortingType
Categories of sorting operations for discovery and organization.
@ ALGORITHMIC
Mathematical/computational sorting algorithms.
void validate_sort_keys(const std::vector< SortKey > &keys)
Checks that every sort key has a positive, finite weight.
std::vector< std::reference_wrapper< const OperationConfig > > ConfigRefs
Borrowed views of the configs an operation holds.
std::optional< double > weighted_sort_score(const Element &element, std::span< const SortKey > keys)
Weighted score of one element across the sort keys.
T data
The actual computation data.
Input/Output container for computation pipeline data flow with structure preservation.
std::vector< SortKey > keys
Terms of the weighted sort score.
uint32_t gpu_sort_threshold
Region count at or above which the GPU path is used.
Settings of RegionKeySorter, stored whole in the operation's facets.
Parent of every sorter's config struct.
Settings for standard sorting.
The config structs an operation class accepts, declared as using supports.