max value calc fix #153

Merged
muellerr merged 3 commits from max-value-fix-v2 into develop 2023-06-20 18:20:01 +02:00
Showing only changes of commit c7037d417a - Show all commits

View File

@ -53,8 +53,9 @@ class VectorOperations {
mulScalar(vector, 1 / norm(vector, size), normalizedVector, size); mulScalar(vector, 1 / norm(vector, size), normalizedVector, size);
} }
static T maxAbsValue(const T *vector, uint8_t size, uint8_t *index = 0) { static T maxAbsValue(const T *vector, uint8_t size, uint8_t *index = nullptr) {
T max = vector[size - 1]; T max = vector[size - 1];
uint8_t foundIndex = size - 1;
for (; size > 0; size--) { for (; size > 0; size--) {
T abs = vector[size - 1]; T abs = vector[size - 1];
@ -64,24 +65,35 @@ class VectorOperations {
if (abs > max) { if (abs > max) {
max = abs; max = abs;
if (index != 0) { if (index != 0) {
*index = size - 1; foundIndex = size - 1;
} }
} }
} }
if (index != nullptr) {
*index = foundIndex;
}
return max; return max;
} }
static T maxValue(const T *vector, uint8_t size, uint8_t *index = 0) { static T maxValue(const T *vector, uint8_t size, uint8_t *index = nullptr) {
T max = vector[size - 1]; T max = vector[size - 1];
uint8_t foundIndex = size - 1;
for (; size > 0; size--) { for (; size > 0; size--) {
if (vector[size - 1] > max) { if (vector[size - 1] > max) {
max = vector[size - 1]; max = vector[size - 1];
if (index != 0) { if (index != 0) {
*index = size - 1; foundIndex = size - 1;
} }
} }
} }
if (index != nullptr) {
*index = foundIndex;
}
return max; return max;
} }