提交 4584ea44 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Fixed theano._asarray under Windows: it looks like dtypes are not singletons after all

上级 9d46ac58
...@@ -28,11 +28,15 @@ def _asarray(a, dtype=None, order=None): ...@@ -28,11 +28,15 @@ def _asarray(a, dtype=None, order=None):
""" """
dtype = numpy.dtype(dtype) # Convert into dtype object. dtype = numpy.dtype(dtype) # Convert into dtype object.
rval = numpy.asarray(a, dtype=dtype, order=order) rval = numpy.asarray(a, dtype=dtype, order=order)
if rval.dtype is not dtype: # Note that dtype comparison must be done by comparing their `num`
# attribute. One cannot assume that two identical data types are pointers
# towards the same object (e.g. under Windows this appears not to be the
# case).
if rval.dtype.num != dtype.num:
# Type mismatch between the data type we asked for, and the one # Type mismatch between the data type we asked for, and the one
# returned by numpy.asarray. # returned by numpy.asarray.
if (dtype is numpy.dtype(numpy.int32) or if (dtype.num == numpy.dtype(numpy.int32).num or
dtype is numpy.dtype(numpy.int64)): dtype.num == numpy.dtype(numpy.int64).num):
# Silent fix. # Silent fix.
return rval.view(dtype=dtype) return rval.view(dtype=dtype)
else: else:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论