From ba73c6cd6f9428a89ddd61024925d8b82a40682b Mon Sep 17 00:00:00 2001 From: MechCoder Date: Sun, 20 Nov 2016 15:54:14 -0500 Subject: [PATCH] Py3 compat --- cle/layers/feedforward.py | 6 +++++- cle/layers/recurrent.py | 6 +++++- cle/train/__init__.py | 9 ++++++--- cle/train/ext.py | 2 +- cle/utils/__init__.py | 12 ++++++------ 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/cle/layers/feedforward.py b/cle/layers/feedforward.py index 8bef366..2649b46 100644 --- a/cle/layers/feedforward.py +++ b/cle/layers/feedforward.py @@ -1,11 +1,15 @@ import ipdb import numpy as np +import sys import theano import theano.tensor as T from cle.cle.layers import StemCell, InitCell -from itertools import izip +if sys.version_info[0] == 3: + izip = zip +else: + from itertools import izip from theano.compat.python2x import OrderedDict diff --git a/cle/layers/recurrent.py b/cle/layers/recurrent.py index 31fec18..31d07b8 100644 --- a/cle/layers/recurrent.py +++ b/cle/layers/recurrent.py @@ -1,5 +1,6 @@ import ipdb import numpy as np +import sys import theano import theano.tensor as T @@ -7,7 +8,10 @@ from cle.cle.utils import tolist from cle.cle.utils.op import add_noise -from itertools import izip +if sys.version_info[0] == 3: + izip = zip +else: + from itertools import izip from theano.compat.python2x import OrderedDict diff --git a/cle/train/__init__.py b/cle/train/__init__.py index d05bbc4..c2ece23 100644 --- a/cle/train/__init__.py +++ b/cle/train/__init__.py @@ -1,7 +1,12 @@ import ipdb import logging +import sys import theano.tensor as T import time +if sys.version_info[0] == 3: + izip = zip +else: + from itertools import izip from cle.cle.graph import TheanoMixin from cle.cle.models import Model @@ -10,8 +15,6 @@ from collections import defaultdict from theano.compat.python2x import OrderedDict -from itertools import izip - logging.basicConfig(level=logging.INFO, format='%(message)s') logger = logging.getLogger(__name__) @@ -53,7 +56,7 @@ def __init__(self, t0 = time.time() self.cost_fn = self.build_training_graph() - print "Elapsed compilation time: %f" % (time.time() - t0) + print("Elapsed compilation time: %f" % (time.time() - t0)) if self.debug_print: from theano.printing import debugprint debugprint(self.cost_fn) diff --git a/cle/train/ext.py b/cle/train/ext.py index 572afd5..0f67129 100644 --- a/cle/train/ext.py +++ b/cle/train/ext.py @@ -1,5 +1,5 @@ import ipdb -import cPickle +from six.moves import cPickle import logging import numpy as np import os diff --git a/cle/utils/__init__.py b/cle/utils/__init__.py index d48134d..0cb497c 100644 --- a/cle/utils/__init__.py +++ b/cle/utils/__init__.py @@ -1,5 +1,4 @@ import ipdb -import cPickle import logging import numpy as np import os @@ -11,6 +10,7 @@ from collections import deque from numpy.lib.stride_tricks import as_strided +from six.moves import cPickle from theano.compat.python2x import OrderedDict @@ -337,10 +337,10 @@ def segment_axis(a, length, overlap=0, axis=None, end='cut', endvalue=0): l = a.shape[axis] if overlap>=length: - raise ValueError, "frames cannot overlap by more than 100%" + raise ValueError("frames cannot overlap by more than 100%") if overlap<0 or length<=0: - raise ValueError, "overlap must be nonnegative and length must be "\ - "positive" + raise ValueError("overlap must be nonnegative and length must be " + "positive") if llength: @@ -374,8 +374,8 @@ def segment_axis(a, length, overlap=0, axis=None, end='cut', endvalue=0): l = a.shape[axis] if l==0: - raise ValueError, "Not enough data points to segment array in 'cut' "\ - "mode; try 'pad' or 'wrap'" + raise ValueError("Not enough data points to segment array in 'cut' " + "mode; try 'pad' or 'wrap'") assert l>=length assert (l-length)%(length-overlap) == 0 n = 1+(l-length)//(length-overlap)