Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1baba0e2
提交
1baba0e2
authored
1月 25, 2017
作者:
Benjamin Scellier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
file theano/compile/tests/test_function.py
上级
78bf69d4
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
20 行增加
和
20 行删除
+20
-20
test_function.py
theano/compile/tests/test_function.py
+20
-20
没有找到文件。
theano/compile/tests/test_function.py
浏览文件 @
1baba0e2
...
@@ -5,7 +5,7 @@ import shutil
...
@@ -5,7 +5,7 @@ import shutil
import
tempfile
import
tempfile
import
unittest
import
unittest
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano.compile.io
import
In
from
theano.compile.io
import
In
...
@@ -27,7 +27,7 @@ def test_function_dump():
...
@@ -27,7 +27,7 @@ def test_function_dump():
fct2
=
theano
.
function
(
**
l
)
fct2
=
theano
.
function
(
**
l
)
x
=
[
1
,
2
,
3
]
x
=
[
1
,
2
,
3
]
assert
n
umpy
.
allclose
(
fct1
(
x
),
fct2
(
x
))
assert
n
p
.
allclose
(
fct1
(
x
),
fct2
(
x
))
class
TestFunctionIn
(
unittest
.
TestCase
):
class
TestFunctionIn
(
unittest
.
TestCase
):
...
@@ -40,14 +40,14 @@ class TestFunctionIn(unittest.TestCase):
...
@@ -40,14 +40,14 @@ class TestFunctionIn(unittest.TestCase):
f
=
theano
.
function
([
In
(
a
,
strict
=
False
)],
out
)
f
=
theano
.
function
([
In
(
a
,
strict
=
False
)],
out
)
# works, rand generates float64 by default
# works, rand generates float64 by default
f
(
n
umpy
.
random
.
rand
(
8
))
f
(
n
p
.
random
.
rand
(
8
))
# works, casting is allowed
# works, casting is allowed
f
(
n
umpy
.
array
([
1
,
2
,
3
,
4
],
dtype
=
'int32'
))
f
(
n
p
.
array
([
1
,
2
,
3
,
4
],
dtype
=
'int32'
))
f
=
theano
.
function
([
In
(
a
,
strict
=
True
)],
out
)
f
=
theano
.
function
([
In
(
a
,
strict
=
True
)],
out
)
try
:
try
:
# fails, f expects float64
# fails, f expects float64
f
(
n
umpy
.
array
([
1
,
2
,
3
,
4
],
dtype
=
'int32'
))
f
(
n
p
.
array
([
1
,
2
,
3
,
4
],
dtype
=
'int32'
))
except
TypeError
:
except
TypeError
:
pass
pass
...
@@ -70,17 +70,17 @@ class TestFunctionIn(unittest.TestCase):
...
@@ -70,17 +70,17 @@ class TestFunctionIn(unittest.TestCase):
# using mutable=True will let f change the value in aval
# using mutable=True will let f change the value in aval
f
=
theano
.
function
([
In
(
a
,
mutable
=
True
)],
a_out
,
mode
=
'FAST_RUN'
)
f
=
theano
.
function
([
In
(
a
,
mutable
=
True
)],
a_out
,
mode
=
'FAST_RUN'
)
aval
=
n
umpy
.
random
.
rand
(
10
)
aval
=
n
p
.
random
.
rand
(
10
)
aval2
=
aval
.
copy
()
aval2
=
aval
.
copy
()
assert
n
umpy
.
all
(
f
(
aval
)
==
(
aval2
*
2
))
assert
n
p
.
all
(
f
(
aval
)
==
(
aval2
*
2
))
assert
not
n
umpy
.
all
(
aval
==
aval2
)
assert
not
n
p
.
all
(
aval
==
aval2
)
# using mutable=False should leave the input untouched
# using mutable=False should leave the input untouched
f
=
theano
.
function
([
In
(
a
,
mutable
=
False
)],
a_out
,
mode
=
'FAST_RUN'
)
f
=
theano
.
function
([
In
(
a
,
mutable
=
False
)],
a_out
,
mode
=
'FAST_RUN'
)
aval
=
n
umpy
.
random
.
rand
(
10
)
aval
=
n
p
.
random
.
rand
(
10
)
aval2
=
aval
.
copy
()
aval2
=
aval
.
copy
()
assert
n
umpy
.
all
(
f
(
aval
)
==
(
aval2
*
2
))
assert
n
p
.
all
(
f
(
aval
)
==
(
aval2
*
2
))
assert
n
umpy
.
all
(
aval
==
aval2
)
assert
n
p
.
all
(
aval
==
aval2
)
def
test_in_update
(
self
):
def
test_in_update
(
self
):
a
=
theano
.
tensor
.
dscalar
(
'a'
)
a
=
theano
.
tensor
.
dscalar
(
'a'
)
...
@@ -115,7 +115,7 @@ class TestFunctionIn(unittest.TestCase):
...
@@ -115,7 +115,7 @@ class TestFunctionIn(unittest.TestCase):
# changes occur at the same time and one doesn't overwrite the other.
# changes occur at the same time and one doesn't overwrite the other.
for
i
in
range
(
5
):
for
i
in
range
(
5
):
f
()
f
()
assert
n
umpy
.
allclose
(
shared_var
.
get_value
(),
i
%
2
)
assert
n
p
.
allclose
(
shared_var
.
get_value
(),
i
%
2
)
def
test_in_allow_downcast_int
(
self
):
def
test_in_allow_downcast_int
(
self
):
a
=
theano
.
tensor
.
wvector
(
'a'
)
# int16
a
=
theano
.
tensor
.
wvector
(
'a'
)
# int16
...
@@ -128,16 +128,16 @@ class TestFunctionIn(unittest.TestCase):
...
@@ -128,16 +128,16 @@ class TestFunctionIn(unittest.TestCase):
# Both values are in range. Since they're not ndarrays (but lists),
# Both values are in range. Since they're not ndarrays (but lists),
# they will be converted, and their value checked.
# they will be converted, and their value checked.
assert
n
umpy
.
all
(
f
([
3
],
[
6
],
1
)
==
10
)
assert
n
p
.
all
(
f
([
3
],
[
6
],
1
)
==
10
)
# Values are in range, but a dtype too large has explicitly been given
# Values are in range, but a dtype too large has explicitly been given
# For performance reasons, no check of the data is explicitly performed
# For performance reasons, no check of the data is explicitly performed
# (It might be OK to change this in the future.)
# (It might be OK to change this in the future.)
self
.
assertRaises
(
TypeError
,
f
,
[
3
],
n
umpy
.
array
([
6
],
dtype
=
'int16'
),
self
.
assertRaises
(
TypeError
,
f
,
[
3
],
n
p
.
array
([
6
],
dtype
=
'int16'
),
1
)
1
)
# Value too big for a, silently ignored
# Value too big for a, silently ignored
assert
n
umpy
.
all
(
f
([
2
**
20
],
numpy
.
ones
(
1
,
dtype
=
'int8'
),
1
)
==
2
)
assert
n
p
.
all
(
f
([
2
**
20
],
np
.
ones
(
1
,
dtype
=
'int8'
),
1
)
==
2
)
# Value too big for b, raises TypeError
# Value too big for b, raises TypeError
self
.
assertRaises
(
TypeError
,
f
,
[
3
],
[
312
],
1
)
self
.
assertRaises
(
TypeError
,
f
,
[
3
],
[
312
],
1
)
...
@@ -156,17 +156,17 @@ class TestFunctionIn(unittest.TestCase):
...
@@ -156,17 +156,17 @@ class TestFunctionIn(unittest.TestCase):
(
a
+
b
+
c
))
(
a
+
b
+
c
))
# If the values can be accurately represented, everything is OK
# If the values can be accurately represented, everything is OK
assert
n
umpy
.
all
(
f
(
0
,
0
,
0
)
==
0
)
assert
n
p
.
all
(
f
(
0
,
0
,
0
)
==
0
)
# If allow_downcast is True, idem
# If allow_downcast is True, idem
assert
n
umpy
.
allclose
(
f
(
0.1
,
0
,
0
),
0.1
)
assert
n
p
.
allclose
(
f
(
0.1
,
0
,
0
),
0.1
)
# If allow_downcast is False, nope
# If allow_downcast is False, nope
self
.
assertRaises
(
TypeError
,
f
,
0
,
0.1
,
0
)
self
.
assertRaises
(
TypeError
,
f
,
0
,
0.1
,
0
)
# If allow_downcast is None, it should work iff floatX=float32
# If allow_downcast is None, it should work iff floatX=float32
if
theano
.
config
.
floatX
==
'float32'
:
if
theano
.
config
.
floatX
==
'float32'
:
assert
n
umpy
.
allclose
(
f
(
0
,
0
,
0.1
),
0.1
)
assert
n
p
.
allclose
(
f
(
0
,
0
,
0.1
),
0.1
)
else
:
else
:
self
.
assertRaises
(
TypeError
,
f
,
0
,
0
,
0.1
)
self
.
assertRaises
(
TypeError
,
f
,
0
,
0
,
0.1
)
...
@@ -182,10 +182,10 @@ class TestFunctionIn(unittest.TestCase):
...
@@ -182,10 +182,10 @@ class TestFunctionIn(unittest.TestCase):
# If the values can be accurately represented, everything is OK
# If the values can be accurately represented, everything is OK
z
=
[
0
]
z
=
[
0
]
assert
n
umpy
.
all
(
f
(
z
,
z
,
z
)
==
0
)
assert
n
p
.
all
(
f
(
z
,
z
,
z
)
==
0
)
# If allow_downcast is True, idem
# If allow_downcast is True, idem
assert
n
umpy
.
allclose
(
f
([
0.1
],
z
,
z
),
0.1
)
assert
n
p
.
allclose
(
f
([
0.1
],
z
,
z
),
0.1
)
# If allow_downcast is False, nope
# If allow_downcast is False, nope
self
.
assertRaises
(
TypeError
,
f
,
z
,
[
0.1
],
z
)
self
.
assertRaises
(
TypeError
,
f
,
z
,
[
0.1
],
z
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论