Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ca52a0fc
提交
ca52a0fc
authored
7月 09, 2012
作者:
Eric Larsen
提交者:
Frederic
8月 15, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
testing infer_shape: op Tile
上级
4a664c8d
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
47 行增加
和
8 行删除
+47
-8
basic.py
theano/tensor/basic.py
+21
-7
test_basic.py
theano/tensor/tests/test_basic.py
+26
-1
没有找到文件。
theano/tensor/basic.py
浏览文件 @
ca52a0fc
...
...
@@ -5527,6 +5527,17 @@ class Tile(Op):
if
len
(
out
[
0
]
.
shape
)
!=
self
.
ndim
:
raise
ValueError
(
'Tile.perform produced incorrect shape'
)
def
infer_shape
(
self
,
node
,
in_shapes
):
# Note: in contrast with numpy, it is assumed that x.shape and reps
# have equal length; see alsor tile function below
x
,
reps
=
node
.
inputs
shp
=
x
.
shape
tiled_shp
=
shp
*
reps
out_shape
=
[]
for
i
in
range
(
self
.
ndim
):
out_shape
.
append
(
tiled_shp
[
i
])
return
[
out_shape
]
def
grad
(
self
,
inp
,
grads
):
x
,
reps
=
inp
g_out
,
=
grads
...
...
@@ -5539,21 +5550,24 @@ def tile(x, reps, ndim=None):
Tile input array `x` according to `reps`. See the docstring of `numpy.tile`
for details.
Currently, `reps` must be a constant.
Currently, `reps` must be a constant, x.ndim and len(reps) must be equal
and, if specified, 'ndim' must be equal to both.
TODO: expand this.
"""
if
len
(
reps
)
!=
x
.
ndim
:
if
isinstance
(
reps
,
theano
.
tensor
.
TensorVariable
):
raise
ValueError
(
"'reps' argument to 'tile' must be a constant (e.g. "
"tuple, list of integers)"
)
elif
len
(
reps
)
!=
x
.
ndim
:
raise
ValueError
(
"len(reps) != x.ndim not currently supported"
)
elif
(
ndim
is
not
None
)
and
ndim
!=
x
.
ndim
:
raise
ValueError
(
"if specified, ndim must be equal to both x.ndim and "
"len(reps)"
)
if
not
hasattr
(
tile
,
'op'
):
tile
.
op
=
{}
try
:
assert
python_all
([
int
(
i
)
==
i
for
i
in
iter
(
reps
)])
except
(
TypeError
,
AssertionError
):
raise
ValueError
(
"reps argument to tile must be a constant (e.g. "
"tuple, list of integers)"
)
if
ndim
is
None
:
ndim
=
len
(
reps
)
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
ca52a0fc
...
...
@@ -37,7 +37,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
tile
,
patternbroadcast
,
Eye
,
Shape
,
Default
,
Dot
,
PermuteRowElements
,
ScalarFromTensor
,
TensorFromScalar
,
dtensor4
,
Rebroadcast
,
Alloc
,
dtensor3
,
SpecifyShape
,
Mean
,
IncSubtensor
,
AdvancedIncSubtensor1
,
itensor3
)
itensor3
,
Tile
)
from
theano.tests
import
unittest_tools
as
utt
from
theano.printing
import
debugprint
...
...
@@ -6625,6 +6625,31 @@ shapes generated:
[
Reshape
(
ndim
,
'_name'
)(
admat
,
aivec
)],
[
admat_val
,
[
4
,
3
]],
Reshape
)
# Tile: basic 5292
advec
=
dvector
()
advec_val
=
rand
(
5
)
aivec_val
=
[
3
]
ndim
=
1
self
.
_compile_and_check
([
advec
],
[
tile
(
advec
,
aivec_val
,
ndim
)],
[
advec_val
],
Tile
)
admat
=
dmatrix
()
admat_val
=
rand
(
2
,
4
)
aivec_val
=
[
2
,
3
]
ndim
=
None
self
.
_compile_and_check
([
admat
],
[
tile
(
admat
,
aivec_val
)],
[
admat_val
],
Tile
)
adtens4
=
dtensor4
()
adtens4_val
=
rand
(
2
,
4
,
3
,
5
)
aivec_val
=
[
2
,
3
,
1
,
4
]
ndim
=
4
self
.
_compile_and_check
([
adtens4
],
[
tile
(
adtens4
,
aivec_val
,
ndim
)],
[
adtens4_val
],
Tile
)
if
__name__
==
'__main__'
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论