Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6c9d52dd
提交
6c9d52dd
authored
6月 04, 2014
作者:
Tanjay94
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added tests for different modes of qr function and a crash test for A_Xinv_b function.
上级
50947b37
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
49 行增加
和
4 行删除
+49
-4
ops.py
theano/sandbox/linalg/ops.py
+1
-0
test_linalg.py
theano/sandbox/linalg/tests/test_linalg.py
+48
-4
没有找到文件。
theano/sandbox/linalg/ops.py
浏览文件 @
6c9d52dd
...
@@ -1133,6 +1133,7 @@ def qr(a, mode="full"):
...
@@ -1133,6 +1133,7 @@ def qr(a, mode="full"):
x
=
[[
2
,
1
],
[
3
,
4
]]
x
=
[[
2
,
1
],
[
3
,
4
]]
if
isinstance
(
numpy
.
linalg
.
qr
(
x
,
mode
),
tuple
):
if
isinstance
(
numpy
.
linalg
.
qr
(
x
,
mode
),
tuple
):
return
QRFull
(
mode
)(
a
)
return
QRFull
(
mode
)(
a
)
else
:
else
:
return
QRIncomplete
(
mode
)(
a
)
return
QRIncomplete
(
mode
)(
a
)
...
...
theano/sandbox/linalg/tests/test_linalg.py
浏览文件 @
6c9d52dd
...
@@ -33,6 +33,7 @@ from theano.sandbox.linalg.ops import (cholesky,
...
@@ -33,6 +33,7 @@ from theano.sandbox.linalg.ops import (cholesky,
imported_scipy
,
imported_scipy
,
Eig
,
Eig
,
inv_as_solve
,
inv_as_solve
,
A_Xinv_b
)
)
from
theano.sandbox.linalg
import
eig
,
eigh
,
eigvalsh
from
theano.sandbox.linalg
import
eig
,
eigh
,
eigvalsh
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
...
@@ -174,7 +175,7 @@ def test_matrix_dot():
...
@@ -174,7 +175,7 @@ def test_matrix_dot():
assert
_allclose
(
numpy_sol
,
theano_sol
)
assert
_allclose
(
numpy_sol
,
theano_sol
)
def
test_qr
():
def
test_qr
_default
():
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
A
=
tensor
.
matrix
(
"A"
,
dtype
=
theano
.
config
.
floatX
)
A
=
tensor
.
matrix
(
"A"
,
dtype
=
theano
.
config
.
floatX
)
Q
=
qr
(
A
)
Q
=
qr
(
A
)
...
@@ -186,18 +187,48 @@ def test_qr():
...
@@ -186,18 +187,48 @@ def test_qr():
assert
_allclose
(
n_q
,
t_q
)
assert
_allclose
(
n_q
,
t_q
)
assert
_allclose
(
n_r
,
t_r
)
assert
_allclose
(
n_r
,
t_r
)
def
test_qr_reduced
():
def
test_qr_modes
():
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
A
=
tensor
.
matrix
(
"A"
,
dtype
=
theano
.
config
.
floatX
)
A
=
tensor
.
matrix
(
"A"
,
dtype
=
theano
.
config
.
floatX
)
Q
=
qr
(
A
,
mode
=
"reduced"
)
Q
=
qr
(
A
,
mode
=
"reduced"
)
fn
=
function
([
A
],
Q
)
R
=
qr
(
A
,
mode
=
"complete"
)
S
=
qr
(
A
,
mode
=
"r"
)
T
=
qr
(
A
,
mode
=
"raw"
)
U
=
qr
(
A
,
mode
=
"full"
)
V
=
qr
(
A
,
mode
=
"economic"
)
fq
=
function
([
A
],
Q
)
fr
=
function
([
A
],
R
)
fs
=
function
([
A
],
S
)
ft
=
function
([
A
],
T
)
fu
=
function
([
A
],
U
)
fv
=
function
([
A
],
V
)
a
=
rng
.
rand
(
4
,
4
)
.
astype
(
theano
.
config
.
floatX
)
a
=
rng
.
rand
(
4
,
4
)
.
astype
(
theano
.
config
.
floatX
)
n_q
=
numpy
.
linalg
.
qr
(
a
,
mode
=
"reduced"
)
n_q
=
numpy
.
linalg
.
qr
(
a
,
mode
=
"reduced"
)
t_q
=
fn
(
a
)
t_q
=
fq
(
a
)
n_r
=
numpy
.
linalg
.
qr
(
a
,
mode
=
"complete"
)
t_r
=
fr
(
a
)
n_s
=
numpy
.
linalg
.
qr
(
a
,
mode
=
"r"
)
t_s
=
fs
(
a
)
n_t
=
numpy
.
linalg
.
qr
(
a
,
mode
=
"raw"
)
t_t
=
ft
(
a
)
n_u
=
numpy
.
linalg
.
qr
(
a
,
mode
=
"full"
)
t_u
=
fu
(
a
)
n_v
=
numpy
.
linalg
.
qr
(
a
,
mode
=
"economic"
)
t_v
=
fv
(
a
)
assert
_allclose
(
n_q
,
t_q
)
assert
_allclose
(
n_q
,
t_q
)
assert
_allclose
(
n_r
,
t_r
)
assert
_allclose
(
n_s
,
t_s
)
assert
_allclose
(
n_u
,
t_u
)
assert
_allclose
(
n_v
,
t_v
)
def
test_svd
():
def
test_svd
():
...
@@ -234,6 +265,7 @@ def test_inverse_grad():
...
@@ -234,6 +265,7 @@ def test_inverse_grad():
r
=
rng
.
randn
(
4
,
4
)
r
=
rng
.
randn
(
4
,
4
)
tensor
.
verify_grad
(
matrix_inverse
,
[
r
],
rng
=
numpy
.
random
)
tensor
.
verify_grad
(
matrix_inverse
,
[
r
],
rng
=
numpy
.
random
)
def
test_rop_lop
():
def
test_rop_lop
():
mx
=
tensor
.
matrix
(
'mx'
)
mx
=
tensor
.
matrix
(
'mx'
)
mv
=
tensor
.
matrix
(
'mv'
)
mv
=
tensor
.
matrix
(
'mv'
)
...
@@ -638,3 +670,15 @@ def test_eigvalsh_grad():
...
@@ -638,3 +670,15 @@ def test_eigvalsh_grad():
b
=
10
*
numpy
.
eye
(
5
,
5
)
+
rng
.
randn
(
5
,
5
)
b
=
10
*
numpy
.
eye
(
5
,
5
)
+
rng
.
randn
(
5
,
5
)
tensor
.
verify_grad
(
lambda
a
,
b
:
eigvalsh
(
a
,
b
)
.
dot
([
1
,
2
,
3
,
4
,
5
]),
tensor
.
verify_grad
(
lambda
a
,
b
:
eigvalsh
(
a
,
b
)
.
dot
([
1
,
2
,
3
,
4
,
5
]),
[
a
,
b
],
rng
=
numpy
.
random
)
[
a
,
b
],
rng
=
numpy
.
random
)
def
test_A_Xinv_b
():
x
=
tensor
.
matrix
()
y
=
tensor
.
matrix
()
z
=
tensor
.
matrix
()
m
=
A_Xinv_b
()(
x
,
y
,
z
)
f
=
function
([
x
,
y
,
z
],
m
)
X
=
[[
1
,
1
],
[
1
,
1
]]
Y
=
[[
2
,
1
],
[
3
,
4
]]
Z
=
[[
1
,
1
],
[
1
,
1
]]
assert
numpy
.
allclose
(
f
(
X
,
Y
,
Z
),
[[
0.20408163
,
0.20408163
],
[
0.20408163
,
0.20408163
]])
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论