arm_entropy_f64.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_logsumexp_f64.c
  4. * Description: LogSumExp
  5. *
  6. * $Date: 10 August 2022
  7. * $Revision: V1.9.1
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #include "dsp/statistics_functions.h"
  29. #include <limits.h>
  30. #include <math.h>
  31. #if defined(ARM_MATH_NEON) && defined(__aarch64__)
  32. #include "arm_vec_math.h"
  33. #endif
  34. /**
  35. * @addtogroup Entropy
  36. * @{
  37. */
  38. /**
  39. * @brief Entropy
  40. *
  41. * @param[in] pSrcA Array of input values.
  42. * @param[in] blockSize Number of samples in the input array.
  43. * @return Entropy -Sum(p ln p)
  44. *
  45. */
  46. float64_t arm_entropy_f64(const float64_t * pSrcA, uint32_t blockSize)
  47. {
  48. const float64_t *pIn;
  49. uint32_t blkCnt;
  50. float64_t accum, p;
  51. pIn = pSrcA;
  52. accum = 0.0;
  53. blkCnt = blockSize;
  54. while(blkCnt > 0)
  55. {
  56. p = *pIn++;
  57. accum += p * log(p);
  58. blkCnt--;
  59. }
  60. return(-accum);
  61. }
  62. /**
  63. * @} end of Entropy group
  64. */