Skip to content

Commit

Permalink
Compatibility fixes for scipy <= 0.7 and numpy <= 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Pedregosa committed Oct 4, 2010
1 parent 4def939 commit 3baf985
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
13 changes: 7 additions & 6 deletions scikits/learn/cross_val.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from .base import is_classifier, clone
from .utils.extmath import factorial, combinations
from .utils.fixes import unique
from .externals.joblib import Parallel, delayed

##############################################################################
Expand Down Expand Up @@ -257,7 +258,7 @@ def __init__(self, y, k):
assert k>0, ValueError('cannot have k below 1')
assert k<n, ValueError('cannot have k=%d greater than the number '
'of samples %d' % (k, n))
_, y_sorted = np.unique1d(y, return_inverse=True)
_, y_sorted = unique(y, return_inverse=True)
assert k <= np.min(np.bincount(y_sorted))
self.y = y
self.k = k
Expand All @@ -267,7 +268,7 @@ def __iter__(self):
k = self.k
n = y.size

classes = np.unique(y)
classes = unique(y)

idx_c = dict()
j_c = dict()
Expand Down Expand Up @@ -345,12 +346,12 @@ def __init__(self, labels):
"""
self.labels = labels
self.n_labels = np.unique(labels).size
self.n_labels = unique(labels).size

def __iter__(self):
# We make a copy here to avoid side-effects during iteration
labels = np.array(self.labels, copy=True)
for i in np.unique(labels):
for i in unique(labels):
test_index = np.zeros(len(labels), dtype=np.bool)
test_index[labels==i] = True
train_index = np.logical_not(test_index)
Expand Down Expand Up @@ -412,14 +413,14 @@ def __init__(self, labels, p):
"""
self.labels = labels
self.unique_labels = np.unique(self.labels)
self.unique_labels = unique(self.labels)
self.n_labels = self.unique_labels.size
self.p = p

def __iter__(self):
# We make a copy here to avoid side-effects during iteration
labels = np.array(self.labels, copy=True)
unique_labels = np.unique(labels)
unique_labels = unique(labels)
n_labels = unique_labels.size
comb = combinations(range(n_labels), self.p)

Expand Down
4 changes: 2 additions & 2 deletions scikits/learn/svm/sparse/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ def fit(self, X, Y, class_weight={}):
self.support_ = sparse.csr_matrix((self._support_data,
self._support_indices,
self._support_indptr),
shape=(n_SV, X.shape[1])
(n_SV, X.shape[1])
)

self.dual_coef_ = sparse.csr_matrix((self._dual_coef_data,
dual_coef_indices,
dual_coef_indptr),
shape=(n_class, n_SV)
(n_class, n_SV)
)
return self

Expand Down
7 changes: 5 additions & 2 deletions scikits/learn/utils/_csgraph.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Compressed Sparse graph algorithms"""
# Backported from scipy 0.9: scipy.sparse.csgraph

# Some compatibility fixes for scipy 0.6
# Fabian Pedregosa, October 2010

__docformat__ = "restructuredtext en"

__all__ = ['cs_graph_components']
Expand All @@ -9,8 +12,8 @@

from sparsetools import cs_graph_components as _cs_graph_components

from scipy.sparse.csr import csr_matrix
from scipy.sparse.base import isspmatrix
from scipy.sparse import csr_matrix
from scipy.sparse import isspmatrix

_msg0 = 'x must be a symmetric square matrix!'
_msg1 = _msg0 + '(has shape %s)'
Expand Down

0 comments on commit 3baf985

Please sign in to comment.