1 /******************************************************************************
2  * @file     distance_functions_f16.h
3  * @brief    Public header file for CMSIS DSP Library
4  * @version  V1.10.0
5  * @date     08 July 2021
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 DISTANCE_FUNCTIONS_F16_H_
28 #define DISTANCE_FUNCTIONS_F16_H_
29 
30 #include "arm_math_types_f16.h"
31 #include "arm_math_memory.h"
32 
33 #include "dsp/none.h"
34 #include "dsp/utils.h"
35 
36 /* 6.14 bug */
37 #if defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100) && (__ARMCC_VERSION < 6150001)
38 /* Defined in minkowski_f32 */
39 __attribute__((weak)) float __powisf2(float a, int b);
40 #endif
41 
42 #include "dsp/statistics_functions_f16.h"
43 #include "dsp/basic_math_functions_f16.h"
44 
45 #include "dsp/fast_math_functions_f16.h"
46 
47 #ifdef   __cplusplus
48 extern "C"
49 {
50 #endif
51 
52 #if defined(ARM_FLOAT16_SUPPORTED)
53 
54 /**
55  * @brief        Euclidean distance between two vectors
56  * @param[in]    pA         First vector
57  * @param[in]    pB         Second vector
58  * @param[in]    blockSize  vector length
59  * @return distance
60  */
61 float16_t arm_euclidean_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
62 
63 
64 /**
65  * @brief        Bray-Curtis distance between two vectors
66  * @param[in]    pA         First vector
67  * @param[in]    pB         Second vector
68  * @param[in]    blockSize  vector length
69  * @return distance
70  */
71 float16_t arm_braycurtis_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
72 
73 /**
74  * @brief        Canberra distance between two vectors
75  *
76  * This function may divide by zero when samples pA[i] and pB[i] are both zero.
77  * The result of the computation will be correct. So the division per zero may be
78  * ignored.
79  *
80  * @param[in]    pA         First vector
81  * @param[in]    pB         Second vector
82  * @param[in]    blockSize  vector length
83  * @return distance
84  */
85 float16_t arm_canberra_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
86 
87 
88 /**
89  * @brief        Chebyshev distance between two vectors
90  * @param[in]    pA         First vector
91  * @param[in]    pB         Second vector
92  * @param[in]    blockSize  vector length
93  * @return distance
94  */
95 float16_t arm_chebyshev_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
96 
97 
98 /**
99  * @brief        Cityblock (Manhattan) distance between two vectors
100  * @param[in]    pA         First vector
101  * @param[in]    pB         Second vector
102  * @param[in]    blockSize  vector length
103  * @return distance
104  */
105 float16_t arm_cityblock_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
106 
107 
108 /**
109  * @brief        Correlation distance between two vectors
110  *
111  * The input vectors are modified in place !
112  *
113  * @param[in]    pA         First vector
114  * @param[in]    pB         Second vector
115  * @param[in]    blockSize  vector length
116  * @return distance
117  */
118 float16_t arm_correlation_distance_f16(float16_t *pA,float16_t *pB, uint32_t blockSize);
119 
120 
121 /**
122  * @brief        Cosine distance between two vectors
123  *
124  * @param[in]    pA         First vector
125  * @param[in]    pB         Second vector
126  * @param[in]    blockSize  vector length
127  * @return distance
128  */
129 float16_t arm_cosine_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
130 
131 
132 /**
133  * @brief        Jensen-Shannon distance between two vectors
134  *
135  * This function is assuming that elements of second vector are > 0
136  * and 0 only when the corresponding element of first vector is 0.
137  * Otherwise the result of the computation does not make sense
138  * and for speed reasons, the cases returning NaN or Infinity are not
139  * managed.
140  *
141  * When the function is computing x log (x / y) with x 0 and y 0,
142  * it will compute the right value (0) but a division per zero will occur
143  * and shoudl be ignored in client code.
144  *
145  * @param[in]    pA         First vector
146  * @param[in]    pB         Second vector
147  * @param[in]    blockSize  vector length
148  * @return distance
149  */
150 float16_t arm_jensenshannon_distance_f16(const float16_t *pA,const float16_t *pB,uint32_t blockSize);
151 
152 
153 /**
154  * @brief        Minkowski distance between two vectors
155  *
156  * @param[in]    pA         First vector
157  * @param[in]    pB         Second vector
158  * @param[in]    n          Norm order (>= 2)
159  * @param[in]    blockSize  vector length
160  * @return distance
161  */
162 float16_t arm_minkowski_distance_f16(const float16_t *pA,const float16_t *pB, int32_t order, uint32_t blockSize);
163 
164 
165 #endif /*defined(ARM_FLOAT16_SUPPORTED)*/
166 #ifdef   __cplusplus
167 }
168 #endif
169 
170 #endif /* ifndef _DISTANCE_FUNCTIONS_F16_H_ */
171