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

scipy-svn@scip... scipy-svn@scip...
Tue Jun 19 10:08:00 CDT 2007


Author: cdavid
Date: 2007-06-19 10:07:48 -0500 (Tue, 19 Jun 2007)
New Revision: 3110

Added:
   trunk/Lib/cluster/src/vq.c
   trunk/Lib/cluster/src/vq.def
   trunk/Lib/cluster/src/vq.tpl
   trunk/Lib/cluster/src/vq_module.c
Removed:
   trunk/Lib/cluster/src/swig_num.i
   trunk/Lib/cluster/src/vq.i
   trunk/Lib/cluster/src/vq_wrap.cpp
Modified:
   trunk/Lib/cluster/setup.py
   trunk/Lib/cluster/src/vq.h
   trunk/Lib/cluster/tests/test_vq.py
   trunk/Lib/cluster/vq.py
Log:
Add support for rank 1 arrays in kmean:

* swig interface was not compatible anymore with current swig, 
  so the module was converted to pure C python module
* all tests pass again, including for rank 1 array.



Modified: trunk/Lib/cluster/setup.py
===================================================================
--- trunk/Lib/cluster/setup.py	2007-06-18 23:22:19 UTC (rev 3109)
+++ trunk/Lib/cluster/setup.py	2007-06-19 15:07:48 UTC (rev 3110)
@@ -3,13 +3,18 @@
 from os.path import join
 
 def configuration(parent_package='',top_path=None):
-    from numpy.distutils.misc_util import Configuration
+    from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs
     config = Configuration('cluster',parent_package,top_path)
 
     config.add_data_dir('tests')
 
     config.add_extension('_vq',
-        sources=[join('src', 'vq_wrap.cpp')])
+        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
 

