Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
825bf41f
提交
825bf41f
authored
10月 21, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make a cache for TensorConstant.
This lower memory usage and speed up optimization by asking for less merge.
上级
d9bad63c
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
24 行增加
和
11 行删除
+24
-11
basic.py
theano/tensor/basic.py
+17
-1
elemwise.py
theano/tensor/elemwise.py
+2
-4
opt.py
theano/tensor/opt.py
+5
-6
没有找到文件。
theano/tensor/basic.py
浏览文件 @
825bf41f
...
@@ -400,10 +400,26 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None):
...
@@ -400,10 +400,26 @@ def constant_or_value(x, rtype, name=None, ndim=None, dtype=None):
raise
TypeError
(
"Could not convert
%
s to TensorType"
%
x
,
type
(
x
))
raise
TypeError
(
"Could not convert
%
s to TensorType"
%
x
,
type
(
x
))
constant_cache
=
{}
def
constant
(
x
,
name
=
None
,
ndim
=
None
,
dtype
=
None
):
def
constant
(
x
,
name
=
None
,
ndim
=
None
,
dtype
=
None
):
ret
urn
constant_or_value
(
x
,
rtype
=
TensorConstant
,
name
=
name
,
ndim
=
ndim
,
ret
=
constant_or_value
(
x
,
rtype
=
TensorConstant
,
name
=
name
,
ndim
=
ndim
,
dtype
=
dtype
)
dtype
=
dtype
)
#We create a small cache of frequently used constant.
#This speed up the Merge optimization for big graph.
#We want to cache all scalar to don't merge as frequently constants.
#But we don't want to cache too much stuff
#So we cache integer with dtype [u]int and float where the value is between -10 and 10
#We want to cache all broadcast pattern for scalar.
sig
=
ret
.
signature
()
if
(
sig
not
in
constant_cache
and
ret
.
data
.
size
==
1
and
ret
.
data
<=
10
and
ret
.
data
>=
-
10
and
(
ret
.
dtype
in
int_dtypes
or
ret
.
dtype
in
uint_dtypes
or
(
ret
.
dtype
in
float_dtypes
and
int
(
ret
.
data
)
==
ret
.
data
))):
constant_cache
[
sig
]
=
ret
return
constant_cache
.
get
(
sig
,
ret
)
def
_obj_is_wrappable_as_tensor
(
x
):
def
_obj_is_wrappable_as_tensor
(
x
):
try
:
try
:
...
...
theano/tensor/elemwise.py
浏览文件 @
825bf41f
...
@@ -749,10 +749,8 @@ class Elemwise(Op):
...
@@ -749,10 +749,8 @@ class Elemwise(Op):
# the gradient contains a constant, translate it as
# the gradient contains a constant, translate it as
# an equivalent TensorType of size 1 and proper number of
# an equivalent TensorType of size 1 and proper number of
# dimensions
# dimensions
res
=
TensorConstant
(
TensorType
(
dtype
=
r
.
type
.
dtype
,
res
=
theano
.
tensor
.
constant
(
numpy
.
asarray
(
r
.
data
),
dtype
=
r
.
type
.
dtype
)
broadcastable
=
()),
return
DimShuffle
((),
[
'x'
]
*
nd
,
inplace
=
False
)(
res
)
numpy
.
asarray
(
r
.
data
))
# .reshape(b)
return
DimShuffle
((),
[
'x'
]
*
nd
,
inplace
=
True
)(
res
)
new_r
=
Elemwise
(
node
.
op
,
{})(
new_r
=
Elemwise
(
node
.
op
,
{})(
*
[
transform
(
ipt
)
for
ipt
in
node
.
inputs
])
*
[
transform
(
ipt
)
for
ipt
in
node
.
inputs
])
return
new_r
return
new_r
...
...
theano/tensor/opt.py
浏览文件 @
825bf41f
...
@@ -3711,17 +3711,16 @@ def local_add_specialize(node):
...
@@ -3711,17 +3711,16 @@ def local_add_specialize(node):
continue
continue
new_inputs
.
append
(
input
)
new_inputs
.
append
(
input
)
if
len
(
new_inputs
)
<
len
(
node
.
inputs
):
if
len
(
new_inputs
)
<
len
(
node
.
inputs
):
dtype
=
node
.
outputs
[
0
]
.
type
.
dtype
dtype
=
node
.
outputs
[
0
]
.
type
.
dtype
if
len
(
new_inputs
)
==
0
:
if
len
(
new_inputs
)
==
0
:
#we got rid of the entire expression!
#we got rid of the entire expression!
ndim
=
node
.
outputs
[
0
]
.
type
.
ndim
ndim
=
node
.
outputs
[
0
]
.
type
.
ndim
return
fill_chain
(
#Reuse call to constant for cache()
T
.
TensorConstant
(
cst
=
T
.
constant
(
numpy
.
zeros
((
1
,)
*
ndim
,
dtype
=
dtype
))
T
.
TensorType
(
assert
cst
.
type
.
broadcastable
==
[
True
]
*
ndim
dtype
=
dtype
,
return
fill_chain
(
cst
)
broadcastable
=
[
True
]
*
ndim
),
numpy
.
zeros
((
1
,)
*
ndim
,
dtype
=
dtype
)))
if
len
(
new_inputs
)
==
1
:
if
len
(
new_inputs
)
==
1
:
ret
=
fill_chain
(
new_inputs
[
0
])
ret
=
fill_chain
(
new_inputs
[
0
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论