Browse Source

!11209 [MS_LITE] add floatToint16

From: @YeFeng_24
Reviewed-by: @hangangqiang,@zhang_xue_tong
Signed-off-by: @hangangqiang
tags/v1.2.0-rc1
mindspore-ci-bot Gitee 4 years ago
parent
commit
76b4adec24
2 changed files with 8 additions and 0 deletions
  1. +5
    -0
      mindspore/lite/nnacl/base/cast_base.h
  2. +3
    -0
      mindspore/lite/src/runtime/kernel/arm/fp32/cast_fp32.cc

+ 5
- 0
mindspore/lite/nnacl/base/cast_base.h View File

@@ -71,6 +71,11 @@ inline void Int32ToInt64(const int32_t *input, int64_t *output, int number) {
} }
} }


inline void Float32ToInt16(const float *input, int16_t *output, int number) {
for (int i = 0; i < number; ++i) {
output[i] = (int16_t)input[i];
}
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif


+ 3
- 0
mindspore/lite/src/runtime/kernel/arm/fp32/cast_fp32.cc View File

@@ -85,6 +85,9 @@ int CastCPUKernel::DoCast(int thread_id) {
} else if (input_data_type == kNumberTypeInt32 && output_data_type == kNumberTypeInt64) { } else if (input_data_type == kNumberTypeInt32 && output_data_type == kNumberTypeInt64) {
Int32ToInt64(reinterpret_cast<int32_t *>(input->data_c()) + offset, Int32ToInt64(reinterpret_cast<int32_t *>(input->data_c()) + offset,
reinterpret_cast<int64_t *>(output_data) + offset, data_num); reinterpret_cast<int64_t *>(output_data) + offset, data_num);
} else if (input_data_type == kNumberTypeFloat32 && output_data_type == kNumberTypeInt16) {
Float32ToInt16(reinterpret_cast<float *>(input->data_c()) + offset,
reinterpret_cast<int16_t *>(output_data) + offset, data_num);
} else { } else {
MS_LOG(ERROR) << "Unsupported datatype from " << input_data_type << " to " << output_data_type; MS_LOG(ERROR) << "Unsupported datatype from " << input_data_type << " to " << output_data_type;
return RET_ERROR; return RET_ERROR;


Loading…
Cancel
Save