Deleted: trunk/Lib/cluster/src/swig_num.i
===================================================================
--- trunk/Lib/cluster/src/swig_num.i	2007-06-18 23:22:19 UTC (rev 3109)
+++ trunk/Lib/cluster/src/swig_num.i	2007-06-19 15:07:48 UTC (rev 3110)
@@ -1,644 +0,0 @@
-
-/************************************************************************/
-/* swig_num.i -- typemaps for mapping C arrays to Python Numeric arrays */
-/*                                                                      */    
-/* This file is auto-generated by swig_num_gen.py.                      */
-/* DO NOT EDIT THIS FILE DIRECTLY unless you want your changes          */
-/* clobbered by the next run of the generator.                          */
-/************************************************************************/
-
-%include typemaps.i
-
-/************************************************************************/
-/*                   helper functions and initialization                */
-/************************************************************************/
-%{
-
-#include "numpy/arrayobject.h"
-
-// hmmm. how do we prevent typedefs from conflicting
-// with users definition on complex numbers?
-//#include "complex_test.h"
-//typedef struct{ float real; 
-//                float imag;} complex;
-//typedef struct{ double real; 
-//                double imag;} zcomplex;
-
-
-// used for converting typecodes to memory sizes.
-int char_to_size(char type)
-{
-    if (type=='i') return sizeof(int);
-    if (type=='f') return sizeof(float);
-    if (type=='d') return sizeof(double);
-    if (type=='c') return 2*sizeof(float);
-    if (type=='z') return 2*sizeof(double);
-}
-int char_to_numtype(char type)
-{
-    if (type=='i') return 'i';
-    if (type=='f') return 'f';
-    if (type=='d') return 'd';
-    if (type=='c') return 'F';
-    if (type=='z') return 'D';
-}
-%}
-
-%init %{
-        import_array();
-%}
-
-%{
-
-typedef int int_IN_D0;
-typedef float float_IN_D0;
-typedef double double_IN_D0;
-typedef int int_IN_D1;
-typedef float float_IN_D1;
-typedef double double_IN_D1;
-typedef int int_IN_D2;
-typedef float float_IN_D2;
-typedef double double_IN_D2;
-typedef int int_IN_D0_D1;
-typedef float float_IN_D0_D1;
-typedef double double_IN_D0_D1;
-typedef int int_IN_D0_D2;
-typedef float float_IN_D0_D2;
-typedef double double_IN_D0_D2;
-typedef int int_IN_D1_D2;
-typedef float float_IN_D1_D2;
-typedef double double_IN_D1_D2;
-typedef int int_IN_D0_D1_D2;
-typedef float float_IN_D0_D1_D2;
-typedef double double_IN_D0_D1_D2;
-
-
-typedef int int_ARGOUT_D0;
-typedef float float_ARGOUT_D0;
-typedef double double_ARGOUT_D0;
-typedef int int_ARGOUT_D1;
-typedef float float_ARGOUT_D1;
-typedef double double_ARGOUT_D1;
-typedef int int_ARGOUT_D2;
-typedef float float_ARGOUT_D2;
-typedef double double_ARGOUT_D2;
-typedef int int_ARGOUT_D0_D1;
-typedef float float_ARGOUT_D0_D1;
-typedef double double_ARGOUT_D0_D1;
-typedef int int_ARGOUT_D0_D2;
-typedef float float_ARGOUT_D0_D2;
-typedef double double_ARGOUT_D0_D2;
-typedef int int_ARGOUT_D1_D2;
-typedef float float_ARGOUT_D1_D2;
-typedef double double_ARGOUT_D1_D2;
-typedef int int_ARGOUT_D0_D1_D2;
-typedef float float_ARGOUT_D0_D1_D2;
-typedef double double_ARGOUT_D0_D1_D2;
-
-
-typedef int int_ARGOUT_TUPLE_D0;
-typedef float float_ARGOUT_TUPLE_D0;
-typedef double double_ARGOUT_TUPLE_D0;
-typedef int int_ARGOUT_TUPLE_D1;
-typedef float float_ARGOUT_TUPLE_D1;
-typedef double double_ARGOUT_TUPLE_D1;
-typedef int int_ARGOUT_TUPLE_D2;
-typedef float float_ARGOUT_TUPLE_D2;
-typedef double double_ARGOUT_TUPLE_D2;
-typedef int int_ARGOUT_TUPLE_D0_D1;
-typedef float float_ARGOUT_TUPLE_D0_D1;
-typedef double double_ARGOUT_TUPLE_D0_D1;
-typedef int int_ARGOUT_TUPLE_D0_D2;
-typedef float float_ARGOUT_TUPLE_D0_D2;
-typedef double double_ARGOUT_TUPLE_D0_D2;
-typedef int int_ARGOUT_TUPLE_D1_D2;
-typedef float float_ARGOUT_TUPLE_D1_D2;
-typedef double double_ARGOUT_TUPLE_D1_D2;
-typedef int int_ARGOUT_TUPLE_D0_D1_D2;
-typedef float float_ARGOUT_TUPLE_D0_D1_D2;
-typedef double double_ARGOUT_TUPLE_D0_D1_D2;
-
-
-typedef int int_OUT_D0;
-typedef float float_OUT_D0;
-typedef double double_OUT_D0;
-typedef int int_OUT_D1;
-typedef float float_OUT_D1;
-typedef double double_OUT_D1;
-typedef int int_OUT_D2;
-typedef float float_OUT_D2;
-typedef double double_OUT_D2;
-typedef int int_OUT_D0_D1;
-typedef float float_OUT_D0_D1;
-typedef double double_OUT_D0_D1;
-typedef int int_OUT_D0_D2;
-typedef float float_OUT_D0_D2;
-typedef double double_OUT_D0_D2;
-typedef int int_OUT_D1_D2;
-typedef float float_OUT_D1_D2;
-typedef double double_OUT_D1_D2;
-typedef int int_OUT_D0_D1_D2;
-typedef float float_OUT_D0_D1_D2;
-typedef double double_OUT_D0_D1_D2;
-
-
-%}
-
-/************************************************************************/
-/*                        typemap code for IN arguments                 */
-/************************************************************************/
-%{                                                                        
-PyArrayObject* IN_in(PyObject* source, char* basetype_string,             
-                             int** target_dims, int dims)                 
-{                                                                         
-    PyArrayObject *a_obj;                                                 
-    char ar_type = char_to_numtype(basetype_string[0]);                   
-    a_obj = (PyArrayObject*) PyArray_ContiguousFromObject(source,ar_type, 
-                                                             dims,dims);  
-    if (a_obj == NULL)                                                    
-    {                                                                     
-        //PyArray Contiguous From Object will set the error value.        
-    	return NULL;                                                      
-    }                                                                     
-    for(int i = 0; i < dims;i++)                                          
-    {                                                                     
-        *(target_dims[i]) = a_obj->dimensions[i];                         
-    }                                                                     
-    return a_obj;                                                         
-}                                                                         
-                                                                          
-%}                                                                        
-%typemap(python,freearg) DECREF {  Py_XDECREF($arg); }                    
-    
-%typemap(python,in) IN_D0 *
-{
-    int* targ_dims[1] = {_d0};
-    PyArrayObject* a_obj = IN_in($source,"$basetype",targ_dims,1);
-    if (a_obj == NULL) return NULL;
-    $target = ($type) a_obj->data;
-    $source = (PyObject*)a_obj;
-}
-
-%typemap(python,freearg) IN_D0 * = DECREF;
-    
-%typemap(python,in) IN_D1 *
-{
-    int* targ_dims[1] = {_d1};
-    PyArrayObject* a_obj = IN_in($source,"$basetype",targ_dims,1);
-    if (a_obj == NULL) return NULL;
-    $target = ($type) a_obj->data;
-    $source = (PyObject*)a_obj;
-}
-
-%typemap(python,freearg) IN_D1 * = DECREF;
-    
-%typemap(python,in) IN_D2 *
-{
-    int* targ_dims[1] = {_d2};
-    PyArrayObject* a_obj = IN_in($source,"$basetype",targ_dims,1);
-    if (a_obj == NULL) return NULL;
-    $target = ($type) a_obj->data;
-    $source = (PyObject*)a_obj;
-}
-
-%typemap(python,freearg) IN_D2 * = DECREF;
-    
-%typemap(python,in) IN_D0_D1 *
-{
-    int* targ_dims[2] = {_d0,_d1};
-    PyArrayObject* a_obj = IN_in($source,"$basetype",targ_dims,2);
-    if (a_obj == NULL) return NULL;
-    $target = ($type) a_obj->data;
-    $source = (PyObject*)a_obj;
-}
-
-%typemap(python,freearg) IN_D0_D1 * = DECREF;
-    
-%typemap(python,in) IN_D0_D2 *
-{
-    int* targ_dims[2] = {_d0,_d2};
-    PyArrayObject* a_obj = IN_in($source,"$basetype",targ_dims,2);
-    if (a_obj == NULL) return NULL;
-    $target = ($type) a_obj->data;
-    $source = (PyObject*)a_obj;
-}
-
-%typemap(python,freearg) IN_D0_D2 * = DECREF;
-    
-%typemap(python,in) IN_D1_D2 *
-{
-    int* targ_dims[2] = {_d1,_d2};
-    PyArrayObject* a_obj = IN_in($source,"$basetype",targ_dims,2);
-    if (a_obj == NULL) return NULL;
-    $target = ($type) a_obj->data;
-    $source = (PyObject*)a_obj;
-}
-
-%typemap(python,freearg) IN_D1_D2 * = DECREF;
-    
-%typemap(python,in) IN_D0_D1_D2 *
-{
-    int* targ_dims[3] = {_d0,_d1,_d2};
-    PyArrayObject* a_obj = IN_in($source,"$basetype",targ_dims,3);
-    if (a_obj == NULL) return NULL;
-    $target = ($type) a_obj->data;
-    $source = (PyObject*)a_obj;
-}
-
-%typemap(python,freearg) IN_D0_D1_D2 * = DECREF;
-
-/************************************************************************/
-/*                  typemap code for ARGOUT arguments                   */
-/************************************************************************/
-%{
-char* ARGOUT_check(char* basetype_string,int* dims, int dim_len)
-{
-    char *rdata;
-    int element_size = char_to_size(basetype_string[0]);
-    int tot_length = 1;
-    for (int i = 0; i < dim_len; i++)
-        tot_length *= dims[i];        
-    rdata = (char*)malloc(tot_length*element_size);
-    if(rdata == NULL)
-	{
-	    PyErr_SetString(PyExc_MemoryError, "can't allocate memory for output array for arg$argnum");
-	    return NULL;
-	}	
-    return rdata;
-}
-
-PyObject* ARGOUT_argout(char* source, char* basetype_string, 
-                                int* dims, int dim_len)
-{
-    PyArrayObject *res;
-    char array_type = char_to_numtype(basetype_string[0]);
-    res = (PyArrayObject *)PyArray_FromDimsAndData(dim_len, dims, 
-                                                   array_type,source);
-    if(res == NULL)
-    {
-        //PyErr_SetString(PyExc_ValueError, "error converting internal data to array");
-    	return NULL;
-    }
-    res->flags |= NPY_OWNDATA; // we want the array to deallocate mem when it is finished.
-    // stick result in the output tuple (target).
-    // Need to think about generality of this one...
-    return (PyObject *) res;
-}
-%}
-
-%typemap(python, ignore) ARGOUT_D0 * {}
-%typemap(python, check) ARGOUT_D0 *
-{
-    int dim_len = 1;
-    int dims[1] = {*_d0};
-    $target = ($type) ARGOUT_check("$basetype",dims,dim_len);
-    if ($target == NULL) return NULL;
-}
-%typemap(python, argout) ARGOUT_D0 *
-{
-    int dim_len = 1;
-    int dims[1] = {*_d0};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-%typemap(python, ignore) ARGOUT_D1 * {}
-%typemap(python, check) ARGOUT_D1 *
-{
-    int dim_len = 1;
-    int dims[1] = {*_d1};
-    $target = ($type) ARGOUT_check("$basetype",dims,dim_len);
-    if ($target == NULL) return NULL;
-}
-%typemap(python, argout) ARGOUT_D1 *
-{
-    int dim_len = 1;
-    int dims[1] = {*_d1};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-%typemap(python, ignore) ARGOUT_D2 * {}
-%typemap(python, check) ARGOUT_D2 *
-{
-    int dim_len = 1;
-    int dims[1] = {*_d2};
-    $target = ($type) ARGOUT_check("$basetype",dims,dim_len);
-    if ($target == NULL) return NULL;
-}
-%typemap(python, argout) ARGOUT_D2 *
-{
-    int dim_len = 1;
-    int dims[1] = {*_d2};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-%typemap(python, ignore) ARGOUT_D0_D1 * {}
-%typemap(python, check) ARGOUT_D0_D1 *
-{
-    int dim_len = 2;
-    int dims[2] = {*_d0,*_d1};
-    $target = ($type) ARGOUT_check("$basetype",dims,dim_len);
-    if ($target == NULL) return NULL;
-}
-%typemap(python, argout) ARGOUT_D0_D1 *
-{
-    int dim_len = 2;
-    int dims[2] = {*_d0,*_d1};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-%typemap(python, ignore) ARGOUT_D0_D2 * {}
-%typemap(python, check) ARGOUT_D0_D2 *
-{
-    int dim_len = 2;
-    int dims[2] = {*_d0,*_d2};
-    $target = ($type) ARGOUT_check("$basetype",dims,dim_len);
-    if ($target == NULL) return NULL;
-}
-%typemap(python, argout) ARGOUT_D0_D2 *
-{
-    int dim_len = 2;
-    int dims[2] = {*_d0,*_d2};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-%typemap(python, ignore) ARGOUT_D1_D2 * {}
-%typemap(python, check) ARGOUT_D1_D2 *
-{
-    int dim_len = 2;
-    int dims[2] = {*_d1,*_d2};
-    $target = ($type) ARGOUT_check("$basetype",dims,dim_len);
-    if ($target == NULL) return NULL;
-}
-%typemap(python, argout) ARGOUT_D1_D2 *
-{
-    int dim_len = 2;
-    int dims[2] = {*_d1,*_d2};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-%typemap(python, ignore) ARGOUT_D0_D1_D2 * {}
-%typemap(python, check) ARGOUT_D0_D1_D2 *
-{
-    int dim_len = 3;
-    int dims[3] = {*_d0,*_d1,*_d2};
-    $target = ($type) ARGOUT_check("$basetype",dims,dim_len);
-    if ($target == NULL) return NULL;
-}
-%typemap(python, argout) ARGOUT_D0_D1_D2 *
-{
-    int dim_len = 3;
-    int dims[3] = {*_d0,*_d1,*_d2};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-/************************************************************************/
-/*             typemap code for ARGOUT_TUPLE arguments                  */
-/************************************************************************/
-
-%typemap(python, ignore) ARGOUT_TUPLE_D0 * = ARGOUT_D0 *;
-%typemap(python, check) ARGOUT_TUPLE_D0 * = ARGOUT_D0 *;
-%typemap(python, argout) ARGOUT_TUPLE_D0 *
-{
-    int dim_len = 1;
-    int dims[1] = {*_d0};
-    PyObject * res;
-    res = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) 
-        return NULL;
-    $target = t_output_helper($target, res);
-}  
-
-%typemap(python, ignore) ARGOUT_TUPLE_D1 * = ARGOUT_D1 *;
-%typemap(python, check) ARGOUT_TUPLE_D1 * = ARGOUT_D1 *;
-%typemap(python, argout) ARGOUT_TUPLE_D1 *
-{
-    int dim_len = 1;
-    int dims[1] = {*_d1};
-    PyObject * res;
-    res = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) 
-        return NULL;
-    $target = t_output_helper($target, res);
-}  
-
-%typemap(python, ignore) ARGOUT_TUPLE_D2 * = ARGOUT_D2 *;
-%typemap(python, check) ARGOUT_TUPLE_D2 * = ARGOUT_D2 *;
-%typemap(python, argout) ARGOUT_TUPLE_D2 *
-{
-    int dim_len = 1;
-    int dims[1] = {*_d2};
-    PyObject * res;
-    res = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) 
-        return NULL;
-    $target = t_output_helper($target, res);
-}  
-
-%typemap(python, ignore) ARGOUT_TUPLE_D0_D1 * = ARGOUT_D0_D1 *;
-%typemap(python, check) ARGOUT_TUPLE_D0_D1 * = ARGOUT_D0_D1 *;
-%typemap(python, argout) ARGOUT_TUPLE_D0_D1 *
-{
-    int dim_len = 2;
-    int dims[2] = {*_d0,*_d1};
-    PyObject * res;
-    res = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) 
-        return NULL;
-    $target = t_output_helper($target, res);
-}  
-
-%typemap(python, ignore) ARGOUT_TUPLE_D0_D2 * = ARGOUT_D0_D2 *;
-%typemap(python, check) ARGOUT_TUPLE_D0_D2 * = ARGOUT_D0_D2 *;
-%typemap(python, argout) ARGOUT_TUPLE_D0_D2 *
-{
-    int dim_len = 2;
-    int dims[2] = {*_d0,*_d2};
-    PyObject * res;
-    res = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) 
-        return NULL;
-    $target = t_output_helper($target, res);
-}  
-
-%typemap(python, ignore) ARGOUT_TUPLE_D1_D2 * = ARGOUT_D1_D2 *;
-%typemap(python, check) ARGOUT_TUPLE_D1_D2 * = ARGOUT_D1_D2 *;
-%typemap(python, argout) ARGOUT_TUPLE_D1_D2 *
-{
-    int dim_len = 2;
-    int dims[2] = {*_d1,*_d2};
-    PyObject * res;
-    res = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) 
-        return NULL;
-    $target = t_output_helper($target, res);
-}  
-
-%typemap(python, ignore) ARGOUT_TUPLE_D0_D1_D2 * = ARGOUT_D0_D1_D2 *;
-%typemap(python, check) ARGOUT_TUPLE_D0_D1_D2 * = ARGOUT_D0_D1_D2 *;
-%typemap(python, argout) ARGOUT_TUPLE_D0_D1_D2 *
-{
-    int dim_len = 3;
-    int dims[3] = {*_d0,*_d1,*_d2};
-    PyObject * res;
-    res = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) 
-        return NULL;
-    $target = t_output_helper($target, res);
-}  
-
-/************************************************************************/
-/*                   typemap code for OUT arguments                     */
-/************************************************************************/
-
-%typemap(python, out) OUT_D0 *
-{
-    // identical to  typemap(python,argout) ARGOUT__D0 *;
-    int dim_len = 1;
-    int dims[1] = {*_d0};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-%typemap(python, out) OUT_D1 *
-{
-    // identical to  typemap(python,argout) ARGOUT__D1 *;
-    int dim_len = 1;
-    int dims[1] = {*_d1};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-%typemap(python, out) OUT_D2 *
-{
-    // identical to  typemap(python,argout) ARGOUT__D2 *;
-    int dim_len = 1;
-    int dims[1] = {*_d2};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-%typemap(python, out) OUT_D0_D1 *
-{
-    // identical to  typemap(python,argout) ARGOUT__D0_D1 *;
-    int dim_len = 2;
-    int dims[2] = {*_d0,*_d1};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-%typemap(python, out) OUT_D0_D2 *
-{
-    // identical to  typemap(python,argout) ARGOUT__D0_D2 *;
-    int dim_len = 2;
-    int dims[2] = {*_d0,*_d2};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-%typemap(python, out) OUT_D1_D2 *
-{
-    // identical to  typemap(python,argout) ARGOUT__D1_D2 *;
-    int dim_len = 2;
-    int dims[2] = {*_d1,*_d2};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-%typemap(python, out) OUT_D0_D1_D2 *
-{
-    // identical to  typemap(python,argout) ARGOUT__D0_D1_D2 *;
-    int dim_len = 3;
-    int dims[3] = {*_d0,*_d1,*_d2};
-    $target = ARGOUT_argout( (char*) $source,"$basetype",
-                                     dims, dim_len);
-    if ($target == NULL) return NULL;
-}
-
-%typemap(python, ignore) int DIM0(int* _d0)
-{ _d0 = &$target; }
-%typemap(python, ignore) int DIM1(int* _d1)
-{ _d1 = &$target; }
-%typemap(python, ignore) int DIM2(int* _d2)
-{ _d2 = &$target; }
-
-%typemap(python, in) int IN_DIM0(int* _d0)
-{
-    $target = (int) PyInt_AsLong($source);
-    _d0 = &$target;
-}
-%typemap(python, in) int IN_DIM1(int* _d1)
-{
-    $target = (int) PyInt_AsLong($source);
-    _d1 = &$target;
-}
-%typemap(python, in) int IN_DIM2(int* _d2)
-{
-    $target = (int) PyInt_AsLong($source);
-    _d2 = &$target;
-}
-
-
-
-%apply IN_D0 * {int_IN_D0 *,float_IN_D0 *,double_IN_D0 *};
-%apply IN_D1 * {int_IN_D1 *,float_IN_D1 *,double_IN_D1 *};
-%apply IN_D2 * {int_IN_D2 *,float_IN_D2 *,double_IN_D2 *};
-%apply IN_D0_D1 * {int_IN_D0_D1 *,float_IN_D0_D1 *,double_IN_D0_D1 *};
-%apply IN_D0_D2 * {int_IN_D0_D2 *,float_IN_D0_D2 *,double_IN_D0_D2 *};
-%apply IN_D1_D2 * {int_IN_D1_D2 *,float_IN_D1_D2 *,double_IN_D1_D2 *};
-%apply IN_D0_D1_D2 * {int_IN_D0_D1_D2 *,float_IN_D0_D1_D2 *,double_IN_D0_D1_D2 *};
-
-
-%apply ARGOUT_D0 * {int_ARGOUT_D0 *,float_ARGOUT_D0 *,double_ARGOUT_D0 *};
-%apply ARGOUT_D1 * {int_ARGOUT_D1 *,float_ARGOUT_D1 *,double_ARGOUT_D1 *};
-%apply ARGOUT_D2 * {int_ARGOUT_D2 *,float_ARGOUT_D2 *,double_ARGOUT_D2 *};
-%apply ARGOUT_D0_D1 * {int_ARGOUT_D0_D1 *,float_ARGOUT_D0_D1 *,double_ARGOUT_D0_D1 *};
-%apply ARGOUT_D0_D2 * {int_ARGOUT_D0_D2 *,float_ARGOUT_D0_D2 *,double_ARGOUT_D0_D2 *};
-%apply ARGOUT_D1_D2 * {int_ARGOUT_D1_D2 *,float_ARGOUT_D1_D2 *,double_ARGOUT_D1_D2 *};
-%apply ARGOUT_D0_D1_D2 * {int_ARGOUT_D0_D1_D2 *,float_ARGOUT_D0_D1_D2 *,double_ARGOUT_D0_D1_D2 *};
-
-
-%apply ARGOUT_TUPLE_D0 * {int_ARGOUT_TUPLE_D0 *,float_ARGOUT_TUPLE_D0 *,double_ARGOUT_TUPLE_D0 *};
-%apply ARGOUT_TUPLE_D1 * {int_ARGOUT_TUPLE_D1 *,float_ARGOUT_TUPLE_D1 *,double_ARGOUT_TUPLE_D1 *};
-%apply ARGOUT_TUPLE_D2 * {int_ARGOUT_TUPLE_D2 *,float_ARGOUT_TUPLE_D2 *,double_ARGOUT_TUPLE_D2 *};
-%apply ARGOUT_TUPLE_D0_D1 * {int_ARGOUT_TUPLE_D0_D1 *,float_ARGOUT_TUPLE_D0_D1 *,double_ARGOUT_TUPLE_D0_D1 *};
-%apply ARGOUT_TUPLE_D0_D2 * {int_ARGOUT_TUPLE_D0_D2 *,float_ARGOUT_TUPLE_D0_D2 *,double_ARGOUT_TUPLE_D0_D2 *};
-%apply ARGOUT_TUPLE_D1_D2 * {int_ARGOUT_TUPLE_D1_D2 *,float_ARGOUT_TUPLE_D1_D2 *,double_ARGOUT_TUPLE_D1_D2 *};
-%apply ARGOUT_TUPLE_D0_D1_D2 * {int_ARGOUT_TUPLE_D0_D1_D2 *,float_ARGOUT_TUPLE_D0_D1_D2 *,double_ARGOUT_TUPLE_D0_D1_D2 *};
-
-
-%apply OUT_D0 * {int_OUT_D0 *,float_OUT_D0 *,double_OUT_D0 *};
-%apply OUT_D1 * {int_OUT_D1 *,float_OUT_D1 *,double_OUT_D1 *};
-%apply OUT_D2 * {int_OUT_D2 *,float_OUT_D2 *,double_OUT_D2 *};
-%apply OUT_D0_D1 * {int_OUT_D0_D1 *,float_OUT_D0_D1 *,double_OUT_D0_D1 *};
-%apply OUT_D0_D2 * {int_OUT_D0_D2 *,float_OUT_D0_D2 *,double_OUT_D0_D2 *};
-%apply OUT_D1_D2 * {int_OUT_D1_D2 *,float_OUT_D1_D2 *,double_OUT_D1_D2 *};
-%apply OUT_D0_D1_D2 * {int_OUT_D0_D1_D2 *,float_OUT_D0_D1_D2 *,double_OUT_D0_D1_D2 *};
-
-

Added: trunk/Lib/cluster/src/vq.c
===================================================================
--- trunk/Lib/cluster/src/vq.c	2007-06-18 23:22:19 UTC (rev 3109)
+++ trunk/Lib/cluster/src/vq.c	2007-06-19 15:07:48 UTC (rev 3110)
@@ -0,0 +1,142 @@
+/*
+ * vim:syntax=c
+ */
+#include <stddef.h>
+#include <math.h>
+
+/*
+ * results is put into code, which contains initially the initial code
+ *
+ * mdist and code should have at least n elements
+ */
+const static double rbig = 1e100;
+
+
+static int float_vq_1d(const float *in, int n, 
+    const float *init, int ncode, 
+    int *code, float *mdist)
+{
+    int i, j;
+    float m, d;
+
+    for (i = 0; i < n; ++i) {
+        m = (float)rbig;
+        /* Compute the minimal distance for obsvervation i */
+        for (j = 0; j < ncode; ++j) {
+            d = (in[i] - init[j]);
+            d *= d;
+            if ( d < m) {
+                m = d;
+            }
+        }
+        mdist[i] = m;
+        code[i] = j;
+    }
+    return 0;
+}
+
+static int float_vq_obs(const float *obs,
+    float *code_book, int Ncodes, int Nfeatures,
+       int* code, float *lowest_dist)
+{
+	int i,j,k=0;
+	float dist, diff;
+
+	*lowest_dist = (float) rbig;
+	for(i = 0; i < Ncodes; i++) {
+		dist = 0;
+		for(j=0; j < Nfeatures; j++) {
+			diff = code_book[k] - obs[j];
+			dist += diff*diff;
+			k++;
+		}
+		dist = (float)sqrt(dist);
+		if (dist < *lowest_dist) {
+			*code = i;
+			*lowest_dist = dist;
+		}
+	}
+
+    return 0;
+}
+
+int float_tvq(
+    float* obs,
+    float* code_book, 
+    int Nobs, int Ncodes, int Nfeatures,
+    int* codes, float* lowest_dist)
+{
+    int i;
+	for( i = 0; i < Nobs; i++) {		
+		float_vq_obs(
+                    &(obs[i*Nfeatures]),
+                    code_book,Ncodes, Nfeatures,
+                    &(codes[i]), &(lowest_dist[i]));
+	}
+    return 0;
+}
+
+static int double_vq_1d(const double *in, int n, 
+    const double *init, int ncode, 
+    int *code, double *mdist)
+{
+    int i, j;
+    double m, d;
+
+    for (i = 0; i < n; ++i) {
+        m = (double)rbig;
+        /* Compute the minimal distance for obsvervation i */
+        for (j = 0; j < ncode; ++j) {
+            d = (in[i] - init[j]);
+            d *= d;
+            if ( d < m) {
+                m = d;
+            }
+        }
+        mdist[i] = m;
+        code[i] = j;
+    }
+    return 0;
+}
+
+static int double_vq_obs(const double *obs,
+    double *code_book, int Ncodes, int Nfeatures,
+       int* code, double *lowest_dist)
+{
+	int i,j,k=0;
+	double dist, diff;
+
+	*lowest_dist = (double) rbig;
+	for(i = 0; i < Ncodes; i++) {
+		dist = 0;
+		for(j=0; j < Nfeatures; j++) {
+			diff = code_book[k] - obs[j];
+			dist += diff*diff;
+			k++;
+		}
+		dist = (double)sqrt(dist);
+		if (dist < *lowest_dist) {
+			*code = i;
+			*lowest_dist = dist;
+		}
+	}
+
+    return 0;
+}
+
+int double_tvq(
+    double* obs,
+    double* code_book, 
+    int Nobs, int Ncodes, int Nfeatures,
+    int* codes, double* lowest_dist)
+{
+    int i;
+	for( i = 0; i < Nobs; i++) {		
+		double_vq_obs(
+                    &(obs[i*Nfeatures]),
+                    code_book,Ncodes, Nfeatures,
+                    &(codes[i]), &(lowest_dist[i]));
+	}
+    return 0;
+}
+

Added: trunk/Lib/cluster/src/vq.def
===================================================================
--- trunk/Lib/cluster/src/vq.def	2007-06-18 23:22:19 UTC (rev 3109)
+++ trunk/Lib/cluster/src/vq.def	2007-06-19 15:07:48 UTC (rev 3110)
@@ -0,0 +1,12 @@
+autogen definitions vq.tpl;
+
+data_type = { 
+	type_name		= float ;
+	data_type		= float ;
+} ;
+
+data_type = { 
+	type_name		= double ;
+	data_type		= double ;
+} ;
+

Modified: trunk/Lib/cluster/src/vq.h
===================================================================
--- trunk/Lib/cluster/src/vq.h	2007-06-18 23:22:19 UTC (rev 3109)
+++ trunk/Lib/cluster/src/vq.h	2007-06-19 15:07:48 UTC (rev 3110)
@@ -1,57 +1,10 @@
-#ifndef vq_h
-#define vq_h
-/*
-//#define real  float 
-//#define scan_format "%f"
+#ifndef _VQ_H_
+#define _VQ_H
 
-#define real double
-#define scan_format "%lf"
+int double_tvq(double* obs, double* code_book, int Nobs, int Ncodes, 
+        int Nfeatures, int* codes, double* lowest_dist);
 
+int float_tvq(float* obs, float* code_book, int Nobs, int Ncodes, 
+        int Nfeatures, int* codes, float* lowest_dist);
 
-
-void vq_obs(real* obs,real* code_book, int Ncodes, int Nfeatures,
-			   int& code, real& lowest_dist);
-
-void vq(real* obs,real* code_book, int Nobs, int Ncodes, int Nfeatures,
-	    int* codes, real* lowest_dist);
-*/
-#define BIG 10000.
-
-template<class T>
-void tvq_obs(T* obs,T* code_book, int Ncodes, int Nfeatures,
-			   int& code, T& lowest_dist)
-{
-	int i,j,k=0;
-	T dist, diff;
-
-	lowest_dist = (T) BIG;
-	for(i=0; i < Ncodes; i++)
-	{
-		dist=0;
-		for(j=0; j < Nfeatures; j++)
-		{
-			diff = code_book[k] - obs[j];
-			dist += diff*diff;
-			k++;
-		}
-		dist = (T)sqrt(dist);
-		if (dist < lowest_dist)
-		{
-			code = i;
-			lowest_dist = dist;
-		}
-	}
-}
-
-template<class T>
-void tvq(T* obs,T* code_book, int Nobs, int Ncodes, int Nfeatures,
-	    int* codes, T* lowest_dist)
-{
-    int i;
-	for( i = 0; i < Nobs; i++)
-	{		
-		tvq_obs<T>(&(obs[i*Nfeatures]),code_book,Ncodes,Nfeatures,
-				  codes[i],lowest_dist[i]);
-	}
-}
-#endif
\ No newline at end of file
+#endif

Deleted: trunk/Lib/cluster/src/vq.i
===================================================================
--- trunk/Lib/cluster/src/vq.i	2007-06-18 23:22:19 UTC (rev 3109)
+++ trunk/Lib/cluster/src/vq.i	2007-06-19 15:07:48 UTC (rev 3110)
@@ -1,30 +0,0 @@
-%module _vq
-%{
-
-#include "vq.h"
-
-/* Wrappers for the template code */
-
-void float_vq(float * obs,float* code_book, int Nobs, int Ncodes, 
-              int Nfeatures, int* codes, float* lowest_dist)
-{
-    tvq<float>(obs,code_book,Nobs,Ncodes,Nfeatures,codes,lowest_dist);
-}
-
-void double_vq(double * obs,double* code_book, int Nobs, int Ncodes, 
-              int Nfeatures, int* codes, double* lowest_dist)
-{
-    tvq<double>(obs,code_book,Nobs,Ncodes,Nfeatures,codes,lowest_dist);
-}
-
-%}
-
-%include swig_num.i
-
-void double_vq(double_IN_D0_D2 *obs,double_IN_D1_D2 *code_book, 
-               int DIM0, int DIM1, int DIM2, 
-               int_ARGOUT_TUPLE_D0 *codes, double_ARGOUT_TUPLE_D0 *lowest_dist);
-
-void float_vq(float_IN_D0_D2 *obs,float_IN_D1_D2 *code_book, 
-              int DIM0, int DIM1, int DIM2, 
-              int_ARGOUT_TUPLE_D0 *codes, float_ARGOUT_TUPLE_D0 *lowest_dist);

Added: trunk/Lib/cluster/src/vq.tpl
===================================================================
--- trunk/Lib/cluster/src/vq.tpl	2007-06-18 23:22:19 UTC (rev 3109)
+++ trunk/Lib/cluster/src/vq.tpl	2007-06-19 15:07:48 UTC (rev 3110)
@@ -0,0 +1,79 @@
+[+ AutoGen5 template c +]
+/*
+ * vim:syntax=c
+ */
+#include <stddef.h>
+#include <math.h>
+
+/*
+ * results is put into code, which contains initially the initial code
+ *
+ * mdist and code should have at least n elements
+ */
+const static double rbig = 1e100;
+
+[+ FOR data_type +]
+static int [+ (get "type_name") +]_vq_1d(const [+ (get "type_name") +] *in, int n, 
+    const [+ (get "type_name") +] *init, int ncode, 
+    int *code, [+ (get "type_name") +] *mdist)
+{
+    int i, j;
+    [+ (get "data_type") +] m, d;
+
+    for (i = 0; i < n; ++i) {
+        m = ([+ (get "data_type") +])rbig;
+        /* Compute the minimal distance for obsvervation i */
+        for (j = 0; j < ncode; ++j) {
+            d = (in[i] - init[j]);
+            d *= d;
+            if ( d < m) {
+                m = d;
+            }
+        }
+        mdist[i] = m;
+        code[i] = j;
+    }
+    return 0;
+}
+
+static int [+ (get "type_name") +]_vq_obs(const [+ (get "data_type") +] *obs,
+    [+ (get "data_type") +] *code_book, int Ncodes, int Nfeatures,
+       int* code, [+ (get "data_type") +] *lowest_dist)
+{
+	int i,j,k=0;
+	[+ (get "data_type") +] dist, diff;
+
+	*lowest_dist = ([+ (get "data_type") +]) rbig;
+	for(i = 0; i < Ncodes; i++) {
+		dist = 0;
+		for(j=0; j < Nfeatures; j++) {
+			diff = code_book[k] - obs[j];
+			dist += diff*diff;
+			k++;
+		}
+		dist = ([+ (get "data_type") +])sqrt(dist);
+		if (dist < *lowest_dist) {
+			*code = i;
+			*lowest_dist = dist;
+		}
+	}
+
+    return 0;
+}
+
+int [+ (get "type_name") +]_tvq(
+    [+ (get "data_type") +]* obs,
+    [+ (get "data_type") +]* code_book, 
+    int Nobs, int Ncodes, int Nfeatures,
+    int* codes, [+ (get "data_type") +]* lowest_dist)
+{
+    int i;
+	for( i = 0; i < Nobs; i++) {		
+		[+ (get "type_name") +]_vq_obs(
+                    &(obs[i*Nfeatures]),
+                    code_book,Ncodes, Nfeatures,
+                    &(codes[i]), &(lowest_dist[i]));
+	}
+    return 0;
+}
+[+ ENDFOR data_type +]

Added: trunk/Lib/cluster/src/vq_module.c
===================================================================
--- trunk/Lib/cluster/src/vq_module.c	2007-06-18 23:22:19 UTC (rev 3109)
+++ trunk/Lib/cluster/src/vq_module.c	2007-06-19 15:07:48 UTC (rev 3110)
@@ -0,0 +1,154 @@
+/*
+ * Last Change: Tue Jun 19 11:00 PM 2007 J
+ *
+ */
+#include <Python.h>
+
+#include <numpy/arrayobject.h>
+
+#include "vq.h"
+
+PyObject* compute_vq(PyObject*, PyObject*);
+
+static PyMethodDef vqmethods [] = {
+    {"vq", compute_vq, METH_VARARGS, "TODO docstring"},
+    {NULL, NULL, 0, NULL}
+};
+
+PyMODINIT_FUNC init_vq(void) 
+{
+    Py_InitModule("_vq", vqmethods);
+    import_array();
+}
+
+PyObject* compute_vq(PyObject* self, PyObject* args)
+{
+    PyObject *obs, *code, *out;
+    PyArrayObject *obs_a, *code_a;
+    PyArrayObject *index_a, *dist_a;
+    int typenum1, typenum2;
+    int n, nc, d, nd;
+
+    if ( !PyArg_ParseTuple(args, "OO", &obs, &code) ) {
+        return NULL;
+    }
+
+    /* Check that obs and code both are arrays of same type, conformant
+     * dimensions, etc...*/
+    if (!(PyArray_Check(obs) && PyArray_Check(code))) {
+		PyErr_Format(PyExc_ValueError,
+			     "observation and code should be numpy arrays");
+        return NULL;
+    }
+
+    typenum1 = PyArray_TYPE(obs);
+    typenum2 = PyArray_TYPE(code);
+    if (typenum1 != typenum1) {
+		PyErr_Format(PyExc_ValueError,
+			     "observation and code should have same type");
+        return NULL;
+    }
+    obs_a = (PyArrayObject*)PyArray_FROM_OF(obs, 
+                NPY_CONTIGUOUS | NPY_NOTSWAPPED | NPY_ALIGNED);
+    if (obs_a == NULL) {
+        return NULL;
+    }
+
+    code_a = (PyArrayObject*)PyArray_FROM_OF(code, 
+                NPY_CONTIGUOUS | NPY_NOTSWAPPED | NPY_ALIGNED);
+    if (code_a == NULL) {
+        goto clean_obs_a;
+    }
+
+    if( !(obs_a->nd == code_a->nd)) {
+		PyErr_Format(PyExc_ValueError,
+			     "observation and code should have same shape");
+        goto clean_code_a;
+    }
+
+    switch (obs_a->nd) {
+        case 1:
+            nd = 1;
+            d = 1;
+            n = PyArray_DIM(obs, 0);
+            nc = PyArray_DIM(code, 0);
+            break;
+        case 2:
+            nd = 2;
+            n = PyArray_DIM(obs, 0);
+            d = PyArray_DIM(obs, 1);
+            nc = PyArray_DIM(code, 0);
+            if (! (d == PyArray_DIM(code, 1)) ) {
+                PyErr_Format(PyExc_ValueError,
+                         "obs and code should have same number of "
+                         " features (columns)");
+                goto clean_code_a;
+            }
+            break;
+        default:
+            PyErr_Format(PyExc_ValueError,
+                     "rank different than 1 or 2 are not supported");
+            goto clean_code_a;
+    }
+
+    switch (PyArray_TYPE(obs)) {
+        case NPY_FLOAT:
+            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);
+            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);
+            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);
+            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);
+            break;
+        default:
+            PyErr_Format(PyExc_ValueError,
+                     "type other than float or double not supported");
+            goto clean_code_a;
+    }
+
+    /* Create output */
+    out = PyTuple_New(2);
+    if (out == NULL) {
+        goto clean_index_a;
+    }
+    if (PyTuple_SetItem(out, 0, (PyObject*)index_a)) {
+        goto clean_out;
+    }
+    if (PyTuple_SetItem(out, 1, (PyObject*)dist_a)) {
+        goto clean_out;
+    }
+
+    /* Clean everything */
+    Py_DECREF(code_a);
+    Py_DECREF(obs_a);
+    return out;
+
+clean_out:
+    Py_DECREF(out);
+clean_dist_a:
+    Py_DECREF(dist_a);
+clean_index_a:
+    Py_DECREF(index_a);
+clean_code_a:
+    Py_DECREF(code_a);
+clean_obs_a:
+    Py_DECREF(obs_a);
+    return NULL;
+}
+

Deleted: trunk/Lib/cluster/src/vq_wrap.cpp
===================================================================
--- trunk/Lib/cluster/src/vq_wrap.cpp	2007-06-18 23:22:19 UTC (rev 3109)
+++ trunk/Lib/cluster/src/vq_wrap.cpp	2007-06-19 15:07:48 UTC (rev 3110)
@@ -1,982 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3u-20010227-1913 (Alpha 5)
- * 
- * This file is not intended to be easily readable and contains a number of 
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG 
- * interface file instead. 
- * ----------------------------------------------------------------------------- */
-
-#define SWIGPYTHON
-/***********************************************************************
- * common.swg
- *
- *     This file contains generic SWIG runtime support for pointer
- *     type checking as well as a few commonly used macros to control
- *     external linkage.
- *
- * Author : David Beazley (beazley@cs.uchicago.edu)
- *
- * Copyright (c) 1999-2000, The University of Chicago
- * 
- * This file may be freely redistributed without license or fee provided
- * this copyright message remains intact.
- ************************************************************************/
-
-#include <string.h>
-
-#if defined(_WIN32) || defined(__WIN32__)
-#       if defined(_MSC_VER)
-#               if defined(STATIC_LINKED)
-#                       define SWIGEXPORT(a) a
-#               else
-#                       define SWIGEXPORT(a) __declspec(dllexport) a
-#               endif
-#       else
-#               if defined(__BORLANDC__)
-#                       define SWIGEXPORT(a) a _export
-#               else
-#                       define SWIGEXPORT(a) a
-#       endif
-#endif
-#else
-#       define SWIGEXPORT(a) a
-#endif
-
-#ifdef SWIG_GLOBAL
-#define SWIGRUNTIME(a) SWIGEXPORT(a)
-#else
-#define SWIGRUNTIME(a) static a
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct swig_type_info {
-  char  *name;                 
-  void *(*converter)(void *);
-  char  *str;
-  struct swig_type_info  *next;
-  struct swig_type_info  *prev;
-} swig_type_info;
-
-#ifdef SWIG_NOINCLUDE
-SWIGEXPORT(swig_type_info *) SWIG_TypeRegister(swig_type_info *);
-SWIGEXPORT(swig_type_info *) SWIG_TypeCheck(char *c, swig_type_info *);
-SWIGEXPORT(void *) SWIG_TypeCast(swig_type_info *, void *);
-#else
-
-static swig_type_info *swig_type_list = 0;
-
-/* Register a type mapping with the type-checking */
-SWIGRUNTIME(swig_type_info *)
-SWIG_TypeRegister(swig_type_info *ti)
-{
-  swig_type_info *tc, *head, *ret, *next;
-  /* Check to see if this type has already been registered */
-  tc = swig_type_list;
-  while (tc) {
-    if (strcmp(tc->name, ti->name) == 0) {
-      /* Already exists in the table.  Just add additional types to the list */
-      head = tc;
-      next = tc->next;
-      goto l1;
-    }
-    tc = tc->prev;
-  }
-  head = ti;
-  next = 0;
-
-  /* Place in list */
-  ti->prev = swig_type_list;
-  swig_type_list = ti;
-
-  /* Build linked lists */
- l1:
-  ret = head;
-  tc = ti + 1;
-  /* Patch up the rest of the links */
-  while (tc->name) {
-    head->next = tc;
-    tc->prev = head;
-    head = tc;
-    tc++;
-  }
-  head->next = next;
-  return ret;
-}
-
-/* Check the typename */
-SWIGRUNTIME(swig_type_info *) 
-SWIG_TypeCheck(char *c, swig_type_info *ty)
-{
-  swig_type_info *s;
-  if (!ty) return 0;        /* Void pointer */
-  s = ty->next;             /* First element always just a name */
-  while (s) {
-    if (strcmp(s->name,c) == 0) {
-      if (s == ty->next) return s;
-      /* Move s to the top of the linked list */
-      s->prev->next = s->next;
-      if (s->next) {
-	s->next->prev = s->prev;
-      }
-      /* Insert s as second element in the list */
-      s->next = ty->next;
-      if (ty->next) ty->next->prev = s;
-      ty->next = s;
-      return s;
-    }
-    s = s->next;
-  }
-  return 0;
-}
-
-/* Cast a pointer (needed for C++ inheritance */
-SWIGRUNTIME(void *) 
-SWIG_TypeCast(swig_type_info *ty, void *ptr) 
-{
-  if ((!ty) || (!ty->converter)) return ptr;
-  return (*ty->converter)(ptr);
-}
-
-/* Search for a swig_type_info structure */
-SWIGRUNTIME(void *)
-SWIG_TypeQuery(const char *name) {
-  swig_type_info *ty = swig_type_list;
-  while (ty) {
-    if (ty->str && (strcmp(name,ty->str) == 0)) return ty;
-    if (ty->name && (strcmp(name,ty->name) == 0)) return ty;
-    ty = ty->prev;
-  }
-  return 0;
-}
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-
-
-/***********************************************************************
- * python.swg
- *
- *     This file contains the runtime support for Python modules
- *     and includes code for managing global variables and pointer
- *     type checking.
- *
- * Author : David Beazley (beazley@cs.uchicago.edu)
- ************************************************************************/
-
-#include <stdlib.h>
-#include "Python.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define SWIG_PY_INT     1
-#define SWIG_PY_FLOAT   2
-#define SWIG_PY_STRING  3
-#define SWIG_PY_POINTER 4
-
-/* Constant information structure */
-typedef struct swig_const_info {
-    int type;
-    char *name;
-    long lvalue;
-    double dvalue;
-    void   *pvalue;
-    swig_type_info **ptype;
-} swig_const_info;
-
-#ifdef SWIG_NOINCLUDE
-
-SWIGEXPORT(PyObject *)        SWIG_newvarlink();
-SWIGEXPORT(void)              SWIG_addvarlink(PyObject *, char *, PyObject *(*)(void), int (*)(PyObject *));
-SWIGEXPORT(int)               SWIG_ConvertPtr(PyObject *, void **, swig_type_info *, int);
-SWIGEXPORT(void)              SWIG_MakePtr(char *c, void *, swig_type_info *);
-SWIGEXPORT(PyObject *)        SWIG_NewPointerObj(void *, swig_type_info *);
-SWIGEXPORT(void)              SWIG_InstallConstants(PyObject *d, swig_const_info constants[]);
-
-#else
-
-/* -----------------------------------------------------------------------------
- * global variable support code.
- * ----------------------------------------------------------------------------- */
-
-typedef struct swig_globalvar {   
-  char       *name;                  /* Name of global variable */
-  PyObject *(*get_attr)(void);       /* Return the current value */
-  int       (*set_attr)(PyObject *); /* Set the value */
-  struct swig_globalvar *next;
-} swig_globalvar;
-
-typedef struct swig_varlinkobject {
-  PyObject_HEAD
-  swig_globalvar *vars;
-} swig_varlinkobject;
-
-static PyObject *
-swig_varlink_repr(swig_varlinkobject *v) {
-  v = v;
-  return PyString_FromString("<Global variables>");
-}
-
-static int
-swig_varlink_print(swig_varlinkobject *v, FILE *fp, int flags) {
-  swig_globalvar  *var;
-  flags = flags;
-  fprintf(fp,"Global variables { ");
-  for (var = v->vars; var; var=var->next) {
-    fprintf(fp,"%s", var->name);
-    if (var->next) fprintf(fp,", ");
-  }
-  fprintf(fp," }\n");
-  return 0;
-}
-
-static PyObject *
-swig_varlink_getattr(swig_varlinkobject *v, char *n) {
-  swig_globalvar *var = v->vars;
-  while (var) {
-    if (strcmp(var->name,n) == 0) {
-      return (*var->get_attr)();
-    }
-    var = var->next;
-  }
-  PyErr_SetString(PyExc_NameError,"Unknown C global variable");
-  return NULL;
-}
-
-static int
-swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) {
-  swig_globalvar *var = v->vars;
-  while (var) {
-    if (strcmp(var->name,n) == 0) {
-      return (*var->set_attr)(p);
-    }
-    var = var->next;
-  }
-  PyErr_SetString(PyExc_NameError,"Unknown C global variable");
-  return 1;
-}
-
-statichere PyTypeObject varlinktype = {
-  PyObject_HEAD_INIT(0)              
-  0,
-  "swigvarlink",                      /* Type name    */
-  sizeof(swig_varlinkobject),         /* Basic size   */
-  0,                                  /* Itemsize     */
-  0,                                  /* Deallocator  */ 
-  (printfunc) swig_varlink_print,     /* Print        */
-  (getattrfunc) swig_varlink_getattr, /* get attr     */
-  (setattrfunc) swig_varlink_setattr, /* Set attr     */
-  0,                                  /* tp_compare   */
-  (reprfunc) swig_varlink_repr,       /* tp_repr      */    
-  0,                                  /* tp_as_number */
-  0,                                  /* tp_as_mapping*/
-  0,                                  /* tp_hash      */
-};
-
-/* Create a variable linking object for use later */
-SWIGRUNTIME(PyObject *)
-SWIG_newvarlink(void) {
-  swig_varlinkobject *result = 0;
-  result = PyMem_NEW(swig_varlinkobject,1);
-  varlinktype.ob_type = &PyType_Type;    /* Patch varlinktype into a PyType */
-  result->ob_type = &varlinktype;
-  result->vars = 0;
-  result->ob_refcnt = 0;
-  Py_XINCREF((PyObject *) result);
-  return ((PyObject*) result);
-}
-
-SWIGRUNTIME(void)
-SWIG_addvarlink(PyObject *p, char *name,
-	   PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) {
-  swig_varlinkobject *v;
-  swig_globalvar *gv;
-  v= (swig_varlinkobject *) p;
-  gv = (swig_globalvar *) malloc(sizeof(swig_globalvar));
-  gv->name = (char *) malloc(strlen(name)+1);
-  strcpy(gv->name,name);
-  gv->get_attr = get_attr;
-  gv->set_attr = set_attr;
-  gv->next = v->vars;
-  v->vars = gv;
-}
-/* Convert a pointer value */
-SWIGRUNTIME(int)
-SWIG_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {
-  unsigned long p;
-  register int d;
-  swig_type_info *tc;
-  char  *c;
-  static PyObject *SWIG_this = 0;
-  int    newref = 0;
-
-  if (!obj || (obj == Py_None)) {
-    *ptr = 0;
-    return 0;
-  }
-#ifdef SWIG_COBJECT_TYPES
-  if (!(PyCObject_Check(obj))) {
-    if (!SWIG_this)
-      SWIG_this = PyString_InternFromString("this");
-    obj = PyObject_GetAttr(obj,SWIG_this);
-    newref = 1;
-    if (!obj) goto type_error;
-    if (!PyCObject_Check(obj)) {
-      Py_DECREF(obj);
-      goto type_error;
-    }
-  } 
-  *ptr = PyCObject_AsVoidPtr(obj);
-  c = (char *) PyCObject_GetDesc(obj);
-  if (newref) Py_DECREF(obj);
-  goto cobject;
-#else
-  if (!(PyString_Check(obj))) {
-    if (!SWIG_this)
-      SWIG_this = PyString_InternFromString("this");
-    obj = PyObject_GetAttr(obj,SWIG_this);
-    newref = 1;
-    if (!obj) goto type_error;
-    if (!PyString_Check(obj)) {
-      Py_DECREF(obj);
-      goto type_error;
-    }
-  } 
-  c = PyString_AsString(obj);
-  p = 0;
-  /* Pointer values must start with leading underscore */
-  if (*c != '_') {
-    *ptr = (void *) 0;
-    if (strcmp(c,"NULL") == 0) {
-      if (newref) Py_DECREF(obj);
-      return 0;
-    } else {
-      if (newref) Py_DECREF(obj);
-      goto type_error;
-    }
-  }
-  c++;
-  /* Extract hex value from pointer */
-  while ((d = *c)) {
-    if ((d >= '0') && (d <= '9'))
-      p = (p << 4) + (d - '0');
-    else if ((d >= 'a') && (d <= 'f'))
-      p = (p << 4) + (d - ('a'-10));
-    else
-      break; 
-    c++;
-  }
-  *ptr = (void *) p;
-  if (newref) Py_DECREF(obj);
-#endif
-
-#ifdef SWIG_COBJECT_TYPES
-cobject:
-#endif
-
-  if (ty) {
-    tc = SWIG_TypeCheck(c,ty);
-    if (!tc) goto type_error;
-    *ptr = SWIG_TypeCast(tc,(void*)p);
-  }
-  return 0;
-
-type_error:
-
-  if (flags) {
-    if (ty) {
-      char *temp = (char *) malloc(64+strlen(ty->name));
-      sprintf(temp,"Type error. Expected %s", ty->name);
-      PyErr_SetString(PyExc_TypeError, temp);
-      free((char *) temp);
-    } else {
-      PyErr_SetString(PyExc_TypeError,"Expected a pointer");
-    }
-  }
-  return -1;
-}
-
-/* Take a pointer and convert it to a string */
-SWIGRUNTIME(void) 
-SWIG_MakePtr(char *c, void *ptr, swig_type_info *ty) {
-  static char hex[17] = "0123456789abcdef";
-  unsigned long p, s;
-  char result[32], *r; 
-  r = result;
-  p = (unsigned long) ptr;
-  if (p > 0) {
-    while (p > 0) {
-      s = p & 0xf;
-      *(r++) = hex[s];
-      p = p >> 4;
-    }
-    *r = '_';
-    while (r >= result)
-      *(c++) = *(r--);
-    strcpy (c, ty->name);
-  } else {
-    strcpy (c, "NULL");
-  }
-}
-
-/* Create a new pointer object */
-SWIGRUNTIME(PyObject *)
-SWIG_NewPointerObj(void *ptr, swig_type_info *type) {
-  char result[512];
-  PyObject *robj;
-  if (!ptr) {
-    Py_INCREF(Py_None);
-    return Py_None;
-  }
-#ifdef SWIG_COBJECT_TYPES
-  robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, type->name, NULL);
-#else
-  SWIG_MakePtr(result,ptr,type);
-  robj = PyString_FromString(result);
-#endif
-  return robj;
-}
-
-/* Install Constants */
-SWIGRUNTIME(void)
-SWIG_InstallConstants(PyObject *d, swig_const_info constants[]) {
-  int i;
-  PyObject *obj;
-  for (i = 0; constants[i].type; i++) {
-    switch(constants[i].type) {
-    case SWIG_PY_INT:
-      obj = PyInt_FromLong(constants[i].lvalue);
-      break;
-    case SWIG_PY_FLOAT:
-      obj = PyFloat_FromDouble(constants[i].dvalue);
-      break;
-    case SWIG_PY_STRING:
-      obj = PyString_FromString((char *) constants[i].pvalue);
-      break;
-    case SWIG_PY_POINTER:
-      obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype);
-      break;
-    default:
-      obj = 0;
-      break;
-    }
-    if (obj) {
-      PyDict_SetItemString(d,constants[i].name,obj);
-      Py_DECREF(obj);
-    }
-  }
-}
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-
-
-/* -------- TYPES TABLE (BEGIN) -------- */
-
-static swig_type_info *swig_types[1];
-
-/* -------- TYPES TABLE (END) -------- */
-
-#define SWIG_init    init_vq
-
-#define SWIG_name    "_vq"
-
-
-#include "vq.h"
-
-/* Wrappers for the template code */
-
-void float_vq(float * obs,float* code_book, int Nobs, int Ncodes, 
-              int Nfeatures, int* codes, float* lowest_dist)
-{
-    tvq<float>(obs,code_book,Nobs,Ncodes,Nfeatures,codes,lowest_dist);
-}
-
-void double_vq(double * obs,double* code_book, int Nobs, int Ncodes, 
-              int Nfeatures, int* codes, double* lowest_dist)
-{
-    tvq<double>(obs,code_book,Nobs,Ncodes,Nfeatures,codes,lowest_dist);
-}
-
-
-static PyObject* l_output_helper(PyObject* target, PyObject* o) {
-    PyObject*   o2;
-    if (!target) {                   
-        target = o;
-    } else if (target == Py_None) {  
-        Py_DECREF(Py_None);
-        target = o;
-    } else {                         
-        if (!PyList_Check(target)) {
-            o2 = target;
-            target = PyList_New(0);
-            PyList_Append(target, o2);
-	    Py_XDECREF(o2);
-        }
-        PyList_Append(target,o);
-	Py_XDECREF(o);
-    }
-    return target;
-}
-
-static PyObject* t_output_helper(PyObject* target, PyObject* o) {
-    PyObject*   o2;
-    PyObject*   o3;
-
-    if (!target) {                   
-        target = o;
-    } else if (target == Py_None) {  
-        Py_DECREF(Py_None);
-        target = o;
-    } else {                         
-        if (!PyTuple_Check(target)) {
-            o2 = target;
-            target = PyTuple_New(1);
-            PyTuple_SetItem(target, 0, o2);
-        }
-        o3 = PyTuple_New(1);            
-        PyTuple_SetItem(o3, 0, o);      
-
-        o2 = target;
-        target = PySequence_Concat(o2, o3); 
-        Py_DECREF(o2);                      
-        Py_DECREF(o3);
-    }
-    return target;
-}
-
-
-#include "numpy/noprefix.h"
-
-// hmmm. how do we prevent typedefs from conflicting
-// with users definition on complex numbers?
-//#include "complex_test.h"
-//typedef struct{ float real; 
-//                float imag;} complex;
-//typedef struct{ double real; 
-//                double imag;} zcomplex;
-
-
-// used for converting typecodes to memory sizes.
-int char_to_size(char type)
-{
-    if (type=='i') return sizeof(int);
-    if (type=='f') return sizeof(float);
-    if (type=='d') return sizeof(double);
-    if (type=='c') return 2*sizeof(float);
-    if (type=='z') return 2*sizeof(double);
-}
-int char_to_numtype(char type)
-{
-    if (type=='i') return 'i';
-    if (type=='f') return 'f';
-    if (type=='d') return 'd';
-    if (type=='c') return 'F';
-    if (type=='z') return 'D';
-}
-
-
-typedef int int_IN_D0;
-typedef float float_IN_D0;
-typedef double double_IN_D0;
-typedef int int_IN_D1;
-typedef float float_IN_D1;
-typedef double double_IN_D1;
-typedef int int_IN_D2;
-typedef float float_IN_D2;
-typedef double double_IN_D2;
-typedef int int_IN_D0_D1;
-typedef float float_IN_D0_D1;
-typedef double double_IN_D0_D1;
-typedef int int_IN_D0_D2;
-typedef float float_IN_D0_D2;
-typedef double double_IN_D0_D2;
-typedef int int_IN_D1_D2;
-typedef float float_IN_D1_D2;
-typedef double double_IN_D1_D2;
-typedef int int_IN_D0_D1_D2;
-typedef float float_IN_D0_D1_D2;
-typedef double double_IN_D0_D1_D2;
-
-
-typedef int int_ARGOUT_D0;
-typedef float float_ARGOUT_D0;
-typedef double double_ARGOUT_D0;
-typedef int int_ARGOUT_D1;
-typedef float float_ARGOUT_D1;
-typedef double double_ARGOUT_D1;
-typedef int int_ARGOUT_D2;
-typedef float float_ARGOUT_D2;
-typedef double double_ARGOUT_D2;
-typedef int int_ARGOUT_D0_D1;
-typedef float float_ARGOUT_D0_D1;
-typedef double double_ARGOUT_D0_D1;
-typedef int int_ARGOUT_D0_D2;
-typedef float float_ARGOUT_D0_D2;
-typedef double double_ARGOUT_D0_D2;
-typedef int int_ARGOUT_D1_D2;
-typedef float float_ARGOUT_D1_D2;
-typedef double double_ARGOUT_D1_D2;
-typedef int int_ARGOUT_D0_D1_D2;
-typedef float float_ARGOUT_D0_D1_D2;
-typedef double double_ARGOUT_D0_D1_D2;
-
-
-typedef int int_ARGOUT_TUPLE_D0;
-typedef float float_ARGOUT_TUPLE_D0;
-typedef double double_ARGOUT_TUPLE_D0;
-typedef int int_ARGOUT_TUPLE_D1;
-typedef float float_ARGOUT_TUPLE_D1;
-typedef double double_ARGOUT_TUPLE_D1;
-typedef int int_ARGOUT_TUPLE_D2;
-typedef float float_ARGOUT_TUPLE_D2;
-typedef double double_ARGOUT_TUPLE_D2;
-typedef int int_ARGOUT_TUPLE_D0_D1;
-typedef float float_ARGOUT_TUPLE_D0_D1;
-typedef double double_ARGOUT_TUPLE_D0_D1;
-typedef int int_ARGOUT_TUPLE_D0_D2;
-typedef float float_ARGOUT_TUPLE_D0_D2;
-typedef double double_ARGOUT_TUPLE_D0_D2;
-typedef int int_ARGOUT_TUPLE_D1_D2;
-typedef float float_ARGOUT_TUPLE_D1_D2;
-typedef double double_ARGOUT_TUPLE_D1_D2;
-typedef int int_ARGOUT_TUPLE_D0_D1_D2;
-typedef float float_ARGOUT_TUPLE_D0_D1_D2;
-typedef double double_ARGOUT_TUPLE_D0_D1_D2;
-
-
-typedef int int_OUT_D0;
-typedef float float_OUT_D0;
-typedef double double_OUT_D0;
-typedef int int_OUT_D1;
-typedef float float_OUT_D1;
-typedef double double_OUT_D1;
-typedef int int_OUT_D2;
-typedef float float_OUT_D2;
-typedef double double_OUT_D2;
-typedef int int_OUT_D0_D1;
-typedef float float_OUT_D0_D1;
-typedef double double_OUT_D0_D1;
-typedef int int_OUT_D0_D2;
-typedef float float_OUT_D0_D2;
-typedef double double_OUT_D0_D2;
-typedef int int_OUT_D1_D2;
-typedef float float_OUT_D1_D2;
-typedef double double_OUT_D1_D2;
-typedef int int_OUT_D0_D1_D2;
-typedef float float_OUT_D0_D1_D2;
-typedef double double_OUT_D0_D1_D2;
-
-
-                                                                        
-PyArrayObject* IN_in(PyObject* source, char* basetype_string,             
-                             int** target_dims, int dims)                 
-{                                                                         
-    PyArrayObject *a_obj;                                                 
-    char ar_type = char_to_numtype(basetype_string[0]);                   
-    a_obj = (PyArrayObject*) PyArray_ContiguousFromObject(source,ar_type, 
-                                                             dims,dims);  
-    if (a_obj == NULL)                                                    
-    {                                                                     
-        //PyArray Contiguous From Object will set the error value.        
-    	return NULL;                                                      
-    }                                                                     
-    for(int i = 0; i < dims;i++)                                          
-    {                                                                     
-        *(target_dims[i]) = a_obj->dimensions[i];                         
-    }                                                                     
-    return a_obj;                                                         
-}                                                                         
-                                                                          
-
-char* ARGOUT_check(char* basetype_string,int* dims, int dim_len)
-{
-    char *rdata;
-    int element_size = char_to_size(basetype_string[0]);
-    int tot_length = 1;
-    for (int i = 0; i < dim_len; i++)
-        tot_length *= dims[i];        
-    rdata = (char*)malloc(tot_length*element_size);
-    if(rdata == NULL)
-	{
-	    PyErr_SetString(PyExc_MemoryError, "can't allocate memory for output array for arg$argnum");
-	    return NULL;
-	}	
-    return rdata;
-}
-
-PyObject* ARGOUT_argout(char* source, char* basetype_string, 
-                                int* dims, int dim_len)
-{
-    PyArrayObject *res;
-    char array_type = char_to_numtype(basetype_string[0]);
-    res = (PyArrayObject *)PyArray_FromDimsAndData(dim_len, dims, 
-                                                   array_type,source);
-    if(res == NULL)
-    {
-        //PyErr_SetString(PyExc_ValueError, "error converting internal data to array");
-    	return NULL;
-    }
-    res->flags |= NPY_OWNDATA; // we want the array to deallocate mem when it is finished.
-    // stick result in the output tuple (target).
-    // Need to think about generality of this one...
-    return (PyObject *) res;
-}
-#ifdef __cplusplus
-extern "C" {
-#endif
-static PyObject *_wrap_double_vq(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    double_IN_D0_D2 *arg0 ;
-    double_IN_D1_D2 *arg1 ;
-    int arg2 ;
-    int arg3 ;
-    int arg4 ;
-    int_ARGOUT_TUPLE_D0 *arg5 ;
-    double_ARGOUT_TUPLE_D0 *arg6 ;
-    int *_d0 ;
-    int *_d1 ;
-    int *_d2 ;
-    PyObject * obj0  = 0 ;
-    PyObject * obj1  = 0 ;
-    
-    {
-        _d0 = &arg2; 
-    }
-    {
-        _d1 = &arg3; 
-    }
-    {
-        _d2 = &arg4; 
-    }
-    {
-    }
-    {
-    }
-    if(!PyArg_ParseTuple(args,"OO:double_vq",&obj0,&obj1)) return NULL;
-    {
-        int* targ_dims[2] = {
-            _d0,_d2
-        };
-        PyArrayObject* a_obj = IN_in(obj0,"double_IN_D0_D2",targ_dims,2);
-        if (a_obj == NULL) return NULL;
-        arg0 = (double_IN_D0_D2 *) a_obj->data;
-        obj0 = (PyObject*)a_obj;
-    }
-    {
-        int* targ_dims[2] = {
-            _d1,_d2
-        };
-        PyArrayObject* a_obj = IN_in(obj1,"double_IN_D1_D2",targ_dims,2);
-        if (a_obj == NULL) return NULL;
-        arg1 = (double_IN_D1_D2 *) a_obj->data;
-        obj1 = (PyObject*)a_obj;
-    }
-    {
-        int dim_len = 1;
-        int dims[1] = {
-            *_d0
-        };
-        arg5 = (int_ARGOUT_TUPLE_D0 *) ARGOUT_check("int_ARGOUT_TUPLE_D0",dims,dim_len);
-        if (arg5 == NULL) return NULL;
-    }
-    {
-        int dim_len = 1;
-        int dims[1] = {
-            *_d0
-        };
-        arg6 = (double_ARGOUT_TUPLE_D0 *) ARGOUT_check("double_ARGOUT_TUPLE_D0",dims,dim_len);
-        if (arg6 == NULL) return NULL;
-    }
-    double_vq(arg0,arg1,arg2,arg3,arg4,arg5,arg6);
-    Py_INCREF(Py_None);
-    resultobj = Py_None;
-    {
-        int dim_len = 1;
-        int dims[1] = {
-            *_d0
-        };
-        PyObject * res;
-        res = ARGOUT_argout( (char*) arg5,"int_ARGOUT_TUPLE_D0",
-        dims, dim_len);
-        if (resultobj == NULL) 
-        return NULL;
-        resultobj = t_output_helper(resultobj, res);
-    }
-    {
-        int dim_len = 1;
-        int dims[1] = {
-            *_d0
-        };
-        PyObject * res;
-        res = ARGOUT_argout( (char*) arg6,"double_ARGOUT_TUPLE_D0",
-        dims, dim_len);
-        if (resultobj == NULL) 
-        return NULL;
-        resultobj = t_output_helper(resultobj, res);
-    }
-    {
-        Py_XDECREF(obj0); 
-    }
-    {
-        Py_XDECREF(obj1); 
-    }
-    return resultobj;
-}
-
-
-static PyObject *_wrap_float_vq(PyObject *self, PyObject *args) {
-    PyObject *resultobj;
-    float_IN_D0_D2 *arg0 ;
-    float_IN_D1_D2 *arg1 ;
-    int arg2 ;
-    int arg3 ;
-    int arg4 ;
-    int_ARGOUT_TUPLE_D0 *arg5 ;
-    float_ARGOUT_TUPLE_D0 *arg6 ;
-    int *_d0 ;
-    int *_d1 ;
-    int *_d2 ;
-    PyObject * obj0  = 0 ;
-    PyObject * obj1  = 0 ;
-    
-    {
-        _d0 = &arg2; 
-    }
-    {
-        _d1 = &arg3; 
-    }
-    {
-        _d2 = &arg4; 
-    }
-    {
-    }
-    {
-    }
-    if(!PyArg_ParseTuple(args,"OO:float_vq",&obj0,&obj1)) return NULL;
-    {
-        int* targ_dims[2] = {
-            _d0,_d2
-        };
-        PyArrayObject* a_obj = IN_in(obj0,"float_IN_D0_D2",targ_dims,2);
-        if (a_obj == NULL) return NULL;
-        arg0 = (float_IN_D0_D2 *) a_obj->data;
-        obj0 = (PyObject*)a_obj;
-    }
-    {
-        int* targ_dims[2] = {
-            _d1,_d2
-        };
-        PyArrayObject* a_obj = IN_in(obj1,"float_IN_D1_D2",targ_dims,2);
-        if (a_obj == NULL) return NULL;
-        arg1 = (float_IN_D1_D2 *) a_obj->data;
-        obj1 = (PyObject*)a_obj;
-    }
-    {
-        int dim_len = 1;
-        int dims[1] = {
-            *_d0
-        };
-        arg5 = (int_ARGOUT_TUPLE_D0 *) ARGOUT_check("int_ARGOUT_TUPLE_D0",dims,dim_len);
-        if (arg5 == NULL) return NULL;
-    }
-    {
-        int dim_len = 1;
-        int dims[1] = {
-            *_d0
-        };
-        arg6 = (float_ARGOUT_TUPLE_D0 *) ARGOUT_check("float_ARGOUT_TUPLE_D0",dims,dim_len);
-        if (arg6 == NULL) return NULL;
-    }
-    float_vq(arg0,arg1,arg2,arg3,arg4,arg5,arg6);
-    Py_INCREF(Py_None);
-    resultobj = Py_None;
-    {
-        int dim_len = 1;
-        int dims[1] = {
-            *_d0
-        };
-        PyObject * res;
-        res = ARGOUT_argout( (char*) arg5,"int_ARGOUT_TUPLE_D0",
-        dims, dim_len);
-        if (resultobj == NULL) 
-        return NULL;
-        resultobj = t_output_helper(resultobj, res);
-    }
-    {
-        int dim_len = 1;
-        int dims[1] = {
-            *_d0
-        };
-        PyObject * res;
-        res = ARGOUT_argout( (char*) arg6,"float_ARGOUT_TUPLE_D0",
-        dims, dim_len);
-        if (resultobj == NULL) 
-        return NULL;
-        resultobj = t_output_helper(resultobj, res);
-    }
-    {
-        Py_XDECREF(obj0); 
-    }
-    {
-        Py_XDECREF(obj1); 
-    }
-    return resultobj;
-}
-
-
-static PyMethodDef _vqMethods[] = {
-	 { "double_vq", _wrap_double_vq, METH_VARARGS },
-	 { "float_vq", _wrap_float_vq, METH_VARARGS },
-	 { NULL, NULL }
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */
-
-
-static swig_type_info *swig_types_initial[] = {
-0
-};
-
-
-/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */
-
-static swig_const_info swig_const_table[] = {
-{0}};
-
-static PyObject *SWIG_globals;
-#ifdef __cplusplus
-extern "C" 
-#endif
-SWIGEXPORT(void) init_vq(void) {
-    PyObject *m, *d;
-    int i;
-    SWIG_globals = SWIG_newvarlink();
-    m = Py_InitModule("_vq", _vqMethods);
-    d = PyModule_GetDict(m);
-    for (i = 0; swig_types_initial[i]; i++) {
-        swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]);
-    }
-    
-    import_array();
-    SWIG_InstallConstants(d,swig_const_table);
-}
-

