Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
676d7810
提交
676d7810
authored
1月 13, 2012
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test file PEP8 fixes
上级
c809a6a0
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
30 行增加
和
25 行删除
+30
-25
test_linalg.py
theano/sandbox/linalg/tests/test_linalg.py
+30
-25
没有找到文件。
theano/sandbox/linalg/tests/test_linalg.py
浏览文件 @
676d7810
...
...
@@ -12,7 +12,7 @@ from theano import config
# The one in comment are not tested...
from
theano.sandbox.linalg.ops
import
(
cholesky
,
Cholesky
,
# op class
Cholesky
,
# op class
CholeskyGrad
,
matrix_inverse
,
pinv
,
...
...
@@ -111,7 +111,7 @@ def test_cholesky_and_cholesky_grad_shape():
def
test_inverse_correctness
():
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
r
=
rng
.
randn
(
4
,
4
)
.
astype
(
theano
.
config
.
floatX
)
r
=
rng
.
randn
(
4
,
4
)
.
astype
(
theano
.
config
.
floatX
)
x
=
tensor
.
matrix
()
xi
=
matrix_inverse
(
x
)
...
...
@@ -120,8 +120,8 @@ def test_inverse_correctness():
assert
ri
.
shape
==
r
.
shape
assert
ri
.
dtype
==
r
.
dtype
rir
=
numpy
.
dot
(
ri
,
r
)
rri
=
numpy
.
dot
(
r
,
ri
)
rir
=
numpy
.
dot
(
ri
,
r
)
rri
=
numpy
.
dot
(
r
,
ri
)
assert
_allclose
(
numpy
.
identity
(
4
),
rir
),
rir
assert
_allclose
(
numpy
.
identity
(
4
),
rri
),
rri
...
...
@@ -174,6 +174,7 @@ def test_inverse_singular():
return
assert
False
def
test_inverse_grad
():
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
r
=
rng
.
randn
(
4
,
4
)
...
...
@@ -181,37 +182,39 @@ def test_inverse_grad():
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
r
=
rng
.
randn
(
4
,
4
)
r
=
rng
.
randn
(
4
,
4
)
tensor
.
verify_grad
(
matrix_inverse
,
[
r
],
rng
=
numpy
.
random
)
def
test_rop_lop
():
mx
=
tensor
.
matrix
(
'mx'
)
mv
=
tensor
.
matrix
(
'mv'
)
v
=
tensor
.
vector
(
'v'
)
v
=
tensor
.
vector
(
'v'
)
y
=
matrix_inverse
(
mx
)
.
sum
(
axis
=
0
)
yv
=
tensor
.
Rop
(
y
,
mx
,
mv
)
rop_f
=
function
([
mx
,
mv
],
yv
)
sy
,
_
=
theano
.
scan
(
lambda
i
,
y
,
x
,
v
:
(
tensor
.
grad
(
y
[
i
],
x
)
*
v
)
.
sum
(),
sequences
=
tensor
.
arange
(
y
.
shape
[
0
]),
non_sequences
=
[
y
,
mx
,
mv
])
scan_f
=
function
([
mx
,
mv
],
sy
)
sy
,
_
=
theano
.
scan
(
lambda
i
,
y
,
x
,
v
:
(
tensor
.
grad
(
y
[
i
],
x
)
*
v
)
.
sum
(),
sequences
=
tensor
.
arange
(
y
.
shape
[
0
]),
non_sequences
=
[
y
,
mx
,
mv
])
scan_f
=
function
([
mx
,
mv
],
sy
)
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
vx
=
numpy
.
asarray
(
rng
.
randn
(
4
,
4
),
theano
.
config
.
floatX
)
vv
=
numpy
.
asarray
(
rng
.
randn
(
4
,
4
),
theano
.
config
.
floatX
)
vx
=
numpy
.
asarray
(
rng
.
randn
(
4
,
4
),
theano
.
config
.
floatX
)
vv
=
numpy
.
asarray
(
rng
.
randn
(
4
,
4
),
theano
.
config
.
floatX
)
v1
=
rop_f
(
vx
,
vv
)
v2
=
scan_f
(
vx
,
vv
)
v1
=
rop_f
(
vx
,
vv
)
v2
=
scan_f
(
vx
,
vv
)
assert
_allclose
(
v1
,
v2
),
(
'ROP mismatch:
%
s
%
s'
%
(
v1
,
v2
))
raised
=
False
try
:
tmp
=
tensor
.
Rop
(
theano
.
clone
(
y
,
replace
=
{
mx
:
break_op
(
mx
)}),
mx
,
mv
)
tmp
=
tensor
.
Rop
(
theano
.
clone
(
y
,
replace
=
{
mx
:
break_op
(
mx
)}),
mx
,
mv
)
except
ValueError
:
raised
=
True
if
not
raised
:
...
...
@@ -223,7 +226,7 @@ def test_rop_lop():
yv
=
tensor
.
Lop
(
y
,
mx
,
v
)
lop_f
=
function
([
mx
,
v
],
yv
)
sy
=
tensor
.
grad
((
v
*
y
)
.
sum
(),
mx
)
sy
=
tensor
.
grad
((
v
*
y
)
.
sum
(),
mx
)
scan_f
=
function
([
mx
,
v
],
sy
)
v1
=
lop_f
(
vx
,
vv
)
...
...
@@ -300,12 +303,14 @@ def test_diag():
"""
Test that linalg.diag has the same behavior as numpy.diag.
numpy.diag has two behaviors:
(1) when given a vector, it returns a matrix with that vector as the diagonal.
(2) when given a matrix, returns a vector which is the diagonal of the matrix.
(1) and (2) are tested by test_alloc_diag and test_extract_diag respectively.
This test makes sure that linalg.diag instantiates the right op based on the dimension of
the input.
(1) when given a vector, it returns a matrix with that vector as the
diagonal.
(2) when given a matrix, returns a vector which is the diagonal of the
matrix.
(1) and (2) are tested by test_alloc_diag and test_extract_diag
respectively. This test makes sure that linalg.diag instantiates
the right op based on the dimension of the input.
"""
# test that it builds a matrix with given diagonal when using vector inputs
...
...
@@ -334,7 +339,7 @@ def test_extract_diag():
g
=
extract_diag
(
x
)
f
=
theano
.
function
([
x
],
g
)
for
shp
in
[(
2
,
3
),
(
3
,
2
),
(
3
,
3
),
(
1
,
1
),
(
0
,
0
)]:
for
shp
in
[(
2
,
3
),
(
3
,
2
),
(
3
,
3
),
(
1
,
1
),
(
0
,
0
)]:
m
=
rng
.
rand
(
*
shp
)
.
astype
(
config
.
floatX
)
v
=
numpy
.
diag
(
m
)
r
=
f
(
m
)
...
...
@@ -362,7 +367,7 @@ def test_extract_diag():
def
test_extract_diag_grad
():
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
x
=
rng
.
rand
(
5
,
4
)
x
=
rng
.
rand
(
5
,
4
)
tensor
.
verify_grad
(
extract_diag
,
[
x
],
rng
=
rng
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论