Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a4a54be6
提交
a4a54be6
authored
8月 28, 2009
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
差异文件
merge backport.
上级
709d654d
aff1bd89
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
44 行增加
和
0 行删除
+44
-0
basic.py
theano/tensor/basic.py
+44
-0
没有找到文件。
theano/tensor/basic.py
浏览文件 @
a4a54be6
...
...
@@ -1857,6 +1857,47 @@ class Split(Op):
"""Join the gradients along the axis that was used to split x."""
return
[
join
(
axis
,
*
g_outputs
),
None
,
None
]
class
Rebroadcast
(
Op
):
"""
Change the input's broadcastable fields in
some predetermined way.
e.g.: Rebroadcast((0, True), (1, False))(x)
would make x broadcastable in axis 0
and not broadcastable in axis 1
See also the unbroadcast function.
"""
view_map
=
{
0
:
[
0
]}
def
__init__
(
self
,
*
axis
):
self
.
axis
=
dict
(
axis
)
def
make_node
(
self
,
x
):
t
=
TensorType
(
dtype
=
x
.
type
.
dtype
,
broadcastable
=
[
self
.
axis
.
get
(
i
,
b
)
for
i
,
b
in
enumerate
(
x
.
type
.
broadcastable
)])
return
Apply
(
self
,
[
x
],
[
t
()])
def
perform
(
self
,
node
,
(
x
,
),
(
out
,
)):
for
axis
,
value
in
self
.
axis
.
iteritems
():
if
value
and
x
.
shape
[
axis
]
!=
1
:
raise
ValueError
(
'Dimension
%
s in Rebroadcast
\'
s input was supposed to be 1 (got
%
s instead)'
%
(
axis
,
x
.
shape
[
axis
]))
out
[
0
]
=
x
def
grad
(
self
,
(
x
,
),
(
gz
,)):
# restore the broadcasting pattern of the input
return
Rebroadcast
(
*
[(
axis
,
x
.
type
.
broadcastable
[
axis
])
for
axis
,
value
in
self
.
axis
.
iteritems
()])(
gz
),
def
addbroadcast
(
x
,
*
axes
):
"""
Make the input broadcastable in the specified axes.
"""
return
Rebroadcast
(
*
[(
axis
,
True
)
for
axis
in
axes
])(
x
)
def
unbroadcast
(
x
,
*
axes
):
"""
Make the input impossible to broadcast in the specified axes.
"""
return
Rebroadcast
(
*
[(
axis
,
False
)
for
axis
in
axes
])(
x
)
class
Join
(
Op
):
"""
Concatenate multiple `TensorVariable`s along some axis.
...
...
@@ -1919,6 +1960,9 @@ class Join(Op):
bcastable
[
axis
]
=
False
except
IndexError
,
e
:
raise
ValueError
(
'Join argument "axis" is out of range (given input dimensions)'
)
as_tensor_variable_args
=
[
unbroadcast
(
x
,
axis
)
for
x
in
as_tensor_variable_args
]
else
:
as_tensor_variable_args
=
[
unbroadcast
(
x
,
*
range
(
x
.
type
.
ndim
))
for
x
in
as_tensor_variable_args
]
inputs
=
[
as_tensor_variable
(
axis
)]
+
as_tensor_variable_args
if
inputs
[
0
]
.
type
not
in
int_types
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论