Modified: trunk/Lib/cluster/tests/test_vq.py
===================================================================
--- trunk/Lib/cluster/tests/test_vq.py	2007-06-18 23:22:19 UTC (rev 3109)
+++ trunk/Lib/cluster/tests/test_vq.py	2007-06-19 15:07:48 UTC (rev 3110)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 
 # David Cournapeau
-# Last Change: Fri Jun 08 12:00 PM 2007 J
+# Last Change: Tue Jun 19 10:00 PM 2007 J
 
 # For now, just copy the tests from sandbox.pyem, so we can check that
 # kmeans works OK for trivial examples.
@@ -12,7 +12,7 @@
 import numpy as N
 
 set_package_path()
-from cluster.vq import kmeans, kmeans2, py_vq, py_vq2, _py_vq_1d
+from cluster.vq import kmeans, kmeans2, py_vq, py_vq2, _py_vq_1d, vq
 try:
     from cluster import _vq
     TESTC=True
@@ -60,19 +60,36 @@
         initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
         code = initc.copy()
         if TESTC:
-            label1 = _vq.double_vq(X, initc)[0]
+            label1, dist = _vq.vq(X, initc)
             assert_array_equal(label1, LABEL1)
+            tlabel1, tdist = vq(X, initc)
         else:
             print "== not testing C imp of vq =="
 
