Skip to content
This repository was archived by the owner on Jul 24, 2020. It is now read-only.

Commit 0ade879

Browse files
committed
ENH Compile & install on Python 3
1 parent 0c83425 commit 0ade879

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+232
-224
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ build
99
dist/
1010
milk.egg-info
1111
docs/milk/
12+
*.cpython*.so

milk/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Copyright (C) 2008-2013, Luis Pedro Coelho <[email protected]>
2+
# Copyright (C) 2008-2015, Luis Pedro Coelho <[email protected]>
33
# vim: set ts=4 sts=4 sw=4 expandtab smartindent:
44
#
55
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -59,10 +59,10 @@
5959
from .supervised.defaultlearner import defaultlearner
6060
from .unsupervised.kmeans import kmeans
6161
from .unsupervised import pdist, zscore, pca
62-
from milk_version import __version__
63-
except ImportError, e:
62+
from .milk_version import __version__
63+
except ImportError as e:
6464
import sys
65-
print >>sys.stderr, '''\
65+
print('''\
6666
Could not import submodules (exact error was: %s).
6767
6868
There are many reasons for this error the most common one is that you have
@@ -71,7 +71,7 @@
7171
milk **without changing the current directory**.
7272
7373
Try installing and then changing to another directory before importing milk.
74-
''' % e
74+
''' % e, file=sys.stderr)
7575

7676
__all__ = [
7777
'__version__',

milk/active/eimpact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def expected_impacts(D,labels,U):
4444
u_labels = (u_probs > .5)
4545
impacts = []
4646
for u,p in zip(U,u_probs):
47-
print len(impacts)
47+
print(len(impacts))
4848
label_classifier.train(numpy.vstack((D,u)),numpy.hstack((labels,[0])))
4949
u_labels_0 = label_classifier(U)
5050

milk/demos/rf_wine_2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# cross validate with this learner and return predictions on left-out elements
1717
cmat,names, preds = milk.nfoldcrossvalidation(features, labels, classifier=learner, return_predictions=1)
1818

19-
print 'cross-validation accuracy:', cmat.trace()/float(cmat.sum())
19+
print('cross-validation accuracy:', cmat.trace()/float(cmat.sum()))
2020

2121
# dimensionality reduction for display
2222
x,v = milk.unsupervised.pca(features)

milk/ext/jugparallel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ def nfoldcrossvalidation(features, labels, **kwargs):
6464
jug.CompoundTask : This function can be used as argument to CompoundTask
6565
'''
6666
nfolds = kwargs.get('nfolds', 10)
67-
features,labels = map(identity, (features,labels))
68-
kwargs = dict( (k,identity(v)) for k,v in kwargs.iteritems())
67+
features,labels = list(map(identity, (features,labels)))
68+
kwargs = dict( (k,identity(v)) for k,v in kwargs.items())
6969
nfold_one = TaskGenerator(milk.nfoldcrossvalidation)
70-
mapped = [nfold_one(features, labels, folds=[i], **kwargs) for i in xrange(nfolds)]
70+
mapped = [nfold_one(features, labels, folds=[i], **kwargs) for i in range(nfolds)]
7171
return jug_reduce(_nfold_reduce, mapped)
7272

7373

@@ -137,7 +137,7 @@ def kmeans_select_best(features, ks, repeats=1, method='AIC', R=None, **kwargs):
137137
start = 7
138138
results = []
139139
for ki,k in enumerate(ks):
140-
for i in xrange(repeats):
140+
for i in range(repeats):
141141
results.append(kmeans(features, k, R=(start+7*repeats*ki+i), **kwargs))
142142
return _select_best(features, results, method)[1]
143143

milk/measures/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from measures import accuracy, waccuracy, zero_one_loss, confusion_matrix, bayesian_significance
1+
from .measures import accuracy, waccuracy, zero_one_loss, confusion_matrix, bayesian_significance

milk/measures/measures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def confusion_matrix(real, predicted, normalisedlabels=False, names=None):
119119
if not normalisedlabels:
120120
from ..supervised.normalise import normaliselabels
121121
real, names = normaliselabels(real)
122-
predicted = map(names.index, predicted)
122+
predicted = list(map(names.index, predicted))
123123
n = np.max(real)+1
124124
cmat = np.zeros((n,n))
125125
for r,p in zip(real, predicted):

milk/measures/nfoldcrossvalidation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from __future__ import division
77
from ..supervised.classifier import normaliselabels
88
import numpy as np
9+
from functools import reduce
910

1011
__all__ = ['foldgenerator', 'getfold', 'nfoldcrossvalidation']
1112
def foldgenerator(labels, nfolds=None, origins=None, folds=None, multi_label=False):
@@ -45,7 +46,7 @@ def foldgenerator(labels, nfolds=None, origins=None, folds=None, multi_label=Fal
4546
'milk.nfoldcrossvalidation.foldgenerator: origins must be of same size as labels')
4647
origins = np.asanyarray(origins)
4748
fmin = len(labels)
48-
for ell in xrange(len(names)):
49+
for ell in range(len(names)):
4950
if multi_label:
5051
matching = (orig for i,orig in enumerate(origins) if labels[i,ell])
5152
else:
@@ -92,7 +93,7 @@ def foldgenerator(labels, nfolds=None, origins=None, folds=None, multi_label=Fal
9293
fold[origins == orig] = f
9394
foldweight[f] += w
9495

95-
for f in xrange(nfolds):
96+
for f in range(nfolds):
9697
if folds is not None and f not in folds: continue
9798
yield (fold != f), (fold == f)
9899

milk/supervised/_lasso.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <cassert>
99
#include <queue>
1010
#include "eigen3/Eigen/Dense"
11+
#include "../utils/utils.h"
1112

1213
using namespace Eigen;
1314

@@ -198,10 +199,5 @@ const char * module_doc =
198199

199200
} // namespace
200201

201-
extern "C"
202-
void init_lasso()
203-
{
204-
import_array();
205-
(void)Py_InitModule3("_lasso", methods, module_doc);
206-
}
202+
DECLARE_MODULE(_lasso)
207203

milk/supervised/_perceptron.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
// Copyright (C) 2011, Luis Pedro Coelho <[email protected]>
1+
// Copyright (C) 2011-2015, Luis Pedro Coelho <[email protected]>
22
// License: MIT
33

44
#include <iostream>
55
#include <memory>
66
#include <cmath>
77
#include <cassert>
8+
#include "../utils/utils.h"
89
extern "C" {
910
#include <Python.h>
1011
#include <numpy/ndarrayobject.h>
@@ -82,10 +83,5 @@ const char * module_doc =
8283

8384
} // namespace
8485

85-
extern "C"
86-
void init_perceptron()
87-
{
88-
import_array();
89-
(void)Py_InitModule3("_perceptron", methods, module_doc);
90-
}
86+
DECLARE_MODULE(_perceptron)
9187

0 commit comments

Comments
 (0)