SupportTestsF32.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. #include "SupportTestsF32.h"
  2. #include "Error.h"
  3. #include "arm_math.h"
  4. #include "Test.h"
  5. #include <cstdio>
  6. #define SNR_THRESHOLD 120
  7. #define REL_ERROR (1.0e-5)
  8. #define ABS_Q15_ERROR ((q15_t)10)
  9. #define ABS_Q31_ERROR ((q31_t)80)
  10. #define ABS_Q7_ERROR ((q7_t)10)
  11. void SupportTestsF32::test_weighted_sum_f32()
  12. {
  13. const float32_t *inp = input.ptr();
  14. const float32_t *coefsp = coefs.ptr();
  15. float32_t *refp = ref.ptr();
  16. float32_t *outp = output.ptr();
  17. *outp=arm_weighted_sum_f32(inp, coefsp,this->nbSamples);
  18. ASSERT_REL_ERROR(*outp,refp[this->offset],REL_ERROR);
  19. ASSERT_EMPTY_TAIL(output);
  20. }
  21. void SupportTestsF32::test_copy_f32()
  22. {
  23. const float32_t *inp = input.ptr();
  24. float32_t *outp = output.ptr();
  25. arm_copy_f32(inp, outp,this->nbSamples);
  26. ASSERT_EQ(input,output);
  27. ASSERT_EMPTY_TAIL(output);
  28. }
  29. void SupportTestsF32::test_fill_f32()
  30. {
  31. float32_t *outp = output.ptr();
  32. float32_t val = 1.1;
  33. int i;
  34. arm_fill_f32(val, outp,this->nbSamples);
  35. for(i=0 ; i < this->nbSamples; i++)
  36. {
  37. ASSERT_EQ(val,outp[i]);
  38. }
  39. ASSERT_EMPTY_TAIL(output);
  40. }
  41. void SupportTestsF32::test_float_to_q15()
  42. {
  43. const float32_t *inp = input.ptr();
  44. q15_t *refp = refQ15.ptr();
  45. q15_t *outp = outputQ15.ptr();
  46. arm_float_to_q15(inp, outp,this->nbSamples);
  47. ASSERT_NEAR_EQ(refQ15,outputQ15,ABS_Q15_ERROR);
  48. ASSERT_EMPTY_TAIL(outputQ15);
  49. }
  50. void SupportTestsF32::test_float_to_q31()
  51. {
  52. const float32_t *inp = input.ptr();
  53. q31_t *refp = refQ31.ptr();
  54. q31_t *outp = outputQ31.ptr();
  55. arm_float_to_q31(inp, outp,this->nbSamples);
  56. ASSERT_NEAR_EQ(refQ31,outputQ31,ABS_Q31_ERROR);
  57. ASSERT_EMPTY_TAIL(outputQ31);
  58. }
  59. void SupportTestsF32::test_float_to_q7()
  60. {
  61. const float32_t *inp = input.ptr();
  62. q7_t *refp = refQ7.ptr();
  63. q7_t *outp = outputQ7.ptr();
  64. arm_float_to_q7(inp, outp,this->nbSamples);
  65. ASSERT_NEAR_EQ(refQ7,outputQ7,ABS_Q7_ERROR);
  66. ASSERT_EMPTY_TAIL(outputQ7);
  67. }
  68. void SupportTestsF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  69. {
  70. switch(id)
  71. {
  72. case TEST_WEIGHTED_SUM_F32_1:
  73. this->nbSamples = 3;
  74. input.reload(SupportTestsF32::INPUTS_F32_ID,mgr,this->nbSamples);
  75. coefs.reload(SupportTestsF32::WEIGHTS_F32_ID,mgr,this->nbSamples);
  76. ref.reload(SupportTestsF32::REF_F32_ID,mgr);
  77. output.create(1,SupportTestsF32::OUT_F32_ID,mgr);
  78. this->offset=0;
  79. break;
  80. case TEST_WEIGHTED_SUM_F32_2:
  81. this->nbSamples = 8;
  82. input.reload(SupportTestsF32::INPUTS_F32_ID,mgr,this->nbSamples);
  83. coefs.reload(SupportTestsF32::WEIGHTS_F32_ID,mgr,this->nbSamples);
  84. ref.reload(SupportTestsF32::REF_F32_ID,mgr);
  85. output.create(1,SupportTestsF32::OUT_F32_ID,mgr);
  86. this->offset=1;
  87. break;
  88. case TEST_WEIGHTED_SUM_F32_3:
  89. this->nbSamples = 9;
  90. input.reload(SupportTestsF32::INPUTS_F32_ID,mgr,this->nbSamples);
  91. coefs.reload(SupportTestsF32::WEIGHTS_F32_ID,mgr,this->nbSamples);
  92. ref.reload(SupportTestsF32::REF_F32_ID,mgr);
  93. output.create(1,SupportTestsF32::OUT_F32_ID,mgr);
  94. this->offset=2;
  95. break;
  96. case TEST_COPY_F32_4:
  97. this->nbSamples = 3;
  98. input.reload(SupportTestsF32::SAMPLES_F32_ID,mgr,this->nbSamples);
  99. output.create(input.nbSamples(),SupportTestsF32::OUT_F32_ID,mgr);
  100. break;
  101. case TEST_COPY_F32_5:
  102. this->nbSamples = 8;
  103. input.reload(SupportTestsF32::SAMPLES_F32_ID,mgr,this->nbSamples);
  104. output.create(input.nbSamples(),SupportTestsF32::OUT_F32_ID,mgr);
  105. break;
  106. case TEST_COPY_F32_6:
  107. this->nbSamples = 9;
  108. input.reload(SupportTestsF32::SAMPLES_F32_ID,mgr,this->nbSamples);
  109. output.create(input.nbSamples(),SupportTestsF32::OUT_F32_ID,mgr);
  110. break;
  111. case TEST_FILL_F32_7:
  112. this->nbSamples = 3;
  113. output.create(this->nbSamples,SupportTestsF32::OUT_F32_ID,mgr);
  114. break;
  115. case TEST_FILL_F32_8:
  116. this->nbSamples = 8;
  117. output.create(this->nbSamples,SupportTestsF32::OUT_F32_ID,mgr);
  118. break;
  119. case TEST_FILL_F32_9:
  120. this->nbSamples = 9;
  121. output.create(this->nbSamples,SupportTestsF32::OUT_F32_ID,mgr);
  122. break;
  123. case TEST_FLOAT_TO_Q15_10:
  124. this->nbSamples = 7;
  125. input.reload(SupportTestsF32::SAMPLES_F32_ID,mgr,this->nbSamples);
  126. refQ15.reload(SupportTestsF32::SAMPLES_Q15_ID,mgr,this->nbSamples);
  127. outputQ15.create(this->nbSamples,SupportTestsF32::OUT_F32_ID,mgr);
  128. break;
  129. case TEST_FLOAT_TO_Q15_11:
  130. this->nbSamples = 16;
  131. input.reload(SupportTestsF32::SAMPLES_F32_ID,mgr,this->nbSamples);
  132. refQ15.reload(SupportTestsF32::SAMPLES_Q15_ID,mgr,this->nbSamples);
  133. outputQ15.create(this->nbSamples,SupportTestsF32::OUT_F32_ID,mgr);
  134. break;
  135. case TEST_FLOAT_TO_Q15_12:
  136. this->nbSamples = 17;
  137. input.reload(SupportTestsF32::SAMPLES_F32_ID,mgr,this->nbSamples);
  138. refQ15.reload(SupportTestsF32::SAMPLES_Q15_ID,mgr,this->nbSamples);
  139. outputQ15.create(this->nbSamples,SupportTestsF32::OUT_F32_ID,mgr);
  140. break;
  141. case TEST_FLOAT_TO_Q31_13:
  142. this->nbSamples = 3;
  143. input.reload(SupportTestsF32::SAMPLES_F32_ID,mgr,this->nbSamples);
  144. refQ31.reload(SupportTestsF32::SAMPLES_Q31_ID,mgr,this->nbSamples);
  145. outputQ31.create(this->nbSamples,SupportTestsF32::OUT_F32_ID,mgr);
  146. break;
  147. case TEST_FLOAT_TO_Q31_14:
  148. this->nbSamples = 8;
  149. input.reload(SupportTestsF32::SAMPLES_F32_ID,mgr,this->nbSamples);
  150. refQ31.reload(SupportTestsF32::SAMPLES_Q31_ID,mgr,this->nbSamples);
  151. outputQ31.create(this->nbSamples,SupportTestsF32::OUT_F32_ID,mgr);
  152. break;
  153. case TEST_FLOAT_TO_Q31_15:
  154. this->nbSamples = 9;
  155. input.reload(SupportTestsF32::SAMPLES_F32_ID,mgr,this->nbSamples);
  156. refQ31.reload(SupportTestsF32::SAMPLES_Q31_ID,mgr,this->nbSamples);
  157. outputQ31.create(this->nbSamples,SupportTestsF32::OUT_F32_ID,mgr);
  158. break;
  159. case TEST_FLOAT_TO_Q7_16:
  160. this->nbSamples = 15;
  161. input.reload(SupportTestsF32::SAMPLES_F32_ID,mgr,this->nbSamples);
  162. refQ7.reload(SupportTestsF32::SAMPLES_Q7_ID,mgr,this->nbSamples);
  163. outputQ7.create(this->nbSamples,SupportTestsF32::OUT_F32_ID,mgr);
  164. break;
  165. case TEST_FLOAT_TO_Q7_17:
  166. this->nbSamples = 32;
  167. input.reload(SupportTestsF32::SAMPLES_F32_ID,mgr,this->nbSamples);
  168. refQ7.reload(SupportTestsF32::SAMPLES_Q7_ID,mgr,this->nbSamples);
  169. outputQ7.create(this->nbSamples,SupportTestsF32::OUT_F32_ID,mgr);
  170. break;
  171. case TEST_FLOAT_TO_Q7_18:
  172. this->nbSamples = 33;
  173. input.reload(SupportTestsF32::SAMPLES_F32_ID,mgr,this->nbSamples);
  174. refQ7.reload(SupportTestsF32::SAMPLES_Q7_ID,mgr,this->nbSamples);
  175. outputQ7.create(this->nbSamples,SupportTestsF32::OUT_F32_ID,mgr);
  176. break;
  177. }
  178. }
  179. void SupportTestsF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  180. {
  181. output.dump(mgr);
  182. }