Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9aad0029
提交
9aad0029
authored
6月 20, 2016
作者:
Cesar Laurent
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adapted c code. Untested yet.
上级
a56ed352
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
30 行增加
和
30 行删除
+30
-30
pool.py
theano/tensor/signal/pool.py
+30
-30
没有找到文件。
theano/tensor/signal/pool.py
浏览文件 @
9aad0029
...
@@ -390,16 +390,16 @@ class Pool(OpenMPOp):
...
@@ -390,16 +390,16 @@ class Pool(OpenMPOp):
headers
+=
super
(
Pool
,
self
)
.
c_headers
()
headers
+=
super
(
Pool
,
self
)
.
c_headers
()
return
headers
return
headers
def
c_code
_
(
self
,
node
,
name
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
if
self
.
mode
not
in
(
'max'
,
'sum'
,
'average_exc_pad'
,
'average_inc_pad'
):
if
self
.
mode
not
in
(
'max'
,
'sum'
,
'average_exc_pad'
,
'average_inc_pad'
):
raise
theano
.
gof
.
utils
.
MethodNotDefined
()
raise
theano
.
gof
.
utils
.
MethodNotDefined
()
x
,
=
inp
x
,
ws
,
stride
,
pad
=
inp
z
,
=
out
z
,
=
out
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
ignore_border
=
int
(
self
.
ignore_border
)
ignore_border
=
int
(
self
.
ignore_border
)
ds0
,
ds1
=
self
.
d
s
ws0
,
ws1
=
w
s
st0
,
st1
=
s
elf
.
st
st0
,
st1
=
s
tride
pd0
,
pd1
=
self
.
padding
pd0
,
pd1
=
pad
if
self
.
openmp
:
if
self
.
openmp
:
omp_parallel
=
'#pragma omp parallel for private(r_st, r_end, c_st, c_end, collector) schedule(static)'
omp_parallel
=
'#pragma omp parallel for private(r_st, r_end, c_st, c_end, collector) schedule(static)'
else
:
else
:
...
@@ -426,42 +426,42 @@ class Pool(OpenMPOp):
...
@@ -426,42 +426,42 @@ class Pool(OpenMPOp):
if (
%(ignore_border)
s)
if (
%(ignore_border)
s)
{
{
// '/' in C is different from '/' in python
// '/' in C is different from '/' in python
if (r -
%(
d
s0)
s < 0)
if (r -
%(
w
s0)
s < 0)
{
{
z_r = 0;
z_r = 0;
}
}
else
else
{
{
z_r = (r -
%(
d
s0)
s) /
%(st0)
s + 1;
z_r = (r -
%(
w
s0)
s) /
%(st0)
s + 1;
}
}
if (c -
%(
d
s1)
s < 0)
if (c -
%(
w
s1)
s < 0)
{
{
z_c = 0;
z_c = 0;
}
}
else
else
{
{
z_c = (c -
%(
d
s1)
s) /
%(st1)
s + 1;
z_c = (c -
%(
w
s1)
s) /
%(st1)
s + 1;
}
}
}
}
else
else
{
{
// decide how many rows the output has
// decide how many rows the output has
if (
%(st0)
s >=
%(
d
s0)
s)
if (
%(st0)
s >=
%(
w
s0)
s)
{
{
z_r = (r - 1) /
%(st0)
s + 1;
z_r = (r - 1) /
%(st0)
s + 1;
}
}
else
else
{
{
z_r = std::max(0, (r - 1 -
%(
d
s0)
s +
%(st0)
s) /
%(st0)
s) + 1;
z_r = std::max(0, (r - 1 -
%(
w
s0)
s +
%(st0)
s) /
%(st0)
s) + 1;
}
}
// decide how many columns the output has
// decide how many columns the output has
if (
%(st1)
s >=
%(
d
s1)
s)
if (
%(st1)
s >=
%(
w
s1)
s)
{
{
z_c = (c - 1) /
%(st1)
s + 1;
z_c = (c - 1) /
%(st1)
s + 1;
}
}
else
else
{
{
z_c = std::max(0, (c - 1 -
%(
d
s1)
s +
%(st0)
s) /
%(st1)
s) + 1;
z_c = std::max(0, (c - 1 -
%(
w
s1)
s +
%(st0)
s) /
%(st1)
s) + 1;
}
}
assert(z_r > 0);
assert(z_r > 0);
assert(z_c > 0);
assert(z_c > 0);
...
@@ -495,7 +495,7 @@ class Pool(OpenMPOp):
...
@@ -495,7 +495,7 @@ class Pool(OpenMPOp):
int k = t / PyArray_DIMS(
%(x)
s)[0];
int k = t / PyArray_DIMS(
%(x)
s)[0];
for(int i=0; i < z_r; i++){
for(int i=0; i < z_r; i++){
r_st = i *
%(st0)
s;
r_st = i *
%(st0)
s;
r_end = r_st +
%(
d
s0)
s;
r_end = r_st +
%(
w
s0)
s;
// skip the padding
// skip the padding
r_st = r_st <
%(pd0)
s ?
%(pd0)
s : r_st;
r_st = r_st <
%(pd0)
s ?
%(pd0)
s : r_st;
r_end = r_end > (r -
%(pd0)
s) ? r -
%(pd0)
s : r_end;
r_end = r_end > (r -
%(pd0)
s) ? r -
%(pd0)
s : r_end;
...
@@ -509,7 +509,7 @@ class Pool(OpenMPOp):
...
@@ -509,7 +509,7 @@ class Pool(OpenMPOp):
}
}
for(int j=0; j<z_c; j++){
for(int j=0; j<z_c; j++){
c_st = j *
%(st1)
s;
c_st = j *
%(st1)
s;
c_end = c_st +
%(
d
s1)
s;
c_end = c_st +
%(
w
s1)
s;
// skip the padding
// skip the padding
c_st = c_st <
%(pd1)
s ?
%(pd1)
s : c_st;
c_st = c_st <
%(pd1)
s ?
%(pd1)
s : c_st;
c_end = c_end > (c -
%(pd1)
s) ? c -
%(pd1)
s : c_end;
c_end = c_end > (c -
%(pd1)
s) ? c -
%(pd1)
s : c_end;
...
@@ -559,7 +559,7 @@ class Pool(OpenMPOp):
...
@@ -559,7 +559,7 @@ class Pool(OpenMPOp):
"""
"""
elif
self
.
mode
==
'average_inc_pad'
and
self
.
ignore_border
:
elif
self
.
mode
==
'average_inc_pad'
and
self
.
ignore_border
:
ccode
+=
"""
ccode
+=
"""
z[0] = collector / (
%(
ds0)
s *
%(d
s1)
s);
z[0] = collector / (
%(
ws0)
s *
%(w
s1)
s);
"""
"""
else
:
else
:
ccode
+=
"""
ccode
+=
"""
...
@@ -778,15 +778,15 @@ class MaxPoolGrad(PoolGrad):
...
@@ -778,15 +778,15 @@ class MaxPoolGrad(PoolGrad):
def
connection_pattern
(
self
,
node
):
def
connection_pattern
(
self
,
node
):
return
[[
1
],
[
1
],
[
1
],
[
0
],
[
0
],
[
0
]]
return
[[
1
],
[
1
],
[
1
],
[
0
],
[
0
],
[
0
]]
def
c_code
_
(
self
,
node
,
name
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
assert
self
.
mode
==
'max'
assert
self
.
mode
==
'max'
x
,
z
,
gz
=
inp
x
,
z
,
gz
,
ws
,
stride
,
pad
=
inp
gx
,
=
out
gx
,
=
out
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
ignore_border
=
int
(
self
.
ignore_border
)
ignore_border
=
int
(
self
.
ignore_border
)
ds0
,
ds1
=
self
.
d
s
ws0
,
ws1
=
w
s
st0
,
st1
=
s
elf
.
st
st0
,
st1
=
s
tride
pd0
,
pd1
=
self
.
padding
pd0
,
pd1
=
pad
if
self
.
openmp
:
if
self
.
openmp
:
omp_parallel
=
'#pragma omp parallel for private(r_st, r_end, c_st, c_end, maximum) schedule(static)'
omp_parallel
=
'#pragma omp parallel for private(r_st, r_end, c_st, c_end, maximum) schedule(static)'
else
:
else
:
...
@@ -850,7 +850,7 @@ class MaxPoolGrad(PoolGrad):
...
@@ -850,7 +850,7 @@ class MaxPoolGrad(PoolGrad):
int k = t / PyArray_DIMS(
%(x)
s)[0];
int k = t / PyArray_DIMS(
%(x)
s)[0];
for(int i=0; i < z_r; i++){
for(int i=0; i < z_r; i++){
r_st = i *
%(st0)
s;
r_st = i *
%(st0)
s;
r_end = r_st +
%(
d
s0)
s;
r_end = r_st +
%(
w
s0)
s;
// skip the padding
// skip the padding
r_st = r_st <
%(pd0)
s ?
%(pd0)
s : r_st;
r_st = r_st <
%(pd0)
s ?
%(pd0)
s : r_st;
r_end = r_end > (r -
%(pd0)
s) ? r -
%(pd0)
s : r_end;
r_end = r_end > (r -
%(pd0)
s) ? r -
%(pd0)
s : r_end;
...
@@ -859,7 +859,7 @@ class MaxPoolGrad(PoolGrad):
...
@@ -859,7 +859,7 @@ class MaxPoolGrad(PoolGrad):
r_end -=
%(pd0)
s;
r_end -=
%(pd0)
s;
for(int j=0; j<z_c; j++){
for(int j=0; j<z_c; j++){
c_st = j *
%(st1)
s;
c_st = j *
%(st1)
s;
c_end = c_st +
%(
d
s1)
s;
c_end = c_st +
%(
w
s1)
s;
// skip the padding
// skip the padding
c_st = c_st <
%(pd1)
s ?
%(pd1)
s : c_st;
c_st = c_st <
%(pd1)
s ?
%(pd1)
s : c_st;
c_end = c_end > (c -
%(pd1)
s) ? c -
%(pd1)
s : c_end;
c_end = c_end > (c -
%(pd1)
s) ? c -
%(pd1)
s : c_end;
...
@@ -1089,16 +1089,16 @@ class DownsampleFactorMaxGradGrad(OpenMPOp):
...
@@ -1089,16 +1089,16 @@ class DownsampleFactorMaxGradGrad(OpenMPOp):
self
.
ds
,
ignore_border
=
self
.
ignore_border
,
self
.
ds
,
ignore_border
=
self
.
ignore_border
,
st
=
self
.
st
,
padding
=
self
.
padding
)(
x
,
maxout
,
gz
)]
st
=
self
.
st
,
padding
=
self
.
padding
)(
x
,
maxout
,
gz
)]
def
c_code
_
(
self
,
node
,
name
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
if
self
.
mode
!=
'max'
:
if
self
.
mode
!=
'max'
:
raise
theano
.
gof
.
utils
.
MethodNotDefined
()
raise
theano
.
gof
.
utils
.
MethodNotDefined
()
x
,
maxout
,
ggx
=
inp
x
,
maxout
,
ggx
,
ws
,
stride
,
pad
=
inp
z
,
=
out
# the grad of grad
z
,
=
out
# the grad of grad
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
ignore_border
=
int
(
self
.
ignore_border
)
ignore_border
=
int
(
self
.
ignore_border
)
ds0
,
ds1
=
self
.
d
s
ws0
,
ws1
=
w
s
st0
,
st1
=
s
elf
.
st
st0
,
st1
=
s
tride
pd0
,
pd1
=
self
.
padding
pd0
,
pd1
=
pad
if
self
.
openmp
:
if
self
.
openmp
:
omp_parallel
=
'#pragma omp parallel for private(r_st, r_end, c_st, c_end, maximum) schedule(static)'
omp_parallel
=
'#pragma omp parallel for private(r_st, r_end, c_st, c_end, maximum) schedule(static)'
else
:
else
:
...
@@ -1137,7 +1137,7 @@ class DownsampleFactorMaxGradGrad(OpenMPOp):
...
@@ -1137,7 +1137,7 @@ class DownsampleFactorMaxGradGrad(OpenMPOp):
int k = t / PyArray_DIMS(
%(x)
s)[0];
int k = t / PyArray_DIMS(
%(x)
s)[0];
for(int i=0; i < z_r; i++){
for(int i=0; i < z_r; i++){
r_st = i *
%(st0)
s;
r_st = i *
%(st0)
s;
r_end = r_st +
%(
d
s0)
s;
r_end = r_st +
%(
w
s0)
s;
// skip the padding
// skip the padding
r_st = r_st <
%(pd0)
s ?
%(pd0)
s : r_st;
r_st = r_st <
%(pd0)
s ?
%(pd0)
s : r_st;
r_end = r_end > (r -
%(pd0)
s) ? r -
%(pd0)
s : r_end;
r_end = r_end > (r -
%(pd0)
s) ? r -
%(pd0)
s : r_end;
...
@@ -1146,7 +1146,7 @@ class DownsampleFactorMaxGradGrad(OpenMPOp):
...
@@ -1146,7 +1146,7 @@ class DownsampleFactorMaxGradGrad(OpenMPOp):
r_end -=
%(pd0)
s;
r_end -=
%(pd0)
s;
for(int j=0; j<z_c; j++){
for(int j=0; j<z_c; j++){
c_st = j *
%(st1)
s;
c_st = j *
%(st1)
s;
c_end = c_st +
%(
d
s1)
s;
c_end = c_st +
%(
w
s1)
s;
// skip the padding
// skip the padding
c_st = c_st <
%(pd1)
s ?
%(pd1)
s : c_st;
c_st = c_st <
%(pd1)
s ?
%(pd1)
s : c_st;
c_end = c_end > (c -
%(pd1)
s) ? c -
%(pd1)
s : c_end;
c_end = c_end > (c -
%(pd1)
s) ? c -
%(pd1)
s : c_end;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论