Commits

Anonymous committed 622f083

check_pointer works!

Comments (0)

Files changed (2)

accesscarray/accesscarraymodule.c

   return Py_BuildValue("");  /* return None */
 }
 
+
 static PyObject *
 check_pointer(PyObject *dummy, PyObject *args)
 {
   int nd;
   PyObject *obj;
   char *data;
+  void *elem;
   int num_elem=0, num_missmatch=0;
 
   if (PyArg_ParseTuple(args, "O:check_pointer", &obj) < 0) {
   nd = PyArray_NDIM(obj);
   data = PyArray_BYTES(obj);
 
+  PySys_WriteStdout("Check elements: ");
   switch(nd){
   case 1:
     {
       int n0 = PyArray_DIM(obj,0);
       int i;
 
-      PySys_WriteStdout("Check stride 0: ");
-      if (PyArray_STRIDE(obj,0) == n0){
-	PySys_WriteStdout("ok\n");
-      }else{
-	  PySys_WriteStdout("fails\n");
-      }
-      PySys_WriteStdout("PyArray_STRIDE(obj,0) = %d, n0 = %d\n",
-			PyArray_STRIDE(obj,0), n0);
-      
-      PySys_WriteStdout("Check elements: ");
       for (i = 0; i < n0; ++i){
-	if (PyArray_GETPTR1(obj, i) == (void *)&data[i]){
+	if (PyArray_ISFLOAT(obj)){
+	  elem = (void *)&((double *)data)[i];
+	}else if (PyArray_ISINTEGER(obj)){
+	  elem = (void *)&((int *)data)[i];
+	}else{
+	  PySys_WriteStdout("Unknown data type\n");
+	  break;
+	}
+	
+	if (PyArray_GETPTR1(obj, i) == elem){
 	  PySys_WriteStdout(".");
 	}else{
 	  num_missmatch++;
       int n0 = PyArray_DIM(obj,0);
       int n1 = PyArray_DIM(obj,1);
       int i,j;
+
       for (i = 0; i < n0; ++i){
 	for (j = 0; j < n1; ++j){
-	  if (PyArray_GETPTR2(obj,i,j) == (void *)&data[i*n0+j]){
+	  if (PyArray_ISFLOAT(obj)){
+	    elem = (void *)&((double *)data)[i*n0+j];
+	  }else if (PyArray_ISINTEGER(obj)){
+	    elem = (void *)&((int *)data)[i*n0+j];
+	  }else{
+	    PySys_WriteStdout("Unknown data type\n");
+	    break;
+	  }
+
+	  if (PyArray_GETPTR2(obj,i,j) == elem){
 	    PySys_WriteStdout(".");
 	  }else{
 	    num_missmatch++;
       int n1 = PyArray_DIM(obj,1);
       int n2 = PyArray_DIM(obj,2);
       int i,j,k;
+
       for (i = 0; i < n0; ++i){
 	for (j = 0; j < n1; ++j){
 	  for (k = 0; k < n2; ++k){
-	    if (PyArray_GETPTR3(obj,i,j,k) == (void *)&data[i*n0*n1+j*n1+k]){
+	    if (PyArray_ISFLOAT(obj)){
+	      elem = (void *)&((double *)data)[i*n0*n1+j*n1+k];
+	    }else if (PyArray_ISINTEGER(obj)){
+	      elem = (void *)&((int *)data)[i*n0*n1+j*n1+k];
+	    }else{
+	      PySys_WriteStdout("Unknown data type\n");
+	      break;
+	    }
+
+	    if (PyArray_GETPTR3(obj,i,j,k) == elem){
 	      PySys_WriteStdout(".");
 	    }else{
 	      num_missmatch++;

accesscarray/check_pointer.py

 check_pointer(iaf1d)
 check_pointer(fac1d)
 check_pointer(faf1d)
-#check_pointer(fac2d)
-#check_pointer(faf2d)
-#check_pointer(fac3d)
+check_pointer(fac2d)
+check_pointer(faf2d)
+check_pointer(fac3d)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.