Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f49e38f7
提交
f49e38f7
authored
6月 06, 2011
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove apply_shape, and tag.shape of variables. Closes #633.
上级
adf4929d
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
8 行增加
和
72 行删除
+8
-72
apply_shape.py
theano/gof/apply_shape.py
+0
-42
basic.py
theano/tensor/basic.py
+4
-22
blas.py
theano/tensor/blas.py
+1
-4
elemwise.py
theano/tensor/elemwise.py
+1
-2
conv.py
theano/tensor/nnet/conv.py
+1
-1
nnet.py
theano/tensor/nnet/nnet.py
+1
-1
没有找到文件。
theano/gof/apply_shape.py
deleted
100644 → 0
浏览文件 @
adf4929d
"""Apply for use with Tensors that implements shape propagation via variable.tag.shape
This is not used currently very used. It appear in some case, but I'm not sure it if work or if it is used by default.
It could help the current system to make it detect problem earlier when contructing the graph instead of during optimization.
"""
import
sys
from
theano
import
gof
def
ishape
(
v
):
try
:
return
(
True
,
v
.
tag
.
shape
)
except
AttributeError
:
return
(
False
,
(
None
,)
*
v
.
type
.
ndim
)
class
Apply
(
gof
.
Apply
):
def
__init__
(
self
,
op
,
inputs
,
outputs
):
super
(
Apply
,
self
)
.
__init__
(
op
,
inputs
,
outputs
)
if
not
inputs
:
return
# if any input has any shape info, then propagate it
try
:
provided
,
ishapes
=
zip
(
*
[
ishape
(
i
)
for
i
in
inputs
])
except
AttributeError
:
# i.type.ndim didn't make sense for some i
return
if
provided
==
[
False
for
i
in
inputs
]:
# no input had a tag.shape
return
try
:
infer_shape
=
op
.
infer_shape
except
AttributeError
:
# op has no infer_shape, that's fine
return
try
:
oshapes
=
infer_shape
(
self
,
ishapes
)
except
NotImplementedError
:
return
for
o
,
oshp
in
zip
(
outputs
,
oshapes
):
o
.
tag
.
shape
=
oshp
theano/tensor/basic.py
浏览文件 @
f49e38f7
...
...
@@ -12,8 +12,7 @@ import numpy, theano
#from copy import copy as python_copy
from
theano
import
gof
,
shared
from
theano.gof
import
Variable
,
Op
,
Type
,
Constant
,
Value
from
theano.gof.apply_shape
import
Apply
from
theano.gof
import
Apply
,
Constant
,
Op
,
Type
,
Value
,
Variable
from
theano
import
gradient
...
...
@@ -287,7 +286,6 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None):
TensorType
(
dtype
=
x_
.
dtype
,
broadcastable
=
bcastable
),
x_
.
copy
(),
name
=
name
)
rval
.
tag
.
shape
=
x_
.
shape
return
rval
else
:
# leave the shape out of the type
...
...
@@ -3501,25 +3499,12 @@ class Join(Op):
def
infer_shape
(
self
,
node
,
ishapes
):
# Join op should get at least two inputs to join
# ishapes[0] contains the size of the axis on which we join
# Join op should get at least one input to join
assert
len
(
ishapes
)
>
1
# Not sure this is needed anymore :( ... basically the apply_shape
# version of the apply node (i.e. the one defined in
# gof/apply_shape) calls infer_shape methods passing None to unknown
# inputs. It can handle NotImplementedError, so for now I just raise
# that whenever I get a None. Should we just remove gof/apply_shape
# if it is depricated ??
if
ishapes
[
1
]
is
None
:
raise
NotImplementedError
n_dim
=
len
(
ishapes
[
1
])
for
shape
in
ishapes
[
1
:]:
if
shape
is
None
:
raise
NotImplementedError
for
shape_i
in
shape
:
if
shape_i
is
None
:
raise
NotImplementedError
# at this point the inputs have been broadcasted so they should
# all have the same shape
assert
shape
is
not
None
assert
len
(
shape
)
==
n_dim
out_shapes
=
[]
...
...
@@ -3837,9 +3822,6 @@ def reshape(x, newshape, ndim=None, name=None):
ndim
=
get_vector_length
(
newshape
)
op
=
Reshape
(
ndim
,
name
)
rval
=
op
(
x
,
newshape
)
if
isinstance
(
newshape
,
(
list
,
tuple
)):
rval
.
tag
.
shape
=
newshape
return
rval
class
Flatten
(
Op
):
...
...
theano/tensor/blas.py
浏览文件 @
f49e38f7
...
...
@@ -6,16 +6,13 @@ import numpy.distutils
from
theano.configparser
import
config
,
AddConfigVar
,
StrParam
from
theano.gof
import
(
utils
,
Op
,
view_roots
,
PatternSub
,
DestroyHandler
,
SeqOptimizer
,
local_optimizer
,
Optimizer
,
LocalOptimizer
,
OpKeyOptimizer
,
InconsistencyError
,
toolbox
,
SequenceDB
,
EquilibriumOptimizer
)
InconsistencyError
,
toolbox
,
SequenceDB
,
EquilibriumOptimizer
,
Apply
)
from
theano.printing
import
pprint
,
FunctionPrinter
,
debugprint
from
theano.compile.mode
import
optdb
from
theano.gof.python25
import
all
,
any
import
theano.scalar
import
basic
as
T
from
theano.gof.apply_shape
import
Apply
#NB: this clobbers the builtin 'compile' symbol
from
theano
import
compile
#to register the optimizer built by this file
...
...
theano/tensor/elemwise.py
浏览文件 @
f49e38f7
...
...
@@ -5,12 +5,11 @@ import numpy
import
elemwise_cgen
as
cgen
import
theano
from
theano
import
gof
from
theano.gof
import
Op
from
theano.gof
import
Apply
,
Op
from
theano
import
scalar
from
theano.scalar
import
Scalar
from
theano.printing
import
pprint
from
theano.gof.python25
import
all
,
any
from
theano.gof.apply_shape
import
Apply
# tensor depends on elemwise to provide definitions for several ops
...
...
theano/tensor/nnet/conv.py
浏览文件 @
f49e38f7
...
...
@@ -18,7 +18,7 @@ import theano
from
theano.tensor
import
(
as_tensor_variable
,
blas
,
get_constant_value
,
patternbroadcast
)
from
theano
import
Op
,
config
from
theano.gof
.apply_shape
import
Apply
from
theano.gof
import
Apply
from
theano.gof.python25
import
any
imported_scipy_signal
=
False
...
...
theano/tensor/nnet/nnet.py
浏览文件 @
f49e38f7
...
...
@@ -11,7 +11,7 @@ from theano.tensor import basic as tensor
from
theano.tensor
import
elemwise
,
dmatrix
,
fmatrix
,
dvector
,
fvector
from
theano.tensor
import
opt
from
theano.compile
import
optdb
from
theano.gof
.apply_shape
import
Apply
from
theano.gof
import
Apply
from
theano.tensor.nnet.sigm
import
sigmoid
,
softplus
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论