提交 a702ad7f authored 作者: Ian Goodfellow's avatar Ian Goodfellow

removed dependence on pylearn2

上级 86e07952
...@@ -12,6 +12,7 @@ import sys ...@@ -12,6 +12,7 @@ import sys
hashlib = None hashlib = None
import numpy import numpy
np = numpy
try: try:
import pydot as pd import pydot as pd
...@@ -1147,6 +1148,17 @@ def position_independent_str(obj): ...@@ -1147,6 +1148,17 @@ def position_independent_str(obj):
return rval return rval
def hex_digest(x):
"""
Returns a short, mostly hexadecimal hash of a numpy ndarray
"""
assert isinstance(x, np.ndarray)
rval = hashlib.md5(x.tostring()).hexdigest()
# hex digest must be annotated with strides to avoid collisions
# because the buffer interface only exposes the raw data, not
# any info about the semantics of how that data should be arranged
# into a tensor
rval = rval + '|strides=[' + ','.join(str(stride) for stride in x.strides) + ']'
rval = rval + '|shape=[' + ','.join(str(s) for s in x.shape) + ']'
return rval
...@@ -7,7 +7,7 @@ __email__ = "goodfeli@iro" ...@@ -7,7 +7,7 @@ __email__ = "goodfeli@iro"
from theano.compile import Mode from theano.compile import Mode
import theano import theano
from pylearn2.utils import hex_digest from theano.printing import hex_digest
class MismatchError(Exception): class MismatchError(Exception):
""" """
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论