Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
89c9b628
提交
89c9b628
authored
2月 21, 2017
作者:
hantek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
changes according to abergeron
上级
7a4bedf2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
21 行增加
和
15 行删除
+21
-15
subtensor.py
theano/gpuarray/subtensor.py
+1
-1
basic.py
theano/tensor/basic.py
+20
-14
没有找到文件。
theano/gpuarray/subtensor.py
浏览文件 @
89c9b628
...
@@ -1078,7 +1078,7 @@ __device__ ga_half atomicExch(ga_half *addr, ga_half val) {
...
@@ -1078,7 +1078,7 @@ __device__ ga_half atomicExch(ga_half *addr, ga_half val) {
"""
%
locals
()
"""
%
locals
()
class
GpuExtractDiag
(
Subtensor
):
class
GpuExtractDiag
(
Op
):
__props__
=
(
"offset"
,
"axis1"
,
"axis2"
,
"view"
)
__props__
=
(
"offset"
,
"axis1"
,
"axis2"
,
"view"
)
def
__init__
(
self
,
offset
=
0
,
axis1
=
0
,
axis2
=
1
,
view
=
False
):
def
__init__
(
self
,
offset
=
0
,
axis1
=
0
,
axis2
=
1
,
view
=
False
):
...
...
theano/tensor/basic.py
浏览文件 @
89c9b628
...
@@ -33,6 +33,7 @@ from theano.compile import Rebroadcast, Shape, shape
...
@@ -33,6 +33,7 @@ from theano.compile import Rebroadcast, Shape, shape
# We use these exceptions as well.
# We use these exceptions as well.
import
theano.scalar.sharedvar
import
theano.scalar.sharedvar
from
theano.gradient
import
grad_undefined
from
theano.gradient
import
grad_undefined
from
theano.gradient
import
grad_not_implemented
from
theano.gradient
import
DisconnectedType
from
theano.gradient
import
DisconnectedType
# set up the external interface
# set up the external interface
...
@@ -6143,18 +6144,21 @@ class ExtractDiag(Op):
...
@@ -6143,18 +6144,21 @@ class ExtractDiag(Op):
z
[
0
]
=
z
[
0
]
.
copy
()
z
[
0
]
=
z
[
0
]
.
copy
()
def
grad
(
self
,
inputs
,
gout
):
def
grad
(
self
,
inputs
,
gout
):
"""
The following code is moved from tensor.nlinalg.ExtractDiag, only works
for matrices.
"""
warnings
.
warn
(
"gradient of theano.tensor.nlinalg.ExtractDiag only"
"works for matrices."
)
(
x
,)
=
inputs
(
x
,)
=
inputs
(
gz
,)
=
gout
(
gz
,)
=
gout
x
=
theano
.
tensor
.
zeros_like
(
x
)
xdiag
=
theano
.
tensor
.
AllocDiag
(
offset
=
self
.
offset
)(
gz
)
if
x
.
ndim
==
2
:
return
[
theano
.
tensor
.
set_subtensor
(
# The following code is moved from tensor.nlinalg.ExtractDiag, only
x
[:
xdiag
.
shape
[
0
],
:
xdiag
.
shape
[
1
]],
xdiag
)]
# works for matrices.
x
=
theano
.
tensor
.
zeros_like
(
x
)
xdiag
=
theano
.
tensor
.
AllocDiag
(
offset
=
self
.
offset
)(
gz
)
return
[
theano
.
tensor
.
set_subtensor
(
x
[:
xdiag
.
shape
[
0
],
:
xdiag
.
shape
[
1
]],
xdiag
)]
else
:
warnings
.
warn
(
"gradient of theano.tensor.nlinalg.ExtractDiag only"
"works for matrices."
)
return
[
grad_not_implemented
(
self
,
0
,
x
)]
def
infer_shape
(
self
,
node
,
shapes
):
def
infer_shape
(
self
,
node
,
shapes
):
in_shape
,
=
shapes
in_shape
,
=
shapes
...
@@ -6204,9 +6208,9 @@ class AllocDiag(Op):
...
@@ -6204,9 +6208,9 @@ class AllocDiag(Op):
Usage: T.AllocDiag()(x)
Usage: T.AllocDiag()(x)
`x` should be a tensor vector. The parenthesis in the front should indicate
`x` should be a tensor vector. The parenthesis in the front should indicate
which main diagonal the vector value goes into. By default it is set to
(
which main diagonal the vector value goes into. By default it is set to
`0`, which corresponds to setting the values of x to the main diagonal in
`0`, which corresponds to setting the values of x to the main diagonal in
the returned matrix.
Currently the gradient is valid only when `offset=0`.
the returned matrix.
Parameters
Parameters
----------
----------
...
@@ -6233,6 +6237,8 @@ class AllocDiag(Op):
...
@@ -6233,6 +6237,8 @@ class AllocDiag(Op):
def
make_node
(
self
,
diag
):
def
make_node
(
self
,
diag
):
diag
=
as_tensor_variable
(
diag
)
diag
=
as_tensor_variable
(
diag
)
if
diag
.
type
.
ndim
!=
1
:
raise
TypeError
(
'data argument must be a vector'
,
diag
.
type
)
return
Apply
(
self
,
[
diag
],
[
matrix
(
dtype
=
diag
.
dtype
)])
return
Apply
(
self
,
[
diag
],
[
matrix
(
dtype
=
diag
.
dtype
)])
def
perform
(
self
,
node
,
inputs
,
outputs
):
def
perform
(
self
,
node
,
inputs
,
outputs
):
...
@@ -6270,11 +6276,11 @@ def diag(v, k=0):
...
@@ -6270,11 +6276,11 @@ def diag(v, k=0):
"""
"""
if
v
.
ndim
==
1
:
if
v
.
ndim
==
1
:
return
AllocDiag
()(
v
)
return
AllocDiag
(
k
)(
v
)
elif
v
.
ndim
>=
2
:
elif
v
.
ndim
>=
2
:
return
diagonal
(
v
,
offset
=
k
)
return
diagonal
(
v
,
offset
=
k
)
else
:
else
:
raise
ValueError
(
"Input must has v.dim >= 1."
)
raise
ValueError
(
"Input must has v.
n
dim >= 1."
)
def
stacklists
(
arg
):
def
stacklists
(
arg
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论