Anonymous avatar Anonymous committed 4b8ac83

add index; print ndim

Comments (0)

Files changed (1)

accesscarray/accesscarraymodule.c

   PyObject *obj;
   char *data;
   void *elem;
+  int index;
   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: ");
+  PySys_WriteStdout("Check elements of %d-dim array: ", nd);
   switch(nd){
   case 1:
     {
       int i;
 
       for (i = 0; i < n0; ++i){
+	index = i;
+
 	if (PyArray_ISFLOAT(obj)){
-	  elem = (void *)&((double *)data)[i];
+	  elem = (void *)&((double *)data)[index];
 	}else if (PyArray_ISINTEGER(obj)){
-	  elem = (void *)&((int *)data)[i];
+	  elem = (void *)&((int *)data)[index];
 	}else{
 	  PySys_WriteStdout("Unknown data type\n");
 	  break;
 
       for (i = 0; i < n0; ++i){
 	for (j = 0; j < n1; ++j){
+	  index = i*n0 + j;
+
 	  if (PyArray_ISFLOAT(obj)){
-	    elem = (void *)&((double *)data)[i*n0+j];
+	    elem = (void *)&((double *)data)[index];
 	  }else if (PyArray_ISINTEGER(obj)){
-	    elem = (void *)&((int *)data)[i*n0+j];
+	    elem = (void *)&((int *)data)[index];
 	  }else{
 	    PySys_WriteStdout("Unknown data type\n");
 	    break;
       for (i = 0; i < n0; ++i){
 	for (j = 0; j < n1; ++j){
 	  for (k = 0; k < n2; ++k){
+	    index = i*n0*n1 + j*n1 + k;
+
 	    if (PyArray_ISFLOAT(obj)){
-	      elem = (void *)&((double *)data)[i*n0*n1+j*n1+k];
+	      elem = (void *)&((double *)data)[index];
 	    }else if (PyArray_ISINTEGER(obj)){
-	      elem = (void *)&((int *)data)[i*n0*n1+j*n1+k];
+	      elem = (void *)&((int *)data)[index];
 	    }else{
 	      PySys_WriteStdout("Unknown data type\n");
 	      break;
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.