Mercurial > hg > audiodb
comparison bindings/python/pyadbmodule.c @ 758:9d32eea0cd78
added queryFromData(), passes equivalence test with queryFromKey
author | mas01mc |
---|---|
date | Fri, 26 Nov 2010 08:06:11 +0000 |
parents | 98d2e1de11bb |
children | b9dbe4611dde |
comparison
equal
deleted
inserted
replaced
751:98d2e1de11bb | 758:9d32eea0cd78 |
---|---|
216 current_db = (adb_t *)PyCObject_AsVoidPtr(incoming); | 216 current_db = (adb_t *)PyCObject_AsVoidPtr(incoming); |
217 status = (adb_status_t *)malloc(sizeof(adb_status_t)); | 217 status = (adb_status_t *)malloc(sizeof(adb_status_t)); |
218 //verify that the data to be inserted is the correct size for the database. | 218 //verify that the data to be inserted is the correct size for the database. |
219 | 219 |
220 ins = (adb_datum_t *)malloc(sizeof(adb_datum_t)); | 220 ins = (adb_datum_t *)malloc(sizeof(adb_datum_t)); |
221 if (PyArray_AsCArray(&features, &(ins->data), dims, 1, descr)){ | 221 if (PyArray_AsCArray((PyObject**)&features, &(ins->data), dims, 1, descr)){ |
222 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the feature np array as a C array."); | 222 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the feature np array as a C array."); |
223 return NULL; | 223 return NULL; |
224 } | 224 } |
225 | 225 |
226 if (power){ | 226 if (power){ |
227 if (PyArray_AsCArray(&power, &(ins->power), dims, 1, descr)){ | 227 if (PyArray_AsCArray((PyObject**)&power, &(ins->power), dims, 1, descr)){ |
228 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the power np array as a C array."); | 228 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the power np array as a C array."); |
229 return NULL; | 229 return NULL; |
230 } | 230 } |
231 }else{ | 231 }else{ |
232 ins->power=NULL; | 232 ins->power=NULL; |
233 } | 233 } |
234 | 234 |
235 if (times){ | 235 if (times){ |
236 if (PyArray_AsCArray(×, &(ins->times), dims, 1, descr)){ | 236 if (PyArray_AsCArray((PyObject**)×, &(ins->times), dims, 1, descr)){ |
237 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the times np array as a C array."); | 237 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the times np array as a C array."); |
238 return NULL; | 238 return NULL; |
239 } | 239 } |
240 }else{ | 240 }else{ |
241 ins->times=NULL; | 241 ins->times=NULL; |
605 PyObject *incoming = NULL; | 605 PyObject *incoming = NULL; |
606 PyObject *outgoing = NULL; | 606 PyObject *outgoing = NULL; |
607 PyObject *thisKey = NULL; | 607 PyObject *thisKey = NULL; |
608 PyObject *currentValue = NULL; | 608 PyObject *currentValue = NULL; |
609 PyObject *newBits = NULL; | 609 PyObject *newBits = NULL; |
610 npy_intp dims[2]; | |
611 unsigned int nDims = 0; | 610 unsigned int nDims = 0; |
612 unsigned int nVect = 0; | 611 unsigned int nVect = 0; |
613 PyArrayObject *features = NULL; | 612 PyArrayObject *features = NULL; |
614 PyArrayObject *power = NULL; | 613 PyArrayObject *power = NULL; |
615 PyArrayObject *times = NULL; | 614 PyArrayObject *times = NULL; |
616 PyArray_Descr *descr; | |
617 adb_status_t *status; | 615 adb_status_t *status; |
618 | 616 |
619 static char *kwlist[] = { "db", "features", | 617 static char *kwlist[] = { "db", "features", |
620 "seqLength", | 618 "seqLength", |
621 "seqStart", | 619 "seqStart", |
720 free(status); | 718 free(status); |
721 return NULL; | 719 return NULL; |
722 } | 720 } |
723 | 721 |
724 free(status); | 722 free(status); |
725 | |
726 | 723 |
727 if (exhaustive){ | 724 if (exhaustive){ |
728 spec->qid.flags = spec->qid.flags | ADB_QID_FLAG_EXHAUSTIVE; | 725 spec->qid.flags = spec->qid.flags | ADB_QID_FLAG_EXHAUSTIVE; |
729 } | 726 } |
730 if (falsePositives){ | 727 if (falsePositives){ |
813 /* not ideal but a temporary bandage fix */ | 810 /* not ideal but a temporary bandage fix */ |
814 spec->refine.qhopsize = hop; | 811 spec->refine.qhopsize = hop; |
815 spec->refine.ihopsize = hop; | 812 spec->refine.ihopsize = hop; |
816 } | 813 } |
817 | 814 |
818 descr = PyArray_DescrFromType(NPY_DOUBLE); | 815 spec->qid.datum->data = (double*) features->data; |
819 | |
820 if (PyArray_AsCArray(&features, &(spec->qid.datum->data), dims, 2, descr)){ | |
821 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the feature np array as a C array."); | |
822 return NULL; | |
823 } | |
824 | 816 |
825 if (power){ | 817 if (power){ |
826 if (PyArray_AsCArray(&power, &(spec->qid.datum->power), dims, 1, descr)){ | 818 spec->qid.datum->power = (double*) power->data; |
827 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the power np array as a C array."); | |
828 return NULL; | |
829 } | |
830 }else{ | 819 }else{ |
831 spec->qid.datum->power=NULL; | 820 spec->qid.datum->power=NULL; |
832 } | 821 } |
833 | 822 |
834 if (times){ | 823 if (times){ |
835 if (PyArray_AsCArray(×, &(spec->qid.datum->times), dims, 1, descr)){ | 824 spec->qid.datum->times = (double*) times->data; |
836 PyErr_SetString(PyExc_RuntimeError, "Trouble expressing the times np array as a C array."); | |
837 return NULL; | |
838 } | |
839 }else{ | 825 }else{ |
840 spec->qid.datum->times=NULL; | 826 spec->qid.datum->times=NULL; |
841 } | 827 } |
842 | 828 |
843 nVect = PyArray_DIMS(features)[0]; | 829 nVect = PyArray_DIMS(features)[0]; |
954 unsigned features=0, powers=0, times=0; | 940 unsigned features=0, powers=0, times=0; |
955 PyObject *incoming = 0; // The ADB database | 941 PyObject *incoming = 0; // The ADB database |
956 PyObject *outgoing = 0; // The PyArrayObject | 942 PyObject *outgoing = 0; // The PyArrayObject |
957 const char *key = NULL; | 943 const char *key = NULL; |
958 static char *kwlist[] = { "db", "key", "features", "powers", "times", NULL}; | 944 static char *kwlist[] = { "db", "key", "features", "powers", "times", NULL}; |
959 double * data; | 945 double * data = NULL; |
960 int dims = 0; | 946 int dims = 0; |
961 npy_intp shape[2] = { 0, 0 }; | 947 npy_intp shape[2] = { 0, 0 }; |
962 | 948 |
963 ok = PyArg_ParseTupleAndKeywords(args, keywds, "Os|III", kwlist, &incoming, &key, &features, &powers, ×); | 949 ok = PyArg_ParseTupleAndKeywords(args, keywds, "Os|III", kwlist, &incoming, &key, &features, &powers, ×); |
964 if (!ok){ | 950 if (!ok){ |
1125 {"_pyadb_queryFromData", (PyCFunction)_pyadb_queryFromData, METH_VARARGS | METH_KEYWORDS, | 1111 {"_pyadb_queryFromData", (PyCFunction)_pyadb_queryFromData, METH_VARARGS | METH_KEYWORDS, |
1126 "data query. Required features=F (numpy ndarray). Optional: power=P (numpy 1d array), times=T (numpy 1d array)"}, | 1112 "data query. Required features=F (numpy ndarray). Optional: power=P (numpy 1d array), times=T (numpy 1d array)"}, |
1127 {NULL,NULL, 0, NULL} | 1113 {NULL,NULL, 0, NULL} |
1128 }; | 1114 }; |
1129 | 1115 |
1130 void init_pyadb() | 1116 void init_pyadb(void) |
1131 { | 1117 { |
1132 Py_InitModule3("_pyadb", _pyadbMethods, "internal c bindings for audioDB. Use pyadb for pythonic access to adb."); | 1118 Py_InitModule3("_pyadb", _pyadbMethods, "internal c bindings for audioDB. Use pyadb for pythonic access to adb."); |
1133 import_array(); | 1119 import_array(); |
1134 return; | 1120 return; |
1135 } | 1121 } |