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