Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6e93976e
提交
6e93976e
authored
5月 25, 2016
作者:
Ilya Kulikov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
infer_shape for TensorInv added, test for it added
上级
dfd24e90
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
10 行删除
+24
-10
nlinalg.py
theano/tensor/nlinalg.py
+5
-1
test_nlinalg.py
theano/tensor/tests/test_nlinalg.py
+19
-9
没有找到文件。
theano/tensor/nlinalg.py
浏览文件 @
6e93976e
...
...
@@ -742,7 +742,7 @@ class TensorInv(Op):
def
make_node
(
self
,
a
):
a
=
as_tensor_variable
(
a
)
out_dtype
=
a
.
dtype
out
=
theano
.
tensor
.
matrix
(
dtype
=
out_dtype
)
out
=
theano
.
tensor
.
tensor4
(
dtype
=
out_dtype
)
return
Apply
(
self
,
[
a
],
[
out
])
def
perform
(
self
,
node
,
inputs
,
outputs
):
...
...
@@ -750,6 +750,10 @@ class TensorInv(Op):
(
x
,)
=
outputs
x
[
0
]
=
self
.
_numop
(
a
,
self
.
ind
)
def
infer_shape
(
self
,
node
,
shapes
):
sp
=
shapes
[
0
][
self
.
ind
:]
+
shapes
[
0
][:
self
.
ind
]
return
[
sp
]
def
tensorinv
(
a
,
ind
=
2
):
"""
...
...
theano/tensor/tests/test_nlinalg.py
浏览文件 @
6e93976e
...
...
@@ -38,6 +38,7 @@ from theano.tensor.nlinalg import ( MatrixInverse,
matrix_power
,
norm
,
svd
,
TensorInv
,
tensorinv
)
from
nose.plugins.attrib
import
attr
...
...
@@ -520,15 +521,24 @@ class T_NormTests(unittest.TestCase):
assert
_allclose
(
n_n
,
t_n
)
def
test_tensorinv
():
A
=
tensor
.
tensor4
(
"A"
,
dtype
=
theano
.
config
.
floatX
)
X
=
tensorinv
(
A
)
tf
=
function
([
A
],
[
X
])
a
=
numpy
.
eye
(
4
*
6
)
.
astype
(
theano
.
config
.
floatX
)
a
.
shape
=
(
4
,
6
,
8
,
3
)
class
test_TensorInv
(
utt
.
InferShapeTester
):
def
setUp
(
self
):
super
(
test_TensorInv
,
self
)
.
setUp
()
self
.
A
=
tensor
.
tensor4
(
"A"
,
dtype
=
theano
.
config
.
floatX
)
self
.
a
=
numpy
.
random
.
rand
(
4
,
6
,
8
,
3
)
.
astype
(
theano
.
config
.
floatX
)
n_ainv
=
numpy
.
linalg
.
tensorinv
(
a
)
t_ainv
=
tf
(
a
)
def
test_infer_shape
(
self
):
A
=
self
.
A
Ai
=
tensorinv
(
A
)
self
.
_compile_and_check
([
A
],
# theano.function inputs
[
Ai
],
# theano.function outputs
[
self
.
a
],
# value to substitute
TensorInv
)
def
test_eval
(
self
):
A
=
self
.
A
Ai
=
tensorinv
(
A
)
n_ainv
=
numpy
.
linalg
.
tensorinv
(
self
.
a
)
tf
=
function
([
A
],
[
Ai
])
t_ainv
=
tf
(
self
.
a
)
assert
_allclose
(
n_ainv
,
t_ainv
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论