提交 b8ca6ed7 authored 作者: abalkin's avatar abalkin

Moved compatibility code from theano.gof.python25 to theano.compat.

上级 d481b479
...@@ -24,6 +24,13 @@ if PY3: ...@@ -24,6 +24,13 @@ if PY3:
"""Return -1 if x<y, 0 if x==y, 1 if x > y.""" """Return -1 if x<y, 0 if x==y, 1 if x > y."""
return (a > b) - (a < b) return (a > b) - (a < b)
all = all
any = any
from functools import partial
from collections import defaultdict, deque
from itertools import combinations, product
from sys import maxsize
else: else:
...@@ -34,3 +41,8 @@ else: ...@@ -34,3 +41,8 @@ else:
return e[0] return e[0]
cmp = cmp cmp = cmp
# Older Python 2.x compatibility
from theano.compat.python2x import all, any, partial, defaultdict, deque
from theano.compat.python2x import combinations, product, maxsize
from theano.compat.python2x import DictMixin, OrderedDict, Callable
""" """
Helper functions to make gof backwards compatible Helper functions to make theano backwards compatible with python 2.4 - 2.7
(tested on python 2.4 and 2.5) (tested on python 2.4 and 2.5)
""" """
...@@ -105,7 +105,7 @@ else: ...@@ -105,7 +105,7 @@ else:
defaultdict = collections.defaultdict defaultdict = collections.defaultdict
deque = collections.deque deque = collections.deque
__all__ = ['all', 'any'] __all__ = ['all', 'any', 'partial', 'defaultdict', 'deque']
if sys.version_info[:2] < (2, 6): if sys.version_info[:2] < (2, 6):
# Borrowed from Python docs # Borrowed from Python docs
...@@ -159,6 +159,8 @@ else: ...@@ -159,6 +159,8 @@ else:
from itertools import combinations, product from itertools import combinations, product
from sys import maxsize from sys import maxsize
__all__ += ['combinations', 'product', 'maxsize']
if sys.version_info[:2] < (2, 7): if sys.version_info[:2] < (2, 7):
# The following implementation of OrderedDict compatible with python 2.4 # The following implementation of OrderedDict compatible with python 2.4
...@@ -301,6 +303,7 @@ else: ...@@ -301,6 +303,7 @@ else:
OrderedDict = collections.OrderedDict OrderedDict = collections.OrderedDict
from collections import Callable from collections import Callable
__all__ += ['DictMixin', 'OrderedDict', 'Callable']
class DefaultOrderedDict(OrderedDict): class DefaultOrderedDict(OrderedDict):
def __init__(self, default_factory=None, *a, **kw): def __init__(self, default_factory=None, *a, **kw):
...@@ -334,3 +337,5 @@ class DefaultOrderedDict(OrderedDict): ...@@ -334,3 +337,5 @@ class DefaultOrderedDict(OrderedDict):
def __copy__(self): def __copy__(self):
return type(self)(self.default_factory, self) return type(self)(self.default_factory, self)
__all__ += ['DefaultOrderedDict']
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论