Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f89ec97d
提交
f89ec97d
authored
9月 21, 2017
作者:
Shawn Tan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Subclassed GpuAllocDiag for infer_shape and modified grad to take self.axis1 and…
Subclassed GpuAllocDiag for infer_shape and modified grad to take self.axis1 and self.axis2 into account
上级
f766415c
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
8 行增加
和
12 行删除
+8
-12
subtensor.py
theano/gpuarray/subtensor.py
+8
-12
没有找到文件。
theano/gpuarray/subtensor.py
浏览文件 @
f89ec97d
...
@@ -9,6 +9,7 @@ from theano.gof import ParamsType
...
@@ -9,6 +9,7 @@ from theano.gof import ParamsType
from
theano.gradient
import
grad_not_implemented
from
theano.gradient
import
grad_not_implemented
import
theano.tensor
as
T
import
theano.tensor
as
T
from
theano.tensor.subtensor
import
IncSubtensor
,
Subtensor
,
get_idx_list
from
theano.tensor.subtensor
import
IncSubtensor
,
Subtensor
,
get_idx_list
from
theano.tensor
import
AllocDiag
from
theano.scalar
import
bool
as
bool_t
,
int32
as
int_t
,
uint32
as
size_t
from
theano.scalar
import
bool
as
bool_t
,
int32
as
int_t
,
uint32
as
size_t
try
:
try
:
...
@@ -1356,7 +1357,7 @@ class GpuExtractDiag(Op):
...
@@ -1356,7 +1357,7 @@ class GpuExtractDiag(Op):
return
[
tuple
(
out_shape
)]
return
[
tuple
(
out_shape
)]
class
GpuAllocDiag
(
Op
):
class
GpuAllocDiag
(
AllocDiag
):
__props__
=
(
"offset"
,
"axis1"
,
"axis2"
)
__props__
=
(
"offset"
,
"axis1"
,
"axis2"
)
def
__init__
(
self
,
offset
=
0
,
axis1
=
0
,
axis2
=
1
):
def
__init__
(
self
,
offset
=
0
,
axis1
=
0
,
axis2
=
1
):
...
@@ -1384,6 +1385,7 @@ class GpuAllocDiag(Op):
...
@@ -1384,6 +1385,7 @@ class GpuAllocDiag(Op):
axis2
=
np
.
maximum
(
self
.
axis1
,
self
.
axis2
)
axis2
=
np
.
maximum
(
self
.
axis1
,
self
.
axis2
)
offset
=
self
.
offset
offset
=
self
.
offset
# Initialise a buffer the same size as the output
result_shape
=
x
.
shape
[:
-
1
]
+
(
x
.
shape
[
-
1
]
+
abs
(
offset
),)
*
2
result_shape
=
x
.
shape
[:
-
1
]
+
(
x
.
shape
[
-
1
]
+
abs
(
offset
),)
*
2
result_buffer_shape
=
((
np
.
prod
(
x
.
shape
[:
-
1
])
.
astype
(
np
.
int64
),)
+
result_buffer_shape
=
((
np
.
prod
(
x
.
shape
[:
-
1
])
.
astype
(
np
.
int64
),)
+
((
x
.
shape
[
-
1
]
+
abs
(
offset
))
**
2
,))
((
x
.
shape
[
-
1
]
+
abs
(
offset
))
**
2
,))
...
@@ -1391,6 +1393,7 @@ class GpuAllocDiag(Op):
...
@@ -1391,6 +1393,7 @@ class GpuAllocDiag(Op):
dtype
=
x
.
dtype
,
dtype
=
x
.
dtype
,
context
=
x
.
context
)
context
=
x
.
context
)
# Slice out a view of the diagonals
if
offset
!=
0
:
if
offset
!=
0
:
row_size
=
x
.
shape
[
-
1
]
+
abs
(
offset
)
row_size
=
x
.
shape
[
-
1
]
+
abs
(
offset
)
if
offset
>=
0
:
if
offset
>=
0
:
...
@@ -1401,18 +1404,15 @@ class GpuAllocDiag(Op):
...
@@ -1401,18 +1404,15 @@ class GpuAllocDiag(Op):
end_flattened_offset
=
abs
(
offset
)
end_flattened_offset
=
abs
(
offset
)
diag_view
=
result_buffer
[:,
start_flattened_offset
:
-
end_flattened_offset
:
row_size
+
1
]
diag_view
=
result_buffer
[:,
start_flattened_offset
:
-
end_flattened_offset
:
row_size
+
1
]
# print("offset", offset)
# print("buffer shape:", result_buffer.shape)
# print("result_buffer[%d:%d:%d]" % (start_flattened_offset, -end_flattened_offset, row_size + 1), diag_view.shape)
# print("input_shape:", x.shape)
else
:
else
:
diag_view
=
result_buffer
[:,
::
x
.
shape
[
-
1
]
+
1
]
diag_view
=
result_buffer
[:,
::
x
.
shape
[
-
1
]
+
1
]
# Fill view with flattened array of diagonals
diag_view
[:]
=
x
.
reshape
(
diag_view
.
shape
)[:]
diag_view
[:]
=
x
.
reshape
(
diag_view
.
shape
)[:]
# Unflatten buffer into output size
result
=
result_buffer
.
reshape
(
result_shape
)
result
=
result_buffer
.
reshape
(
result_shape
)
# print(result)
# Fill in final 2 axes with x
if
len
(
x
.
shape
)
>
1
:
if
len
(
x
.
shape
)
>
1
:
# Re-order axes so they correspond to diagonals at axis1, axis2
# Re-order axes so they correspond to diagonals at axis1, axis2
axes
=
list
(
range
(
len
(
x
.
shape
[:
-
1
])))
axes
=
list
(
range
(
len
(
x
.
shape
[:
-
1
])))
...
@@ -1425,8 +1425,4 @@ class GpuAllocDiag(Op):
...
@@ -1425,8 +1425,4 @@ class GpuAllocDiag(Op):
def
grad
(
self
,
inputs
,
gout
):
def
grad
(
self
,
inputs
,
gout
):
(
gz
,)
=
gout
(
gz
,)
=
gout
return
[
GpuExtractDiag
(
offset
=
self
.
offset
,
axis1
=
0
,
axis2
=
1
)(
gz
)]
return
[
GpuExtractDiag
(
offset
=
self
.
offset
,
axis1
=
self
.
axis1
,
axis2
=
self
.
axis2
)(
gz
)]
def
infer_shape
(
self
,
node
,
shapes
):
dim
=
shapes
[
0
][
0
]
+
abs
(
self
.
offset
)
return
[[
dim
,
dim
]]
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论