mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 16:40:38 +08:00
Move CompactifyArray to array_utils.
1. Rename it to MapValuesToContiguousRange. 2. Improve implementation to just use a vector. Change-Id: I2a5e73e3a6fb81694c6f452a00d60df16c0149e6
This commit is contained in:
@@ -30,10 +30,11 @@
|
||||
|
||||
#include "ceres/array_utils.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
#include <vector>
|
||||
#include "ceres/fpclassify.h"
|
||||
#include "ceres/stringprintf.h"
|
||||
|
||||
@@ -94,5 +95,19 @@ void AppendArrayToString(const int size, const double* x, string* result) {
|
||||
}
|
||||
}
|
||||
|
||||
void MapValuesToContiguousRange(const int size, int* array) {
|
||||
std::vector<int> unique_values(array, array + size);
|
||||
std::sort(unique_values.begin(), unique_values.end());
|
||||
unique_values.erase(std::unique(unique_values.begin(),
|
||||
unique_values.end()),
|
||||
unique_values.end());
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
array[i] = std::lower_bound(unique_values.begin(),
|
||||
unique_values.end(),
|
||||
array[i]) - unique_values.begin();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace ceres
|
||||
|
||||
Reference in New Issue
Block a user