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