1 /******************************************************************************
2  * @file     support_functions.h
3  * @brief    Public header file for CMSIS DSP Library
4  * @version  V1.10.1
5  * @date     18 August 2022
6  * Target Processor: Cortex-M and Cortex-A cores
7  ******************************************************************************/
8 /*
9  * Copyright (c) 2010-2020 Arm Limited or its affiliates. All rights reserved.
10  *
11  * SPDX-License-Identifier: Apache-2.0
12  *
13  * Licensed under the Apache License, Version 2.0 (the License); you may
14  * not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  * www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
21  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  */
25 
26 
27 #ifndef _SUPPORT_FUNCTIONS_H_
28 #define _SUPPORT_FUNCTIONS_H_
29 
30 #include "arm_math_types.h"
31 #include "arm_math_memory.h"
32 
33 #include "dsp/none.h"
34 #include "dsp/utils.h"
35 
36 #ifdef   __cplusplus
37 extern "C"
38 {
39 #endif
40 
41 /**
42  * @defgroup groupSupport Support Functions
43  */
44 
45 
46 /**
47    * @brief Converts the elements of the 64 bit floating-point vector to floating-point vector.
48    * @param[in]  pSrc       points to the floating-point 64 input vector
49    * @param[out] pDst       points to the floating-point output vector
50    * @param[in]  blockSize  length of the input vector
51    */
52   void arm_f64_to_float(
53   const float64_t * pSrc,
54         float32_t * pDst,
55         uint32_t blockSize);
56 
57 /**
58    * @brief Converts the elements of the 64 bit floating-point vector to Q31 vector.
59    * @param[in]  pSrc       points to the floating-point 64 input vector
60    * @param[out] pDst       points to the Q31 output vector
61    * @param[in]  blockSize  length of the input vector
62    */
63   void arm_f64_to_q31(
64   const float64_t * pSrc,
65         q31_t * pDst,
66         uint32_t blockSize);
67 
68 /**
69    * @brief Converts the elements of the 64 bit floating-point vector to Q15 vector.
70    * @param[in]  pSrc       points to the floating-point 64 input vector
71    * @param[out] pDst       points to the Q15 output vector
72    * @param[in]  blockSize  length of the input vector
73    */
74   void arm_f64_to_q15(
75   const float64_t * pSrc,
76         q15_t * pDst,
77         uint32_t blockSize);
78 
79 /**
80    * @brief Converts the elements of the 64 bit floating-point vector to Q7 vector.
81    * @param[in]  pSrc       points to the floating-point 64 input vector
82    * @param[out] pDst       points to the Q7 output vector
83    * @param[in]  blockSize  length of the input vector
84    */
85   void arm_f64_to_q7(
86   const float64_t * pSrc,
87         q7_t * pDst,
88         uint32_t blockSize);
89 
90 
91 
92 /**
93    * @brief Converts the elements of the floating-point  vector to 64 bit floating-point  vector.
94    * @param[in]  pSrc       points to the floating-point input vector
95    * @param[out] pDst       points to the 64 bit floating-point output vector
96    * @param[in]  blockSize  length of the input vector
97    */
98   void arm_float_to_f64(
99   const float32_t * pSrc,
100         float64_t * pDst,
101         uint32_t blockSize);
102 
103 /**
104    * @brief Converts the elements of the floating-point vector to Q31 vector.
105    * @param[in]  pSrc       points to the floating-point input vector
106    * @param[out] pDst       points to the Q31 output vector
107    * @param[in]  blockSize  length of the input vector
108    */
109   void arm_float_to_q31(
110   const float32_t * pSrc,
111         q31_t * pDst,
112         uint32_t blockSize);
113 
114 
115   /**
116    * @brief Converts the elements of the floating-point vector to Q15 vector.
117    * @param[in]  pSrc       points to the floating-point input vector
118    * @param[out] pDst       points to the Q15 output vector
119    * @param[in]  blockSize  length of the input vector
120    */
121   void arm_float_to_q15(
122   const float32_t * pSrc,
123         q15_t * pDst,
124         uint32_t blockSize);
125 
126 
127   /**
128    * @brief Converts the elements of the floating-point vector to Q7 vector.
129    * @param[in]  pSrc       points to the floating-point input vector
130    * @param[out] pDst       points to the Q7 output vector
131    * @param[in]  blockSize  length of the input vector
132    */
133   void arm_float_to_q7(
134   const float32_t * pSrc,
135         q7_t * pDst,
136         uint32_t blockSize);
137 
138 /**
139  * @brief  Converts the elements of the Q31 vector to 64 bit floating-point vector.
140  * @param[in]  pSrc       is input pointer
141  * @param[out] pDst       is output pointer
142  * @param[in]  blockSize  is the number of samples to process
143  */
144 void arm_q31_to_f64(
145 const q31_t * pSrc,
146       float64_t * pDst,
147       uint32_t blockSize);
148 
149   /**
150    * @brief  Converts the elements of the Q31 vector to floating-point vector.
151    * @param[in]  pSrc       is input pointer
152    * @param[out] pDst       is output pointer
153    * @param[in]  blockSize  is the number of samples to process
154    */
155   void arm_q31_to_float(
156   const q31_t * pSrc,
157         float32_t * pDst,
158         uint32_t blockSize);
159 
160 
161   /**
162    * @brief  Converts the elements of the Q31 vector to Q15 vector.
163    * @param[in]  pSrc       is input pointer
164    * @param[out] pDst       is output pointer
165    * @param[in]  blockSize  is the number of samples to process
166    */
167   void arm_q31_to_q15(
168   const q31_t * pSrc,
169         q15_t * pDst,
170         uint32_t blockSize);
171 
172 
173   /**
174    * @brief  Converts the elements of the Q31 vector to Q7 vector.
175    * @param[in]  pSrc       is input pointer
176    * @param[out] pDst       is output pointer
177    * @param[in]  blockSize  is the number of samples to process
178    */
179   void arm_q31_to_q7(
180   const q31_t * pSrc,
181         q7_t * pDst,
182         uint32_t blockSize);
183 
184 /**
185  * @brief  Converts the elements of the Q15 vector to 64 bit floating-point vector.
186  * @param[in]  pSrc       is input pointer
187  * @param[out] pDst       is output pointer
188  * @param[in]  blockSize  is the number of samples to process
189  */
190 void arm_q15_to_f64(
191 const q15_t * pSrc,
192       float64_t * pDst,
193       uint32_t blockSize);
194 
195   /**
196    * @brief  Converts the elements of the Q15 vector to floating-point vector.
197    * @param[in]  pSrc       is input pointer
198    * @param[out] pDst       is output pointer
199    * @param[in]  blockSize  is the number of samples to process
200    */
201   void arm_q15_to_float(
202   const q15_t * pSrc,
203         float32_t * pDst,
204         uint32_t blockSize);
205 
206 
207   /**
208    * @brief  Converts the elements of the Q15 vector to Q31 vector.
209    * @param[in]  pSrc       is input pointer
210    * @param[out] pDst       is output pointer
211    * @param[in]  blockSize  is the number of samples to process
212    */
213   void arm_q15_to_q31(
214   const q15_t * pSrc,
215         q31_t * pDst,
216         uint32_t blockSize);
217 
218 
219   /**
220    * @brief  Converts the elements of the Q15 vector to Q7 vector.
221    * @param[in]  pSrc       is input pointer
222    * @param[out] pDst       is output pointer
223    * @param[in]  blockSize  is the number of samples to process
224    */
225   void arm_q15_to_q7(
226   const q15_t * pSrc,
227         q7_t * pDst,
228         uint32_t blockSize);
229 
230 /**
231  * @brief  Converts the elements of the Q7 vector to 64 bit floating-point vector.
232  * @param[in]  pSrc       is input pointer
233  * @param[out] pDst       is output pointer
234  * @param[in]  blockSize  is the number of samples to process
235  */
236 void arm_q7_to_f64(
237 const q7_t * pSrc,
238       float64_t * pDst,
239       uint32_t blockSize);
240 
241   /**
242    * @brief  Converts the elements of the Q7 vector to floating-point vector.
243    * @param[in]  pSrc       is input pointer
244    * @param[out] pDst       is output pointer
245    * @param[in]  blockSize  is the number of samples to process
246    */
247   void arm_q7_to_float(
248   const q7_t * pSrc,
249         float32_t * pDst,
250         uint32_t blockSize);
251 
252 
253   /**
254    * @brief  Converts the elements of the Q7 vector to Q31 vector.
255    * @param[in]  pSrc       input pointer
256    * @param[out] pDst       output pointer
257    * @param[in]  blockSize  number of samples to process
258    */
259   void arm_q7_to_q31(
260   const q7_t * pSrc,
261         q31_t * pDst,
262         uint32_t blockSize);
263 
264 
265   /**
266    * @brief  Converts the elements of the Q7 vector to Q15 vector.
267    * @param[in]  pSrc       input pointer
268    * @param[out] pDst       output pointer
269    * @param[in]  blockSize  number of samples to process
270    */
271   void arm_q7_to_q15(
272   const q7_t * pSrc,
273         q15_t * pDst,
274         uint32_t blockSize);
275 
276 
277 
278 
279 
280   /**
281    * @brief Struct for specifying sorting algorithm
282    */
283   typedef enum
284   {
285     ARM_SORT_BITONIC   = 0,
286              /**< Bitonic sort   */
287     ARM_SORT_BUBBLE    = 1,
288              /**< Bubble sort    */
289     ARM_SORT_HEAP      = 2,
290              /**< Heap sort      */
291     ARM_SORT_INSERTION = 3,
292              /**< Insertion sort */
293     ARM_SORT_QUICK     = 4,
294              /**< Quick sort     */
295     ARM_SORT_SELECTION = 5
296              /**< Selection sort */
297   } arm_sort_alg;
298 
299   /**
300    * @brief Struct for specifying sorting algorithm
301    */
302   typedef enum
303   {
304     ARM_SORT_DESCENDING = 0,
305              /**< Descending order (9 to 0) */
306     ARM_SORT_ASCENDING = 1
307              /**< Ascending order (0 to 9) */
308   } arm_sort_dir;
309 
310   /**
311    * @brief Instance structure for the sorting algorithms.
312    */
313   typedef struct
314   {
315     arm_sort_alg alg;        /**< Sorting algorithm selected */
316     arm_sort_dir dir;        /**< Sorting order (direction)  */
317   } arm_sort_instance_f32;
318 
319   /**
320    * @param[in]  S          points to an instance of the sorting structure.
321    * @param[in]  pSrc       points to the block of input data.
322    * @param[out] pDst       points to the block of output data.
323    * @param[in]  blockSize  number of samples to process.
324    */
325   void arm_sort_f32(
326     const arm_sort_instance_f32 * S,
327           float32_t * pSrc,
328           float32_t * pDst,
329           uint32_t blockSize);
330 
331   /**
332    * @param[in,out]  S            points to an instance of the sorting structure.
333    * @param[in]      alg          Selected algorithm.
334    * @param[in]      dir          Sorting order.
335    */
336   void arm_sort_init_f32(
337     arm_sort_instance_f32 * S,
338     arm_sort_alg alg,
339     arm_sort_dir dir);
340 
341   /**
342    * @brief Instance structure for the sorting algorithms.
343    */
344   typedef struct
345   {
346     arm_sort_dir dir;        /**< Sorting order (direction)  */
347     float32_t * buffer;      /**< Working buffer */
348   } arm_merge_sort_instance_f32;
349 
350   /**
351    * @param[in]      S          points to an instance of the sorting structure.
352    * @param[in,out]  pSrc       points to the block of input data.
353    * @param[out]     pDst       points to the block of output data
354    * @param[in]      blockSize  number of samples to process.
355    */
356   void arm_merge_sort_f32(
357     const arm_merge_sort_instance_f32 * S,
358           float32_t *pSrc,
359           float32_t *pDst,
360           uint32_t blockSize);
361 
362   /**
363    * @param[in,out]  S            points to an instance of the sorting structure.
364    * @param[in]      dir          Sorting order.
365    * @param[in]      buffer       Working buffer.
366    */
367   void arm_merge_sort_init_f32(
368     arm_merge_sort_instance_f32 * S,
369     arm_sort_dir dir,
370     float32_t * buffer);
371 
372 
373 
374   /**
375    * @brief  Copies the elements of a floating-point vector.
376    * @param[in]  pSrc       input pointer
377    * @param[out] pDst       output pointer
378    * @param[in]  blockSize  number of samples to process
379    */
380   void arm_copy_f32(
381   const float32_t * pSrc,
382         float32_t * pDst,
383         uint32_t blockSize);
384 
385 
386 
387   /**
388    * @brief  Copies the elements of a floating-point vector.
389    * @param[in]  pSrc       input pointer
390    * @param[out] pDst       output pointer
391    * @param[in]  blockSize  number of samples to process
392    */
393   void arm_copy_f64(
394   const float64_t * pSrc,
395         float64_t * pDst,
396         uint32_t blockSize);
397 
398 
399 
400   /**
401    * @brief  Copies the elements of a Q7 vector.
402    * @param[in]  pSrc       input pointer
403    * @param[out] pDst       output pointer
404    * @param[in]  blockSize  number of samples to process
405    */
406   void arm_copy_q7(
407   const q7_t * pSrc,
408         q7_t * pDst,
409         uint32_t blockSize);
410 
411 
412   /**
413    * @brief  Copies the elements of a Q15 vector.
414    * @param[in]  pSrc       input pointer
415    * @param[out] pDst       output pointer
416    * @param[in]  blockSize  number of samples to process
417    */
418   void arm_copy_q15(
419   const q15_t * pSrc,
420         q15_t * pDst,
421         uint32_t blockSize);
422 
423 
424   /**
425    * @brief  Copies the elements of a Q31 vector.
426    * @param[in]  pSrc       input pointer
427    * @param[out] pDst       output pointer
428    * @param[in]  blockSize  number of samples to process
429    */
430   void arm_copy_q31(
431   const q31_t * pSrc,
432         q31_t * pDst,
433         uint32_t blockSize);
434 
435 
436   /**
437    * @brief  Fills a constant value into a floating-point vector.
438    * @param[in]  value      input value to be filled
439    * @param[out] pDst       output pointer
440    * @param[in]  blockSize  number of samples to process
441    */
442   void arm_fill_f32(
443         float32_t value,
444         float32_t * pDst,
445         uint32_t blockSize);
446 
447 
448   /**
449    * @brief  Fills a constant value into a floating-point vector.
450    * @param[in]  value      input value to be filled
451    * @param[out] pDst       output pointer
452    * @param[in]  blockSize  number of samples to process
453    */
454   void arm_fill_f64(
455         float64_t value,
456         float64_t * pDst,
457         uint32_t blockSize);
458 
459 
460   /**
461    * @brief  Fills a constant value into a Q7 vector.
462    * @param[in]  value      input value to be filled
463    * @param[out] pDst       output pointer
464    * @param[in]  blockSize  number of samples to process
465    */
466   void arm_fill_q7(
467         q7_t value,
468         q7_t * pDst,
469         uint32_t blockSize);
470 
471 
472   /**
473    * @brief  Fills a constant value into a Q15 vector.
474    * @param[in]  value      input value to be filled
475    * @param[out] pDst       output pointer
476    * @param[in]  blockSize  number of samples to process
477    */
478   void arm_fill_q15(
479         q15_t value,
480         q15_t * pDst,
481         uint32_t blockSize);
482 
483 
484   /**
485    * @brief  Fills a constant value into a Q31 vector.
486    * @param[in]  value      input value to be filled
487    * @param[out] pDst       output pointer
488    * @param[in]  blockSize  number of samples to process
489    */
490   void arm_fill_q31(
491         q31_t value,
492         q31_t * pDst,
493         uint32_t blockSize);
494 
495 
496 
497 
498 
499 
500 
501 /**
502  * @brief Weighted sum
503  *
504  *
505  * @param[in]    *in           Array of input values.
506  * @param[in]    *weigths      Weights
507  * @param[in]    blockSize     Number of samples in the input array.
508  * @return Weighted sum
509  *
510  */
511 float32_t arm_weighted_sum_f32(const float32_t *in
512   , const float32_t *weigths
513   , uint32_t blockSize);
514 
515 
516 /**
517  * @brief Barycenter
518  *
519  *
520  * @param[in]    in         List of vectors
521  * @param[in]    weights    Weights of the vectors
522  * @param[out]   out        Barycenter
523  * @param[in]    nbVectors  Number of vectors
524  * @param[in]    vecDim     Dimension of space (vector dimension)
525  * @return       None
526  *
527  */
528 void arm_barycenter_f32(const float32_t *in
529   , const float32_t *weights
530   , float32_t *out
531   , uint32_t nbVectors
532   , uint32_t vecDim);
533 
534 
535 
536 #ifdef   __cplusplus
537 }
538 #endif
539 
540 #endif /* ifndef _SUPPORT_FUNCTIONS_H_ */
541