StatsTestsF64.cpp 2.5 KB

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