InterpolationTestsF16.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #include "InterpolationTestsF16.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #define SNR_THRESHOLD 55
  5. /*
  6. Reference patterns are generated with
  7. a double precision computation.
  8. */
  9. #define REL_ERROR (5.0e-3)
  10. #define ABS_ERROR (5.0e-3)
  11. void InterpolationTestsF16::test_linear_interp_f16()
  12. {
  13. const float16_t *inp = input.ptr();
  14. float16_t *outp = output.ptr();
  15. unsigned long nb;
  16. for(nb = 0; nb < input.nbSamples(); nb++)
  17. {
  18. outp[nb] = arm_linear_interp_f16(&S,inp[nb]);
  19. }
  20. ASSERT_EMPTY_TAIL(output);
  21. ASSERT_SNR(output,ref,(float16_t)SNR_THRESHOLD);
  22. ASSERT_CLOSE_ERROR(output,ref,ABS_ERROR,REL_ERROR);
  23. }
  24. void InterpolationTestsF16::test_bilinear_interp_f16()
  25. {
  26. const float16_t *inp = input.ptr();
  27. float16_t *outp = output.ptr();
  28. float16_t x,y;
  29. unsigned long nb;
  30. for(nb = 0; nb < input.nbSamples(); nb += 2)
  31. {
  32. x = inp[nb];
  33. y = inp[nb+1];
  34. *outp++=arm_bilinear_interp_f16(&SBI,x,y);
  35. }
  36. ASSERT_EMPTY_TAIL(output);
  37. ASSERT_SNR(output,ref,(float16_t)SNR_THRESHOLD);
  38. ASSERT_CLOSE_ERROR(output,ref,ABS_ERROR,REL_ERROR);
  39. }
  40. #if 0
  41. void InterpolationTestsF16::test_spline_square_f16()
  42. {
  43. const float16_t *inpX = inputX.ptr();
  44. const float16_t *inpY = inputY.ptr();
  45. const float16_t *outX = outputX.ptr();
  46. float16_t *outp = output.ptr();
  47. float16_t *buf = buffer.ptr(); // ((2*4-1)*sizeof(float16_t))
  48. float16_t *coef = splineCoefs.ptr(); // ((3*(4-1))*sizeof(float16_t))
  49. arm_spline_instance_f16 S;
  50. arm_spline_init_f16(&S, ARM_SPLINE_PARABOLIC_RUNOUT, inpX, inpY, 4, coef, buf);
  51. arm_spline_f16(&S, outX, outp, 20);
  52. ASSERT_EMPTY_TAIL(buffer);
  53. ASSERT_EMPTY_TAIL(splineCoefs);
  54. ASSERT_EMPTY_TAIL(output);
  55. ASSERT_SNR(output,ref,(float16_t)SNR_THRESHOLD);
  56. }
  57. void InterpolationTestsF16::test_spline_sine_f16()
  58. {
  59. const float16_t *inpX = inputX.ptr();
  60. const float16_t *inpY = inputY.ptr();
  61. const float16_t *outX = outputX.ptr();
  62. float16_t *outp = output.ptr();
  63. float16_t *buf = buffer.ptr(); // ((2*9-1)*sizeof(float16_t))
  64. float16_t *coef = splineCoefs.ptr(); // ((3*(9-1))*sizeof(float16_t))
  65. arm_spline_instance_f16 S;
  66. arm_spline_init_f16(&S, ARM_SPLINE_NATURAL, inpX, inpY, 9, coef, buf);
  67. arm_spline_f16(&S, outX, outp, 33);
  68. ASSERT_EMPTY_TAIL(buffer);
  69. ASSERT_EMPTY_TAIL(splineCoefs);
  70. ASSERT_EMPTY_TAIL(output);
  71. ASSERT_SNR(output,ref,(float16_t)SNR_THRESHOLD);
  72. }
  73. void InterpolationTestsF16::test_spline_ramp_f16()
  74. {
  75. const float16_t *inpX = inputX.ptr();
  76. const float16_t *inpY = inputY.ptr();
  77. const float16_t *outX = outputX.ptr();
  78. float16_t *outp = output.ptr();
  79. float16_t *buf = buffer.ptr(); // ((2*3-1)*sizeof(float16_t))
  80. float16_t *coef = splineCoefs.ptr(); // ((3*(3-1))*sizeof(float16_t))
  81. arm_spline_instance_f16 S;
  82. arm_spline_init_f16(&S, ARM_SPLINE_PARABOLIC_RUNOUT, inpX, inpY, 3, coef, buf);
  83. arm_spline_f16(&S, outX, outp, 30);
  84. ASSERT_EMPTY_TAIL(buffer);
  85. ASSERT_EMPTY_TAIL(splineCoefs);
  86. ASSERT_EMPTY_TAIL(output);
  87. ASSERT_SNR(output,ref,(float16_t)SNR_THRESHOLD);
  88. }
  89. #endif
  90. void InterpolationTestsF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  91. {
  92. const int16_t *pConfig;
  93. Testing::nbSamples_t nb=MAX_NB_SAMPLES;
  94. (void)params;
  95. switch(id)
  96. {
  97. case InterpolationTestsF16::TEST_LINEAR_INTERP_F16_1:
  98. input.reload(InterpolationTestsF16::INPUT_F16_ID,mgr,nb);
  99. y.reload(InterpolationTestsF16::YVAL_F16_ID,mgr,nb);
  100. ref.reload(InterpolationTestsF16::REF_LINEAR_F16_ID,mgr,nb);
  101. S.nValues=y.nbSamples(); /**< nValues */
  102. /* Those values must be coherent with the ones in the
  103. Python script generating the patterns */
  104. S.x1=0.0; /**< x1 */
  105. S.xSpacing=1.0; /**< xSpacing */
  106. S.pYData=y.ptr(); /**< pointer to the table of Y values */
  107. break;
  108. case InterpolationTestsF16::TEST_BILINEAR_INTERP_F16_2:
  109. input.reload(InterpolationTestsF16::INPUTBI_F16_ID,mgr,nb);
  110. config.reload(InterpolationTestsF16::CONFIGBI_S16_ID,mgr,nb);
  111. y.reload(InterpolationTestsF16::YVALBI_F16_ID,mgr,nb);
  112. ref.reload(InterpolationTestsF16::REF_BILINEAR_F16_ID,mgr,nb);
  113. pConfig = config.ptr();
  114. SBI.numRows = pConfig[1];
  115. SBI.numCols = pConfig[0];
  116. SBI.pData = y.ptr();
  117. break;
  118. #if 0
  119. case TEST_SPLINE_SQUARE_F16_3:
  120. inputX.reload(InterpolationTestsF16::INPUT_SPLINE_SQU_X_F16_ID,mgr,4);
  121. inputY.reload(InterpolationTestsF16::INPUT_SPLINE_SQU_Y_F16_ID,mgr,4);
  122. outputX.reload(InterpolationTestsF16::OUTPUT_SPLINE_SQU_X_F16_ID,mgr,20);
  123. ref.reload(InterpolationTestsF16::REF_SPLINE_SQU_F16_ID,mgr,20);
  124. splineCoefs.create(3*(4-1),InterpolationTestsF16::COEFS_SPLINE_F16_ID,mgr);
  125. buffer.create(2*4-1,InterpolationTestsF16::TEMP_SPLINE_F16_ID,mgr);
  126. output.create(20,InterpolationTestsF16::OUT_SAMPLES_F16_ID,mgr);
  127. break;
  128. case TEST_SPLINE_SINE_F16_4:
  129. inputX.reload(InterpolationTestsF16::INPUT_SPLINE_SIN_X_F16_ID,mgr,9);
  130. inputY.reload(InterpolationTestsF16::INPUT_SPLINE_SIN_Y_F16_ID,mgr,9);
  131. outputX.reload(InterpolationTestsF16::OUTPUT_SPLINE_SIN_X_F16_ID,mgr,33);
  132. ref.reload(InterpolationTestsF16::REF_SPLINE_SIN_F16_ID,mgr,33);
  133. splineCoefs.create(3*(9-1),InterpolationTestsF16::COEFS_SPLINE_F16_ID,mgr);
  134. buffer.create(2*9-1,InterpolationTestsF16::TEMP_SPLINE_F16_ID,mgr);
  135. output.create(33,InterpolationTestsF16::OUT_SAMPLES_F16_ID,mgr);
  136. break;
  137. case TEST_SPLINE_RAMP_F16_5:
  138. inputX.reload(InterpolationTestsF16::INPUT_SPLINE_RAM_X_F16_ID,mgr,3);
  139. inputY.reload(InterpolationTestsF16::INPUT_SPLINE_RAM_Y_F16_ID,mgr,3);
  140. outputX.reload(InterpolationTestsF16::OUTPUT_SPLINE_RAM_X_F16_ID,mgr,30);
  141. ref.reload(InterpolationTestsF16::REF_SPLINE_RAM_F16_ID,mgr,30);
  142. splineCoefs.create(3*(3-1),InterpolationTestsF16::COEFS_SPLINE_F16_ID,mgr);
  143. buffer.create(2*3-1,InterpolationTestsF16::TEMP_SPLINE_F16_ID,mgr);
  144. output.create(30,InterpolationTestsF16::OUT_SAMPLES_F16_ID,mgr);
  145. break;
  146. #endif
  147. }
  148. output.create(ref.nbSamples(),InterpolationTestsF16::OUT_SAMPLES_F16_ID,mgr);
  149. }
  150. void InterpolationTestsF16::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  151. {
  152. (void)id;
  153. output.dump(mgr);
  154. }