Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
29403884
提交
29403884
authored
3月 16, 2011
作者:
Olivier Breuleux
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
backport to 2.4 and additional documentation for my last commit
上级
4bbac540
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
35 行增加
和
20 行删除
+35
-20
graph.py
theano/gof/graph.py
+4
-2
basic.py
theano/tensor/basic.py
+14
-6
elemwise.py
theano/tensor/elemwise.py
+17
-12
没有找到文件。
theano/gof/graph.py
浏览文件 @
29403884
...
...
@@ -417,8 +417,10 @@ def stack_search(start, expand, mode='bfs', build_inv = False):
raise
ValueError
(
'mode should be bfs or dfs'
,
mode
)
rval_set
=
set
()
rval_list
=
list
()
if
mode
==
'bfs'
:
start_pop
=
start
.
popleft
else
:
start_pop
=
start
.
pop
if
mode
==
'bfs'
:
start_pop
=
start
.
popleft
else
:
start_pop
=
start
.
pop
expand_inv
=
{}
while
start
:
l
=
start_pop
()
...
...
theano/tensor/basic.py
浏览文件 @
29403884
...
...
@@ -1337,7 +1337,16 @@ def _redefine_asRoutine(real_symbol_value):
return
decorator
def
_scal_elemwise_with_nfunc
(
nfunc
,
nin
,
nout
):
"""Replace a symbol definition with an elementwise version of the corresponding scalar Op"""
"""
Replace a symbol definition with an elementwise version of the
corresponding scalar Op. If it is not None, the nfunc argument
should be a string such that getattr(numpy, nfunc) implements
a vectorized version of the elemwise operation. nin is the number
of inputs expected by that function, and nout is the number of
**destination** inputs it takes. That is, the function should
take nin+nout inputs. nout == 0 means that the numpy function
does not take a numpy array argument to put its result in.
"""
def
construct
(
symbol
):
symbolname
=
symbol
.
__name__
inplace
=
symbolname
.
endswith
(
'_inplace'
)
...
...
@@ -1350,10 +1359,12 @@ def _scal_elemwise_with_nfunc(nfunc, nin, nout):
if
inplace
:
scalar_op
=
getattr
(
scal
,
symbolname
[:
-
len
(
'_inplace'
)])
inplace_scalar_op
=
scalar_op
.
__class__
(
scal
.
transfer_type
(
0
))
rval
=
elemwise
.
Elemwise
(
inplace_scalar_op
,
{
0
:
0
},
name
=
n
,
nfunc_spec
=
((
nfunc
,
nin
,
nout
)
if
nfunc
else
None
))
rval
=
elemwise
.
Elemwise
(
inplace_scalar_op
,
{
0
:
0
},
name
=
n
,
nfunc_spec
=
nfunc
and
(
nfunc
,
nin
,
nout
))
else
:
scalar_op
=
getattr
(
scal
,
symbolname
)
rval
=
elemwise
.
Elemwise
(
scalar_op
,
name
=
n
,
nfunc_spec
=
((
nfunc
,
nin
,
nout
)
if
nfunc
else
None
))
rval
=
elemwise
.
Elemwise
(
scalar_op
,
name
=
n
,
nfunc_spec
=
nfunc
and
(
nfunc
,
nin
,
nout
))
if
getattr
(
symbol
,
'__doc__'
,
False
):
rval
.
__doc__
=
symbol
.
__doc__
+
'
\n
'
+
rval
.
__doc__
...
...
@@ -1993,9 +2004,6 @@ def round(a, mode="half_away_from_zero"):
else
:
raise
Exception
(
"round mode
%
s is not implemented."
%
mode
)
# def __round_half_to_even(a, dest):
# dest[:] = numpy.around(a)
@_scal_elemwise_with_nfunc
(
'around'
,
1
,
0
)
def
round_half_to_even
(
a
):
"""round_half_to_even(a)"""
...
...
theano/tensor/elemwise.py
浏览文件 @
29403884
...
...
@@ -365,16 +365,6 @@ def _make_nfunc(name, nin, nout):
f
=
getattr
(
numpy
,
name
)
return
f
# if name.endswith("*"):
# name = name[:-1]
# f = getattr(numpy, name)
# def fn(*args):
# args[-1][:] = f(*(args[:-1]))
# return fn
# else:
# f = getattr(numpy, name)
# return f
################
### Elemwise ###
...
...
@@ -416,6 +406,13 @@ class Elemwise(Op):
* inplace_pattern: a dictionary that maps the index of an output to the
index of an input so the output is calculated inplace using
the input's storage. (Just like destroymap, but without the lists.)
* nfunc_spec: either None or a tuple of three elements, (nfunc_name, nin, nout) such
that getattr(numpy, nfunc_name) implements this operation, takes nin
inputs and nout **destination** outputs (nout == 0 if the numpy function
does not provide the option of providing a numpy array to store the
results in). Note that nin cannot always be inferred from the scalar op's
own nin field because that value is sometimes 0 (meaning a variable number
of inputs), whereas the numpy function may not have varargs.
"""
self
.
name
=
name
self
.
scalar_op
=
scalar_op
...
...
@@ -647,7 +644,14 @@ class Elemwise(Op):
ufunc_args
=
inputs
# + output_storage
if
self
.
nfunc
and
len
(
inputs
)
==
self
.
nfunc_spec
[
1
]:
ufunc
=
self
.
nfunc
nout
=
1
nout
=
self
.
nfunc_spec
[
2
]
if
nout
==
0
:
nout
=
1
# Unfortunately, the else case does not allow us to
# directly feed the destination arguments to the nfunc
# since it sometimes requires resizing. Doing this
# optimization is probably not worth the effort, since we
# should normally run the C version of the Op.
else
:
# the second calling form is used because in certain versions of numpy
# the first (faster) version leads to segfaults
...
...
@@ -661,7 +665,8 @@ class Elemwise(Op):
'for params of shape'
,
[
arg
.
shape
for
arg
in
ufunc_args
]
e
.
args
=
e
.
args
+
errormsg
raise
if
nout
==
1
:
variables
=
[
variables
]
if
nout
==
1
:
variables
=
[
variables
]
for
variable
,
storage
in
zip
(
variables
,
output_storage
):
if
hasattr
(
variable
,
'shape'
)
and
storage
[
0
]
.
shape
!=
variable
.
shape
:
storage
[
0
]
.
resize
(
variable
.
shape
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论