Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
30556a7c
提交
30556a7c
authored
4月 23, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix test error with NumPy 1.7.1.
This is for python long that fit in uint64, but not in an int64. NumPy 1.7 raise an Overflow error, but NumPy 1.7.1 return an uint64.
上级
c1179017
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
35 行增加
和
2 行删除
+35
-2
basic.py
theano/tensor/basic.py
+11
-2
test_basic.py
theano/tensor/tests/test_basic.py
+24
-0
没有找到文件。
theano/tensor/basic.py
浏览文件 @
30556a7c
...
...
@@ -366,9 +366,14 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None):
# Theano graph, because on Windows 64, all shapes are expressed
# with longs.
# If a long fits in int64, we convert it into an int64, like
# numpy.asarray() does.
# numpy.asarray() does up to 1.7. NumPy 1.7.1 upcaset to int64
# if possible, but fallback to uint64 if int64 isn't possible but
# uint64 is. We always do as NumPy 1.7.1 here.
# If x is too big, an OverflowError will be raised by numpy.
x_
=
theano
.
_asarray
(
x
,
dtype
=
'int64'
)
try
:
x_
=
theano
.
_asarray
(
x
,
dtype
=
'int64'
)
except
OverflowError
:
x_
=
theano
.
_asarray
(
x
,
dtype
=
'uint64'
)
elif
isinstance
(
x
,
numpy
.
ndarray
):
x_
=
x
# Currently we do not have a bool dtype in Theano.
...
...
@@ -377,6 +382,10 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None):
if
x
.
dtype
==
'bool'
:
x_
=
numpy
.
asarray
(
x_
,
dtype
=
'uint8'
)
else
:
# Here x is probably a list or a tuple. If it contain a long,
# we will behave like the current NumPy version: 1.7 and bellow,
# it will only work if the long fit in int64. For NumPy 1.7.1+,
# it will work if the long git in int64 or uint64.
x_
=
numpy
.
asarray
(
x
)
assert
type
(
x_
)
==
numpy
.
ndarray
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
30556a7c
...
...
@@ -6392,6 +6392,30 @@ class T_long_tensor(unittest.TestCase):
def
test_too_big
(
self
):
val
=
2L
**
63
#NumPy 1.7 this will raise an exception
#NumPy 1.7.1 this will work
try
:
cst
=
constant
(
val
)
assert
cst
.
value
==
val
assert
cst
.
dtype
==
"uint64"
except
Exception
:
pass
try
:
cst
=
constant
([
val
,
val
])
assert
cst
.
value
==
val
assert
cst
.
dtype
==
"uint64"
except
Exception
:
pass
try
:
cst
=
constant
([[
val
,
val
]])
assert
cst
.
value
==
val
assert
cst
.
dtype
==
"uint64"
except
Exception
:
pass
val
=
2L
**
64
# This fail for all NumPy version.
self
.
assertRaises
(
Exception
,
constant
,
val
)
self
.
assertRaises
(
Exception
,
constant
,
[
val
,
val
])
self
.
assertRaises
(
Exception
,
constant
,
[[
val
,
val
]])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论