BinaryTestsF32.cpp 4.2 KB

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