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
1 changed files with 18 additions and 6 deletions

View File

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