Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
66ba51fe
提交
66ba51fe
authored
11月 22, 2012
作者:
abalkin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
WIP: Restricted offset and axes arguments to constants and implemented infer_shape.
上级
6c67891a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
27 行增加
和
10 行删除
+27
-10
basic.py
theano/tensor/basic.py
+20
-9
test_basic.py
theano/tensor/tests/test_basic.py
+7
-1
没有找到文件。
theano/tensor/basic.py
浏览文件 @
66ba51fe
...
@@ -7191,6 +7191,11 @@ class Diagonal(Op):
...
@@ -7191,6 +7191,11 @@ class Diagonal(Op):
:return: A vector representing the diagonal elements.
:return: A vector representing the diagonal elements.
"""
"""
def
__init__
(
self
,
offset
=
0
,
axis1
=
0
,
axis2
=
1
):
self
.
offset
=
offset
self
.
axis1
=
axis1
self
.
axis2
=
axis2
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
))
return
(
type
(
self
)
==
type
(
other
))
...
@@ -7198,22 +7203,28 @@ class Diagonal(Op):
...
@@ -7198,22 +7203,28 @@ class Diagonal(Op):
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
type
(
self
))
return
hash
(
type
(
self
))
def
make_node
(
self
,
x
,
offset
=
0
,
axis1
=
0
,
axis2
=
1
):
def
make_node
(
self
,
x
):
x
=
as_tensor_variable
(
x
)
x
=
as_tensor_variable
(
x
)
assert
x
.
ndim
>=
2
assert
x
.
ndim
>=
2
offset
,
axis1
,
axis2
=
map
(
scal
.
as_scalar
,
(
offset
,
axis1
,
axis2
))
return
Apply
(
self
,
[
x
],
[
tensor
(
dtype
=
x
.
dtype
,
return
Apply
(
self
,
[
x
,
offset
,
axis1
,
axis2
],
[
tensor
(
dtype
=
x
.
dtype
,
broadcastable
=
[
False
]
*
(
x
.
ndim
-
1
))])
broadcastable
=
[
False
]
*
(
x
.
ndim
-
1
))])
def
perform
(
self
,
node
,
(
x
,
off
,
ax1
,
ax2
),
(
z
,)):
def
perform
(
self
,
node
,
(
x
,),
(
z
,)):
z
[
0
]
=
x
.
diagonal
(
off
,
ax1
,
ax
2
)
z
[
0
]
=
x
.
diagonal
(
self
.
offset
,
self
.
axis1
,
self
.
axis
2
)
def
grad
(
self
,
(
x
,),
(
gz
,)):
def
grad
(
self
,
(
x
,),
(
gz
,)):
return
[
square_diagonal
(
gz
)]
return
[
square_diagonal
(
gz
)]
def
infer_shape
(
self
,
nodes
,
shapes
):
def
infer_shape
(
self
,
node
,
shapes
):
return
[(
minimum
(
*
shapes
[
0
]),
)]
xdims
=
list
(
shapes
[
0
])
d0
=
minimum
(
xdims
[
self
.
axis1
],
xdims
[
self
.
axis2
])
xdims
=
[
d
for
i
,
d
in
enumerate
(
shapes
[
0
])
if
i
not
in
(
self
.
axis1
,
self
.
axis2
)]
xdims
.
append
(
d0
)
return
[
tuple
(
xdims
)]
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
__class__
.
__name__
return
self
.
__class__
.
__name__
diagonal
=
Diagonal
()
def
diagonal
(
a
,
offset
=
0
,
axis1
=
0
,
axis2
=
1
):
return
Diagonal
(
offset
,
axis1
,
axis2
)(
a
)
theano/tensor/tests/test_basic.py
浏览文件 @
66ba51fe
...
@@ -40,7 +40,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
...
@@ -40,7 +40,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
tile
,
patternbroadcast
,
Eye
,
Shape
,
Default
,
Dot
,
PermuteRowElements
,
tile
,
patternbroadcast
,
Eye
,
Shape
,
Default
,
Dot
,
PermuteRowElements
,
ScalarFromTensor
,
TensorFromScalar
,
dtensor4
,
Rebroadcast
,
Alloc
,
ScalarFromTensor
,
TensorFromScalar
,
dtensor4
,
Rebroadcast
,
Alloc
,
dtensor3
,
SpecifyShape
,
Mean
,
IncSubtensor
,
AdvancedIncSubtensor1
,
dtensor3
,
SpecifyShape
,
Mean
,
IncSubtensor
,
AdvancedIncSubtensor1
,
itensor3
,
Tile
,
AdvancedIncSubtensor
,
switch
)
itensor3
,
Tile
,
AdvancedIncSubtensor
,
switch
,
Diagonal
)
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
from
theano.printing
import
debugprint
from
theano.printing
import
debugprint
...
@@ -6542,6 +6542,12 @@ class TestInferShape(utt.InferShapeTester):
...
@@ -6542,6 +6542,12 @@ class TestInferShape(utt.InferShapeTester):
[
Eye
()(
aiscal
,
biscal
,
ciscal
)],
[
Eye
()(
aiscal
,
biscal
,
ciscal
)],
[
3
,
5
,
0
],
Eye
)
[
3
,
5
,
0
],
Eye
)
# Diagonal
atens3
=
tensor3
()
atens3_val
=
rand
(
4
,
5
,
3
)
atens3_diag
=
Diagonal
()(
atens3
)
self
.
_compile_and_check
([
atens3
],
[
atens3_diag
],
[
atens3_val
],
Diagonal
)
# Shape
# Shape
# 'opt.Makevector' precludes optimizer from disentangling
# 'opt.Makevector' precludes optimizer from disentangling
# elements of shape
# elements of shape
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论