Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5381bbda
提交
5381bbda
authored
8月 14, 2015
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make broadcast fixup in filter_variable() depend on an argument and stop doing…
Make broadcast fixup in filter_variable() depend on an argument and stop doing it for shared variables.
上级
b2f62a1e
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
43 行增加
和
33 行删除
+43
-33
pfunc.py
theano/compile/pfunc.py
+4
-2
null_type.py
theano/gof/null_type.py
+1
-1
type.py
theano/gof/type.py
+20
-19
type.py
theano/sandbox/cuda/type.py
+6
-3
type.py
theano/sandbox/gpuarray/type.py
+6
-3
type.py
theano/tensor/type.py
+6
-5
没有找到文件。
theano/compile/pfunc.py
浏览文件 @
5381bbda
...
...
@@ -101,7 +101,8 @@ def rebuild_collect_shared(outputs,
# Do not use default_update if a "real" update was
# provided
if
v
not
in
update_d
:
v_update
=
v
.
type
.
filter_variable
(
v
.
default_update
)
v_update
=
v
.
type
.
filter_variable
(
v
.
default_update
,
allow_convert
=
False
)
if
v_update
.
type
!=
v
.
type
:
raise
TypeError
(
'an update must have the same type as '
...
...
@@ -197,7 +198,8 @@ def rebuild_collect_shared(outputs,
# filter_variable ensure smooth conversion of cpu/gpu Types
try
:
update_val
=
store_into
.
type
.
filter_variable
(
update_val
)
update_val
=
store_into
.
type
.
filter_variable
(
update_val
,
allow_convert
=
False
)
except
TypeError
:
err_msg
=
(
'An update must have the same type as the'
' original shared variable (shared_var=
%
s,'
...
...
theano/gof/null_type.py
浏览文件 @
5381bbda
...
...
@@ -21,7 +21,7 @@ class NullType(Type):
def
filter
(
self
,
data
,
strict
=
False
,
allow_downcast
=
None
):
raise
ValueError
(
"No values may be assigned to a NullType"
)
def
filter_variable
(
self
,
other
):
def
filter_variable
(
self
,
other
,
allow_convert
=
True
):
raise
ValueError
(
"No values may be assigned to a NullType"
)
def
may_share_memory
(
a
,
b
):
...
...
theano/gof/type.py
浏览文件 @
5381bbda
...
...
@@ -263,7 +263,7 @@ class PureType(object):
# def filter_inplace(value, storage, strict=False, allow_downcast=None)
def
filter_variable
(
self
,
other
):
def
filter_variable
(
self
,
other
,
allow_convert
=
True
):
"""Convert a symbolic variable into this Type, if compatible.
For the moment, the only Types compatible with one another are
...
...
@@ -277,7 +277,7 @@ class PureType(object):
# a Constant of the appropriate Type.
other
=
self
.
Constant
(
type
=
self
,
data
=
other
)
if
other
.
type
!=
self
:
if
other
.
type
!=
self
and
allow_convert
:
other2
=
self
.
convert_variable
(
other
)
if
other2
is
not
None
:
return
other2
...
...
@@ -290,6 +290,24 @@ class PureType(object):
%
dict
(
othertype
=
other
.
type
,
other
=
other
,
self
=
self
))
return
other
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
def
is_valid_value
(
self
,
a
):
"""Required: Return True for any python object `a` that would be a
legal value for a Variable of this Type"""
...
...
@@ -409,23 +427,6 @@ class Type(object2, PureType, CLinkerType):
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
浏览文件 @
5381bbda
...
...
@@ -119,7 +119,7 @@ class CudaNdarrayType(Type):
%
(
self
,
self
.
dtype
,
data
,
converted_data
,
self
.
dtype
),
data
)
def
filter_variable
(
self
,
other
):
def
filter_variable
(
self
,
other
,
allow_convert
=
True
):
"""Convert a Variable into a CudaNdarrayType, if compatible.
This Variable should either already be a CudaNdarrayType, or be
...
...
@@ -146,8 +146,11 @@ class CudaNdarrayType(Type):
raise
TypeError
(
'Incompatible number of dimensions.'
' Expected
%
d, got
%
d.'
%
(
self
.
ndim
,
other
.
ndim
))
if
other
.
type
.
broadcastable
!=
self
.
broadcastable
:
type2
=
other
.
type
.
clone
(
broadcastable
=
self
.
broadcastable
)
other2
=
type2
.
convert_variable
(
other
)
if
allow_convert
:
type2
=
other
.
type
.
clone
(
broadcastable
=
self
.
broadcastable
)
other2
=
type2
.
convert_variable
(
other
)
else
:
other2
=
None
if
other2
is
None
:
raise
TypeError
(
'Incompatible broadcastable dimensions.'
' Expected
%
s, got
%
s.'
%
...
...
theano/sandbox/gpuarray/type.py
浏览文件 @
5381bbda
...
...
@@ -89,7 +89,7 @@ class GpuArrayType(Type):
" dimension."
,
shp
,
self
.
broadcastable
)
return
data
def
filter_variable
(
self
,
other
):
def
filter_variable
(
self
,
other
,
allow_convert
=
True
):
if
hasattr
(
other
,
'_as_GpuArrayVariable'
):
other
=
other
.
_as_GpuArrayVariable
()
...
...
@@ -108,8 +108,11 @@ class GpuArrayType(Type):
raise
TypeError
(
'Incompatible number of dimensions.'
' Expected
%
d, got
%
d.'
%
(
self
.
ndim
,
other
.
ndim
))
if
other
.
type
.
broadcastable
!=
self
.
broadcastable
:
type2
=
other
.
type
.
clone
(
broadcastable
=
self
.
broadcastable
)
other2
=
type2
.
convert_variable
(
other
)
if
allow_convert
:
type2
=
other
.
type
.
clone
(
broadcastable
=
self
.
broadcastable
)
other2
=
type2
.
convert_variable
(
other
)
else
:
other2
=
None
if
other2
is
None
:
raise
TypeError
(
'Incompatible broadcastable dimensions.'
' Expected
%
s, got
%
s.'
%
...
...
theano/tensor/type.py
浏览文件 @
5381bbda
...
...
@@ -190,7 +190,7 @@ class TensorType(Type):
raise
ValueError
(
"non-finite elements not allowed"
)
return
data
def
filter_variable
(
self
,
other
):
def
filter_variable
(
self
,
other
,
allow_convert
=
True
):
"""Convert a symbolic Variable into a TensorType, if compatible.
For the moment, only a TensorType or CudaNdarrayType will be
...
...
@@ -208,10 +208,11 @@ class TensorType(Type):
if
other
.
type
==
self
:
return
other
# Attempt safe broadcast conversion.
other2
=
self
.
convert_variable
(
other
)
if
other2
is
not
None
and
other2
.
type
==
self
:
return
other2
if
allow_convert
:
# Attempt safe broadcast conversion.
other2
=
self
.
convert_variable
(
other
)
if
other2
is
not
None
and
other2
.
type
==
self
:
return
other2
raise
TypeError
(
'Cannot convert Type
%(othertype)
s '
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论