-    #def check_vq_1d(self, level=1):
+    #def check_py_vq_1d(self, level=1):
+    #    """Test special rank 1 vq algo, python implementation."""
     #    data = X[:, 0]
     #    initc = data[:3]
     #    code = initc.copy()
-    #    print _py_vq_1d(data, initc)
+    #    a, b = _py_vq_1d(data, initc)
+    #    ta, tb = py_vq(data[:, N.newaxis], initc[:, N.newaxis])
+    #    assert_array_equal(a, ta)
+    #    assert_array_equal(b, tb)
 
+    def check_vq_1d(self, level=1):
+        """Test special rank 1 vq algo, python implementation."""
+        data = X[:, 0]
+        initc = data[:3]
+        code = initc.copy()
+        if TESTC:
+            a, b = _vq.vq(data, initc)
+            ta, tb = py_vq(data[:, N.newaxis], initc[:, N.newaxis])
+            assert_array_equal(a, ta)
+            assert_array_equal(b, tb)
+        else:
+            print "== not testing C imp of vq (rank 1) =="
+
 class test_kmean(NumpyTestCase):
-    #def check_kmeans
     def check_kmeans_simple(self, level=1):
         initc = N.concatenate(([[X[0]], [X[1]], [X[2]]]))
         code = initc.copy()
