Skip to content

Commit

Permalink
[bugfix] fix coverity issues
Browse files Browse the repository at this point in the history
This PR resolves coverity issues in the ShortTensor class.
Replace max_abs() implementation with maxValue() since the maximum absolute value of unsigned int equals to the maximum value.

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

Signed-off-by: Donghyeon Jeong <dhyeon.jeong@samsung.com>
  • Loading branch information
djeong20 committed Aug 29, 2024
1 parent 1377f1c commit b1ea432
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions nntrainer/tensor/short_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ void ShortTensor::copyData(const Tensor &from) {
switch (from.getDataType()) {
case ml::train::TensorDim::DataType::UINT16:
copy(from.getData());
break;
default:
throw std::invalid_argument("Error: Unsupported data type");
break;
Expand Down Expand Up @@ -278,20 +279,7 @@ std::vector<unsigned int> ShortTensor::argmax() const {
return result;
}

float ShortTensor::max_abs() const {
const uint16_t *data = (uint16_t *)getData();
unsigned int idx;

uint16_t max_val = data[0];
for (unsigned int i = 1; i < size(); i += 1) {
uint16_t cur_val = (data[i] >= 0) ? data[i] : -1 * data[i];
if (cur_val > max_val) {
max_val = cur_val;
}
}

return max_val;
}
float ShortTensor::max_abs() const { return maxValue(); }

float ShortTensor::maxValue() const {
const uint16_t *data = (uint16_t *)getData();
Expand Down

0 comments on commit b1ea432

Please sign in to comment.