diff --git a/scikits/learn/utils/fixes.py b/scikits/learn/utils/fixes.py index bf5307f99a1ee7036a30d99cc7e6730b72fca06f..9937b3e60c71a3057695b35a89e6b42e18b5f1a4 100644 --- a/scikits/learn/utils/fixes.py +++ b/scikits/learn/utils/fixes.py @@ -3,6 +3,7 @@ Fixes for older version of numpy and scipy. """ # Authors: Emmanuelle Gouillart <emmanuelle.gouillart@normalesup.org> # Gael Varoquaux <gael.varoquaux@normalesup.org> +# Fabian Pedregosa <fpedregosa@acm.org> # License: BSD import numpy as np @@ -46,6 +47,11 @@ def _unique(ar, return_index=False, return_inverse=False): flag = np.concatenate(([True], ar[1:] != ar[:-1])) return ar[flag] +if not hasattr(np, 'unique'): + unique = _unique +else: + unique = np.unique + def _copysign (x1, x2): """ @@ -53,6 +59,12 @@ def _copysign (x1, x2): """ return np.abs(x1) * np.sign(x2) +if not hasattr(np, 'copysign'): + copysign = _copysign +else: + copysign = np.copysign + + def _in1d(ar1, ar2, assume_unique=False): """ Replacement for in1d that is provided for numpy >= 1.4 """ @@ -74,6 +86,11 @@ def _in1d(ar1, ar2, assume_unique=False): else: return flag[indx][rev_idx] +if not hasattr(np, 'in1d'): + in1d = _in1d +else: + in1d = np.in1d + def qr_economic(A, **kwargs): """ @@ -86,6 +103,7 @@ def qr_economic(A, **kwargs): else: return scipy.linalg.qr(A, econ=True, **kwargs) + def arpack_eigsh(A, **kwargs): """ Scipy 0.9 renamed eigen_symmetric to eigsh in @@ -97,13 +115,6 @@ def arpack_eigsh(A, **kwargs): else: return arpack.eigen_symmetric(A, **kwargs) -# export fixes for np < 1.4 -if not hasattr(np, 'copysign'): - in1d = _in1d - copysign = _copysign - unique = _unique -else: - from numpy import in1d, copysign, unique