1
2 /* ----------------------------------------------------------------------
3 * Project: CMSIS DSP Library
4 * Title: arm_cosine_distance_f64.c
5 * Description: Cosine distance between two vectors
6 *
7 * $Date: 13 September 2021
8 * $Revision: V1.10.0
9 *
10 * Target Processor: Cortex-M and Cortex-A cores
11 * -------------------------------------------------------------------- */
12 /*
13 * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
14 *
15 * SPDX-License-Identifier: Apache-2.0
16 *
17 * Licensed under the Apache License, Version 2.0 (the License); you may
18 * not use this file except in compliance with the License.
19 * You may obtain a copy of the License at
20 *
21 * www.apache.org/licenses/LICENSE-2.0
22 *
23 * Unless required by applicable law or agreed to in writing, software
24 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
25 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 * See the License for the specific language governing permissions and
27 * limitations under the License.
28 */
29
30 #include "dsp/distance_functions.h"
31 #include <limits.h>
32 #include <math.h>
33
34
35 /**
36 @addtogroup CosineDist
37 @{
38 */
39
40
41
42 /**
43 * @brief Cosine distance between two vectors
44 *
45 * @param[in] pA First vector
46 * @param[in] pB Second vector
47 * @param[in] blockSize vector length
48 * @return distance
49 *
50 */
51
arm_cosine_distance_f64(const float64_t * pA,const float64_t * pB,uint32_t blockSize)52 float64_t arm_cosine_distance_f64(const float64_t *pA,const float64_t *pB, uint32_t blockSize)
53 {
54 float64_t pwra,pwrb,dot,tmp;
55
56 arm_power_f64(pA, blockSize, &pwra);
57 arm_power_f64(pB, blockSize, &pwrb);
58
59 arm_dot_prod_f64(pA,pB,blockSize,&dot);
60
61 tmp = sqrt(pwra * pwrb);
62 return(1.0 - dot / tmp);
63
64 }
65
66
67
68 /**
69 * @} end of CosineDist group
70 */
71