From 2d96d426e063a4c2c33cabf9c6ebf570db1fcf1b Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Nov 2008 22:00:50 +0100 Subject: culprit: step2a row should start at zero plus cleanup Signed-off-by: Henrik Rydberg --- match/match.c | 189 +++++++++++++++++++++++++++++----------------------------- match/match.h | 4 -- match/test.c | 44 +++++++++++++- 3 files changed, 137 insertions(+), 100 deletions(-) (limited to 'match') diff --git a/match/match.c b/match/match.c index 551e2f6..3c5ea0c 100644 --- a/match/match.c +++ b/match/match.c @@ -8,22 +8,25 @@ * modified by Henrik Rydberg (2008) */ -const float BIG_VALUE = 1e20; +typedef unsigned short col_t[1]; +typedef unsigned short mat_t[DIM_FINGER]; -typedef unsigned short col_t; +#define GET1(m, x) ((m[0]>>(x))&1U) +#define SET1(m, x) (m[0]|=(1U<<(x))) +#define CLEAR1(m, x) (m[0]&=~(1U<<(x))) -#define GETBIT2(m, row, col) ((m[col]>>(row))&1U) -#define SETBIT2(m, row, col) (m[col]|=(1U<<(row))) -#define CLEARBIT2(m, row, col) (m[col]&=~(1U<<(row))) +#define GET2(m, row, col) ((m[col]>>(row))&1U) +#define SET2(m, row, col) (m[col]|=(1U<<(row))) +#define CLEAR2(m, row, col) (m[col]&=~(1U<<(row))) /********************************************************/ -static void buildixvector(int *ix, col_t *mstar, int nrows, int ncols) +static void buildixvector(int *ix, mat_t mstar, int nrows, int ncols) { int row, col; for (row = 0; row < nrows; row++) { for (col = 0; col < ncols; col++) { - if (GETBIT2(mstar, row, col)) { + if (GET2(mstar, row, col)) { ix[row] = col; break; } @@ -34,24 +37,25 @@ static void buildixvector(int *ix, col_t *mstar, int nrows, int ncols) /********************************************************/ -static void step2a(int *ix, float *mdist, col_t *mstar, col_t *nmstar, col_t *mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin); -static void step2b(int *ix, float *mdist, col_t *mstar, col_t *nmstar, col_t *mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin); -static void step3 (int *ix, float *mdist, col_t *mstar, col_t *nmstar, col_t *mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin); -static void step4 (int *ix, float *mdist, col_t *mstar, col_t *nmstar, col_t *mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin, int row, int col); -static void step5 (int *ix, float *mdist, col_t *mstar, col_t *nmstar, col_t *mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin); +static void step2a(int *ix, float *mdist, mat_t mstar, mat_t nmstar, mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin); +static void step2b(int *ix, float *mdist, mat_t mstar, mat_t nmstar, mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin); +static void step3(int *ix, float *mdist, mat_t mstar, mat_t nmstar, mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin); +static void step4(int *ix, float *mdist, mat_t mstar, mat_t nmstar, mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin, int row, int col); +static void step5(int *ix, float *mdist, mat_t mstar, mat_t nmstar, mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols, int dmin); static void ixoptimal(int *ix, float *mdist, int nrows, int ncols) { float *mdistTemp, *mdistEnd, *columnEnd, value, minValue; int dmin, row, col; - col_t ccol,crow, mstar[DIM_FINGER],mprime[DIM_FINGER],nmstar[DIM_FINGER]; + col_t ccol, crow; + mat_t mstar, mprime, nmstar; - ccol = crow = 0; - memset(mstar, 0, sizeof(mstar)); - memset(mprime, 0, sizeof(mprime)); - memset(nmstar, 0, sizeof(nmstar)); + memset(ccol, 0, sizeof(col_t)); + memset(crow, 0, sizeof(col_t)); + memset(mstar, 0, sizeof(mat_t)); + memset(mprime, 0, sizeof(mat_t)); + memset(nmstar, 0, sizeof(mat_t)); - /* initialization */ for(row=0; row ncols) */ - { + } else { dmin = ncols; - for(col=0; col max) + max = A[i]; + for (i = 0; i < nrow * ncol; i++) + A[i] /= max; ixoptimal(ix, A, nrow, ncol); } diff --git a/match/match.h b/match/match.h index 03bf600..8936de4 100644 --- a/match/match.h +++ b/match/match.h @@ -13,10 +13,6 @@ #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) < (b) ? (b) : (a)) -#define GETBIT(m, x) ((m>>(x))&1U) -#define SETBIT(m, x) (m|=(1U<<(x))) -#define CLEARBIT(m, x) (m&=~(1U<<(x))) - typedef int bool; //////////////////////////////////////////////////////// diff --git a/match/test.c b/match/test.c index ad39370..1f535d1 100644 --- a/match/test.c +++ b/match/test.c @@ -24,8 +24,45 @@ static void test1() 942941.000000, 462820.000000, }; - int index[DIM_FINGER]; + int index[DIM_FINGER], i; match_fingers(index, A, 4, 4); + for (i = 0; i < 4; i++) + printf("match[%d] = %d\n", i, index[i]); +} + +static void test2() +{ + float A[]={ + 0.000000, + 4534330.000000, + 22653552.000000, + 12252500.000000, + 685352.000000, + 4534330.000000, + 0.000000, + 9619317.000000, + 28409530.000000, + 6710170.000000, + 22653552.000000, + 9619317.000000, + 0.000000, + 47015292.000000, + 29788572.000000, + 2809040.000000, + 10428866.000000, + 38615920.000000, + 17732500.000000, + 719528.000000, + 12113945.000000, + 28196220.000000, + 46778656.000000, + 405.000000, + 14175493.000000, + }; + int index[DIM_FINGER], i; + match_fingers(index, A, 5, 5); + for (i = 0; i < 5; i++) + printf("match[%d] = %d\n", i, index[i]); } static void speed1() @@ -65,7 +102,12 @@ static void speed1() int main(int argc,char* argv[]) { + printf("test1\n"); test1(); + printf("test2\n"); + test2(); + printf("speed1\n"); speed1(); + printf("done\n"); return 0; } -- cgit v1.2.3