@@ -100,18 +117,17 @@
         assert_array_almost_equal(code1, CODET1)
         assert_array_almost_equal(code2, CODET2)
 
-    #def check_kmeans2_rank1(self, level=1):
-    #    """Testing simple call to kmeans2 with rank 1 data."""
-    #    data = N.fromfile(open(DATAFILE1), sep = ", ")
-    #    data = data.reshape((200, 2))
-    #    data1 = data[:, 0]
-    #    data2 = data[:, 1]
+    def check_kmeans2_rank1(self, level=1):
+        """Testing simple call to kmeans2 with rank 1 data."""
+        data = N.fromfile(open(DATAFILE1), sep = ", ")
+        data = data.reshape((200, 2))
+        data1 = data[:, 0]
+        data2 = data[:, 1]
 
-    #    initc = data1[:3]
-    #    code = initc.copy()
-    #    print _py_vq_1d(data1, code)
-    #    code1 = kmeans2(data1, code, niter = 1)[0]
-    #    code2 = kmeans2(data1, code, niter = 2)[0]
+        initc = data1[:3]
+        code = initc.copy()
+        code1 = kmeans2(data1, code, iter = 1)[0]
+        code2 = kmeans2(data1, code, iter = 2)[0]
 
     def check_kmeans2_init(self, level = 1):
         """Testing that kmeans2 init methods work."""
