Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] fix coverity issues #2722

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

@skykongkong8 skykongkong8 Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And just curious, if this tensor is containing 'unsigned' integer, why should it be max_"abs" ? it is already absolute.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I didn't quite understand. do you mean why max_abs() should be used?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I think can't see any difference between maxValue and maxAbsoluteValue for this tensor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right! There's no difference between max_abs() and maxValue() for this tensor class. That's why max_abs() is using maxValue(). The reason why there are max_abs() and maxValue() is to be compatible with the TensorBase and Tensor class. While max_abs() is currently a pure virtual function, it will get a compile error without implementing max_abs() in the ShortTensor class.

const uint16_t *data = (uint16_t *)getData();
Expand Down
Loading