diff options
Diffstat (limited to 'test/mtdev-matching.c')
| -rw-r--r-- | test/mtdev-matching.c | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/test/mtdev-matching.c b/test/mtdev-matching.c new file mode 100644 index 0000000..dc68994 --- /dev/null +++ b/test/mtdev-matching.c | |||
| @@ -0,0 +1,141 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * mtdev - Multitouch Protocol Translation Library (MIT license) | ||
| 4 | * | ||
| 5 | * Copyright (C) 2010 Henrik Rydberg <rydberg@euromail.se> | ||
| 6 | * Copyright (C) 2010 Canonical Ltd. | ||
| 7 | * | ||
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a | ||
| 9 | * copy of this software and associated documentation files (the "Software"), | ||
| 10 | * to deal in the Software without restriction, including without limitation | ||
| 11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
| 12 | * and/or sell copies of the Software, and to permit persons to whom the | ||
| 13 | * Software is furnished to do so, subject to the following conditions: | ||
| 14 | * | ||
| 15 | * The above copyright notice and this permission notice (including the next | ||
| 16 | * paragraph) shall be included in all copies or substantial portions of the | ||
| 17 | * Software. | ||
| 18 | * | ||
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
| 22 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| 24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| 25 | * DEALINGS IN THE SOFTWARE. | ||
| 26 | * | ||
| 27 | ****************************************************************************/ | ||
| 28 | |||
| 29 | #include <src/match.h> | ||
| 30 | #include <stdio.h> | ||
| 31 | #include <time.h> | ||
| 32 | |||
| 33 | #define ITS 1000000 | ||
| 34 | |||
| 35 | static void test1() | ||
| 36 | { | ||
| 37 | int A[] = { | ||
| 38 | 1013, | ||
| 39 | 3030660, | ||
| 40 | 3559354, | ||
| 41 | 12505925, | ||
| 42 | 19008450, | ||
| 43 | 6946421, | ||
| 44 | 6118613, | ||
| 45 | 698020, | ||
| 46 | 3021800, | ||
| 47 | 1017, | ||
| 48 | 37573, | ||
| 49 | 3242018, | ||
| 50 | 8152794, | ||
| 51 | 1266053, | ||
| 52 | 942941, | ||
| 53 | 462820, | ||
| 54 | }; | ||
| 55 | int index[DIM_FINGER], i; | ||
| 56 | mtdev_match(index, A, 4, 4); | ||
| 57 | for (i = 0; i < 4; i++) | ||
| 58 | printf("match[%d] = %d\n", i, index[i]); | ||
| 59 | } | ||
| 60 | |||
| 61 | static void test2() | ||
| 62 | { | ||
| 63 | int A[] = { | ||
| 64 | 0, | ||
| 65 | 4534330, | ||
| 66 | 22653552, | ||
| 67 | 12252500, | ||
| 68 | 685352, | ||
| 69 | 4534330, | ||
| 70 | 0, | ||
| 71 | 9619317, | ||
| 72 | 28409530, | ||
| 73 | 6710170, | ||
| 74 | 22653552, | ||
| 75 | 9619317, | ||
| 76 | 0, | ||
| 77 | 47015292, | ||
| 78 | 29788572, | ||
| 79 | 2809040, | ||
| 80 | 10428866, | ||
| 81 | 38615920, | ||
| 82 | 17732500, | ||
| 83 | 719528, | ||
| 84 | 12113945, | ||
| 85 | 28196220, | ||
| 86 | 46778656, | ||
| 87 | 405, | ||
| 88 | 14175493, | ||
| 89 | }; | ||
| 90 | int index[DIM_FINGER], i; | ||
| 91 | mtdev_match(index, A, 5, 5); | ||
| 92 | for (i = 0; i < 5; i++) | ||
| 93 | printf("match[%d] = %d\n", i, index[i]); | ||
| 94 | } | ||
| 95 | |||
| 96 | static void speed1() | ||
| 97 | { | ||
| 98 | /* column-by-column matrix */ | ||
| 99 | int A[DIM2_FINGER]; | ||
| 100 | int x1[DIM_FINGER] = { 1, 5, 2, 3, 4, 5, 6, 7, 8 }; | ||
| 101 | int y1[DIM_FINGER] = { 1, 5, 2, 3, 4, 6, 6, 7, 8 }; | ||
| 102 | int x2[DIM_FINGER] = { 1.1, 3, 2, 4, 5, 6, 7, 8 }; | ||
| 103 | int y2[DIM_FINGER] = { 1, 3, 2, 4, 5, 6, 7, 8 }; | ||
| 104 | int index[DIM_FINGER]; | ||
| 105 | int n1 = 4; | ||
| 106 | int n2 = 7; | ||
| 107 | |||
| 108 | int i, j; | ||
| 109 | |||
| 110 | for (i = 0; i < n1; i++) { | ||
| 111 | for (j = 0; j < n2; j++) { | ||
| 112 | A[i + n1 * j] = | ||
| 113 | (x1[i] - x2[j]) * (x1[i] - x2[j]) + | ||
| 114 | (y1[i] - y2[j]) * (y1[i] - y2[j]); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | clock_t t1 = clock(); | ||
| 119 | for (i = 0; i < ITS; i++) | ||
| 120 | mtdev_match(index, A, n1, n2); | ||
| 121 | clock_t t2 = clock(); | ||
| 122 | |||
| 123 | printf("%lf matches per second\n", | ||
| 124 | ITS * ((float)CLOCKS_PER_SEC / (t2 - t1))); | ||
| 125 | |||
| 126 | for (i = 0; i < n1; i++) | ||
| 127 | printf("match[%d] = %d\n", i, index[i]); | ||
| 128 | |||
| 129 | } | ||
| 130 | |||
| 131 | int main(int argc, char *argv[]) | ||
| 132 | { | ||
| 133 | printf("test1\n"); | ||
| 134 | test1(); | ||
| 135 | printf("test2\n"); | ||
| 136 | test2(); | ||
| 137 | printf("speed1\n"); | ||
| 138 | speed1(); | ||
| 139 | printf("done\n"); | ||
| 140 | return 0; | ||
| 141 | } | ||
