1 /******************************************************************************
2  * @file     distance_functions_f16.h
3  * @brief    Public header file for CMSIS DSP Library
4  * @version  V1.9.0
5  * @date     23 April 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  */
62 
63 float16_t arm_euclidean_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
64 
65 /**
66  * @brief        Bray-Curtis distance between two vectors
67  * @param[in]    pA         First vector
68  * @param[in]    pB         Second vector
69  * @param[in]    blockSize  vector length
70  * @return distance
71  *
72  */
73 float16_t arm_braycurtis_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
74 
75 /**
76  * @brief        Canberra distance between two vectors
77  *
78  * This function may divide by zero when samples pA[i] and pB[i] are both zero.
79  * The result of the computation will be correct. So the division per zero may be
80  * ignored.
81  *
82  * @param[in]    pA         First vector
83  * @param[in]    pB         Second vector
84  * @param[in]    blockSize  vector length
85  * @return distance
86  *
87  */
88 float16_t arm_canberra_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
89 
90 
91 /**
92  * @brief        Chebyshev distance between two vectors
93  * @param[in]    pA         First vector
94  * @param[in]    pB         Second vector
95  * @param[in]    blockSize  vector length
96  * @return distance
97  *
98  */
99 float16_t arm_chebyshev_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
100 
101 
102 /**
103  * @brief        Cityblock (Manhattan) distance between two vectors
104  * @param[in]    pA         First vector
105  * @param[in]    pB         Second vector
106  * @param[in]    blockSize  vector length
107  * @return distance
108  *
109  */
110 float16_t arm_cityblock_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
111 
112 /**
113  * @brief        Correlation distance between two vectors
114  *
115  * The input vectors are modified in place !
116  *
117  * @param[in]    pA         First vector
118  * @param[in]    pB         Second vector
119  * @param[in]    blockSize  vector length
120  * @return distance
121  *
122  */
123 float16_t arm_correlation_distance_f16(float16_t *pA,float16_t *pB, uint32_t blockSize);
124 
125 /**
126  * @brief        Cosine distance between two vectors
127  *
128  * @param[in]    pA         First vector
129  * @param[in]    pB         Second vector
130  * @param[in]    blockSize  vector length
131  * @return distance
132  *
133  */
134 
135 float16_t arm_cosine_distance_f16(const float16_t *pA,const float16_t *pB, uint32_t blockSize);
136 
137 /**
138  * @brief        Jensen-Shannon distance between two vectors
139  *
140  * This function is assuming that elements of second vector are > 0
141  * and 0 only when the corresponding element of first vector is 0.
142  * Otherwise the result of the computation does not make sense
143  * and for speed reasons, the cases returning NaN or Infinity are not
144  * managed.
145  *
146  * When the function is computing x log (x / y) with x 0 and y 0,
147  * it will compute the right value (0) but a division per zero will occur
148  * and shoudl be ignored in client code.
149  *
150  * @param[in]    pA         First vector
151  * @param[in]    pB         Second vector
152  * @param[in]    blockSize  vector length
153  * @return distance
154  *
155  */
156 
157 float16_t arm_jensenshannon_distance_f16(const float16_t *pA,const float16_t *pB,uint32_t blockSize);
158 
159 /**
160  * @brief        Minkowski distance between two vectors
161  *
162  * @param[in]    pA         First vector
163  * @param[in]    pB         Second vector
164  * @param[in]    n          Norm order (>= 2)
165  * @param[in]    blockSize  vector length
166  * @return distance
167  *
168  */
169 
170 
171 
172 float16_t arm_minkowski_distance_f16(const float16_t *pA,const float16_t *pB, int32_t order, uint32_t blockSize);
173 
174 
175 #endif /*defined(ARM_FLOAT16_SUPPORTED)*/
176 #ifdef   __cplusplus
177 }
178 #endif
179 
180 #endif /* ifndef _DISTANCE_FUNCTIONS_F16_H_ */
181