Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8e85dbab
提交
8e85dbab
authored
2月 24, 2015
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2527 from abergeron/allow_rebroadcast
Add a way for almost-equal types replacements to be patched over automatically.
上级
1d9b897b
2583dd15
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
57 行增加
和
7 行删除
+57
-7
fg.py
theano/gof/fg.py
+17
-7
type.py
theano/gof/type.py
+17
-0
type.py
theano/sandbox/cuda/type.py
+7
-0
type.py
theano/sandbox/gpuarray/type.py
+8
-0
type.py
theano/tensor/type.py
+8
-0
没有找到文件。
theano/gof/fg.py
浏览文件 @
8e85dbab
...
...
@@ -89,7 +89,7 @@ class FunctionGraph(utils.object2):
Note: the intermediate nodes between 'inputs' and 'outputs' are not explicitely
passed.
:param inputs: inputs nodes of the graph, usually declared by the user
:param outputs: outputs nodes of the graph.
:param clone: If true, we will clone the graph. This is
...
...
@@ -462,12 +462,22 @@ class FunctionGraph(utils.object2):
if
verbose
:
print
reason
,
r
,
new_r
if
r
.
fgraph
is
not
self
:
raise
Exception
(
"Cannot replace
%
s because it does not belong to this FunctionGraph"
%
r
,
str
(
reason
))
if
not
r
.
type
==
new_r
.
type
:
raise
TypeError
(
"The type of the replacement must be the same as the type of the original Variable."
,
r
,
new_r
,
r
.
type
,
new_r
.
type
,
str
(
reason
))
raise
Exception
(
"Cannot replace
%
s because it does not belong "
"to this FunctionGraph"
%
r
,
str
(
reason
))
if
r
.
type
!=
new_r
.
type
:
new_r2
=
r
.
type
.
convert_variable
(
new_r
)
# We still make sure that the type converts correctly
if
new_r2
is
None
or
new_r2
.
type
!=
r
.
type
:
raise
TypeError
(
"The type of the replacement must be "
"compatible with the type of the original "
"Variable."
,
r
,
new_r
,
r
.
type
,
new_r
.
type
,
str
(
reason
))
new_r
=
new_r2
if
r
not
in
self
.
variables
:
# this variable isn't in the graph... don't raise an exception here, just return silently
# because it makes it easier to implement some optimizations for multiple-output ops
# this variable isn't in the graph... don't raise an
# exception here, just return silently because it makes it
# easier to implement some optimizations for
# multiple-output ops
return
if
theano
.
config
.
compute_test_value
!=
'off'
:
...
...
@@ -756,7 +766,7 @@ class FunctionGraph(utils.object2):
del
d
[
attr
]
# The class Updater take fct as parameter and they are lambda function, so unpicklable.
# execute_callbacks_times have reference to optimizer, and they can't
# execute_callbacks_times have reference to optimizer, and they can't
# be pickled as the decorators with parameters aren't pickable.
if
"execute_callbacks_times"
in
d
:
del
d
[
"execute_callbacks_times"
]
...
...
theano/gof/type.py
浏览文件 @
8e85dbab
...
...
@@ -394,6 +394,23 @@ class Type(object2, PureType, CLinkerType):
types. Type references are also useful to do type-checking in pattern-based optimizations.
"""
def
convert_variable
(
self
,
var
):
"""Patch variable so that its type will match self, if possible.
If the variable can't be converted, this should return None.
The conversion can only happen if the following implication is
true for all possible `val`.
self.is_valid_value(val) => var.type.is_valid_value(val)
For the majority of types this means that you can only have
non-broadcastable dimensions become broadcastable and not the
inverse.
The default is to not convert anything which is always safe.
"""
return
None
class
SingletonType
(
Type
):
...
...
theano/sandbox/cuda/type.py
浏览文件 @
8e85dbab
...
...
@@ -232,6 +232,13 @@ class CudaNdarrayType(Type):
return
(
type
(
self
)
==
type
(
other
)
and
other
.
broadcastable
==
self
.
broadcastable
)
def
convert_variable
(
self
,
var
):
if
(
type
(
self
)
==
type
(
var
.
type
)
and
self
.
ndim
==
var
.
type
.
ndim
and
all
(
sb
==
ob
or
ob
for
sb
,
ob
in
zip
(
self
.
broadcastable
,
var
.
type
.
broadcastable
))):
return
theano
.
tensor
.
patternbroadcast
(
var
,
self
.
broadcastable
)
def
__hash__
(
self
):
"""Hash equal for same kinds of CudaNdarrayType"""
return
hash
(
type
(
self
))
^
hash
(
self
.
broadcastable
)
...
...
theano/sandbox/gpuarray/type.py
浏览文件 @
8e85dbab
...
...
@@ -148,6 +148,14 @@ class GpuArrayType(Type):
self
.
typecode
==
other
.
typecode
and
self
.
broadcastable
==
other
.
broadcastable
)
def
convert_variable
(
self
,
var
):
if
(
type
(
self
)
==
type
(
var
.
type
)
and
self
.
typecode
==
var
.
type
.
typecode
and
self
.
ndim
==
var
.
type
.
ndim
and
all
(
sb
==
ob
or
ob
for
sb
,
ob
in
zip
(
self
.
broadcastable
,
var
.
type
.
broadcastable
))):
return
theano
.
tensor
.
patternbroadcast
(
var
,
self
.
broadcastable
)
def
__hash__
(
self
):
return
(
hash
(
self
.
typecode
)
^
hash
(
self
.
broadcastable
))
...
...
theano/tensor/type.py
浏览文件 @
8e85dbab
...
...
@@ -260,6 +260,14 @@ class TensorType(Type):
return
type
(
self
)
==
type
(
other
)
and
other
.
dtype
==
self
.
dtype
\
and
other
.
broadcastable
==
self
.
broadcastable
def
convert_variable
(
self
,
var
):
if
(
type
(
self
)
==
type
(
var
.
type
)
and
self
.
dtype
==
var
.
type
.
dtype
and
self
.
ndim
==
var
.
type
.
ndim
and
all
(
sb
==
ob
or
ob
for
sb
,
ob
in
zip
(
self
.
broadcastable
,
var
.
type
.
broadcastable
))):
return
theano
.
tensor
.
patternbroadcast
(
var
,
self
.
broadcastable
)
@staticmethod
def
may_share_memory
(
a
,
b
):
# This is a method of TensorType, so both a and b should be ndarrays
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论