[Scipy-svn] r3111 - in trunk/Lib/cluster: . src

scipy-svn@scip... scipy-svn@scip...
Wed Jun 20 05:23:38 CDT 2007


Author: cdavid
Date: 2007-06-20 05:23:17 -0500 (Wed, 20 Jun 2007)
New Revision: 3111

Modified:
   trunk/Lib/cluster/setup.py
   trunk/Lib/cluster/src/vq.tpl
   trunk/Lib/cluster/src/vq_module.c
   trunk/Lib/cluster/vq.py
Log:
Change int to npy_intp for index array + cosmetic change in python code.

Modified: trunk/Lib/cluster/setup.py
===================================================================
--- trunk/Lib/cluster/setup.py	2007-06-19 15:07:48 UTC (rev 3110)
+++ trunk/Lib/cluster/setup.py	2007-06-20 10:23:17 UTC (rev 3111)
@@ -2,19 +2,15 @@
 
 from os.path import join
 
-def configuration(parent_package='',top_path=None):
+def configuration(parent_package = '', top_path = None):
     from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs
-    config = Configuration('cluster',parent_package,top_path)
+    config = Configuration('cluster', parent_package, top_path)
 
     config.add_data_dir('tests')
 
     config.add_extension('_vq',
         sources=[join('src', 'vq_module.c'), join('src', 'vq.c')],
         include_dirs = [get_numpy_include_dirs()])
-    #config.add_extension('_vq',
-    #    sources=[join('src', 'vq_wrap.cpp')])
-    #config.add_extension('_c_vq',
-    #    sources=[join('src', 'vq.c') ])
 
     return config
 

Modified: trunk/Lib/cluster/src/vq.tpl
===================================================================
--- trunk/Lib/cluster/src/vq.tpl	2007-06-19 15:07:48 UTC (rev 3110)
+++ trunk/Lib/cluster/src/vq.tpl	2007-06-20 10:23:17 UTC (rev 3111)
@@ -1,6 +1,10 @@
 [+ AutoGen5 template c +]
 /*
  * vim:syntax=c
+ *
+ * This file implements vq for float and double in C. It is a direct
+ * translation from the swig interface which could not be generated anymore
+ * with recent swig
  */
 #include <stddef.h>
 #include <math.h>

Modified: trunk/Lib/cluster/src/vq_module.c
===================================================================
--- trunk/Lib/cluster/src/vq_module.c	2007-06-19 15:07:48 UTC (rev 3110)
+++ trunk/Lib/cluster/src/vq_module.c	2007-06-20 10:23:17 UTC (rev 3111)
@@ -1,5 +1,5 @@
 /*
- * Last Change: Tue Jun 19 11:00 PM 2007 J
+ * Last Change: Wed Jun 20 04:00 PM 2007 J
  *
  */
 #include <Python.h>
@@ -97,24 +97,24 @@
             if (dist_a == NULL) {
                 goto clean_code_a;
             }
-            index_a = (PyArrayObject*)PyArray_EMPTY(1, &n, NPY_INT, 0);
+            index_a = (PyArrayObject*)PyArray_EMPTY(1, &n, PyArray_INTP, 0);
             if (index_a == NULL) {
                 goto clean_dist_a;
             }
             float_tvq((float*)obs_a->data, (float*)code_a->data, n, nc, d,
-                    (int*)index_a->data, (float*)dist_a->data);
+                    (npy_intp*)index_a->data, (float*)dist_a->data);
             break;
         case NPY_DOUBLE:
             dist_a = (PyArrayObject*)PyArray_EMPTY(1, &n, typenum1, 0);
             if (dist_a == NULL) {
                 goto clean_code_a;
             }
-            index_a = (PyArrayObject*)PyArray_EMPTY(1, &n, NPY_INT, 0);
+            index_a = (PyArrayObject*)PyArray_EMPTY(1, &n, PyArray_INTP, 0);
             if (index_a == NULL) {
                 goto clean_dist_a;
             }
             double_tvq((double*)obs_a->data, (double*)code_a->data, n, nc, d,
-                    (int*)index_a->data, (double*)dist_a->data);
+                    (npy_intp*)index_a->data, (double*)dist_a->data);
             break;
         default:
             PyErr_Format(PyExc_ValueError,
@@ -151,4 +151,3 @@
     Py_DECREF(obs_a);
     return NULL;
 }
-

Modified: trunk/Lib/cluster/vq.py
===================================================================
--- trunk/Lib/cluster/vq.py	2007-06-19 15:07:48 UTC (rev 3110)
+++ trunk/Lib/cluster/vq.py	2007-06-20 10:23:17 UTC (rev 3111)
@@ -181,7 +181,8 @@
     # d = number of features
     if N.ndim(obs) == 1:
         if not N.ndim(obs) == N.ndim(code_book):
-            raise ValueError("Observation and code_book should have the same rank")
+            raise ValueError(
+                    "Observation and code_book should have the same rank")
         else:
             return _py_vq_1d(obs, code_book)
     else:
@@ -192,7 +193,8 @@
         raise ValueError("Observation and code_book should have the same rank")
     elif not d == code_book.shape[1]:
         raise ValueError("Code book(%d) and obs(%d) should have the same " \
-                         "number of features (eg columns)""" % (code_book.shape[1], d))
+                         "number of features (eg columns)""" %
+                         (code_book.shape[1], d))
 
     code = zeros(n, dtype=int)
     min_dist = zeros(n)
@@ -547,11 +549,7 @@
 def _kmeans2(data, code, niter, nc):
     """ "raw" version of kmeans2. Do not use directly.
 
-    Run kmeans with a given initial codebook.
-
-    :undocumented
-
-    """
+    Run kmeans with a given initial codebook.  """
     for i in range(niter):
         # Compute the nearest neighbour for each obs
         # using the current code book
@@ -568,13 +566,15 @@
     return code, label
 
 if __name__  == '__main__':
-    import _vq
-    a = N.random.randn(4, 2)
-    b = N.random.randn(2, 2)
+    pass
+    #import _vq
+    #a = N.random.randn(4, 2)
+    #b = N.random.randn(2, 2)
 
-    print _vq.vq(a, b)
-    print _vq.vq(N.array([[1], [2], [3], [4], [5], [6.]]), N.array([[2.], [5.]]))
-    print _vq.vq(N.array([1, 2, 3, 4, 5, 6.]), N.array([2., 5.]))
-    _vq.vq(a.astype(N.float32), b.astype(N.float32))
-    _vq.vq(a, b.astype(N.float32))
-    _vq.vq([0], b)
+    #print _vq.vq(a, b)
+    #print _vq.vq(N.array([[1], [2], [3], [4], [5], [6.]]), 
+    #        N.array([[2.], [5.]]))
+    #print _vq.vq(N.array([1, 2, 3, 4, 5, 6.]), N.array([2., 5.]))
+    #_vq.vq(a.astype(N.float32), b.astype(N.float32))
+    #_vq.vq(a, b.astype(N.float32))
+    #_vq.vq([0], b)



More information about the Scipy-svn mailing list