Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ed337d4e
提交
ed337d4e
authored
10月 19, 2015
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
For scalar that have nin=-1 cache the builded ufunc in the node.tag
上级
bdcb752a
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
26 行增加
和
3 行删除
+26
-3
elemwise.py
theano/tensor/elemwise.py
+26
-3
没有找到文件。
theano/tensor/elemwise.py
浏览文件 @
ed337d4e
...
@@ -7,6 +7,7 @@ import numpy
...
@@ -7,6 +7,7 @@ import numpy
import
theano
import
theano
from
theano
import
gof
from
theano
import
gof
from
theano.compat
import
izip
from
theano.compat
import
izip
from
theano.compat
import
get_unbound_function
from
six
import
iteritems
from
six
import
iteritems
from
six.moves
import
xrange
from
six.moves
import
xrange
from
theano.gof
import
Apply
,
Op
,
OpenMPOp
from
theano.gof
import
Apply
,
Op
,
OpenMPOp
...
@@ -506,6 +507,9 @@ class Elemwise(OpenMPOp):
...
@@ -506,6 +507,9 @@ class Elemwise(OpenMPOp):
if
nfunc_spec
:
if
nfunc_spec
:
self
.
nfunc
=
getattr
(
numpy
,
nfunc_spec
[
0
])
self
.
nfunc
=
getattr
(
numpy
,
nfunc_spec
[
0
])
elif
scalar_op
.
nin
>
0
and
scalar_op
.
nin
<
32
:
elif
scalar_op
.
nin
>
0
and
scalar_op
.
nin
<
32
:
# NumPy ufunc support only up to 31 inputs.
# But our c code support more.
# when nin == -1, we will build the ufunc in the make_thunk.
self
.
ufunc
=
numpy
.
frompyfunc
(
scalar_op
.
impl
,
scalar_op
.
nin
,
self
.
ufunc
=
numpy
.
frompyfunc
(
scalar_op
.
impl
,
scalar_op
.
nin
,
scalar_op
.
nout
)
scalar_op
.
nout
)
...
@@ -792,6 +796,20 @@ class Elemwise(OpenMPOp):
...
@@ -792,6 +796,20 @@ class Elemwise(OpenMPOp):
return
ret
return
ret
def
make_thunk
(
self
,
node
,
storage_map
,
compute_map
,
no_recycling
):
node_
=
node
if
self
.
ufunc
is
None
and
self
.
scalar_op
.
nin
==
-
1
:
node_
=
copy
(
node
)
assert
node
.
op
is
node_
.
op
ufunc
=
numpy
.
frompyfunc
(
self
.
scalar_op
.
impl
,
len
(
node
.
inputs
),
self
.
scalar_op
.
nout
)
node_
.
op
.
ufunc
=
ufunc
return
super
(
Elemwise
,
node_
.
op
)
.
make_thunk
(
node_
,
storage_map
,
compute_map
,
no_recycling
)
def
perform
(
self
,
node
,
inputs
,
output_storage
):
def
perform
(
self
,
node
,
inputs
,
output_storage
):
if
len
(
node
.
inputs
)
>=
32
:
if
len
(
node
.
inputs
)
>=
32
:
# Some versions of NumPy will segfault, other will raise a
# Some versions of NumPy will segfault, other will raise a
...
@@ -859,9 +877,11 @@ class Elemwise(OpenMPOp):
...
@@ -859,9 +877,11 @@ class Elemwise(OpenMPOp):
else
:
else
:
# the second calling form is used because in certain versions of
# the second calling form is used because in certain versions of
# numpy the first (faster) version leads to segfaults
# numpy the first (faster) version leads to segfaults
ufunc
=
(
self
.
ufunc
or
if
self
.
ufunc
:
numpy
.
frompyfunc
(
self
.
scalar_op
.
impl
,
len
(
inputs
),
ufunc
=
self
.
ufunc
self
.
scalar_op
.
nout
))
else
:
ufunc
=
node
.
tag
.
ufunc
nout
=
ufunc
.
nout
nout
=
ufunc
.
nout
variables
=
ufunc
(
*
ufunc_args
,
**
ufunc_kwargs
)
variables
=
ufunc
(
*
ufunc_args
,
**
ufunc_kwargs
)
...
@@ -1234,6 +1254,9 @@ class Elemwise(OpenMPOp):
...
@@ -1234,6 +1254,9 @@ class Elemwise(OpenMPOp):
"""
"""
return
node
.
outputs
[
0
]
.
ndim
==
0
return
node
.
outputs
[
0
]
.
ndim
==
0
theano
.
compile
.
debugmode
.
default_make_thunk
.
append
(
get_unbound_function
(
Elemwise
.
make_thunk
))
# def elemwise_to_scal(fgraph):
# def elemwise_to_scal(fgraph):
# TODO: why is this commented out? should it be removed?
# TODO: why is this commented out? should it be removed?
# it has needed maintenance despite being commented
# it has needed maintenance despite being commented
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论