!11209 [MS_LITE] add floatToint16

From: @YeFeng_24
Reviewed-by: @hangangqiang,@zhang_xue_tong
Signed-off-by: @hangangqiang
pull/11209/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit 76b4adec24

@ -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
}
#endif

@ -85,6 +85,9 @@ int CastCPUKernel::DoCast(int thread_id) {
} else if (input_data_type == kNumberTypeInt32 && output_data_type == kNumberTypeInt64) {
Int32ToInt64(reinterpret_cast<int32_t *>(input->data_c()) + offset,
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 {
MS_LOG(ERROR) << "Unsupported datatype from " << input_data_type << " to " << output_data_type;
return RET_ERROR;

Loading…
Cancel
Save