Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1d6bd3c2
提交
1d6bd3c2
authored
5月 18, 2015
作者:
Saizheng Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add more error checks, fix minor errors
上级
0dd5090c
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
31 行增加
和
30 行删除
+31
-30
basic.py
theano/tensor/basic.py
+31
-30
没有找到文件。
theano/tensor/basic.py
浏览文件 @
1d6bd3c2
...
@@ -4711,10 +4711,15 @@ def tile(x, reps, ndim=None):
...
@@ -4711,10 +4711,15 @@ def tile(x, reps, ndim=None):
See the docstring of `numpy.tile` for details.
See the docstring of `numpy.tile` for details.
Currently, x.ndim and len(reps) must be equal, and, if specified, 'ndim'
Currently, 'reps' can be constant integer (e.g. 3), constant vector(e.g. [2 3]),
must be equal to both.
symbolic scalar (e.g. tensor.iscalar()), symbolic vector (e.g. tensor.ivector())
or a list of symbolic scalar (e.g. [tensor.iscalar(), tensor.iscalar()]).
If reps is constant vector/list/symbolic vector, the length of such vector(list)
should be less or equal to x.ndim, and if specified, 'ndim' should be less or equal
to x.ndim.
TODO: expand this.
TODO: expand this so that it could support cases when the length of reps (or 'ndim')
is larger than x.ndim, which is supported by numpy.
"""
"""
...
@@ -4722,52 +4727,48 @@ def tile(x, reps, ndim=None):
...
@@ -4722,52 +4727,48 @@ def tile(x, reps, ndim=None):
if
not
isinstance
(
reps
,
(
list
,
tuple
)):
if
not
isinstance
(
reps
,
(
list
,
tuple
)):
reps_astensor
=
as_tensor_variable
(
reps
)
reps_astensor
=
as_tensor_variable
(
reps
)
ndim_check
=
reps_astensor
.
ndim
ndim_check
=
reps_astensor
.
ndim
if
reps_astensor
.
dtype
not
in
theano
.
tensor
.
discrete_dtypes
:
raise
ValueError
(
"elements of reps must be integer dtype"
)
# tensor.scalar/integer case
# tensor.scalar/integer case
if
ndim_check
==
0
:
if
ndim_check
==
0
:
reps_
=
[]
reps
=
[
reps
]
reps_
.
append
(
reps
)
reps
=
reps_
# tensor.vector case
# tesor.vector case
elif
ndim_check
==
1
:
elif
ndim_check
==
1
:
if
ndim
==
None
:
if
ndim
is
None
:
raise
ValueError
(
"if reps is tensor.vector, you should specify "
raise
ValueError
(
"if reps is tensor.vector, you should specify "
"the ndim"
)
"the ndim"
)
else
:
else
:
if
ndim
>
x
.
ndim
:
raise
ValueError
(
"ndim > x.ndim not currently supported"
)
offset
=
ndim
-
reps
.
shape
[
0
]
offset
=
ndim
-
reps
.
shape
[
0
]
# assert that reps.shape[0] does not exceed ndim
# assert that reps.shape[0] does not exceed ndim
offset
=
theano
.
tensor
.
opt
.
assert_
(
offset
,
ge
(
offset
,
0
))
offset
=
theano
.
tensor
.
opt
.
assert_
(
offset
,
ge
(
offset
,
0
))
# if reps.ndim is less than x.ndim, we pad the reps with
# "1" so that reps will have the same ndim as x.
reps_
=
[
switch
(
i
<
offset
,
1
,
reps
[
i
-
offset
])
for
i
in
range
(
ndim
)]
reps_
=
[
switch
(
i
<
offset
,
1
,
reps
[
i
-
offset
])
for
i
in
range
(
ndim
)]
reps
=
reps_
reps
=
reps_
#other raise error
#other raise error
else
:
else
:
raise
ValueError
(
"the dimension of reps should not exceed 1"
)
raise
ValueError
(
"the dimension of reps should not exceed 1"
)
else
:
else
:
ndim_check
=
None
if
len
(
reps
)
>
x
.
ndim
:
raise
ValueError
(
"len(reps) > x.ndim not currently supported"
)
if
not
numpy
.
all
([
isinstance
(
r
,
(
int
,
long
))
or
(
isinstance
(
r
,
TensorVariable
)
and
r
.
dtype
in
theano
.
tensor
.
discrete_dtypes
)
for
r
in
reps
]):
raise
ValueError
(
"elements of reps must be scalars of integer dtype"
)
# if reps.ndim is less than x.ndim, we pad the reps with
# if reps.ndim is less than x.ndim, we pad the reps with
# "1" so that reps will have the same ndim as x.
# "1" so that reps will have the same ndim as x.
reps
=
list
(
reps
)
if
len
(
reps
)
<
x
.
ndim
:
if
len
(
reps
)
<
x
.
ndim
:
reps
=
[
1
]
*
(
x
.
ndim
-
len
(
reps
))
+
reps
reps
=
[
1
]
*
(
x
.
ndim
-
len
(
reps
))
+
reps
try
:
iter
(
reps
)
except
TypeError
:
raise
ValueError
(
"reps must be iterable"
)
# if reps is tensor.vector, this check should not go through
if
not
ndim_check
==
1
:
if
not
numpy
.
all
([
isinstance
(
r
,
integer_types
)
or
(
isinstance
(
r
,
TensorVariable
)
and
r
.
dtype
in
[
"int8"
,
"int16"
,
"int32"
,
"int64"
])
for
r
in
reps
]):
raise
ValueError
(
"elements of reps must be scalars of integer dtype"
)
if
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
ndim
is
None
:
if
ndim
is
None
:
ndim
=
len
(
reps
)
ndim
=
len
(
reps
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论