blob: 1d8b0d31ccc399f003d58e2aa78814e846436451 [file] [log] [blame]
Éanna Ó Catháinc6ab02a2021-04-07 14:35:25 +01001//
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
11class MathUtils
12{
13
14public:
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 */
George Gekov23c26272021-08-16 11:32:10 +010038 static float DotProductF32(const float* srcPtrA, float* srcPtrB,
39 int srcLen);
Éanna Ó Catháinc6ab02a2021-04-07 14:35:25 +010040
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 */
George Gekov23c26272021-08-16 11:32:10 +010051 static bool ComplexMagnitudeSquaredF32(const float* ptrSrc,
52 int srcLen,
Éanna Ó Catháinc6ab02a2021-04-07 14:35:25 +010053 float* ptrDst,
George Gekov23c26272021-08-16 11:32:10 +010054 int dstLen);
Éanna Ó Catháinc6ab02a2021-04-07 14:35:25 +010055
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 */
George Gekov23c26272021-08-16 11:32:10 +010073 static float MeanF32(const float* ptrSrc, uint32_t srcLen);
Éanna Ó Catháinc6ab02a2021-04-07 14:35:25 +010074
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 */
George Gekov23c26272021-08-16 11:32:10 +010083 static float StdDevF32(const float* ptrSrc, uint32_t srcLen,
84 float mean);
Éanna Ó Catháinc6ab02a2021-04-07 14:35:25 +010085};