Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
08425470
提交
08425470
authored
1月 31, 2013
作者:
Jeremiah Lowin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
move tests into class
上级
da44df32
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
21 行删除
+22
-21
test_basic.py
theano/tensor/tests/test_basic.py
+22
-21
没有找到文件。
theano/tensor/tests/test_basic.py
浏览文件 @
08425470
...
@@ -1826,7 +1826,8 @@ def test_eye():
...
@@ -1826,7 +1826,8 @@ def test_eye():
yield
check
,
dtype
,
5
,
3
,
-
1
yield
check
,
dtype
,
5
,
3
,
-
1
def
test_tri
():
class
test_triangle
(
unittest
.
TestCase
):
def
test_tri
(
self
):
def
check
(
dtype
,
N
,
M_
=
None
,
k
=
0
):
def
check
(
dtype
,
N
,
M_
=
None
,
k
=
0
):
# Theano does not accept None as a tensor.
# Theano does not accept None as a tensor.
# So we must use a real value.
# So we must use a real value.
...
@@ -1841,8 +1842,9 @@ def test_tri():
...
@@ -1841,8 +1842,9 @@ def test_tri():
f
=
function
([
N_symb
,
M_symb
,
k_symb
],
f
=
function
([
N_symb
,
M_symb
,
k_symb
],
tri
(
N_symb
,
M_symb
,
k_symb
,
dtype
=
dtype
))
tri
(
N_symb
,
M_symb
,
k_symb
,
dtype
=
dtype
))
result
=
f
(
N
,
M
,
k
)
result
=
f
(
N
,
M
,
k
)
assert
numpy
.
allclose
(
result
,
numpy
.
tri
(
N
,
M_
,
k
,
dtype
=
dtype
))
self
.
assertTrue
(
assert
result
.
dtype
==
numpy
.
dtype
(
dtype
)
numpy
.
allclose
(
result
,
numpy
.
tri
(
N
,
M_
,
k
,
dtype
=
dtype
)))
self
.
assertTrue
(
result
.
dtype
==
numpy
.
dtype
(
dtype
))
for
dtype
in
ALL_DTYPES
:
for
dtype
in
ALL_DTYPES
:
yield
check
,
dtype
,
3
yield
check
,
dtype
,
3
# M != N, k = 0
# M != N, k = 0
...
@@ -1859,22 +1861,22 @@ def test_tri():
...
@@ -1859,22 +1861,22 @@ def test_tri():
yield
check
,
dtype
,
5
,
3
,
-
1
yield
check
,
dtype
,
5
,
3
,
-
1
def
test_tril_triu
(
):
def
test_tril_triu
(
self
):
def
check_l
(
m
,
k
=
0
):
def
check_l
(
m
,
k
=
0
):
m_symb
=
matrix
(
dtype
=
m
.
dtype
)
m_symb
=
matrix
(
dtype
=
m
.
dtype
)
k_symb
=
iscalar
()
k_symb
=
iscalar
()
f
=
function
([
m_symb
,
k_symb
],
tril
(
m_symb
,
k_symb
))
f
=
function
([
m_symb
,
k_symb
],
tril
(
m_symb
,
k_symb
))
result
=
f
(
m
,
k
)
result
=
f
(
m
,
k
)
assert
numpy
.
allclose
(
result
,
numpy
.
tril
(
m
,
k
))
self
.
assertTrue
(
numpy
.
allclose
(
result
,
numpy
.
tril
(
m
,
k
)
))
assert
result
.
dtype
==
numpy
.
dtype
(
dtype
)
self
.
assertTrue
(
result
.
dtype
==
numpy
.
dtype
(
dtype
)
)
def
check_u
(
m
,
k
=
0
):
def
check_u
(
m
,
k
=
0
):
m_symb
=
matrix
(
dtype
=
m
.
dtype
)
m_symb
=
matrix
(
dtype
=
m
.
dtype
)
k_symb
=
iscalar
()
k_symb
=
iscalar
()
f
=
function
([
m_symb
,
k_symb
],
triu
(
m_symb
,
k_symb
))
f
=
function
([
m_symb
,
k_symb
],
triu
(
m_symb
,
k_symb
))
result
=
f
(
m
,
k
)
result
=
f
(
m
,
k
)
assert
numpy
.
allclose
(
result
,
numpy
.
triu
(
m
,
k
))
self
.
assertTrue
(
numpy
.
allclose
(
result
,
numpy
.
triu
(
m
,
k
)
))
assert
result
.
dtype
==
numpy
.
dtype
(
dtype
)
self
.
assertTrue
(
result
.
dtype
==
numpy
.
dtype
(
dtype
)
)
for
dtype
in
ALL_DTYPES
:
for
dtype
in
ALL_DTYPES
:
m
=
rand_of_dtype
((
10
,
10
),
dtype
)
m
=
rand_of_dtype
((
10
,
10
),
dtype
)
...
@@ -1896,7 +1898,8 @@ def test_tril_triu():
...
@@ -1896,7 +1898,8 @@ def test_tril_triu():
yield
check_u
,
m
,
-
1
yield
check_u
,
m
,
-
1
def
test_nonzero
():
class
test_nonzero
(
unittest
.
TestCase
):
def
test_nonzero
(
self
):
def
check
(
m
):
def
check
(
m
):
m_symb
=
theano
.
tensor
.
tensor
(
dtype
=
m
.
dtype
,
m_symb
=
theano
.
tensor
.
tensor
(
dtype
=
m
.
dtype
,
broadcastable
=
(
False
,)
*
m
.
ndim
)
broadcastable
=
(
False
,)
*
m
.
ndim
)
...
@@ -1904,15 +1907,12 @@ def test_nonzero():
...
@@ -1904,15 +1907,12 @@ def test_nonzero():
f_tuple
=
function
([
m_symb
],
nonzero
(
m_symb
,
return_matrix
=
False
))
f_tuple
=
function
([
m_symb
],
nonzero
(
m_symb
,
return_matrix
=
False
))
f_matrix
=
function
([
m_symb
],
nonzero
(
m_symb
,
return_matrix
=
True
))
f_matrix
=
function
([
m_symb
],
nonzero
(
m_symb
,
return_matrix
=
True
))
assert
numpy
.
allclose
(
f_matrix
(
m
),
numpy
.
vstack
(
numpy
.
nonzero
(
m
)))
self
.
assertTrue
(
numpy
.
allclose
(
f_matrix
(
m
),
numpy
.
vstack
(
numpy
.
nonzero
(
m
)
)))
for
i
,
j
in
zip
(
f_tuple
(
m
),
numpy
.
nonzero
(
m
)):
for
i
,
j
in
zip
(
f_tuple
(
m
),
numpy
.
nonzero
(
m
)):
assert
numpy
.
allclose
(
i
,
j
)
self
.
assertTrue
(
numpy
.
allclose
(
i
,
j
)
)
rand0d
=
numpy
.
array
(
rand
())
rand0d
=
numpy
.
array
(
rand
())
check
(
rand0d
)
self
.
assertRaises
(
ValueError
,
check
,
rand0d
)
rand0d_0
=
numpy
.
array
(
0
,
dtype
=
theano
.
config
.
floatX
)
check
(
rand0d_0
)
rand1d
=
rand
(
8
)
rand1d
=
rand
(
8
)
rand1d
[:
4
]
=
0
rand1d
[:
4
]
=
0
...
@@ -1930,7 +1930,8 @@ def test_nonzero():
...
@@ -1930,7 +1930,8 @@ def test_nonzero():
rand4d
[:
4
]
=
0
rand4d
[:
4
]
=
0
check
(
rand4d
)
check
(
rand4d
)
def
test_flatnonzero
():
def
test_flatnonzero
(
self
):
def
check
(
m
):
def
check
(
m
):
m_symb
=
theano
.
tensor
.
tensor
(
dtype
=
m
.
dtype
,
m_symb
=
theano
.
tensor
.
tensor
(
dtype
=
m
.
dtype
,
broadcastable
=
(
False
,)
*
m
.
ndim
)
broadcastable
=
(
False
,)
*
m
.
ndim
)
...
@@ -1939,10 +1940,7 @@ def test_flatnonzero():
...
@@ -1939,10 +1940,7 @@ def test_flatnonzero():
assert
numpy
.
allclose
(
result
,
numpy
.
flatnonzero
(
m
))
assert
numpy
.
allclose
(
result
,
numpy
.
flatnonzero
(
m
))
rand0d
=
numpy
.
array
(
rand
())
rand0d
=
numpy
.
array
(
rand
())
check
(
rand0d
)
self
.
assertRaises
(
ValueError
,
check
,
rand0d
)
rand0d_0
=
numpy
.
array
(
0
,
dtype
=
theano
.
config
.
floatX
)
check
(
rand0d_0
)
rand1d
=
rand
(
8
)
rand1d
=
rand
(
8
)
rand1d
[:
4
]
=
0
rand1d
[:
4
]
=
0
...
@@ -1960,7 +1958,7 @@ def test_flatnonzero():
...
@@ -1960,7 +1958,7 @@ def test_flatnonzero():
rand4d
[:
4
]
=
0
rand4d
[:
4
]
=
0
check
(
rand4d
)
check
(
rand4d
)
def
test_nonzero_values
(
):
def
test_nonzero_values
(
self
):
def
check
(
m
):
def
check
(
m
):
m_symb
=
theano
.
tensor
.
tensor
(
dtype
=
m
.
dtype
,
m_symb
=
theano
.
tensor
.
tensor
(
dtype
=
m
.
dtype
,
broadcastable
=
(
False
,)
*
m
.
ndim
)
broadcastable
=
(
False
,)
*
m
.
ndim
)
...
@@ -1968,6 +1966,9 @@ def test_nonzero_values():
...
@@ -1968,6 +1966,9 @@ def test_nonzero_values():
result
=
f
(
m
)
result
=
f
(
m
)
assert
numpy
.
allclose
(
result
,
m
[
numpy
.
nonzero
(
m
)])
assert
numpy
.
allclose
(
result
,
m
[
numpy
.
nonzero
(
m
)])
rand0d
=
rand
()
self
.
assertRaises
(
ValueError
,
check
,
rand0d
)
rand1d
=
rand
(
8
)
rand1d
=
rand
(
8
)
rand1d
[:
4
]
=
0
rand1d
[:
4
]
=
0
check
(
rand1d
)
check
(
rand1d
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论