+
+ // Convert to fp16.
+ for (int i = 0; i < src_bilinear_samples; ++i) {
+ bilinear_weights_fp16_ptr[i * 2 + 0] = fp64_to_fp16(bilinear_weights_ptr[i * 2 + 0]);
+ bilinear_weights_fp16_ptr[i * 2 + 1] = fp64_to_fp16(bilinear_weights_ptr[i * 2 + 1]);
+ }
+
+ // Normalize so that the sum becomes one. Note that we do it twice;
+ // this sometimes helps a tiny little bit when we have many samples.
+ for (int normalize_pass = 0; normalize_pass < 2; ++normalize_pass) {
+ double sum = 0.0;
+ for (int i = 0; i < src_bilinear_samples; ++i) {
+ sum += fp16_to_fp64(bilinear_weights_fp16_ptr[i * 2 + 0]);
+ }
+ for (int i = 0; i < src_bilinear_samples; ++i) {
+ bilinear_weights_fp16_ptr[i * 2 + 0] = fp64_to_fp16(
+ fp16_to_fp64(bilinear_weights_fp16_ptr[i * 2 + 0]) / sum);
+ }
+ }
+ }