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 29 #include "dsp/statistics_functions.h" 30 #include <limits.h> 31 #include <math.h> 32 #if defined(ARM_MATH_NEON) && defined(__aarch64__) 33 #include "arm_vec_math.h" 34 #endif 35 36 /** 37 * @addtogroup Entropy 38 * @{ 39 */ 40 41 /** 42 * @brief Entropy 43 * 44 * @param[in] pSrcA Array of input values. 45 * @param[in] blockSize Number of samples in the input array. 46 * @return Entropy -Sum(p ln p) 47 * 48 */ 49 arm_entropy_f64(const float64_t * pSrcA,uint32_t blockSize)50float64_t arm_entropy_f64(const float64_t * pSrcA, uint32_t blockSize) 51 { 52 const float64_t *pIn; 53 uint32_t blkCnt; 54 float64_t accum, p; 55 56 pIn = pSrcA; 57 58 accum = 0.0; 59 60 blkCnt = blockSize; 61 62 while(blkCnt > 0) 63 { 64 p = *pIn++; 65 66 accum += p * log(p); 67 68 blkCnt--; 69 70 } 71 72 return(-accum); 73 } 74 75 /** 76 * @} end of Entropy group 77 */ 78