| 50 | } |
| 51 | } |
| 52 | void TensorStatistic::updateRange() { |
| 53 | if (mUpdatedRangeFlags) { |
| 54 | return; |
| 55 | } |
| 56 | mUpdatedRangeFlags = true; |
| 57 | auto tmpTensor = mOriginTensor; |
| 58 | bool res = mOriginTensor->copyToHostTensor(mHostTensor.get()); |
| 59 | if (res) { |
| 60 | tmpTensor = mHostTensor.get(); |
| 61 | } |
| 62 | int size = tmpTensor->elementSize(); |
| 63 | float* dataPtr = tmpTensor->host<float>(); |
| 64 | auto minValue = mRange.first; |
| 65 | auto maxValue = mRange.second; |
| 66 | for (int i = 0; i < size; ++i) { |
| 67 | minValue = std::min(minValue, dataPtr[i]); |
| 68 | maxValue = std::max(maxValue, dataPtr[i]); |
| 69 | } |
| 70 | mRange.first = minValue; |
| 71 | mRange.second = maxValue; |
| 72 | // if (mRange.first > 0.0f) { |
| 73 | // mRange.first = 0.0f; |
| 74 | // } |
| 75 | // if (mRange.second < 0.0f) { |
| 76 | // mRange.second = 0.0f; |
| 77 | // } |
| 78 | mVisited = true; |
| 79 | } |
| 80 | |
| 81 | void TensorStatistic::resetDistribution() { |
| 82 | auto maxValue = std::max(fabsf(mRange.second), fabsf(mRange.first)); |
no test coverage detected