[Scipy-svn] r4151 - in trunk/scipy/cluster: . tests

scipy-svn@scip... scipy-svn@scip...
Thu Apr 17 22:15:09 CDT 2008


Author: damian.eads
Date: 2008-04-17 22:15:07 -0500 (Thu, 17 Apr 2008)
New Revision: 4151

Modified:
   trunk/scipy/cluster/hierarchy.py
   trunk/scipy/cluster/tests/test_hierarchy.py
Log:
Minor change to type checking in pdist('mahalanobis', ...)

Modified: trunk/scipy/cluster/hierarchy.py
===================================================================
--- trunk/scipy/cluster/hierarchy.py	2008-04-18 03:06:35 UTC (rev 4150)
+++ trunk/scipy/cluster/hierarchy.py	2008-04-18 03:15:07 UTC (rev 4151)
@@ -1366,15 +1366,15 @@
                 _hierarchy_wrap.pdist_jaccard_bool_wrap(X, dm)
             else:
                 raise TypeError('Invalid input array value type %s for jaccard.' % str(X.dtype))
-        elif mstr in set(['chebyshev', 'cheby', 'cheb', 'ch']):
+        elif mstr in set(['chebychev', 'chebyshev', 'cheby', 'cheb', 'ch']):
             _hierarchy_wrap.pdist_chebyshev_wrap(X, dm)            
         elif mstr in set(['minkowski', 'mi', 'm']):
             _hierarchy_wrap.pdist_minkowski_wrap(X, dm, p)
         elif mstr in set(['seuclidean', 'se', 's']):
-            if V:
+            if V is not None:
                 if type(V) is not _array_type:
                     raise TypeError('Variance vector V must be a numpy array')
-                if V.dtype != 'double':
+                if V.dtype != 'float64':
                     raise TypeError('Variance vector V must contain doubles.')
                 if len(V.shape) != 1:
                     raise ValueError('Variance vector V must be one-dimensional.')
@@ -1408,11 +1408,11 @@
             norms = numpy.sqrt(numpy.sum(X2 * X2, axis=1))
             _hierarchy_wrap.pdist_cosine_wrap(X2, dm, norms)
         elif mstr in set(['mahalanobis', 'mahal', 'mah']):
-            if VI:
+            if VI is not None:
                 if type(VI) != _array_type:
                     raise TypeError('VI must be a numpy array.')
-                if VI.dtype != 'double':
-                    raise TypeError('The array must contain doubles.')
+                if VI.dtype != 'float64':
+                    raise TypeError('The array must contain 64-bit floats.')
                 [VI] = _copy_arrays_if_base_present([VI])
             else:
                 V = numpy.cov(X.T)
@@ -1466,7 +1466,7 @@
             dm = pdist(X, hamming)
         elif metric == 'test_jaccard':
             dm = pdist(X, jaccard)
-        elif metric == 'test_chebyshev':
+        elif metric == 'test_chebyshev' or metric == 'test_chebychev':
             dm = pdist(X, chebyshev)
         elif metric == 'test_yule':
             dm = pdist(X, yule)

Modified: trunk/scipy/cluster/tests/test_hierarchy.py
===================================================================
--- trunk/scipy/cluster/tests/test_hierarchy.py	2008-04-18 03:06:35 UTC (rev 4150)
+++ trunk/scipy/cluster/tests/test_hierarchy.py	2008-04-18 03:15:07 UTC (rev 4151)
@@ -149,7 +149,7 @@
         VI = numpy.zeros((10, 10), dtype='float96')
 
         try:
-            pdist(X, 'mahalanobis', VI)
+            pdist(X, 'mahalanobis', VI=VI)
         except TypeError:
             pass
         except:



More information about the Scipy-svn mailing list