BinaryTestsF32.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #include "BinaryTestsF32.h"
  2. #include "Error.h"
  3. #define SNR_THRESHOLD 120
  4. /*
  5. Reference patterns are generated with
  6. a double precision computation.
  7. */
  8. #define REL_ERROR (1.0e-6)
  9. #define ABS_ERROR (1.0e-5)
  10. /* Upper bound of maximum matrix dimension used by Python */
  11. #define MAXMATRIXDIM 40
  12. #define LOADDATA2() \
  13. const float32_t *inp1=input1.ptr(); \
  14. const float32_t *inp2=input2.ptr(); \
  15. \
  16. float32_t *ap=a.ptr(); \
  17. float32_t *bp=b.ptr(); \
  18. \
  19. float32_t *outp=output.ptr(); \
  20. int16_t *dimsp = dims.ptr(); \
  21. int nbMatrixes = dims.nbSamples() / 3;\
  22. int rows,internal,columns; \
  23. int i;
  24. #define PREPAREDATA2() \
  25. in1.numRows=rows; \
  26. in1.numCols=internal; \
  27. memcpy((void*)ap,(const void*)inp1,2*sizeof(float32_t)*rows*internal);\
  28. in1.pData = ap; \
  29. \
  30. in2.numRows=internal; \
  31. in2.numCols=columns; \
  32. memcpy((void*)bp,(const void*)inp2,2*sizeof(float32_t)*internal*columns);\
  33. in2.pData = bp; \
  34. \
  35. out.numRows=rows; \
  36. out.numCols=columns; \
  37. out.pData = outp;
  38. void BinaryTestsF32::test_mat_mult_f32()
  39. {
  40. LOADDATA2();
  41. for(i=0;i < nbMatrixes ; i ++)
  42. {
  43. rows = *dimsp++;
  44. internal = *dimsp++;
  45. columns = *dimsp++;
  46. PREPAREDATA2();
  47. arm_mat_mult_f32(&this->in1,&this->in2,&this->out);
  48. outp += (rows * columns);
  49. }
  50. ASSERT_EMPTY_TAIL(output);
  51. ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD);
  52. ASSERT_CLOSE_ERROR(output,ref,ABS_ERROR,REL_ERROR);
  53. }
  54. void BinaryTestsF32::test_mat_cmplx_mult_f32()
  55. {
  56. LOADDATA2();
  57. for(i=0;i < nbMatrixes ; i ++)
  58. {
  59. rows = *dimsp++;
  60. internal = *dimsp++;
  61. columns = *dimsp++;
  62. PREPAREDATA2();
  63. arm_mat_cmplx_mult_f32(&this->in1,&this->in2,&this->out);
  64. outp += (2*rows * columns);
  65. }
  66. ASSERT_EMPTY_TAIL(output);
  67. ASSERT_SNR(output,ref,(float32_t)SNR_THRESHOLD);
  68. ASSERT_CLOSE_ERROR(output,ref,ABS_ERROR,REL_ERROR);
  69. }
  70. void BinaryTestsF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
  71. {
  72. switch(id)
  73. {
  74. case TEST_MAT_MULT_F32_1:
  75. input1.reload(BinaryTestsF32::INPUTS1_F32_ID,mgr);
  76. input2.reload(BinaryTestsF32::INPUTS2_F32_ID,mgr);
  77. dims.reload(BinaryTestsF32::DIMSBINARY1_S16_ID,mgr);
  78. ref.reload(BinaryTestsF32::REFMUL1_F32_ID,mgr);
  79. output.create(ref.nbSamples(),BinaryTestsF32::OUT_F32_ID,mgr);
  80. a.create(MAXMATRIXDIM*MAXMATRIXDIM,BinaryTestsF32::TMPA_F32_ID,mgr);
  81. b.create(MAXMATRIXDIM*MAXMATRIXDIM,BinaryTestsF32::TMPB_F32_ID,mgr);
  82. break;
  83. case TEST_MAT_CMPLX_MULT_F32_2:
  84. input1.reload(BinaryTestsF32::INPUTSC1_F32_ID,mgr);
  85. input2.reload(BinaryTestsF32::INPUTSC2_F32_ID,mgr);
  86. dims.reload(BinaryTestsF32::DIMSBINARY1_S16_ID,mgr);
  87. ref.reload(BinaryTestsF32::REFCMPLXMUL1_F32_ID,mgr);
  88. output.create(ref.nbSamples(),BinaryTestsF32::OUT_F32_ID,mgr);
  89. a.create(2*MAXMATRIXDIM*MAXMATRIXDIM,BinaryTestsF32::TMPA_F32_ID,mgr);
  90. b.create(2*MAXMATRIXDIM*MAXMATRIXDIM,BinaryTestsF32::TMPB_F32_ID,mgr);
  91. break;
  92. }
  93. }
  94. void BinaryTestsF32::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  95. {
  96. output.dump(mgr);
  97. }