Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ba38ab4b
提交
ba38ab4b
authored
5月 28, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Elemwise output is now fortran when all inputs are fortran.
This speed up hard_sigmoid and ultra_fast_sigmoid by 2x. We ignore input that are broadcasted scalar when checking for fortran inputs.
上级
f982cbd7
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
25 行增加
和
9 行删除
+25
-9
nnet.txt
doc/library/tensor/nnet/nnet.txt
+2
-2
elemwise.py
theano/tensor/elemwise.py
+14
-2
elemwise_cgen.py
theano/tensor/elemwise_cgen.py
+9
-5
没有找到文件。
doc/library/tensor/nnet/nnet.txt
浏览文件 @
ba38ab4b
...
...
@@ -18,8 +18,8 @@
:note: see :func:`ultra_fast_sigmoid` or :func:`hard_sigmoid` for faster version.
Speed comparison for 100M float64 element on a Core2 Duo @ 3.16 GHz.
- hard_sigmoid: 1.
1
s
- ultra_fast_sigmoid: 1.
4
s
- hard_sigmoid: 1.
0
s
- ultra_fast_sigmoid: 1.
3
s
- sigmoid (with amdlibm): 2.3s
- sigmoid (without amdlibm): 3.7s
...
...
theano/tensor/elemwise.py
浏览文件 @
ba38ab4b
...
...
@@ -1011,6 +1011,17 @@ class Elemwise(Op):
decl
=
cgen
.
make_declare
(
orders
,
idtypes
,
sub
)
checks
=
cgen
.
make_checks
(
orders
,
idtypes
,
sub
)
# Check if all inputs (except broadcasted scalar) are fortran.
# In that case, create an fortran output ndarray.
z
=
zip
(
inames
,
inputs
)
alloc_fortran
=
' && '
.
join
([
"PyArray_ISFORTRAN(
%
s)"
%
arr
for
arr
,
var
in
z
if
not
all
(
var
.
broadcastable
)])
# If it is a scalar, make it c contig to prevent problem with
# NumPy C and F contig not always set as both of them.
if
len
(
alloc_fortran
)
==
0
:
alloc_fortran
=
'0'
alloc
=
""
# We loop over the "real" outputs, i.e., those that are not
# inplace (must be allocated) and we declare/allocate/check
...
...
@@ -1022,7 +1033,8 @@ class Elemwise(Op):
sub
[
'olv'
]
=
oname
alloc
+=
cgen
.
make_declare
([
range
(
nnested
)],
[
odtype
],
dict
(
sub
,
lv0
=
oname
))
alloc
+=
cgen
.
make_alloc
(
orders
,
odtype
,
sub
)
alloc
+=
cgen
.
make_alloc
(
orders
,
odtype
,
sub
,
fortran
=
alloc_fortran
)
alloc
+=
cgen
.
make_checks
([
range
(
nnested
)],
[
odtype
],
dict
(
sub
,
lv0
=
oname
))
olv_index
=
i
# index of the last output
...
...
@@ -1176,7 +1188,7 @@ class Elemwise(Op):
return
support_code
def
c_code_cache_version_apply
(
self
,
node
):
version
=
[
9
]
# the version corresponding to the c code in this Op
version
=
[
10
]
# 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
,
...
...
theano/tensor/elemwise_cgen.py
浏览文件 @
ba38ab4b
...
...
@@ -113,9 +113,12 @@ def make_checks(loop_orders, dtypes, sub):
return
init
%
sub
+
check
%
sub
def
make_alloc
(
loop_orders
,
dtype
,
sub
):
"""
Generate C code to allocate outputs.
def
make_alloc
(
loop_orders
,
dtype
,
sub
,
fortran
=
'0'
):
"""Generate C code to allocate outputs.
:param fortran: if non-zero, will create a ndarray in fortran
order.
"""
nd
=
len
(
loop_orders
[
0
])
...
...
@@ -133,7 +136,6 @@ def make_alloc(loop_orders, dtype, sub):
break
else
:
init_dims
+=
"dims[
%(i)
s] = 1;
\n
"
%
locals
()
#raise Exception("For each looping dimension, at least one input must have a non-broadcastable dimension.")
# TODO: it would be interesting to allocate the output in such a
# way that its contiguous dimensions match one of the input's
...
...
@@ -146,7 +148,9 @@ def make_alloc(loop_orders, dtype, sub):
//npy_intp* dims = (npy_intp*)malloc(
%(nd)
s * sizeof(npy_intp));
%(init_dims)
s
if (!
%(olv)
s) {
%(olv)
s = (PyArrayObject*)PyArray_EMPTY(
%(nd)
s, dims, type_num_
%(olv)
s, 0);
%(olv)
s = (PyArrayObject*)PyArray_EMPTY(
%(nd)
s, dims,
type_num_
%(olv)
s,
%(fortran)
s);
}
else {
PyArray_Dims new_dims;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论