[PATCH 15/24] avoid div by 0

This commit is contained in:
yafeng 2020-02-27 23:38:08 +08:00 committed by xiaying
parent f29bf3bd53
commit 5915d0ce45
1 changed files with 1 additions and 1 deletions

View File

@ -17,7 +17,6 @@ ErrorCode CPULinSpace::onExecute(const std::vector<Tensor*>& inputs, const std::
const float stop = inputs[1]->host<float>()[0]; const float stop = inputs[1]->host<float>()[0];
const int num = inputs[2]->host<int32_t>()[0]; const int num = inputs[2]->host<int32_t>()[0];
MNN_ASSERT(num > 0); MNN_ASSERT(num > 0);
const float step = (stop - start) / (num - 1);
float* outputData = outputs[0]->host<float>(); float* outputData = outputs[0]->host<float>();
@ -35,6 +34,7 @@ ErrorCode CPULinSpace::onExecute(const std::vector<Tensor*>& inputs, const std::
// make sure that start with the first and end with the last. // make sure that start with the first and end with the last.
outputData[0] = start; outputData[0] = start;
outputData[num - 1] = stop; outputData[num - 1] = stop;
const float step = (stop - start) / (num - 1);
for (int i = 1; i < num - 1; ++i) { for (int i = 1; i < num - 1; ++i) {
outputData[i] = start + i * step; outputData[i] = start + i * step;
} }