UnaryTestsQ7.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #include "UnaryTestsQ7.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #define SNR_THRESHOLD 20
  5. #define SNR_LOW_THRESHOLD 11
  6. /*
  7. Reference patterns are generated with
  8. a double precision computation.
  9. */
  10. #define ABS_ERROR_Q7 ((q7_t)2)
  11. #define ABS_ERROR_Q63 ((q63_t)(1<<16))
  12. #define ONEHALF 0x4000
  13. /* Upper bound of maximum matrix dimension used by Python */
  14. #define MAXMATRIXDIM 47
  15. #define LOADDATA2() \
  16. const q7_t *inp1=input1.ptr(); \
  17. const q7_t *inp2=input2.ptr(); \
  18. \
  19. q7_t *ap=a.ptr(); \
  20. q7_t *bp=b.ptr(); \
  21. \
  22. q7_t *outp=output.ptr(); \
  23. int16_t *dimsp = dims.ptr(); \
  24. int nbMatrixes = dims.nbSamples() >> 1;\
  25. int rows,columns; \
  26. int i;
  27. #define LOADDATA1() \
  28. const q7_t *inp1=input1.ptr(); \
  29. \
  30. q7_t *ap=a.ptr(); \
  31. \
  32. q7_t *outp=output.ptr(); \
  33. int16_t *dimsp = dims.ptr(); \
  34. int nbMatrixes = dims.nbSamples() >> 1;\
  35. int rows,columns; \
  36. int i;
  37. #define PREPAREDATA2() \
  38. in1.numRows=rows; \
  39. in1.numCols=columns; \
  40. memcpy((void*)ap,(const void*)inp1,sizeof(q7_t)*rows*columns);\
  41. in1.pData = ap; \
  42. \
  43. in2.numRows=rows; \
  44. in2.numCols=columns; \
  45. memcpy((void*)bp,(const void*)inp2,sizeof(q7_t)*rows*columns);\
  46. in2.pData = bp; \
  47. \
  48. out.numRows=rows; \
  49. out.numCols=columns; \
  50. out.pData = outp;
  51. #define PREPAREDATA1(TRANSPOSED) \
  52. in1.numRows=rows; \
  53. in1.numCols=columns; \
  54. memcpy((void*)ap,(const void*)inp1,sizeof(q7_t)*rows*columns);\
  55. in1.pData = ap; \
  56. \
  57. if (TRANSPOSED) \
  58. { \
  59. out.numRows=columns; \
  60. out.numCols=rows; \
  61. } \
  62. else \
  63. { \
  64. out.numRows=rows; \
  65. out.numCols=columns; \
  66. } \
  67. out.pData = outp;
  68. #define LOADVECDATA2() \
  69. const q7_t *inp1=input1.ptr(); \
  70. const q7_t *inp2=input2.ptr(); \
  71. \
  72. q7_t *ap=a.ptr(); \
  73. q7_t *bp=b.ptr(); \
  74. \
  75. q7_t *outp=output.ptr(); \
  76. int16_t *dimsp = dims.ptr(); \
  77. int nbMatrixes = dims.nbSamples() / 2;\
  78. int rows,internal; \
  79. int i;
  80. #define PREPAREVECDATA2() \
  81. in1.numRows=rows; \
  82. in1.numCols=internal; \
  83. memcpy((void*)ap,(const void*)inp1,2*sizeof(q7_t)*rows*internal);\
  84. in1.pData = ap; \
  85. \
  86. memcpy((void*)bp,(const void*)inp2,2*sizeof(q7_t)*internal);
  87. void UnaryTestsQ7::test_mat_vec_mult_q7()
  88. {
  89. LOADVECDATA2();
  90. for(i=0;i < nbMatrixes ; i ++)
  91. {
  92. rows = *dimsp++;
  93. internal = *dimsp++;
  94. PREPAREVECDATA2();
  95. arm_mat_vec_mult_q7(&this->in1, bp, outp);
  96. outp += rows ;
  97. }
  98. ASSERT_EMPTY_TAIL(output);
  99. ASSERT_SNR(output,ref,(q7_t)SNR_LOW_THRESHOLD);
  100. ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q7);
  101. }
  102. void UnaryTestsQ7::test_mat_trans_q7()
  103. {
  104. LOADDATA1();
  105. for(i=0;i < nbMatrixes ; i ++)
  106. {
  107. rows = *dimsp++;
  108. columns = *dimsp++;
  109. PREPAREDATA1(true);
  110. arm_mat_trans_q7(&this->in1,&this->out);
  111. outp += (rows * columns);
  112. }
  113. ASSERT_EMPTY_TAIL(output);
  114. ASSERT_SNR(output,ref,(q7_t)SNR_THRESHOLD);
  115. ASSERT_NEAR_EQ(output,ref,ABS_ERROR_Q7);
  116. }
  117. void UnaryTestsQ7::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  118. {
  119. (void)params;
  120. switch(id)
  121. {
  122. case TEST_MAT_TRANS_Q7_1:
  123. input1.reload(UnaryTestsQ7::INPUTS1_Q7_ID,mgr);
  124. dims.reload(UnaryTestsQ7::DIMSUNARY1_S16_ID,mgr);
  125. ref.reload(UnaryTestsQ7::REFTRANS1_Q7_ID,mgr);
  126. output.create(ref.nbSamples(),UnaryTestsQ7::OUT_Q7_ID,mgr);
  127. a.create(MAXMATRIXDIM*MAXMATRIXDIM,UnaryTestsQ7::TMPA_Q7_ID,mgr);
  128. break;
  129. case TEST_MAT_VEC_MULT_Q7_2:
  130. input1.reload(UnaryTestsQ7::INPUTS1_Q7_ID,mgr);
  131. input2.reload(UnaryTestsQ7::INPUTVEC1_Q7_ID,mgr);
  132. dims.reload(UnaryTestsQ7::DIMSUNARY1_S16_ID,mgr);
  133. ref.reload(UnaryTestsQ7::REFVECMUL1_Q7_ID,mgr);
  134. output.create(ref.nbSamples(),UnaryTestsQ7::OUT_Q7_ID,mgr);
  135. a.create(MAXMATRIXDIM*MAXMATRIXDIM,UnaryTestsQ7::TMPA_Q7_ID,mgr);
  136. b.create(MAXMATRIXDIM,UnaryTestsQ7::TMPB_Q7_ID,mgr);
  137. break;
  138. }
  139. }
  140. void UnaryTestsQ7::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  141. {
  142. (void)id;
  143. output.dump(mgr);
  144. }