@@ -126,6 +142,5 @@
         kmeans2(data, 3, minit = 'random')
         kmeans2(data, 3, minit = 'points')
 
-
 if __name__ == "__main__":
     NumpyTest().run()

Modified: trunk/Lib/cluster/vq.py
===================================================================
--- trunk/Lib/cluster/vq.py	2007-06-18 23:22:19 UTC (rev 3109)
+++ trunk/Lib/cluster/vq.py	2007-06-19 15:07:48 UTC (rev 3110)
@@ -139,9 +139,9 @@
         c_obs = obs.astype(ct)
         c_code_book = code_book.astype(ct)
         if ct is single:
-            results = _vq.float_vq(c_obs, c_code_book)
+            results = _vq.vq(c_obs, c_code_book)
         elif ct is double:
-            results = _vq.double_vq(c_obs, c_code_book)
+            results = _vq.vq(c_obs, c_code_book)
         else:
             results = py_vq(obs, code_book)
     except ImportError:
@@ -512,7 +512,7 @@
     nd  = N.ndim(data)
     if nd == 1:
         d = 1
-        raise ValueError("Input of rank 1 not supported yet")
+        #raise ValueError("Input of rank 1 not supported yet")
     elif nd == 2:
         d = data.shape[1]
     else:
@@ -560,9 +560,21 @@
         for j in range(nc):
             mbs = N.where(label==j)
             if mbs[0].size > 0:
-                code[j,:] = N.mean(data[mbs], axis=0)
+                code[j] = N.mean(data[mbs], axis=0)
             else:
                 warnings.warn("One of the clusters are empty. " \
                               "Re-run kmean with a different initialization.")
 
     return code, label
+
+if __name__  == '__main__':
+    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)



More information about the Scipy-svn mailing list