Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
074c39ef
提交
074c39ef
authored
8月 29, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
NaNType -> NullType following code review. Made NullType raise
ValueErrors
上级
aa0024bb
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
22 行增加
和
22 行删除
+22
-22
fg.py
theano/gof/fg.py
+6
-7
null_type.py
theano/gof/null_type.py
+9
-8
gradient.py
theano/gradient.py
+7
-7
没有找到文件。
theano/gof/fg.py
浏览文件 @
074c39ef
...
@@ -11,8 +11,7 @@ import toolbox
...
@@ -11,8 +11,7 @@ import toolbox
from
python25
import
all
from
python25
import
all
from
theano
import
config
from
theano
import
config
import
warnings
import
warnings
NaNType
=
None
NullType
=
None
class
InconsistencyError
(
Exception
):
class
InconsistencyError
(
Exception
):
"""
"""
...
@@ -212,9 +211,9 @@ class FunctionGraph(utils.object2):
...
@@ -212,9 +211,9 @@ class FunctionGraph(utils.object2):
### import ###
### import ###
def
__import_r__
(
self
,
variables
):
def
__import_r__
(
self
,
variables
):
global
N
aN
Type
global
N
ull
Type
if
N
aN
Type
is
None
:
if
N
ull
Type
is
None
:
from
n
an_type
import
NaN
Type
from
n
ull_type
import
Null
Type
# Imports the owners of the variables
# Imports the owners of the variables
r_owner_done
=
set
(
self
.
nodes
)
r_owner_done
=
set
(
self
.
nodes
)
for
node
in
[
r
.
owner
for
r
in
variables
if
r
.
owner
is
not
None
]:
for
node
in
[
r
.
owner
for
r
in
variables
if
r
.
owner
is
not
None
]:
...
@@ -223,8 +222,8 @@ class FunctionGraph(utils.object2):
...
@@ -223,8 +222,8 @@ class FunctionGraph(utils.object2):
self
.
__import__
(
node
)
self
.
__import__
(
node
)
for
r
in
variables
:
for
r
in
variables
:
if
r
.
owner
is
None
and
not
isinstance
(
r
,
graph
.
Constant
)
and
r
not
in
self
.
inputs
:
if
r
.
owner
is
None
and
not
isinstance
(
r
,
graph
.
Constant
)
and
r
not
in
self
.
inputs
:
if
isinstance
(
r
.
type
,
N
aN
Type
):
if
isinstance
(
r
.
type
,
N
ull
Type
):
raise
TypeError
(
"Computation graph contains a NaN. "
+
r
.
type
.
why_n
an
)
raise
TypeError
(
"Computation graph contains a NaN. "
+
r
.
type
.
why_n
ull
)
raise
MissingInputError
(
"Undeclared input"
,
r
)
raise
MissingInputError
(
"Undeclared input"
,
r
)
if
not
getattr
(
r
,
'fgraph'
,
None
)
is
self
:
if
not
getattr
(
r
,
'fgraph'
,
None
)
is
self
:
self
.
__setup_r__
(
r
)
self
.
__setup_r__
(
r
)
...
...
theano/gof/n
an
_type.py
→
theano/gof/n
ull
_type.py
浏览文件 @
074c39ef
from
type
import
Type
from
type
import
Type
from
graph
import
Variable
from
graph
import
Variable
class
N
aN
Type
(
Type
):
class
N
ull
Type
(
Type
):
def
__init__
(
self
,
why_n
an
=
'(no explanation given)'
):
def
__init__
(
self
,
why_n
ull
=
'(no explanation given)'
):
"""
"""
why_nan: A string explaining why this variable is NaN
why_null: A string explaining why this variable
can't take on any values
"""
"""
self
.
why_n
an
=
why_nan
self
.
why_n
ull
=
why_null
def
filter
(
self
,
data
,
strict
=
False
,
allow_downcast
=
None
):
def
filter
(
self
,
data
,
strict
=
False
,
allow_downcast
=
None
):
raise
raise
ValueError
(
"No values may be assigned to a NullType"
)
def
filter_variable
(
self
,
other
):
def
filter_variable
(
self
,
other
):
raise
raise
ValueError
(
"No values may be assigned to a NullType"
)
def
may_share_memory
(
a
,
b
):
def
may_share_memory
(
a
,
b
):
return
False
return
False
def
values_eq
(
a
,
b
,
force_same_dtype
=
True
):
def
values_eq
(
a
,
b
,
force_same_dtype
=
True
):
raise
raise
ValueError
(
"NullType has no values to compare"
)
class
N
aN
Variable
(
Variable
):
class
N
ull
Variable
(
Variable
):
pass
pass
theano/gradient.py
浏览文件 @
074c39ef
...
@@ -20,7 +20,7 @@ from theano import gof
...
@@ -20,7 +20,7 @@ from theano import gof
from
theano.gof
import
Variable
from
theano.gof
import
Variable
from
theano.gof.python25
import
all
from
theano.gof.python25
import
all
import
theano.gof.utils
import
theano.gof.utils
from
theano.gof.n
an_type
import
NaN
Type
from
theano.gof.n
ull_type
import
Null
Type
from
theano.printing
import
min_informative_str
from
theano.printing
import
min_informative_str
tensor
=
None
tensor
=
None
...
@@ -68,7 +68,7 @@ def grad_not_implemented(op, x_pos, x, comment = ""):
...
@@ -68,7 +68,7 @@ def grad_not_implemented(op, x_pos, x, comment = ""):
gradient is not implemented.
gradient is not implemented.
"""
"""
return
N
aN
Type
(
"This variable is NaN because the grad method for "
+
\
return
N
ull
Type
(
"This variable is NaN because the grad method for "
+
\
"input "
+
str
(
x_pos
)
+
" ("
+
str
(
x
)
+
") of the "
+
str
(
op
)
+
" op is"
+
\
"input "
+
str
(
x_pos
)
+
" ("
+
str
(
x
)
+
") of the "
+
str
(
op
)
+
" op is"
+
\
" not implemented."
+
comment
)()
" not implemented."
+
comment
)()
...
@@ -86,7 +86,7 @@ def grad_undefined(op, x_pos, x, comment = ""):
...
@@ -86,7 +86,7 @@ def grad_undefined(op, x_pos, x, comment = ""):
gradient is not defined.
gradient is not defined.
"""
"""
return
N
aN
Type
(
"This variable is NaN because the gradient for "
+
\
return
N
ull
Type
(
"This variable is NaN because the gradient for "
+
\
"input "
+
str
(
x_pos
)
+
" ("
+
str
(
x
)
+
") of the "
+
str
(
op
)
+
" op is"
+
\
"input "
+
str
(
x_pos
)
+
" ("
+
str
(
x
)
+
") of the "
+
str
(
op
)
+
" op is"
+
\
" mathematically undefined."
+
comment
)()
" mathematically undefined."
+
comment
)()
...
@@ -375,9 +375,9 @@ def grad(cost, wrt, g_cost = None, consider_constant = None, warn_type = False,
...
@@ -375,9 +375,9 @@ def grad(cost, wrt, g_cost = None, consider_constant = None, warn_type = False,
raise
TypeError
(
"cost must be a scalar."
)
raise
TypeError
(
"cost must be a scalar."
)
if
isinstance
(
cost
.
type
,
N
aN
Type
):
if
isinstance
(
cost
.
type
,
N
ull
Type
):
raise
ValueError
(
"Can't differentiate a NaN cost. cost is NaN because "
+
\
raise
ValueError
(
"Can't differentiate a NaN cost. cost is NaN because "
+
\
cost
.
type
.
why_n
an
)
cost
.
type
.
why_n
ull
)
if
consider_constant
is
None
:
if
consider_constant
is
None
:
consider_constant
=
[]
consider_constant
=
[]
...
@@ -609,9 +609,9 @@ def _populate_grad_dict(var_to_node_to_idx,\
...
@@ -609,9 +609,9 @@ def _populate_grad_dict(var_to_node_to_idx,\
" Variable instance."
%
(
str
(
node
.
op
),
" Variable instance."
%
(
str
(
node
.
op
),
type
(
term
)))
type
(
term
)))
if
isinstance
(
term
.
type
,
N
aN
Type
):
if
isinstance
(
term
.
type
,
N
ull
Type
):
raise
TypeError
(
"tensor.grad encountered a NaN. "
+
\
raise
TypeError
(
"tensor.grad encountered a NaN. "
+
\
term
.
type
.
why_n
an
)
term
.
type
.
why_n
ull
)
terms
.
append
(
term
)
terms
.
append
(
term
)
grad_dict
[
var
]
=
nonempty_sum
(
terms
)
grad_dict
[
var
]
=
nonempty_sum
(
terms
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论