From 148c5ef65df548f4fc39490a55ca2d290504ccd7 Mon Sep 17 00:00:00 2001 From: Fabian Pedregosa <fabian.pedregosa@inria.fr> Date: Thu, 16 Dec 2010 20:34:59 +0100 Subject: [PATCH] More robust utils.fixes. --- scikits/learn/utils/fixes.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/scikits/learn/utils/fixes.py b/scikits/learn/utils/fixes.py index bf5307f99a..9937b3e60c 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 -- GitLab