Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8eeaea6c
提交
8eeaea6c
authored
6月 19, 2014
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1919 from nouiz/crash_fix_broadcast
Crash fix broadcast
上级
4b60641c
b0572f5c
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
29 行增加
和
14 行删除
+29
-14
subtensor.py
theano/sandbox/gpuarray/subtensor.py
+3
-8
subtensor.py
theano/tensor/subtensor.py
+0
-0
test_subtensor.py
theano/tensor/tests/test_subtensor.py
+24
-4
type.py
theano/tensor/type.py
+2
-2
没有找到文件。
theano/sandbox/gpuarray/subtensor.py
浏览文件 @
8eeaea6c
...
@@ -20,7 +20,6 @@ from theano.sandbox.gpuarray.elemwise import GpuElemwise
...
@@ -20,7 +20,6 @@ from theano.sandbox.gpuarray.elemwise import GpuElemwise
from
theano.sandbox.gpuarray.comp
import
NVCC_compiler
from
theano.sandbox.gpuarray.comp
import
NVCC_compiler
class
GpuSubtensor
(
HideC
,
Subtensor
):
class
GpuSubtensor
(
HideC
,
Subtensor
):
def
make_node
(
self
,
x
,
*
inputs
):
def
make_node
(
self
,
x
,
*
inputs
):
rval
=
tensor
.
Subtensor
.
make_node
(
self
,
x
,
*
inputs
)
rval
=
tensor
.
Subtensor
.
make_node
(
self
,
x
,
*
inputs
)
...
@@ -32,15 +31,10 @@ class GpuSubtensor(HideC, Subtensor):
...
@@ -32,15 +31,10 @@ class GpuSubtensor(HideC, Subtensor):
def
perform
(
self
,
node
,
inputs
,
out_
):
def
perform
(
self
,
node
,
inputs
,
out_
):
out
,
=
out_
out
,
=
out_
x
=
inputs
[
0
]
x
=
inputs
[
0
]
if
self
.
perform_cache_cdata
is
not
None
:
out
[
0
]
=
x
.
__getitem__
(
self
.
perform_cache_cdata
)
return
cdata
=
get_idx_list
(
inputs
,
self
.
idx_list
)
cdata
=
get_idx_list
(
inputs
,
self
.
idx_list
)
if
len
(
cdata
)
==
1
:
if
len
(
cdata
)
==
1
:
cdata
=
cdata
[
0
]
cdata
=
cdata
[
0
]
if
len
(
inputs
)
==
1
:
self
.
perform_cache_cdata
=
cdata
out
[
0
]
=
x
.
__getitem__
(
cdata
)
out
[
0
]
=
x
.
__getitem__
(
cdata
)
...
@@ -232,7 +226,8 @@ class GpuIncSubtensor(IncSubtensor):
...
@@ -232,7 +226,8 @@ class GpuIncSubtensor(IncSubtensor):
# scalar case
# scalar case
if
not
self
.
set_instead_of_inc
:
if
not
self
.
set_instead_of_inc
:
#x.__setitem__(cdata, sub_x + y)
#x.__setitem__(cdata, sub_x + y)
tmp
=
pygpu
.
elemwise
.
elemwise2
(
sub_x
,
'+'
,
y
,
sub_x
,
broadcast
=
False
)
tmp
=
pygpu
.
elemwise
.
elemwise2
(
sub_x
,
'+'
,
y
,
sub_x
,
broadcast
=
False
)
x
.
__setitem__
(
cdata
,
tmp
)
x
.
__setitem__
(
cdata
,
tmp
)
else
:
else
:
x
.
__setitem__
(
cdata
,
y
)
x
.
__setitem__
(
cdata
,
y
)
...
@@ -592,4 +587,4 @@ class GpuAdvancedIncSubtensor1_dev20(GpuAdvancedIncSubtensor1):
...
@@ -592,4 +587,4 @@ class GpuAdvancedIncSubtensor1_dev20(GpuAdvancedIncSubtensor1):
return;
return;
}
}
"""
%
locals
()
"""
%
locals
()
theano/tensor/subtensor.py
浏览文件 @
8eeaea6c
差异被折叠。
点击展开。
theano/tensor/tests/test_subtensor.py
浏览文件 @
8eeaea6c
...
@@ -88,7 +88,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -88,7 +88,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
f
=
inplace_func
([],
t
,
mode
=
self
.
mode
)
f
=
inplace_func
([],
t
,
mode
=
self
.
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
self
.
ignore_topo
)]
assert
len
(
topo_
)
==
1
assert
len
(
topo_
)
==
1
if
not
list
:
if
not
list
:
assert
isinstance
(
topo_
[
0
]
.
op
,
self
.
sub
)
assert
isinstance
(
topo_
[
0
]
.
op
,
self
.
sub
)
...
@@ -365,19 +365,39 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -365,19 +365,39 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
f
=
inplace_func
([],
gn
,
mode
=
self
.
mode
)
f
=
inplace_func
([],
gn
,
mode
=
self
.
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
self
.
ignore_topo
)]
if
not
self
.
fast_compile
:
if
not
self
.
fast_compile
:
assert
len
(
topo_
)
==
6
assert
len
(
topo_
)
==
6
assert
numpy
.
sum
([
isinstance
(
node
.
op
,
self
.
inc_sub
)
assert
numpy
.
sum
([
isinstance
(
node
.
op
,
self
.
inc_sub
)
for
node
in
topo_
])
==
1
for
node
in
topo_
])
==
1
assert
numpy
.
sum
([
isinstance
(
node
.
op
,
self
.
sub
)
assert
numpy
.
sum
([
isinstance
(
node
.
op
,
self
.
sub
)
for
node
in
topo_
])
==
1
for
node
in
topo_
])
==
1
gval
=
f
()
gval
=
f
()
good
=
numpy
.
zeros_like
(
data
)
good
=
numpy
.
zeros_like
(
data
)
good
[
subi
:,
subi
]
=
numpy
.
exp
(
data
[
subi
:,
subi
])
good
[
subi
:,
subi
]
=
numpy
.
exp
(
data
[
subi
:,
subi
])
self
.
assertTrue
(
numpy
.
allclose
(
gval
,
good
),
(
gval
,
good
))
self
.
assertTrue
(
numpy
.
allclose
(
gval
,
good
),
(
gval
,
good
))
def
test_grad_2d_inc_set_subtensor
(
self
):
for
n_shape
,
m_shape
in
[
[(
2
,
3
),
(
2
,
2
)],
[(
3
,
2
),
(
2
,
2
)],
[(
3
,
2
),
(
1
,
2
)],
[(
3
,
2
),
(
2
,)],
]:
for
op
in
[
inc_subtensor
,
set_subtensor
]:
subi
=
2
data
=
numpy
.
asarray
(
rand
(
*
n_shape
),
dtype
=
self
.
dtype
)
n
=
self
.
shared
(
data
)
z
=
scal
.
constant
(
subi
)
m
=
matrix
(
'm'
,
dtype
=
self
.
dtype
)
mv
=
numpy
.
asarray
(
rand
(
*
m_shape
),
dtype
=
self
.
dtype
)
t
=
op
(
n
[:
z
,
:
z
],
m
)
gn
,
gm
=
theano
.
tensor
.
grad
(
theano
.
tensor
.
sum
(
t
),
[
n
,
m
])
utt
.
verify_grad
(
lambda
m
:
op
(
n
[:
z
,
:
z
],
m
),
[
mv
])
utt
.
verify_grad
(
lambda
nn
:
op
(
nn
[:
z
,
:
z
],
mv
),
[
data
])
def
test_grad_0d
(
self
):
def
test_grad_0d
(
self
):
data
=
numpy
.
asarray
(
rand
(
2
,
3
),
dtype
=
self
.
dtype
)
data
=
numpy
.
asarray
(
rand
(
2
,
3
),
dtype
=
self
.
dtype
)
n
=
self
.
shared
(
data
)
n
=
self
.
shared
(
data
)
...
...
theano/tensor/type.py
浏览文件 @
8eeaea6c
...
@@ -643,10 +643,10 @@ theano.compile.register_shape_i_c_code(
...
@@ -643,10 +643,10 @@ theano.compile.register_shape_i_c_code(
TensorType
,
TensorType
,
"""
"""
if(!
%(oname)
s)
if(!
%(oname)
s)
%(oname)
s=(PyArrayObject*)PyArray_
ZEROS
(0, NULL, NPY_INT64, 0);
%(oname)
s=(PyArrayObject*)PyArray_
EMPTY
(0, NULL, NPY_INT64, 0);
((npy_int64*)PyArray_DATA(
%(oname)
s))[0]=PyArray_DIMS(
%(iname)
s)[
%(i)
s];
((npy_int64*)PyArray_DATA(
%(oname)
s))[0]=PyArray_DIMS(
%(iname)
s)[
%(i)
s];
"""
,
"""
,
version
=
1
)
version
=
2
)
# Register TensorType C code for DeepCopyOp
# Register TensorType C code for DeepCopyOp
theano
.
compile
.
register_deep_copy_op_c_code
(
theano
.
compile
.
register_deep_copy_op_c_code
(
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论