Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f982cbd7
提交
f982cbd7
authored
5月 28, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Elemwise now special case the code when all inputs are contiguous.
Do not work yet when the inputs is fortran, as the outputs is always c contig for now.
上级
6ab3dddc
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
45 行增加
和
9 行删除
+45
-9
elemwise.py
theano/tensor/elemwise.py
+45
-9
没有找到文件。
theano/tensor/elemwise.py
浏览文件 @
f982cbd7
...
...
@@ -1100,8 +1100,9 @@ class Elemwise(Op):
# If all inputs and outputs are contiguous
# and the scalar op define optimized code for that case
# use it!
# use it!
The scalar_op need to check the broadcast flag himself.
if
all
([
o
.
ndim
>=
1
for
o
in
node
.
outputs
]):
contig
=
None
try
:
contig
=
self
.
scalar_op
.
c_code_contiguous
(
node
,
...
...
@@ -1109,19 +1110,54 @@ class Elemwise(Op):
_inames
,
onames
,
sub
)
# PyArray_ISONESEGMENT(arr)
# return true if arr is fortran or c contiguous.
cond
=
' && '
.
join
([
"PyArray_ISONESEGMENT(
%
s)"
%
arr
for
arr
in
_inames
+
onames
])
except
theano
.
gof
.
utils
.
MethodNotDefined
:
# Try to make one generic version, this will help the
# compiler to vectorize the code as their won't be as
# many ptr and the stride will be hard coded.
if
all
([
io
.
broadcastable
==
node
.
outputs
[
0
]
.
broadcastable
or
all
(
io
.
broadcastable
)
for
io
in
node
.
inputs
+
node
.
outputs
]):
z
=
onames
[
0
]
contig
=
"""
// All output have the same size
npy_intp n = PyArray_SIZE(
%(z)
s);
"""
%
locals
()
index
=
""
for
x
,
var
in
zip
(
inames
+
onames
,
inputs
+
node
.
outputs
):
if
not
all
(
var
.
broadcastable
):
contig
+=
"""
dtype_
%(x)
s *
%(x)
s_ptr = (dtype_
%(x)
s*) PyArray_DATA(
%(x)
s);
"""
%
locals
()
index
+=
"""
dtype_
%(x)
s&
%(x)
s_i =
%(x)
s_ptr[i];
"""
%
locals
()
else
:
contig
+=
"""
dtype_
%(x)
s&
%(x)
s_i = ((dtype_
%(x)
s*) PyArray_DATA(
%(x)
s))[0];
"""
%
locals
()
contig
+=
"""
for(int i=0; i<n; i++){
%(index)
s
%(task_code)
s;
}
"""
%
locals
()
if
contig
is
not
None
:
z
=
zip
(
inames
+
onames
,
inputs
+
node
.
outputs
)
cond1
=
' && '
.
join
([
"PyArray_ISCONTIGUOUS(
%
s)"
%
arr
for
arr
,
var
in
z
if
not
all
(
var
.
broadcastable
)])
cond2
=
' && '
.
join
([
"PyArray_ISFORTRAN(
%
s)"
%
arr
for
arr
,
var
in
z
if
not
all
(
var
.
broadcastable
)])
loop
=
"""
if(
%(cond)
s
){
if(
(
%(cond1)
s) || (
%(cond2)
s)
){
%(contig)
s
}else{
%(loop)
s
}
"""
%
locals
()
except
theano
.
gof
.
utils
.
MethodNotDefined
:
pass
return
decl
,
checks
,
alloc
,
loop
def
c_code
(
self
,
node
,
nodename
,
inames
,
onames
,
sub
):
...
...
@@ -1140,7 +1176,7 @@ class Elemwise(Op):
return
support_code
def
c_code_cache_version_apply
(
self
,
node
):
version
=
[
8
]
# the version corresponding to the c code in this Op
version
=
[
9
]
# the version corresponding to the c code in this Op
# now we insert versions for the ops on which we depend...
scalar_node
=
Apply
(
self
.
scalar_op
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论