From b792446cc927866093304463b81b9e29b8d653fc Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Sat, 11 Jan 2020 17:25:36 -0800 Subject: [PATCH] Move from long double to flaot Signed-off-by: James Ketrenos --- scanner/json2db.c | 18 +++++++++--------- scanner/scanner.c | 7 +------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/scanner/json2db.c b/scanner/json2db.c index 319182a..2d44e42 100644 --- a/scanner/json2db.c +++ b/scanner/json2db.c @@ -15,17 +15,17 @@ #endif typedef struct Face { - long double descriptor[128]; + float descriptor[128]; long int clusterId; long faceId; long photoId; - double confidence; - double *distances; + float confidence; + float *distances; } Face; typedef struct FaceLink { struct FaceLink *pNext; - long double distance; + float distance; Face *pFace; } FaceLink; @@ -56,7 +56,7 @@ Face *readFaceDescriptor(Face *pFace, long id, char *path) { break; } *p++ = 0; - sscanf(start, "%Lf", &pFace->descriptor[i]); + sscanf(start, "%f", &pFace->descriptor[i]); } if (i != 128) { @@ -68,7 +68,7 @@ Face *readFaceDescriptor(Face *pFace, long id, char *path) { return pFace; } -int insert_descriptors(sqlite3 *db, long int faceId, long double descriptor[128]) { +int insert_descriptors(sqlite3 *db, long int faceId, float descriptor[128]) { char sql_buf[1024]; int rc; @@ -82,7 +82,7 @@ int insert_descriptors(sqlite3 *db, long int faceId, long double descriptor[128] } // Bind a block of zeros the size of the file we're going to insert later - sqlite3_bind_zeroblob(insert_stmt, 1, sizeof(long double) * 128); + sqlite3_bind_zeroblob(insert_stmt, 1, sizeof(float) * 128); if (SQLITE_DONE != (rc = sqlite3_step(insert_stmt))) { fprintf(stderr, "Insert statement didn't work (%i): %s\n", rc, sqlite3_errmsg(db)); return rc; @@ -99,7 +99,7 @@ int insert_descriptors(sqlite3 *db, long int faceId, long double descriptor[128] return rc; } - if(SQLITE_OK != (rc = sqlite3_blob_write(blob, descriptor, 128 * sizeof(*descriptor), 0))) { + if(SQLITE_OK != (rc = sqlite3_blob_write(blob, descriptor, 128 * sizeof(float), 0))) { fprintf(stderr, "Error writing to blob handle.\n"); return rc; } @@ -121,7 +121,7 @@ int main(int argc, char *argv[]) { long i; long entries = 0; long int minPts = MIN_PTS; - long double maxDistance = MAX_DISTANCE; + float maxDistance = MAX_DISTANCE; char sqlBuf[1024]; if (argc == 1) { diff --git a/scanner/scanner.c b/scanner/scanner.c index 1c797ce..4cfb694 100644 --- a/scanner/scanner.c +++ b/scanner/scanner.c @@ -265,16 +265,11 @@ int parseFaceDescriptor(void *data, int argc, char **argv, char **column) { return rc; } - long double vector[128]; - if (SQLITE_OK != (rc = sqlite3_blob_read(blob, vector, sizeof(vector), 0))) { + if (SQLITE_OK != (rc = sqlite3_blob_read(blob, pFace->descriptor, sizeof(pFace->descriptor), 0))) { fprintf(stderr, "Error reading from blob handle.\n"); return rc; } - for (int i = 0; i < 128; i++) { - pFace->descriptor[i] = vector[i]; - } - sqlite3_blob_close(blob); return SQLITE_OK;