Mercurial > hg > audiodb
changeset 718:14568e432e73
segfaults are gone, but the new bits still aren't quite behaving correctly.
Also, some weird behavior when the query result is blank
author | map01bf |
---|---|
date | Thu, 24 Jun 2010 16:38:32 +0000 |
parents | 159becb0701e |
children | e3f1cf653c30 |
files | bindings/python/pyadbmodule.c bindings/python/tests/InitialisationRelated.py |
diffstat | 2 files changed, 23 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/bindings/python/pyadbmodule.c Wed Jun 23 17:52:30 2010 +0000 +++ b/bindings/python/pyadbmodule.c Thu Jun 24 16:38:32 2010 +0000 @@ -152,20 +152,20 @@ unsigned int nDims = 0; unsigned int nVect = 0; PyObject *incoming = 0; - PyObject *features = NULL; - PyObject *power = NULL; + PyArrayObject *features = 0; + PyArrayObject *power = 0; + PyArrayObject *times = 0; const char *key = NULL; - PyObject *times = NULL; PyArray_Descr *descr; static char *kwlist[] = { "db", "features", "nDim", "nVect", "power", "key", "times" , NULL}; - ok = PyArg_ParseTupleAndKeywords(args, keywds, "OOII|OsO", kwlist, &incoming, &features, &nDims, &nVect, &power, &key, ×); + ok = PyArg_ParseTupleAndKeywords(args, keywds, "OO!II|O!sO!", kwlist, &incoming, &PyArray_Type, &features, &nDims, &nVect, &PyArray_Type, &power, &key, &PyArray_Type, ×); if (!ok){return NULL;} //check our arrays - if (!PyArray_Check(features)){ - PyErr_SetString(PyExc_TypeError, "features must be a numpy array (of floats or doubles)"); - return NULL; - } + // if (!PyArray_Check(features)){ + // PyErr_SetString(PyExc_TypeError, "features must be a numpy array (of floats or doubles)"); + // return NULL; + // } if (!PyArray_ISFLOAT(features)){ PyErr_SetString(PyExc_TypeError, "features numpy array must contain floats or doubles"); return NULL; @@ -211,20 +211,20 @@ //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(&features, &(ins->data), dims, 1, descr)){ PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the feature np array as a C array."); return NULL; } - if (power != NULL){ - if (!PyArray_AsCArray(&power, ins->power, dims, 1, descr)){ + if (power){ + if (!PyArray_AsCArray(&power, &(ins->power), dims, 1, descr)){ PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the power np array as a C array."); return NULL; } } - if (power != NULL){ - if (!PyArray_AsCArray(×, ins->times, dims, 1, descr)){ + if (times){ + if (!PyArray_AsCArray(×, &(ins->times), dims, 1, descr)){ PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the times np array as a C array."); return NULL; } @@ -326,8 +326,8 @@ "relThres", "durRatio", "hopSize", - "resFmt", - NULL + "resFmt", + NULL }; spec = (adb_query_spec_t *)malloc(sizeof(adb_query_spec_t)); spec->qid.datum = (adb_datum_t *)malloc(sizeof(adb_datum_t)); @@ -458,7 +458,7 @@ } result = audiodb_query_spec(current_db, spec); if (result == NULL){ - PyErr_SetString(PyExc_RuntimeError, "Encountered an error while running the actual query.\n"); + PyErr_SetString(PyExc_RuntimeError, "Encountered an error while running the actual query, or there was nothing returned.\n"); return NULL; } if(strcmp(resFmt, "dict")==0){ @@ -562,7 +562,9 @@ { "_pyadb_power", _pyadb_power, METH_VARARGS, "_pyadb_power(adb_t *)->int return code (0 for sucess)"}, {"_pyadb_insertFromArray", (PyCFunction)_pyadb_insertFromArray, METH_VARARGS | METH_KEYWORDS, - "insert feature data from a numpy array\n\ + "_pyadb_insertFromArray(adb_t *, features=ndarray, [power=ndarray | key=keystring | times=ndarray])->\ + int return code (0 for sucess)\n\ + insert feature data from a numpy array\n\ array given should have ndarray.shape = (numDims*numVectors,)\n\ array datatype needs to be doubles (float may work...)\n\ if power is given, must be 1d array of length numVectors\n\ @@ -602,8 +604,8 @@ void init_pyadb() { - Py_InitModule3("_pyadb", _pyadbMethods, "internal c bindings for audioDB. Use pyadb for pythonic access to adb (when it exists)."); - // import_array(); + Py_InitModule3("_pyadb", _pyadbMethods, "internal c bindings for audioDB. Use pyadb for pythonic access to adb."); + import_array(); return; }
--- a/bindings/python/tests/InitialisationRelated.py Wed Jun 23 17:52:30 2010 +0000 +++ b/bindings/python/tests/InitialisationRelated.py Thu Jun 24 16:38:32 2010 +0000 @@ -33,7 +33,7 @@ tH = open("testfeature", 'w') tH.write(struct.pack("=id",1,1)) tH.close() - self.adb.insert("testfeature") + self.adb.insert("testfeature", key='testfeature') self.adb.configQuery["seqLength"] = 1 result = self.adb.query("testfeature") self.assert_(len(result.rawData) == 1) @@ -42,7 +42,7 @@ self.assert_(result.rawData["testfeature"][0] == (float("-inf"), 0,0)) os.remove(self.adb.path)#delete the db def test_1DinsertionFromArraySelfQuery(self): - test1 = np.ones(6) + test1 = np.ones(1) print "test1: " + str(test1) self.adb.insert(featData=test1, key="testfeature") self.adb.configQuery["seqLength"] = 1