Merge pull request 'max value calc fix' (#153) from max-value-fix-v2 into develop

Reviewed-on: #153
This commit is contained in:
Robin Müller 2023-06-20 18:20:00 +02:00
commit 268c2e87c9

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 = -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 = -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;
} }