StatsTestsF64.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include "StatsTestsF64.h"
  2. #include <stdio.h>
  3. #include "Error.h"
  4. #include "arm_math.h"
  5. #include "Test.h"
  6. #define SNR_THRESHOLD 300
  7. /*
  8. Reference patterns are generated with
  9. a double precision computation.
  10. */
  11. #define REL_ERROR (1.0e-14)
  12. void StatsTestsF64::test_entropy_f64()
  13. {
  14. const float64_t *inp = inputA.ptr();
  15. const int16_t *dimsp = dims.ptr();
  16. float64_t *refp = ref.ptr();
  17. float64_t *outp = output.ptr();
  18. for(int i=0;i < this->nbPatterns; i++)
  19. {
  20. *outp = arm_entropy_f64(inp,dimsp[i+1]);
  21. outp++;
  22. inp += dimsp[i+1];
  23. }
  24. ASSERT_SNR(ref,output,(float64_t)SNR_THRESHOLD);
  25. ASSERT_REL_ERROR(ref,output,REL_ERROR);
  26. }
  27. void StatsTestsF64::test_kullback_leibler_f64()
  28. {
  29. const float64_t *inpA = inputA.ptr();
  30. const float64_t *inpB = inputB.ptr();
  31. const int16_t *dimsp = dims.ptr();
  32. float64_t *refp = ref.ptr();
  33. float64_t *outp = output.ptr();
  34. for(int i=0;i < this->nbPatterns; i++)
  35. {
  36. *outp = arm_kullback_leibler_f64(inpA,inpB,dimsp[i+1]);
  37. outp++;
  38. inpA += dimsp[i+1];
  39. inpB += dimsp[i+1];
  40. }
  41. ASSERT_SNR(ref,output,(float64_t)SNR_THRESHOLD);
  42. ASSERT_REL_ERROR(ref,output,REL_ERROR);
  43. }
  44. void StatsTestsF64::setUp(Testing::testID_t id,std::vector<Testing::param_t>& paramsArgs,Client::PatternMgr *mgr)
  45. {
  46. switch(id)
  47. {
  48. case StatsTestsF64::TEST_ENTROPY_F64_1:
  49. {
  50. inputA.reload(StatsTestsF64::INPUT22_F64_ID,mgr);
  51. dims.reload(StatsTestsF64::DIM22_S16_ID,mgr);
  52. ref.reload(StatsTestsF64::REF22_ENTROPY_F64_ID,mgr);
  53. output.create(ref.nbSamples(),StatsTestsF64::OUT_F64_ID,mgr);
  54. const int16_t *dimsp = dims.ptr();
  55. this->nbPatterns=dimsp[0];
  56. }
  57. break;
  58. case StatsTestsF64::TEST_KULLBACK_LEIBLER_F64_2:
  59. {
  60. inputA.reload(StatsTestsF64::INPUTA24_F64_ID,mgr);
  61. inputB.reload(StatsTestsF64::INPUTB24_F64_ID,mgr);
  62. dims.reload(StatsTestsF64::DIM24_S16_ID,mgr);
  63. ref.reload(StatsTestsF64::REF24_KL_F64_ID,mgr);
  64. output.create(ref.nbSamples(),StatsTestsF64::OUT_F64_ID,mgr);
  65. const int16_t *dimsp = dims.ptr();
  66. this->nbPatterns=dimsp[0];
  67. }
  68. break;
  69. }
  70. }
  71. void StatsTestsF64::tearDown(Testing::testID_t id,Client::PatternMgr *mgr)
  72. {
  73. output.dump(mgr);
  74. }