Skip to content

Commit

Permalink
[ util ] Use proper STL in max element comparison
Browse files Browse the repository at this point in the history
- For cleaner code use std::max_element instead of for-loop

**Self evaluation:**
1. Build test:     [X]Passed [ ]Failed [ ]Skipped
2. Run test:     [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: skykongkong8 <[email protected]>
  • Loading branch information
skykongkong8 committed Feb 26, 2024
1 parent c87da5a commit 94d3328
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
3 changes: 1 addition & 2 deletions nntrainer/tensor/tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ class SrcSharedTensor {
SrcSharedTensor() : src(nullptr), off(0) {}

SrcSharedTensor(const Tensor *tensor, size_t offset) :
src(tensor),
off(offset) {}
src(tensor), off(offset) {}

/**
* @brief Get the allocated src tensor
Expand Down
18 changes: 4 additions & 14 deletions nntrainer/utils/util_simd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,8 @@ float max(const unsigned int N, float *X) {
#ifdef USE_NEON
return nntrainer::neon::max(N, X);
#else
float ret = X[0];
unsigned int i = 1;
while (i < N) {
ret = std::fmax(ret, X[i]);
++i;
}
return ret;
std::vector<float> v(X, X+N);
return *std::max_element(v.begin(), v.end());
#endif
}

Expand Down Expand Up @@ -106,13 +101,8 @@ _FP16 max(const unsigned int N, _FP16 *X) {
#ifdef USE_NEON
return nntrainer::neon::max(N, X);
#else
_FP16 ret = X[0];
unsigned int i = 1;
while (i < N) {
ret = (ret > X[i]) ? ret : X[i];
++i;
}
return ret;
std::vector<_FP16> v(X, X+N);
return *std::max_element(v.begin(), v.end());
#endif
}

Expand Down

0 comments on commit 94d3328

Please sign in to comment.