changeset 757:ee612b7bd922 mkc_lsh_update

added queryFromData(), passes equivalence test with queryFromKey
author mas01mc
date Fri, 26 Nov 2010 08:05:48 +0000
parents 9b75573be3b9
children be4fa5716df5
files bindings/python/pyadbmodule.c
diffstat 1 files changed, 8 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/bindings/python/pyadbmodule.c	Fri Nov 26 06:58:55 2010 +0000
+++ b/bindings/python/pyadbmodule.c	Fri Nov 26 08:05:48 2010 +0000
@@ -218,13 +218,13 @@
 	//verify that the data to be inserted is the correct size for the database.
 	
 	ins = (adb_datum_t *)malloc(sizeof(adb_datum_t));
-	if (PyArray_AsCArray(&features, &(ins->data), dims,  1, descr)){
+	if (PyArray_AsCArray((PyObject**)&features, &(ins->data), dims,  1, descr)){
 		PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the feature np array as a C array.");
 		return NULL;
 	}
 	
 	if (power){
-		if (PyArray_AsCArray(&power, &(ins->power), dims,  1, descr)){
+	  if (PyArray_AsCArray((PyObject**)&power, &(ins->power), dims,  1, descr)){
 			PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the power np array as a C array.");
 			return NULL;
 		}
@@ -233,7 +233,7 @@
 	}
 	
 	if (times){
-		if (PyArray_AsCArray(&times, &(ins->times), dims,  1, descr)){
+	  if (PyArray_AsCArray((PyObject**)&times, &(ins->times), dims,  1, descr)){
 			PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the times np array as a C array.");
 			return NULL;
 		}
@@ -607,13 +607,11 @@
 	PyObject *thisKey = NULL;
 	PyObject *currentValue = NULL;
 	PyObject *newBits = NULL;
-	npy_intp dims[2];
 	unsigned int nDims = 0;
 	unsigned int nVect = 0;
 	PyArrayObject *features = NULL;
 	PyArrayObject *power = NULL;
 	PyArrayObject *times = NULL;
-	PyArray_Descr *descr;
 	adb_status_t *status;
 
 	static char *kwlist[]  = { "db", "features", 
@@ -722,7 +720,6 @@
 	}
 
 	free(status);
-
 	
 	if (exhaustive){
 		spec->qid.flags = spec->qid.flags | ADB_QID_FLAG_EXHAUSTIVE;
@@ -815,27 +812,16 @@
 		spec->refine.ihopsize = hop;
 	}
 
-	descr = PyArray_DescrFromType(NPY_DOUBLE);
-
-	if (PyArray_AsCArray(&features, &(spec->qid.datum->data), dims, PyArray_NDIM(features), descr)){
-	  PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the feature np array as a C array.");
-	  return NULL;
-	}
+	spec->qid.datum->data = (double*) features->data;
 	
 	if (power){
-	  if (PyArray_AsCArray(&power, &(spec->qid.datum->power), dims,  1, descr)){
-	    PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the power np array as a C array.");
-	    return NULL;
-	  }
+	  spec->qid.datum->power = (double*) power->data;
 	}else{
 	  spec->qid.datum->power=NULL;
 	}
 	
 	if (times){
-	  if (PyArray_AsCArray(&times, &(spec->qid.datum->times), dims,  1, descr)){
-	    PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the times np array as a C array.");
-	    return NULL;
-	  }
+	  spec->qid.datum->times = (double*) times->data;
 	}else{
 	  spec->qid.datum->times=NULL;
 	}
@@ -847,7 +833,6 @@
 
 	result = audiodb_query_spec(current_db, spec);
 
-
 	if (result == NULL){
 		PyErr_SetString(PyExc_RuntimeError, "Encountered an error while running the actual query, or there was nothing returned.\n");
 		return NULL;
@@ -957,7 +942,7 @@
 	PyObject *outgoing = 0; // The PyArrayObject
 	const char *key = NULL;
 	static char *kwlist[]  = { "db", "key", "features", "powers", "times", NULL};
-	double * data;
+	double * data = NULL;
 	int dims = 0;
 	npy_intp shape[2] = { 0, 0 };	
 
@@ -1128,7 +1113,7 @@
 	{NULL,NULL, 0, NULL}
 };
 
-void init_pyadb()
+void init_pyadb(void)
 {
 	Py_InitModule3("_pyadb", _pyadbMethods, "internal c bindings for audioDB.  Use pyadb for pythonic access to adb.");
 	import_array();