changeset 743:63a75a2b5fa6

Added insert featureData and powerData from numpy ndarray pathway
author mas01mc
date Tue, 09 Nov 2010 08:21:49 +0000
parents 040f14b5a5fc
children 124ae047b968
files bindings/python/README.txt bindings/python/pyadb.py bindings/python/pyadbmodule.c
diffstat 3 files changed, 23 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/bindings/python/README.txt	Wed Sep 22 15:56:14 2010 +0000
+++ b/bindings/python/README.txt	Tue Nov 09 08:21:49 2010 +0000
@@ -13,4 +13,10 @@
 
 
 
-Updated 23 June 2009, Ben Fields, b.fields@gold.ac.uk
\ No newline at end of file
+Updated 23 June 2009, Ben Fields, b.fields@gold.ac.uk
+
+
+NOTES AND COMMENTS (mcasey@dartmouth.edu)
+
+* how to apply L2norm to a database: make default behaviour
+* query behaviour without L2norm doesn't seem right
--- a/bindings/python/pyadb.py	Wed Sep 22 15:56:14 2010 +0000
+++ b/bindings/python/pyadb.py	Tue Nov 09 08:21:49 2010 +0000
@@ -54,10 +54,10 @@
 		"""
 		#While python style normally advocates leaping before looking, these check are nessecary as 
 		#it is very difficult to assertain why the insertion failed once it has been called.
-		if (self.hasPower and (((featFile) and powerFile==None) or ((featData) and powerData==None))):
+		if (self.hasPower and (((featFile) and powerFile==None) or ((not featData==None) and powerData==None))):
 			raise(Usage, "The db you are attempting an insert on (%s) expects power and you either\
  haven't provided any or have done so in the wrong format."%self.path)
-		if (self.hasTimes and (((timesFile) and timesFile==None) or ((timesData) and timesData==None))):
+		if (self.hasTimes and (((timesFile) and timesFile==None) or ((not timesData==None) and timesData==None))):
 			raise(Usage, "The db you are attempting an insert on (%s) expects times and you either\
  haven't provided any or have done so in the wrong format."%self.path)
 		args = {"db":self._db}
@@ -70,12 +70,12 @@
 		if self.hasPower:
 			if featFile:
 				args["power"]=powerFile
-			elif featData:
-				pass
+			elif featData.any():
+				args["power"]=powerData
 		if self.hasTimes:
 			if featFile:
 				args["times"]=timesFile
-			elif timesData:
+			elif timesData.any():
 				pass
 		if key:
 			args["key"]=str(key)
@@ -86,9 +86,14 @@
 				self._updateDBAttributes()
 				return
 		elif (featData != None):
-			if (len(args["features"].shape) == 1) : args["features"] = args["features"].reshape((args["features"].shape[0],1))
+			if (len(args["features"].shape) == 1) : 
+				args["features"] = args["features"].reshape((args["features"].shape[0],1))
 			args["nVect"], args["nDim"] = args["features"].shape
 			args["features"] = args["features"].flatten()
+			if(powerData != None):
+				if (len(args["power"].shape) == 1) : 
+					args["power"] = args["power"].reshape((args["power"].shape[0],1))
+				args["power"] = args["power"].flatten()
 			print "args: " + str(args)
 			ok = _pyadb._pyadb_insertFromArray(**args)
 			if not (ok==0):
--- a/bindings/python/pyadbmodule.c	Wed Sep 22 15:56:14 2010 +0000
+++ b/bindings/python/pyadbmodule.c	Tue Nov 09 08:21:49 2010 +0000
@@ -160,7 +160,10 @@
 	static char *kwlist[]  = { "db", "features", "nDim", "nVect", "power", "key", "times" , NULL};
 	
 	ok =  PyArg_ParseTupleAndKeywords(args, keywds, "OO!II|O!sO!", kwlist, &incoming, &PyArray_Type, &features, &nDims, &nVect, &PyArray_Type,  &power, &key, &PyArray_Type, &times);
-	if (!ok){return NULL;}
+	if (!ok){
+	  PyErr_SetString(PyExc_TypeError, "Failed at PyArg_ParseTupleAndKeywords");
+	  return NULL;
+	}
 	//check our arrays
 	// if (!PyArray_Check(features)){
 	// 	PyErr_SetString(PyExc_TypeError, "features must be a numpy array (of floats or doubles)");
@@ -186,7 +189,7 @@
 			return NULL;
 		}
 		// power = (PyArrayObject *)PyCObject_AsVoidPtr(incomingPow);
-		if (PyArray_NDIM(features) != 1 || PyArray_DIMS(power)[0] == nVect){
+		if (PyArray_NDIM(features) != 1 || PyArray_DIMS(power)[0] != nVect){
 			PyErr_SetString(PyExc_ValueError, "power, if given must be a 1d numpy array with shape =  (numVectors,)");
 			return NULL;
 		}