Éanna Ó Catháin | c6ab02a | 2021-04-07 14:35:25 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include <vector> |
| 7 | #include <cmath> |
| 8 | #include <cstdint> |
| 9 | #include <numeric> |
| 10 | |
| 11 | class MathUtils |
| 12 | { |
| 13 | |
| 14 | public: |
| 15 | |
| 16 | /** |
| 17 | * @brief Computes the FFT for the input vector |
| 18 | * @param[in] input Floating point vector of input elements |
| 19 | * @param[out] fftOutput Output buffer to be populated by computed |
| 20 | * FFTs |
| 21 | * @return none |
| 22 | */ |
| 23 | static void FftF32(std::vector<float>& input, |
| 24 | std::vector<float>& fftOutput); |
| 25 | |
| 26 | |
| 27 | /** |
| 28 | * @brief Computes the dot product of two 1D floating point |
| 29 | * vectors. |
| 30 | * result = sum(srcA[0]*srcB[0] + srcA[1]*srcB[1] + ..) |
| 31 | * @param[in] srcPtrA pointer to the first element of first |
| 32 | * array |
| 33 | * @param[in] srcPtrB pointer to the first element of second |
| 34 | * array |
| 35 | * @param[in] srcLen Number of elements in the array/vector |
| 36 | * @return dot product |
| 37 | */ |
| 38 | static float DotProductF32(float* srcPtrA, float* srcPtrB, |
| 39 | const int srcLen); |
| 40 | |
| 41 | /** |
| 42 | * @brief Computes the squared magnitude of floating point |
| 43 | * complex number array. |
| 44 | * @param[in] ptrSrc pointer to the first element of input |
| 45 | * array |
| 46 | * @param[in] srcLen Number of elements in the array/vector |
| 47 | * @param[out] ptrDst Output buffer to be populated |
| 48 | * @param[in] dstLen output buffer len (for sanity check only) |
| 49 | * @return true if successful, false otherwise |
| 50 | */ |
| 51 | static bool ComplexMagnitudeSquaredF32(float* ptrSrc, |
| 52 | const int srcLen, |
| 53 | float* ptrDst, |
| 54 | const int dstLen); |
| 55 | |
| 56 | /** |
| 57 | * @brief Computes the natural logarithms of input floating point |
| 58 | * vector |
| 59 | * @param[in] input Floating point input vector |
| 60 | * @param[out] output Pre-allocated buffer to be populated with |
| 61 | * natural log values of each input element |
| 62 | * @return none |
| 63 | */ |
| 64 | static void VecLogarithmF32(std::vector <float>& input, |
| 65 | std::vector <float>& output); |
| 66 | |
| 67 | /** |
| 68 | * @brief Gets the mean of a floating point array of elements |
| 69 | * @param[in] ptrSrc pointer to the first element |
| 70 | * @param[in] srcLen Number of elements in the array/vector |
| 71 | * @return average value |
| 72 | */ |
| 73 | static float MeanF32(float* ptrSrc, const uint32_t srcLen); |
| 74 | |
| 75 | /** |
| 76 | * @brief Gets the standard deviation of a floating point array |
| 77 | * of elements |
| 78 | * @param[in] ptrSrc pointer to the first element |
| 79 | * @param[in] srcLen Number of elements in the array/vector |
| 80 | * @param[in] mean pre-computed mean value |
| 81 | * @return standard deviation value |
| 82 | */ |
| 83 | static float StdDevF32(float* ptrSrc, const uint32_t srcLen, |
| 84 | const float mean); |
| 85 | }; |