Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
317389c3
提交
317389c3
authored
9月 11, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
many changes to sandbox/downsample
上级
63fb1356
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
40 行增加
和
23 行删除
+40
-23
downsample.py
theano/sandbox/downsample.py
+40
-23
没有找到文件。
theano/sandbox/downsample.py
浏览文件 @
317389c3
...
...
@@ -22,6 +22,9 @@ class DownsampleFactorMaxGrad(Op):
def
__hash__
(
self
):
return
hash
(
type
(
self
))
^
hash
(
self
.
ds
)
^
hash
(
self
.
ignore_border
)
def
__str__
(
self
):
return
'
%
s{
%
s,
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
ds
,
self
.
ignore_border
)
def
make_node
(
self
,
x
,
maxout
,
gz
):
# make_node should only be called by the grad function of DownsampleFactorMax,
# so these asserts should not fail.
...
...
@@ -48,7 +51,7 @@ class DownsampleFactorMaxGrad(Op):
def
c_code
(
self
,
node
,
name
,
(
x
,
z
,
gz
),
(
gx
,),
sub
):
fail
=
sub
[
'fail'
]
self_
ignore_border
=
int
(
self
.
ignore_border
)
ignore_border
=
int
(
self
.
ignore_border
)
ds0
,
ds1
=
self
.
ds
return
"""
int x_typenum = PyArray_ObjectType((PyObject*)
%(x)
s, 0);
...
...
@@ -79,7 +82,7 @@ class DownsampleFactorMaxGrad(Op):
}
z_shp0 =
%(z)
s->dimensions[2];
z_shp1 =
%(z)
s->dimensions[3];
if (
%(
self_
ignore_border)
s)
if (
%(ignore_border)
s)
{
x_shp0_usable = z_shp0 *
%(ds0)
s;
x_shp1_usable = z_shp1 *
%(ds1)
s;
...
...
@@ -136,6 +139,9 @@ class DownsampleFactorMaxGrad(Op):
}//for b
"""
%
locals
()
def
c_code_cache_version
(
self
):
return
()
class
DownsampleFactorMax
(
Op
):
"""
...
...
@@ -153,17 +159,20 @@ class DownsampleFactorMax(Op):
rval
[
2
]
+=
1
if
d
%
ds
[
1
]:
rval
[
3
]
+=
1
return
rval
;
return
rval
def
__init__
(
self
,
ds
,
ignore_border
=
False
):
self
.
ds
=
tuple
(
ds
)
self
.
ignore_border
=
ignore_border
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
self
.
ds
==
other
.
ds
return
type
(
self
)
==
type
(
other
)
and
self
.
ds
==
other
.
ds
and
self
.
ignore_border
==
other
.
ignore_border
def
__hash__
(
self
):
return
hash
(
type
(
self
))
^
hash
(
self
.
ds
)
return
hash
(
type
(
self
))
^
hash
(
self
.
ds
)
^
hash
(
self
.
ignore_border
)
def
__str__
(
self
):
return
'
%
s{
%
s,
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
ds
,
self
.
ignore_border
)
def
make_node
(
self
,
x
):
dmatrix4
=
tensor
.
TensorType
(
x
.
type
.
dtype
,
(
False
,
False
,
False
,
False
))
...
...
@@ -178,6 +187,7 @@ class DownsampleFactorMax(Op):
raise
NotImplementedError
(
'DownsampleFactorMax requires 4D input for now'
)
if
z
[
0
]
is
None
:
z
[
0
]
=
numpy
.
zeros
(
self
.
out_shape
(
x
.
shape
,
self
.
ds
,
self
.
ignore_border
))
-
float
(
'inf'
)
z
[
0
]
=
numpy
.
asarray
(
z
[
0
],
dtype
=
x
.
dtype
)
zz
=
z
[
0
]
ds0
,
ds1
=
self
.
ds
...
...
@@ -197,7 +207,8 @@ class DownsampleFactorMax(Op):
def
c_code
(
self
,
node
,
name
,
(
x
,),
(
z
,
),
sub
):
fail
=
sub
[
'fail'
]
self_ignore_border
=
int
(
self
.
ignore_border
)
ignore_border
=
int
(
self
.
ignore_border
)
print
"IGNORE_BORDER"
,
ignore_border
ds0
,
ds1
=
self
.
ds
return
"""
int typenum = PyArray_ObjectType((PyObject*)
%(x)
s, 0);
...
...
@@ -211,7 +222,7 @@ class DownsampleFactorMax(Op):
}
z_shp0 =
%(x)
s->dimensions[2] /
%(ds0)
s;
z_shp1 =
%(x)
s->dimensions[3] /
%(ds1)
s;
if (
%(
self_
ignore_border)
s)
if (
%(ignore_border)
s)
{
x_shp0_usable = z_shp0 *
%(ds0)
s;
x_shp1_usable = z_shp1 *
%(ds1)
s;
...
...
@@ -240,23 +251,29 @@ class DownsampleFactorMax(Op):
%(z)
s = (PyArrayObject*) PyArray_ZEROS(4, dims, typenum,0); //TODO: zeros not necessary
}
for(int b=0;b<
%(x)
s->dimensions[0];b++){
for(int k=0;k<
%(x)
s->dimensions[1];k++){
int mini_i = 0;
int zi = 0;
for(int i=0;i< x_shp0_usable; i++){
int mini_j = 0;
int zj = 0;
for(int j=0; j<x_shp1_usable; j++){
dtype_
%(x)
s a = ((dtype_
%(x)
s*)(PyArray_GETPTR4(
%(x)
s,b,k,i,j)))[0];
dtype_
%(z)
s * __restrict__ z = ((dtype_
%(z)
s*)(PyArray_GETPTR4(
%(z)
s,b,k,zi,zj)));
z[0] = (((mini_j|mini_i) == 0) || z[0] < a) ? a : z[0];
mini_j = ((mini_j + 1) ==
%(ds1)
s) ? 0 : mini_j+1;
zj += (mini_j == 0);
if (z_shp0 && z_shp1)
{
for(int b=0;b<
%(x)
s->dimensions[0];b++){
for(int k=0;k<
%(x)
s->dimensions[1];k++){
int mini_i = 0;
int zi = 0;
for(int i=0;i< x_shp0_usable; i++){
int mini_j = 0;
int zj = 0;
for(int j=0; j<x_shp1_usable; j++){
dtype_
%(x)
s a = ((dtype_
%(x)
s*)(PyArray_GETPTR4(
%(x)
s,b,k,i,j)))[0];
dtype_
%(z)
s * __restrict__ z = ((dtype_
%(z)
s*)(PyArray_GETPTR4(
%(z)
s,b,k,zi,zj)));
z[0] = (((mini_j|mini_i) == 0) || z[0] < a) ? a : z[0];
mini_j = ((mini_j + 1) ==
%(ds1)
s) ? 0 : mini_j+1;
zj += (mini_j == 0);
}
mini_i = ((mini_i + 1) ==
%(ds0)
s) ? 0 : mini_i+1;
zi += (mini_i == 0);
}
}
mini_i = ((mini_i + 1) ==
%(ds0)
s) ? 0 : mini_i+1;
zi += (mini_i == 0);
}
}
}
"""
%
locals
()
def
c_code_cache_version
(
self
):
return
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论