Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a79c9a16
提交
a79c9a16
authored
9月 19, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor the helper c code from subtensor and incsubtensor
I'll reuse it for gpusubtensor.
上级
85f9247a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
50 行增加
和
25 行删除
+50
-25
basic.py
theano/tensor/basic.py
+50
-25
没有找到文件。
theano/tensor/basic.py
浏览文件 @
a79c9a16
...
@@ -4019,7 +4019,6 @@ class Subtensor(Op):
...
@@ -4019,7 +4019,6 @@ class Subtensor(Op):
assert
len
(
is_slice
)
<=
node
.
inputs
[
0
]
.
ndim
,
node
.
inputs
[
0
]
.
ndim
assert
len
(
is_slice
)
<=
node
.
inputs
[
0
]
.
ndim
,
node
.
inputs
[
0
]
.
ndim
len_is_slice
=
len
(
is_slice
)
len_is_slice
=
len
(
is_slice
)
view_ndim
=
node
.
inputs
[
0
]
.
ndim
-
(
numpy
.
asarray
(
is_slice
)
==
0
)
.
sum
()
len_subtensor_spec
=
spec_pos
()
len_subtensor_spec
=
spec_pos
()
...
@@ -4040,23 +4039,6 @@ class Subtensor(Op):
...
@@ -4040,23 +4039,6 @@ class Subtensor(Op):
int inner_ii = 0; // the current dimension of zview
int inner_ii = 0; // the current dimension of zview
int outer_ii = 0; // current dimension of z
int outer_ii = 0; // current dimension of z
//TODO: give this Op a second output so that this view can be cached
//TODO: alternatively, fix the memory leak on failure
Py_INCREF(PyArray_DESCR(
%(x)
s));
PyArrayObject * xview = (PyArrayObject*)PyArray_NewFromDescr(
&PyArray_Type,
PyArray_DESCR(
%(x)
s),
%(view_ndim)
s,
PyArray_DIMS(
%(x)
s),
PyArray_STRIDES(
%(x)
s),
PyArray_DATA(
%(x)
s),
%(x)
s->flags,
NULL);
if (!xview)
{
%(fail)
s;
}
if ((PyArray_DIMS(xview) == PyArray_DIMS(
%(x)
s))
if ((PyArray_DIMS(xview) == PyArray_DIMS(
%(x)
s))
&& (PyArray_DIMS(
%(x)
s) != NULL))
&& (PyArray_DIMS(
%(x)
s) != NULL))
{
{
...
@@ -4195,12 +4177,33 @@ class Subtensor(Op):
...
@@ -4195,12 +4177,33 @@ class Subtensor(Op):
return
(
4
,)
return
(
4
,)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
# DEBUG
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
# DEBUG
part0
=
self
.
helper_c_code
(
node
,
name
,
inputs
,
outputs
,
sub
,
self
.
idx_list
)
x
=
inputs
[
0
]
x
=
inputs
[
0
]
z
,
=
outputs
z
,
=
outputs
part1
=
"""
view_ndim
=
node
.
outputs
[
0
]
.
ndim
fail
=
sub
[
'fail'
]
build_view
=
"""
//TODO: give this Op a second output so that this view can be cached
//TODO: alternatively, fix the memory leak on failure
Py_INCREF(PyArray_DESCR(
%(x)
s));
PyArrayObject * xview = (PyArrayObject*)PyArray_NewFromDescr(
&PyArray_Type,
PyArray_DESCR(
%(x)
s),
%(view_ndim)
s,
PyArray_DIMS(
%(x)
s),
PyArray_STRIDES(
%(x)
s),
PyArray_DATA(
%(x)
s),
%(x)
s->flags,
NULL);
if (!xview)
{
%(fail)
s;
}
"""
%
locals
()
get_xview
=
self
.
helper_c_code
(
node
,
name
,
inputs
,
outputs
,
sub
,
self
.
idx_list
)
finish_view
=
"""
if (
%(z)
s) Py_DECREF(
%(z)
s);
if (
%(z)
s) Py_DECREF(
%(z)
s);
Py_INCREF(py_
%(x)
s);
Py_INCREF(py_
%(x)
s);
PyArray_BASE(xview) = py_
%(x)
s;
PyArray_BASE(xview) = py_
%(x)
s;
...
@@ -4208,7 +4211,7 @@ class Subtensor(Op):
...
@@ -4208,7 +4211,7 @@ class Subtensor(Op):
%(z)
s = xview;
%(z)
s = xview;
"""
%
locals
()
"""
%
locals
()
return
part0
+
part1
return
build_view
+
"{"
+
get_xview
+
"}"
+
finish_view
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
hv
=
self
.
helper_c_code_cache_version
()
hv
=
self
.
helper_c_code_cache_version
()
...
@@ -4489,7 +4492,9 @@ class IncSubtensor(Op):
...
@@ -4489,7 +4492,9 @@ class IncSubtensor(Op):
else
:
else
:
op_is_set
=
0
op_is_set
=
0
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
view_ndim
=
(
node
.
inputs
[
0
]
.
ndim
-
numpy
.
sum
([
not
isinstance
(
idx
,
slice
)
for
idx
in
self
.
idx_list
]))
copy_input_if_necessary
=
"""
copy_input_if_necessary
=
"""
if (
%(inplace)
s)
if (
%(inplace)
s)
{
{
...
@@ -4508,6 +4513,25 @@ class IncSubtensor(Op):
...
@@ -4508,6 +4513,25 @@ class IncSubtensor(Op):
}
}
"""
%
locals
()
"""
%
locals
()
#Make a first view on the output, as we will write into it.
build_view
=
"""
//TODO: give this Op a second output so that this view can be cached
//TODO: alternatively, fix the memory leak on failure
Py_INCREF(PyArray_DESCR(
%(z)
s));
PyArrayObject * xview = (PyArrayObject*)PyArray_NewFromDescr(
&PyArray_Type,
PyArray_DESCR(
%(z)
s),
%(view_ndim)
s,
PyArray_DIMS(
%(z)
s),
PyArray_STRIDES(
%(z)
s),
PyArray_DATA(
%(z)
s),
%(z)
s->flags,
NULL);
if (!xview)
{
%(fail)
s;
}
"""
%
locals
()
# make xview actually a view of %(z)s
# make xview actually a view of %(z)s
get_xview
=
Subtensor
.
helper_c_code
(
node
,
name
,
get_xview
=
Subtensor
.
helper_c_code
(
node
,
name
,
outputs
[:
1
]
+
inputs
[
2
:],
outputs
[:
1
]
+
inputs
[
2
:],
...
@@ -4541,7 +4565,8 @@ class IncSubtensor(Op):
...
@@ -4541,7 +4565,8 @@ class IncSubtensor(Op):
"""
%
locals
()
"""
%
locals
()
return
(
copy_input_if_necessary
return
(
copy_input_if_necessary
+
get_xview
+
build_view
+
"{"
+
get_xview
+
"}"
+
make_modification
+
make_modification
+
"Py_DECREF(xview);"
+
"Py_DECREF(xview);"
)
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论