Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
30d2c4c3
提交
30d2c4c3
authored
1月 20, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gpucareduce port continue.
上级
a482cc6f
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
38 行增加
和
13 行删除
+38
-13
elemwise.py
theano/sandbox/gpuarray/elemwise.py
+38
-13
没有找到文件。
theano/sandbox/gpuarray/elemwise.py
浏览文件 @
30d2c4c3
import
copy
from
itertools
import
izip
from
StringIO
import
StringIO
import
numpy
from
theano
import
Op
,
Apply
,
scalar
,
config
from
theano.tensor.elemwise
import
Elemwise
,
DimShuffle
,
CAReduceDtype
from
theano
import
scalar
as
scal
from
theano.scalar
import
Scalar
from
theano.tensor.elemwise
import
(
Elemwise
,
DimShuffle
,
CAReduce
,
CAReduceDtype
)
from
theano.sandbox.cuda.nvcc_compiler
import
NVCC_compiler
try
:
...
...
@@ -518,7 +522,7 @@ class GpuDimShuffle(HideC, DimShuffle):
return
(
3
,)
class
GpuCAReduce
(
GpuOp
):
class
GpuCAReduce
(
HideC
,
CAReduce
):
"""GpuCAReduce is a Reduction along some dimensions by a scalar op.
The dimensions along which to reduce is specified by the
...
...
@@ -552,36 +556,57 @@ class GpuCAReduce(GpuOp):
"""
def
__init__
(
self
,
reduce_mask
,
scalar_op
):
self
.
reduce_mask
=
tuple
(
reduce_mask
)
self
.
scalar_op
=
scalar_op
def
__init__
(
self
,
scalar_op
,
axis
=
None
,
reduce_mask
=
None
):
if
reduce_mask
is
not
None
:
reduce_mask
=
tuple
(
reduce_mask
)
self
.
reduce_mask
=
reduce_mask
# used to make sure that calls to scalar op
# have unique name arguments
self
.
_n_scalar_op_calls
=
0
if
not
hasattr
(
scalar_op
,
'identity'
):
raise
ValueError
(
"No identity on scalar op"
)
CAReduce
.
__init__
(
self
,
scalar_op
,
axis
=
axis
)
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
)
and
self
.
axis
==
other
.
axis
and
self
.
reduce_mask
==
other
.
reduce_mask
and
self
.
scalar_op
==
other
.
scalar_op
)
def
__hash__
(
self
):
return
(
hash
(
type
(
self
))
^
hash
(
self
.
axis
)
^
hash
(
self
.
reduce_mask
)
^
hash
(
type
(
self
.
scalar_op
)))
def
__str__
(
self
):
return
"GpuCAReduce{
%
s}{
%
s}"
%
(
str
(
self
.
scalar_op
),
','
.
join
(
str
(
i
)
for
i
in
self
.
reduce_mask
)
)
ax
=
''
if
self
.
axis
is
not
None
:
ax
=
'{
%
s}'
%
(
', '
.
join
(
str
(
x
)
for
x
in
self
.
axis
),
)
return
"GpuCAReduce{
%
s}
%
s"
%
(
str
(
self
.
scalar_op
),
ax
)
def
make_node
(
self
,
x
):
x
=
as_gpu_array_varible
(
x
)
x
=
as_gpuarray_variable
(
x
)
assert
x
.
dtype
==
"float32"
ret
=
super
(
GpuCAReduce
,
self
)
.
make_node
(
x
)
self
=
copy
.
copy
(
self
)
self
.
axis
=
ret
.
op
.
axis
if
self
.
reduce_mask
is
None
:
if
self
.
axis
is
None
:
reduce_mask
=
[
1
]
*
x
.
type
.
ndim
else
:
reduce_mask
=
[
0
]
*
x
.
type
.
ndim
for
a
in
self
.
axis
:
assert
reduce_mask
[
a
]
==
0
reduce_mask
[
a
]
=
1
self
.
reduce_mask
=
tuple
(
reduce_mask
)
if
(
x
.
type
.
ndim
!=
len
(
self
.
reduce_mask
)):
raise
TypeError
(
"x must have rank
%
i"
%
len
(
self
.
reduce_mask
))
o_broadcast
=
[
x
.
type
.
broadcastable
[
i
]
for
i
in
xrange
(
x
.
type
.
ndim
)
if
not
self
.
reduce_mask
[
i
]]
return
Apply
(
self
,
[
x
],
[
GpuArrayType
(
x
.
type
.
dtype
,
o_broadcast
)()])
return
Apply
(
self
,
[
x
],
[
GpuArrayType
(
x
.
dtype
,
ret
.
outputs
[
0
]
.
type
.
broadcastable
)()])
"""
This method must be commented, because there's no way
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论