1. Takafumi Arakaki
  2. Numpy Toy Box

Commits

Takafumi Arakaki  committed a423b2b

use PySys_WriteStdout; check stride

  • Participants
  • Parent commits a917c40
  • Branches default

Comments (0)

Files changed (2)

File accesscarray/accesscarraymodule.c

View file
     {
       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_GETPTR1(obj, i) == (void *)&data[i]){
+	  PySys_WriteStdout(".");
+	}else{
 	  num_missmatch++;
+	  PySys_WriteStdout("!");
 	}
 	num_elem++;
       }
       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_GETPTR2(obj,i,j) == (void *)&data[i*n0+j]){
+	    PySys_WriteStdout(".");
+	  }else{
 	    num_missmatch++;
+	    PySys_WriteStdout("!");
 	  }
 	  num_elem++;
 	}
       for (i = 0; i < n0; ++i){
 	for (j = 0; j < n1; ++j){
 	  for (k = 0; k < n2; ++k){
-	    if (PyArray_GETPTR1(obj, i) != (void *)&data[i*n0*n1+j*n1+k]){
+	    if (PyArray_GETPTR3(obj,i,j,k) == (void *)&data[i*n0*n1+j*n1+k]){
+	      PySys_WriteStdout(".");
+	    }else{
 	      num_missmatch++;
+	      PySys_WriteStdout("!");
 	    }
 	    num_elem++;
 	  }
     }
     break;
   }
-  //PySys_WriteStdout
-  printf("Missmatch: %.2f%% (%d/%d) \n",
-	 100.0*num_missmatch/num_elem, num_missmatch, num_elem);
+  
+  PySys_WriteStdout("\n");
+  PySys_WriteStdout("Missmatch: %.2f%% (%d/%d) \n",
+		    100.0*num_missmatch/num_elem, num_missmatch, num_elem);
 
   return Py_BuildValue("");  /* return None */
 }

File accesscarray/check_pointer.py

View file
 import numpy
 from accesscarray import *
 
+iac1d = numpy.array([1,2,3], dtype=numpy.int, order='C')
+iaf1d = numpy.array([1,2,3], dtype=numpy.int, order='F')
 fac1d = numpy.array([1,2,3], dtype=numpy.float, order='C')
 faf1d = numpy.array([1,2,3], dtype=numpy.float, order='F')
 fac2d = numpy.array([[1,2,3],[1,2,3],[1,2,3]], dtype=numpy.float)
 
 print
 print 'check_pointer'
+check_pointer(iac1d)
+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)