Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
64b126df
提交
64b126df
authored
10月 14, 2008
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new klass!
上级
f7151839
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
31 行增加
和
9 行删除
+31
-9
function_module.py
theano/compile/function_module.py
+18
-4
io.py
theano/compile/io.py
+2
-0
klass.py
theano/sandbox/klass.py
+0
-0
basic.py
theano/tensor/basic.py
+3
-3
raw_random.py
theano/tensor/raw_random.py
+8
-2
没有找到文件。
theano/compile/function_module.py
浏览文件 @
64b126df
...
@@ -258,9 +258,9 @@ class Function(object):
...
@@ -258,9 +258,9 @@ class Function(object):
# Check if inputs are missing or if inputs were set more than once
# Check if inputs are missing or if inputs were set more than once
for
c
in
self
.
input_storage
:
for
c
in
self
.
input_storage
:
if
c
.
required
and
not
c
.
provided
:
if
c
.
required
and
not
c
.
provided
:
raise
TypeError
(
"Missing required input:
%
s"
%
self
.
inv_finder
[
c
]
.
result
)
raise
TypeError
(
"Missing required input:
%
s"
%
getattr
(
self
.
inv_finder
[
c
],
'result'
,
self
.
inv_finder
[
c
])
)
if
c
.
provided
>
1
:
if
c
.
provided
>
1
:
raise
TypeError
(
"Multiple values for input:
%
s"
%
self
.
inv_finder
[
c
]
.
result
)
raise
TypeError
(
"Multiple values for input:
%
s"
%
getattr
(
self
.
inv_finder
[
c
],
'result'
,
self
.
inv_finder
[
c
])
)
# Do the actual work
# Do the actual work
self
.
fn
()
self
.
fn
()
outputs
=
[
x
.
data
for
x
in
self
.
output_storage
]
outputs
=
[
x
.
data
for
x
in
self
.
output_storage
]
...
@@ -351,6 +351,7 @@ class SanityCheckFunction(Function):
...
@@ -351,6 +351,7 @@ class SanityCheckFunction(Function):
### FunctionMaker
### FunctionMaker
###
###
NODEFAULT
=
[
'NODEFAULT'
]
class
FunctionMaker
(
object
):
class
FunctionMaker
(
object
):
@staticmethod
@staticmethod
...
@@ -404,6 +405,7 @@ class FunctionMaker(object):
...
@@ -404,6 +405,7 @@ class FunctionMaker(object):
in the graph from the inputs to the outputs
in the graph from the inputs to the outputs
"""
"""
# Handle the case where inputs and/or outputs is a single Result (not in a list)
# Handle the case where inputs and/or outputs is a single Result (not in a list)
unpack_single
=
False
unpack_single
=
False
if
not
isinstance
(
outputs
,
(
list
,
tuple
)):
if
not
isinstance
(
outputs
,
(
list
,
tuple
)):
...
@@ -414,7 +416,7 @@ class FunctionMaker(object):
...
@@ -414,7 +416,7 @@ class FunctionMaker(object):
# Wrap them in In or Out instances if needed.
# Wrap them in In or Out instances if needed.
inputs
,
outputs
=
map
(
self
.
wrap_in
,
inputs
),
map
(
self
.
wrap_out
,
outputs
)
inputs
,
outputs
=
map
(
self
.
wrap_in
,
inputs
),
map
(
self
.
wrap_out
,
outputs
)
_inputs
=
gof
.
graph
.
inputs
([
o
.
result
for
o
in
outputs
])
_inputs
=
gof
.
graph
.
inputs
([
o
.
result
for
o
in
outputs
]
+
[
i
.
update
for
i
in
inputs
if
getattr
(
i
,
'update'
,
False
)]
)
indices
=
[[
input
]
+
self
.
expand_in
(
input
,
_inputs
)
for
input
in
inputs
]
indices
=
[[
input
]
+
self
.
expand_in
(
input
,
_inputs
)
for
input
in
inputs
]
expanded_inputs
=
reduce
(
list
.
__add__
,
[
list
(
z
)
for
x
,
y
,
z
in
indices
],
[])
expanded_inputs
=
reduce
(
list
.
__add__
,
[
list
(
z
)
for
x
,
y
,
z
in
indices
],
[])
...
@@ -482,7 +484,17 @@ class FunctionMaker(object):
...
@@ -482,7 +484,17 @@ class FunctionMaker(object):
# one storage unit. The indices and subinputs lists represent which
# one storage unit. The indices and subinputs lists represent which
# of the kit's inputs are active in this graph, so we make as many
# of the kit's inputs are active in this graph, so we make as many
# storage units as needed
# storage units as needed
input_storage
+=
[[
None
]
for
i
in
indices
]
if
isinstance
(
default
,
(
list
,
tuple
))
\
and
all
(
isinstance
(
x
,
gof
.
Container
)
for
x
in
default
):
if
len
(
default
)
==
len
(
indices
):
input_storage
+=
[
x
.
storage
for
x
in
default
]
elif
len
(
default
)
>
len
(
indices
):
input_storage
+=
[
default
[
i
]
.
storage
for
i
in
indices
]
else
:
raise
ValueError
(
'Not enough storage for SymbolicInputKit'
,
input
,
indices
,
default
)
default
=
NODEFAULT
else
:
input_storage
+=
[[
None
]
for
i
in
indices
]
else
:
else
:
# Normal case: one new, independent storage unit
# Normal case: one new, independent storage unit
input_storage
.
append
([
None
])
input_storage
.
append
([
None
])
...
@@ -496,6 +508,8 @@ class FunctionMaker(object):
...
@@ -496,6 +508,8 @@ class FunctionMaker(object):
# Even though a SymbolicInputKit represents more than one input,
# Even though a SymbolicInputKit represents more than one input,
# we still only have one entry for the defaults list.
# we still only have one entry for the defaults list.
if
isinstance
(
input
,
SymbolicInputKit
):
if
isinstance
(
input
,
SymbolicInputKit
):
if
default
is
NODEFAULT
:
_defaults
.
append
((
False
,
False
,
None
))
if
default
is
None
:
if
default
is
None
:
_defaults
.
append
((
True
,
True
,
None
))
_defaults
.
append
((
True
,
True
,
None
))
else
:
else
:
...
...
theano/compile/io.py
浏览文件 @
64b126df
...
@@ -99,6 +99,8 @@ class SymbolicInputKit(object):
...
@@ -99,6 +99,8 @@ class SymbolicInputKit(object):
except
ValueError
:
except
ValueError
:
pass
pass
ret
.
sort
()
ret
.
sort
()
if
not
ret
:
return
[[],
[]]
return
zip
(
*
ret
)
return
zip
(
*
ret
)
...
...
theano/sandbox/klass.py
浏览文件 @
64b126df
差异被折叠。
点击展开。
theano/tensor/basic.py
浏览文件 @
64b126df
...
@@ -366,11 +366,11 @@ def tensor(*args, **kwargs):
...
@@ -366,11 +366,11 @@ def tensor(*args, **kwargs):
def
_multi
(
*
fns
):
def
_multi
(
*
fns
):
def
f2
(
f
,
*
names
):
def
f2
(
f
,
*
names
):
if
isinstance
(
names
,
int
):
if
names
and
isinstance
(
names
[
0
]
,
int
):
if
names
==
1
:
if
names
==
1
:
return
f
()
return
f
()
else
:
else
:
return
[
f
()
for
i
in
xrange
(
names
)]
return
[
f
()
for
i
in
xrange
(
names
[
0
]
)]
if
isinstance
(
names
,
tuple
):
if
isinstance
(
names
,
tuple
):
if
len
(
names
)
==
1
:
if
len
(
names
)
==
1
:
names
=
names
[
0
]
names
=
names
[
0
]
...
@@ -1537,7 +1537,7 @@ def get_vector_length(v):
...
@@ -1537,7 +1537,7 @@ def get_vector_length(v):
raise
TypeError
(
'argument must be symbolic vector'
)
raise
TypeError
(
'argument must be symbolic vector'
)
if
isinstance
(
v
,
gof
.
Constant
)
and
v
.
type
.
ndim
==
1
:
if
isinstance
(
v
,
gof
.
Constant
)
and
v
.
type
.
ndim
==
1
:
return
len
(
v
.
data
)
return
len
(
v
.
data
)
if
v
.
owner
and
isinstance
(
v
.
owner
.
op
,
j
oin
):
if
v
.
owner
and
isinstance
(
v
.
owner
.
op
,
J
oin
):
try
:
try
:
return
join
.
vec_length
(
v
)
return
join
.
vec_length
(
v
)
except
:
except
:
...
...
theano/tensor/raw_random.py
浏览文件 @
64b126df
...
@@ -32,7 +32,10 @@ class RandomFunction(gof.Op):
...
@@ -32,7 +32,10 @@ class RandomFunction(gof.Op):
out -> the random numbers we generated
out -> the random numbers we generated
"""
"""
args
=
map
(
tensor
.
as_tensor
,
args
)
args
=
map
(
tensor
.
as_tensor
,
args
)
shape
=
tensor
.
as_tensor
(
shape
)
if
shape
==
()
or
shape
==
[]:
shape
=
tensor
.
lvector
()
else
:
shape
=
tensor
.
as_tensor
(
shape
)
assert
shape
.
type
==
tensor
.
lvector
assert
shape
.
type
==
tensor
.
lvector
assert
len
(
args
)
<=
len
(
self
.
args
)
assert
len
(
args
)
<=
len
(
self
.
args
)
args
+=
(
None
,)
*
(
len
(
self
.
args
)
-
len
(
args
))
args
+=
(
None
,)
*
(
len
(
self
.
args
)
-
len
(
args
))
...
@@ -96,7 +99,10 @@ def random_function(fn, dtype, *rfargs, **rfkwargs):
...
@@ -96,7 +99,10 @@ def random_function(fn, dtype, *rfargs, **rfkwargs):
r
,
shape
,
args
=
args
[
0
],
args
[
1
],
args
[
2
:]
r
,
shape
,
args
=
args
[
0
],
args
[
1
],
args
[
2
:]
else
:
else
:
r
,
shape
,
args
=
ndim
,
args
[
0
],
args
[
1
:]
r
,
shape
,
args
=
ndim
,
args
[
0
],
args
[
1
:]
shape
=
tensor
.
as_tensor
(
shape
)
if
shape
==
()
or
shape
==
[]:
shape
=
tensor
.
TensorConstant
(
type
=
tensor
.
lvector
,
data
=
shape
)
else
:
shape
=
tensor
.
as_tensor
(
shape
)
ndim
=
tensor
.
get_vector_length
(
shape
)
ndim
=
tensor
.
get_vector_length
(
shape
)
if
ndim
is
None
:
if
ndim
is
None
:
raise
ValueError
(
'Cannot infer the number of dimensions from the shape argument.'
)
raise
ValueError
(
'Cannot infer the number of dimensions from the shape argument.'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论