• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /* ----------------------------------------------------------------------
3  * Project:      CMSIS DSP Library
4  * Title:        arm_dice_distance.c
5  * Description:  Dice distance between two vectors
6  *
7  * $Date:        23 April 2021
8  * $Revision:    V1.9.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 extern void arm_boolean_distance_TT_TF_FT(const uint32_t *pA
35        , const uint32_t *pB
36        , uint32_t numberOfBools
37        , uint32_t *cTT
38        , uint32_t *cTF
39        , uint32_t *cFT
40        );
41 
42 
43 /**
44  * @ingroup groupDistance
45  * @{
46  */
47 
48 /**
49  * @defgroup BoolDist Boolean Distances
50  *
51  * Distances between two vectors of boolean values.
52  *
53  * Booleans are packed in 32 bit words.
54  * numberOfBooleans argument is the number of booleans and not the
55  * number of words.
56  *
57  * Bits are packed in big-endian mode (because of behavior of numpy packbits in
58  * in version < 1.17)
59  */
60 
61 /**
62   @addtogroup BoolDist
63   @{
64  */
65 
66 /**
67  * @brief        Dice distance between two vectors
68  *
69  * @param[in]    pA              First vector of packed booleans
70  * @param[in]    pB              Second vector of packed booleans
71  * @param[in]    numberOfBools   Number of booleans
72  * @return distance
73  *
74  */
75 
arm_dice_distance(const uint32_t * pA,const uint32_t * pB,uint32_t numberOfBools)76 float32_t arm_dice_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools)
77 {
78     uint32_t ctt=0,ctf=0,cft=0;
79 
80     arm_boolean_distance_TT_TF_FT(pA, pB, numberOfBools, &ctt, &ctf, &cft);
81 
82     return(1.0*(ctf + cft) / (2.0*ctt + cft + ctf));
83 }
84 
85 
86 /**
87  * @} end of BoolDist group
88  */
89 
90 /**
91  * @} end of groupDistance group
92  */
93