-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python 3 compatibility improved #6
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from basic import Linear, Polynomial, RBF | ||
from regular import Exponential, Laplacian, RationalQuadratic, InverseMultiquadratic, Cauchy, TStudent,\ | ||
from .basic import Linear, Polynomial, RBF | ||
from .regular import Exponential, Laplacian, RationalQuadratic, InverseMultiquadratic, Cauchy, TStudent,\ | ||
ANOVA, Spline, Min, Log, Power, Chi2, AdditiveChi2, GeneralizedHistogramIntersection,\ | ||
Tanimoto, Sorensen, MinMax, Wavelet, Fourier | ||
from graph.randomwalk import RandomWalk | ||
from graph.allgraphlets import All34Graphlets | ||
from .graph.randomwalk import RandomWalk | ||
from .graph.allgraphlets import All34Graphlets |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from randomwalk import RandomWalk | ||
from allgraphlets import All34Graphlets | ||
from shortestpath import ShortestPath | ||
from .randomwalk import RandomWalk | ||
from .allgraphlets import All34Graphlets | ||
from .shortestpath import ShortestPath |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
import numpy as np | ||
import numpy.matlib as matlib | ||
import basic | ||
from .basic import graphs_to_adjacency_lists, relabel | ||
from pykernels.base import Kernel, GraphKernel | ||
from scipy.sparse import lil_matrix | ||
|
||
|
@@ -18,9 +18,9 @@ def floyd_warshall(adj_mat, weights): | |
res = res + ((adj_mat != 0) * weights) | ||
res[res == 0] = np.inf | ||
np.fill_diagonal(res, 0) | ||
for i in xrange(N): | ||
for j in xrange(N): | ||
for k in xrange(N): | ||
for i in range(N): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will slow down code for Python2. I would use range from six module (http://pythonhosted.org/six/) which defaults to xrange for Python2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are talking about one single file where the xrange functions were replaced, we could simply do this: try:
range = xrange
except:
pass |
||
for j in range(N): | ||
for k in range(N): | ||
if res[i, j] + res[j, k] < res[i, k]: | ||
res[i, k] = res[i, j] + res[j, k] | ||
return res | ||
|
@@ -85,16 +85,16 @@ def _create_accum_list(self, shortest_paths, maxpath): | |
return res | ||
|
||
def _compute(self, data_1, data_2): | ||
ams_1 = basic.graphs_to_adjacency_lists(data_1) | ||
ams_2 = basic.graphs_to_adjacency_lists(data_2) | ||
ams_1 = graphs_to_adjacency_lists(data_1) | ||
ams_2 = graphs_to_adjacency_lists(data_2) | ||
sp_1, max1 = _apply_floyd_warshall(np.array(ams_1)) | ||
sp_2, max2 = _apply_floyd_warshall(np.array(ams_2)) | ||
maxpath = max(max1, max2) | ||
if not self.labeled: | ||
accum_list_1 = self._create_accum_list(sp_1, maxpath) | ||
accum_list_2 = self._create_accum_list(sp_2, maxpath) | ||
else: | ||
labels_1, labels_2, numlabels = basic.relabel( | ||
labels_1, labels_2, numlabels = relabel( | ||
[G.node_labels for G in data_1], [G.node_labels for G in data_2]) | ||
accum_list_1 = self._create_accum_list_labeled(sp_1, maxpath, | ||
labels_1, numlabels) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we decide to use relative imports, I would keep it consistent, i.e. also change pykernels.base import to .base
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, I don't have strong feelings either way, it is just the previous import scheme was broken in Python 3.