Changeset: fa5bedf47134 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fa5bedf47134 Modified Files: monetdb5/extras/pyapi/Tests/pyapi00.malC monetdb5/extras/pyapi/pyapi.c Branch: pyapi Log Message:
Python API: Full circle and first test output diffs (87 lines): diff --git a/monetdb5/extras/pyapi/Tests/pyapi00.malC b/monetdb5/extras/pyapi/Tests/pyapi00.malC --- a/monetdb5/extras/pyapi/Tests/pyapi00.malC +++ b/monetdb5/extras/pyapi/Tests/pyapi00.malC @@ -1,18 +1,18 @@ b:= bat.new(:oid,:int); -bat.append(b,1804289383); -bat.append(b,846930886); -bat.append(b,1681692777); -bat.append(b,1714636915); -bat.append(b,1957747793); -bat.append(b,424238335); -bat.append(b,719885386); -bat.append(b,1649760492); -bat.append(b,596516649); -bat.append(b,1189641421); +bat.append(b, 42); +bat.append(b, 43); +bat.append(b, 44); +bat.append(b, 45); +bat.append(b, 46); +bat.append(b, 47); +bat.append(b, 48); +bat.append(b, 49); +bat.append(b, 50); +bat.append(b, 51); io.print(b); -r:bat[:oid,:int] := pyapi.eval(nil:ptr,"r=[e**2 for e in arg1]\nreturn ([numpy.asarray(r)])",b); +r:bat[:oid,:int] := pyapi.eval(nil:ptr, "r=[e+1 for e in arg1]\nreturn ([r])", b); io.print(r); diff --git a/monetdb5/extras/pyapi/pyapi.c b/monetdb5/extras/pyapi/pyapi.c --- a/monetdb5/extras/pyapi/pyapi.c +++ b/monetdb5/extras/pyapi/pyapi.c @@ -250,7 +250,7 @@ str PyAPIeval(MalBlkPtr mb, MalStkPtr st } #ifdef _PYAPI_DEBUG_ - printf("# Actual Python function definition: %s\n",pycall); + printf("Actual Python function definition: \n%s\n", pycall); #endif { @@ -278,6 +278,7 @@ str PyAPIeval(MalBlkPtr mb, MalStkPtr st goto wrapup; // shudder } + // TODO: handle the case where only a single array is returned (nice to have) if (!pResult || !PyList_Check(pResult) || PyList_Size(pResult) != pci->retc) { msg = createException(MAL, "pyapi.eval", "Invalid result object. Need list of size %d containing numpy arrays", pci->retc); goto wrapup; @@ -293,28 +294,24 @@ str PyAPIeval(MalBlkPtr mb, MalStkPtr st switch (bat_type) { case TYPE_int: { - int *p; BUN j; // this only copies if it has to PyArrayObject* pCol = (PyArrayObject*) PyArray_FromAny(pColO, PyArray_DescrFromType(NPY_INT32), 1, 1, NPY_ARRAY_CARRAY | NPY_ARRAY_FORCECAST, NULL); - //size_t cnt = pCol->dimensions[0]; - size_t cnt = 5; - // TODO: get actual length from array + size_t cnt = PyArray_DIMS(pCol)[0]; // TODO null rewriting, we are guaranteed to be able to write to this - // TODO: only accepted masked array as output? - // TODO check whether the length of our output /* We would like to simply pass over the BAT from numpy, * but cannot due to malloc/free incompatibility */ + b = BATnew(TYPE_void, TYPE_int, cnt, TRANSIENT); BATseqbase(b, 0); b->T->nil = 0; b->T->nonil = 1; b->tkey = 0; b->tsorted = 0; b->trevsorted = 0; - p = (int*) Tloc(b, BUNfirst(b)); \ - for( j =0; j< cnt; j++, p++){ - *p = (int) PyArray_GETPTR1(pCol, j); + for( j =0; j< cnt; j++){ + ((int*) Tloc(b, BUNfirst(b)))[j] = *(int*) PyArray_GETPTR1(pCol, j); } + BATsetcount(b, cnt); break; } // TODO: implement other types _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list