Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bca70569
提交
bca70569
authored
3月 05, 2012
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Define specific exceptions
上级
2be13335
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
41 行增加
和
22 行删除
+41
-22
function_module.py
theano/compile/function_module.py
+7
-1
pfunc.py
theano/compile/pfunc.py
+2
-1
test_function_module.py
theano/compile/tests/test_function_module.py
+13
-14
__init__.py
theano/gof/__init__.py
+1
-1
env.py
theano/gof/env.py
+18
-5
没有找到文件。
theano/compile/function_module.py
浏览文件 @
bca70569
...
@@ -21,6 +21,12 @@ import logging
...
@@ -21,6 +21,12 @@ import logging
_logger
=
logging
.
getLogger
(
'theano.compile.function_module'
)
_logger
=
logging
.
getLogger
(
'theano.compile.function_module'
)
class
UnusedInputError
(
Exception
):
"""
A symbolic input passed to function is not needed
"""
pass
def
alias_root
(
v
):
def
alias_root
(
v
):
"""Return the variable to which v is aliased by view_maps and destroy_maps"""
"""Return the variable to which v is aliased by view_maps and destroy_maps"""
if
v
.
owner
is
None
:
return
v
if
v
.
owner
is
None
:
return
v
...
@@ -1110,7 +1116,7 @@ class FunctionMaker(object):
...
@@ -1110,7 +1116,7 @@ class FunctionMaker(object):
if
on_unused_input
==
'warn'
:
if
on_unused_input
==
'warn'
:
warnings
.
warn
(
msg
%
(
i
.
variable
,
warn_msg
),
stacklevel
=
5
)
warnings
.
warn
(
msg
%
(
i
.
variable
,
warn_msg
),
stacklevel
=
5
)
elif
on_unused_input
==
'raise'
:
elif
on_unused_input
==
'raise'
:
raise
Value
Error
(
msg
%
(
i
.
variable
,
err_msg
))
raise
UnusedInput
Error
(
msg
%
(
i
.
variable
,
err_msg
))
else
:
else
:
raise
ValueError
((
"Invalid value for keyword "
raise
ValueError
((
"Invalid value for keyword "
"on_unused_input of theano.function: '
%
s'. "
"on_unused_input of theano.function: '
%
s'. "
...
...
theano/compile/pfunc.py
浏览文件 @
bca70569
...
@@ -7,6 +7,7 @@ from profiling import ProfileStats
...
@@ -7,6 +7,7 @@ from profiling import ProfileStats
from
theano
import
config
from
theano
import
config
from
theano.compile
import
orig_function
,
In
,
Out
from
theano.compile
import
orig_function
,
In
,
Out
from
theano.compile
import
UnusedInputError
from
theano.compile.sharedvalue
import
SharedVariable
,
shared
from
theano.compile.sharedvalue
import
SharedVariable
,
shared
from
theano.gof
import
Container
,
Variable
,
generic
,
graph
,
Constant
,
Value
from
theano.gof
import
Container
,
Variable
,
generic
,
graph
,
Constant
,
Value
from
theano.gof.python25
import
any
from
theano.gof.python25
import
any
...
@@ -432,7 +433,7 @@ def pfunc(params, outputs=None, mode=None, updates=[], givens=[],
...
@@ -432,7 +433,7 @@ def pfunc(params, outputs=None, mode=None, updates=[], givens=[],
for
i
,
v
in
enumerate
(
in_variables
):
for
i
,
v
in
enumerate
(
in_variables
):
if
v
in
in_variables
[(
i
+
1
):]:
if
v
in
in_variables
[(
i
+
1
):]:
dup_v_i
=
in_variables
.
index
(
v
,
(
i
+
1
))
dup_v_i
=
in_variables
.
index
(
v
,
(
i
+
1
))
raise
Value
Error
(
raise
UnusedInput
Error
(
(
"Variable
%
s is used twice in inputs to theano.function, "
(
"Variable
%
s is used twice in inputs to theano.function, "
"at indices
%
i and
%
i. This would result in values "
"at indices
%
i and
%
i. This would result in values "
"provided for it being ignored. Please do not duplicate "
"provided for it being ignored. Please do not duplicate "
...
...
theano/compile/tests/test_function_module.py
浏览文件 @
bca70569
...
@@ -8,6 +8,8 @@ from theano import gof,config
...
@@ -8,6 +8,8 @@ from theano import gof,config
from
theano.scalar
import
mul
from
theano.scalar
import
mul
from
theano.compile.io
import
In
,
Out
from
theano.compile.io
import
In
,
Out
from
theano.compile
import
function
from
theano.compile
import
function
from
theano.compile
import
UnusedInputError
from
theano.gof
import
MissingInputError
from
theano.gof.python25
import
all
,
any
from
theano.gof.python25
import
all
,
any
from
theano
import
tensor
from
theano
import
tensor
...
@@ -53,56 +55,53 @@ class T_function(unittest.TestCase):
...
@@ -53,56 +55,53 @@ class T_function(unittest.TestCase):
def
test_missing_inputs
(
self
):
def
test_missing_inputs
(
self
):
MissingInputException
=
TypeError
UnusedInputException
=
ValueError
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([],
[
x
])
fn
=
function
([],
[
x
])
checkfor
(
self
,
fn
,
MissingInputE
xception
)
checkfor
(
self
,
fn
,
MissingInputE
rror
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
# Ignore unused input s, as it hides the other error
# Ignore unused input s, as it hides the other error
fn
=
function
([
s
],
[
x
],
on_unused_input
=
'ignore'
)
fn
=
function
([
s
],
[
x
],
on_unused_input
=
'ignore'
)
checkfor
(
self
,
fn
,
MissingInputE
xception
)
checkfor
(
self
,
fn
,
MissingInputE
rror
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
s
],
[
x
])
fn
=
function
([
s
],
[
x
])
checkfor
(
self
,
fn
,
UnusedInputE
xception
)
checkfor
(
self
,
fn
,
UnusedInputE
rror
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
# Ignore unused input s, as it hides the other error
# Ignore unused input s, as it hides the other error
fn
=
function
([
s
],
x
,
on_unused_input
=
'ignore'
)
fn
=
function
([
s
],
x
,
on_unused_input
=
'ignore'
)
checkfor
(
self
,
fn
,
MissingInputE
xception
)
checkfor
(
self
,
fn
,
MissingInputE
rror
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
s
],
x
)
fn
=
function
([
s
],
x
)
checkfor
(
self
,
fn
,
UnusedInputE
xception
)
checkfor
(
self
,
fn
,
UnusedInputE
rror
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
# Ignore unused input s, as it hides the other error
# Ignore unused input s, as it hides the other error
fn
=
function
([
s
],
Out
(
x
),
on_unused_input
=
'ignore'
)
fn
=
function
([
s
],
Out
(
x
),
on_unused_input
=
'ignore'
)
checkfor
(
self
,
fn
,
MissingInputE
xception
)
checkfor
(
self
,
fn
,
MissingInputE
rror
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
s
],
Out
(
x
))
fn
=
function
([
s
],
Out
(
x
))
checkfor
(
self
,
fn
,
UnusedInputE
xception
)
checkfor
(
self
,
fn
,
UnusedInputE
rror
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
In
(
x
,
update
=
s
+
x
)],
x
)
fn
=
function
([
In
(
x
,
update
=
s
+
x
)],
x
)
checkfor
(
self
,
fn
,
MissingInputE
xception
)
checkfor
(
self
,
fn
,
MissingInputE
rror
)
def
fn
():
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
In
(
x
,
update
=
mul
(
s
,
s
)
+
x
)],
x
)
fn
=
function
([
In
(
x
,
update
=
mul
(
s
,
s
)
+
x
)],
x
)
checkfor
(
self
,
fn
,
MissingInputE
xception
)
checkfor
(
self
,
fn
,
MissingInputE
rror
)
def
test_input_anon_singleton
(
self
):
def
test_input_anon_singleton
(
self
):
x
,
s
=
T
.
scalars
(
'xs'
)
x
,
s
=
T
.
scalars
(
'xs'
)
...
@@ -378,14 +377,14 @@ class T_function(unittest.TestCase):
...
@@ -378,14 +377,14 @@ class T_function(unittest.TestCase):
def
test_disconnected_input
(
self
):
def
test_disconnected_input
(
self
):
a
=
T
.
scalar
(
'a'
)
a
=
T
.
scalar
(
'a'
)
v
=
T
.
vector
(
'v'
)
v
=
T
.
vector
(
'v'
)
self
.
assertRaises
(
Value
Error
,
function
,
[
a
,
v
],
v
*
2
)
self
.
assertRaises
(
UnusedInput
Error
,
function
,
[
a
,
v
],
v
*
2
)
f
=
function
([
a
,
v
],
v
*
2
,
on_unused_input
=
'ignore'
)
f
=
function
([
a
,
v
],
v
*
2
,
on_unused_input
=
'ignore'
)
def
test_masked_input
(
self
):
def
test_masked_input
(
self
):
m
=
T
.
matrix
(
'm'
)
m
=
T
.
matrix
(
'm'
)
mt
=
m
.
T
mt
=
m
.
T
mt
.
name
=
'm.T'
mt
.
name
=
'm.T'
self
.
assertRaises
(
Value
Error
,
function
,
[
m
,
mt
],
mt
*
2
)
self
.
assertRaises
(
UnusedInput
Error
,
function
,
[
m
,
mt
],
mt
*
2
)
f
=
function
([
m
,
mt
],
mt
*
2
,
on_unused_input
=
'ignore'
)
f
=
function
([
m
,
mt
],
mt
*
2
,
on_unused_input
=
'ignore'
)
...
...
theano/gof/__init__.py
浏览文件 @
bca70569
...
@@ -6,7 +6,7 @@ from cc import \
...
@@ -6,7 +6,7 @@ from cc import \
import
compiledir
# adds config vars
import
compiledir
# adds config vars
from
env
import
\
from
env
import
\
InconsistencyError
,
Env
InconsistencyError
,
MissingInputError
,
Env
from
destroyhandler
import
\
from
destroyhandler
import
\
DestroyHandler
DestroyHandler
...
...
theano/gof/env.py
浏览文件 @
bca70569
...
@@ -15,6 +15,12 @@ class InconsistencyError(Exception):
...
@@ -15,6 +15,12 @@ class InconsistencyError(Exception):
"""
"""
pass
pass
class
MissingInputError
(
Exception
):
"""
A symbolic input needed to compute the outputs is missing.
"""
pass
class
Env
(
utils
.
object2
):
class
Env
(
utils
.
object2
):
...
@@ -213,7 +219,7 @@ class Env(utils.object2):
...
@@ -213,7 +219,7 @@ class Env(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
.
Value
)
and
r
not
in
self
.
inputs
:
if
r
.
owner
is
None
and
not
isinstance
(
r
,
graph
.
Value
)
and
r
not
in
self
.
inputs
:
raise
Type
Error
(
"Undeclared input"
,
r
)
raise
MissingInput
Error
(
"Undeclared input"
,
r
)
if
not
getattr
(
r
,
'env'
,
None
)
is
self
:
if
not
getattr
(
r
,
'env'
,
None
)
is
self
:
self
.
__setup_r__
(
r
)
self
.
__setup_r__
(
r
)
self
.
variables
.
add
(
r
)
self
.
variables
.
add
(
r
)
...
@@ -285,12 +291,19 @@ class Env(utils.object2):
...
@@ -285,12 +291,19 @@ class Env(utils.object2):
#handler code in the first place
#handler code in the first place
assert
path
is
not
None
assert
path
is
not
None
raise
TypeError
(
'A variable that is an input to the graph was neither provided as an '
raise
MissingInputError
((
'input to the function nor given a value. A chain of variables leading from '
'A variable that is an input to the graph was '
'this input to an output is '
+
str
(
path
)
+
'. This chain may not be unique'
)
'neither provided as an input to the function '
'nor given a value. A chain of variables '
'leading from this input to an output is
%
s. '
'This chain may not be unique'
%
str
(
path
)))
#Standard error message
#Standard error message
raise
TypeError
(
"An input of the graph, used to compute "
+
str
(
node
)
+
", was not provided and not given a value"
,
r
)
raise
MissingInputError
((
"An input of the graph, used to compute
%
s, "
"was not provided and not given a value"
%
str
(
node
)),
r
)
for
node
in
new_nodes
:
for
node
in
new_nodes
:
assert
node
not
in
self
.
nodes
assert
node
not
in
self
.
nodes
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论