Move from long double to flaot

Signed-off-by: James Ketrenos <james_gitlab@ketrenos.com>
This commit is contained in:
James Ketrenos 2020-01-11 17:25:36 -08:00
parent f665ed0beb
commit b792446cc9
2 changed files with 10 additions and 15 deletions

View File

@ -15,17 +15,17 @@
#endif #endif
typedef struct Face { typedef struct Face {
long double descriptor[128]; float descriptor[128];
long int clusterId; long int clusterId;
long faceId; long faceId;
long photoId; long photoId;
double confidence; float confidence;
double *distances; float *distances;
} Face; } Face;
typedef struct FaceLink { typedef struct FaceLink {
struct FaceLink *pNext; struct FaceLink *pNext;
long double distance; float distance;
Face *pFace; Face *pFace;
} FaceLink; } FaceLink;
@ -56,7 +56,7 @@ Face *readFaceDescriptor(Face *pFace, long id, char *path) {
break; break;
} }
*p++ = 0; *p++ = 0;
sscanf(start, "%Lf", &pFace->descriptor[i]); sscanf(start, "%f", &pFace->descriptor[i]);
} }
if (i != 128) { if (i != 128) {
@ -68,7 +68,7 @@ Face *readFaceDescriptor(Face *pFace, long id, char *path) {
return pFace; 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]; char sql_buf[1024];
int rc; 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 // 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))) { if (SQLITE_DONE != (rc = sqlite3_step(insert_stmt))) {
fprintf(stderr, "Insert statement didn't work (%i): %s\n", rc, sqlite3_errmsg(db)); fprintf(stderr, "Insert statement didn't work (%i): %s\n", rc, sqlite3_errmsg(db));
return rc; return rc;
@ -99,7 +99,7 @@ int insert_descriptors(sqlite3 *db, long int faceId, long double descriptor[128]
return rc; 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"); fprintf(stderr, "Error writing to blob handle.\n");
return rc; return rc;
} }
@ -121,7 +121,7 @@ int main(int argc, char *argv[]) {
long i; long i;
long entries = 0; long entries = 0;
long int minPts = MIN_PTS; long int minPts = MIN_PTS;
long double maxDistance = MAX_DISTANCE; float maxDistance = MAX_DISTANCE;
char sqlBuf[1024]; char sqlBuf[1024];
if (argc == 1) { if (argc == 1) {

View File

@ -265,16 +265,11 @@ int parseFaceDescriptor(void *data, int argc, char **argv, char **column) {
return rc; return rc;
} }
long double vector[128]; if (SQLITE_OK != (rc = sqlite3_blob_read(blob, pFace->descriptor, sizeof(pFace->descriptor), 0))) {
if (SQLITE_OK != (rc = sqlite3_blob_read(blob, vector, sizeof(vector), 0))) {
fprintf(stderr, "Error reading from blob handle.\n"); fprintf(stderr, "Error reading from blob handle.\n");
return rc; return rc;
} }
for (int i = 0; i < 128; i++) {
pFace->descriptor[i] = vector[i];
}
sqlite3_blob_close(blob); sqlite3_blob_close(blob);
return SQLITE_OK; return SQLITE_OK;