Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4e6ef4aa
提交
4e6ef4aa
authored
7月 10, 2012
作者:
Eric Larsen
提交者:
Frederic
8月 15, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
testing infer_shape: op AdvancedIncSubtensor
上级
ca52a0fc
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
90 行增加
和
45 行删除
+90
-45
basic.py
theano/tensor/basic.py
+41
-8
test_basic.py
theano/tensor/tests/test_basic.py
+49
-37
没有找到文件。
theano/tensor/basic.py
浏览文件 @
4e6ef4aa
...
@@ -4298,7 +4298,14 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
...
@@ -4298,7 +4298,14 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
the_op
=
AdvancedIncSubtensor1
(
inplace
,
set_instead_of_inc
=
False
)
the_op
=
AdvancedIncSubtensor1
(
inplace
,
set_instead_of_inc
=
False
)
return
the_op
(
real_x
,
y
,
ilist
)
return
the_op
(
real_x
,
y
,
ilist
)
elif
isinstance
(
x
.
owner
.
op
,
AdvancedSubtensor
):
elif
isinstance
(
x
.
owner
.
op
,
AdvancedSubtensor
):
raise
NotImplementedError
()
real_x
=
x
.
owner
.
inputs
[
0
]
coordvec_0
=
x
.
owner
.
inputs
[
1
]
coordvec_1
=
x
.
owner
.
inputs
[
2
]
if
set_instead_of_inc
:
the_op
=
AdvancedIncSubtensor
(
inplace
,
set_instead_of_inc
=
True
)
else
:
the_op
=
AdvancedIncSubtensor
(
inplace
,
set_instead_of_inc
=
False
)
return
the_op
(
real_x
,
y
,
coordvec_0
,
coordvec_1
)
else
:
else
:
raise
TypeError
(
'x must be result of a subtensor operation'
)
raise
TypeError
(
'x must be result of a subtensor operation'
)
...
@@ -6056,6 +6063,8 @@ class AdvancedSubtensor(Op):
...
@@ -6056,6 +6063,8 @@ class AdvancedSubtensor(Op):
def
make_node
(
self
,
x
,
*
inputs
):
def
make_node
(
self
,
x
,
*
inputs
):
x
=
as_tensor_variable
(
x
)
x
=
as_tensor_variable
(
x
)
#FIXME
#FIXME
# Note (9 Jul 2012): what does this 'FIXME' mean? Possibly that the
# current implementation must be generalized? Please specify.
if
x
.
ndim
==
2
and
len
(
inputs
)
==
2
:
if
x
.
ndim
==
2
and
len
(
inputs
)
==
2
:
ind1
=
as_tensor_variable
(
inputs
[
0
])
ind1
=
as_tensor_variable
(
inputs
[
0
])
ind2
=
as_tensor_variable
(
inputs
[
1
])
ind2
=
as_tensor_variable
(
inputs
[
1
])
...
@@ -6131,14 +6140,28 @@ class AdvancedIncSubtensor(Op):
...
@@ -6131,14 +6140,28 @@ class AdvancedIncSubtensor(Op):
"""Increments a subtensor using advanced indexing.
"""Increments a subtensor using advanced indexing.
"""
"""
def
__eq__
(
self
,
other
):
def
__init__
(
self
,
inplace
=
False
,
set_instead_of_inc
=
False
):
return
self
.
__class__
==
other
.
__class__
self
.
inplace
=
inplace
self
.
set_instead_of_inc
=
set_instead_of_inc
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
self
.
__class__
)
return
hash
((
type
(
self
),
self
.
inplace
,
self
.
set_instead_of_inc
))
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
)
and
self
.
inplace
==
other
.
inplace
and
self
.
set_instead_of_inc
==
other
.
set_instead_of_inc
)
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
__class__
.
__name__
return
"
%
s{
%
s,
%
s}"
%
(
self
.
__class__
.
__name__
,
"inplace="
.
join
(
str
(
self
.
inplace
)),
" set_instead_of_inc"
.
join
(
str
(
self
.
set_instead_of_inc
)))
def
props
(
self
):
return
(
self
.
inplace
,
self
.
set_instead_of_inc
)
def
__repr__
(
self
):
return
'AdvancedIncSubtensor{
%
s}'
%
str
(
self
.
props
())
def
make_node
(
self
,
x
,
y
,
*
inputs
):
def
make_node
(
self
,
x
,
y
,
*
inputs
):
x
=
as_tensor_variable
(
x
)
x
=
as_tensor_variable
(
x
)
...
@@ -6153,21 +6176,31 @@ class AdvancedIncSubtensor(Op):
...
@@ -6153,21 +6176,31 @@ class AdvancedIncSubtensor(Op):
[
tensor
(
dtype
=
x
.
type
.
dtype
,
[
tensor
(
dtype
=
x
.
type
.
dtype
,
broadcastable
=
x
.
type
.
broadcastable
)])
broadcastable
=
x
.
type
.
broadcastable
)])
raise
NotImplementedError
(
raise
NotImplementedError
(
'Advanced indexing increment of x (of dimension
%
i) by y'
'Advanced indexing increment
/set
of x (of dimension
%
i) by y'
' (of dimension
%
i) with these argument dimensions (
%
s) not'
' (of dimension
%
i) with these argument dimensions (
%
s) not'
' supported yet'
' supported yet'
%
(
x
.
ndim
,
y
.
ndim
,
%
(
x
.
ndim
,
y
.
ndim
,
','
.
join
(
str
(
input
.
ndim
)
for
input
in
inputs
)))
','
.
join
(
str
(
input
.
ndim
)
for
input
in
inputs
)))
raise
NotImplementedError
(
raise
NotImplementedError
(
'Advanced indexing increment of x (of dim
%
i) by y (of dim
%
i)'
'Advanced indexing increment
/set
of x (of dim
%
i) by y (of dim
%
i)'
' with arguments (
%
s) not supported yet'
' with arguments (
%
s) not supported yet'
%
(
x
.
ndim
,
y
.
ndim
,
','
.
join
(
str
(
input
)
for
input
in
inputs
)))
%
(
x
.
ndim
,
y
.
ndim
,
','
.
join
(
str
(
input
)
for
input
in
inputs
)))
def
perform
(
self
,
node
,
inputs
,
out_
):
def
perform
(
self
,
node
,
inputs
,
out_
):
# TODO: 1. opt to make this in place 2. generalize as described in
# AdvancedSubtensor's perform TODO
out
,
=
out_
out
,
=
out_
# TODO: same thing as in AdvancedSubtensor's perform TODO
if
not
self
.
inplace
:
out
[
0
]
=
inputs
[
0
]
.
copy
()
out
[
0
]
=
inputs
[
0
]
.
copy
()
else
:
raise
NotImplementedError
(
'In place computation is not'
' implemented'
)
if
self
.
set_instead_of_inc
:
out
[
0
][
inputs
[
2
:]]
=
inputs
[
1
]
else
:
out
[
0
][
inputs
[
2
:]]
+=
inputs
[
1
]
out
[
0
][
inputs
[
2
:]]
+=
inputs
[
1
]
if
(
numpy
.
__version__
<=
'1.6.1'
and
if
(
numpy
.
__version__
<=
'1.6.1'
and
out
[
0
]
.
size
!=
numpy
.
uint32
(
out
[
0
]
.
size
)):
out
[
0
]
.
size
!=
numpy
.
uint32
(
out
[
0
]
.
size
)):
warnings
.
warn
(
warnings
.
warn
(
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
4e6ef4aa
...
@@ -37,7 +37,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
...
@@ -37,7 +37,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
tile
,
patternbroadcast
,
Eye
,
Shape
,
Default
,
Dot
,
PermuteRowElements
,
tile
,
patternbroadcast
,
Eye
,
Shape
,
Default
,
Dot
,
PermuteRowElements
,
ScalarFromTensor
,
TensorFromScalar
,
dtensor4
,
Rebroadcast
,
Alloc
,
ScalarFromTensor
,
TensorFromScalar
,
dtensor4
,
Rebroadcast
,
Alloc
,
dtensor3
,
SpecifyShape
,
Mean
,
IncSubtensor
,
AdvancedIncSubtensor1
,
dtensor3
,
SpecifyShape
,
Mean
,
IncSubtensor
,
AdvancedIncSubtensor1
,
itensor3
,
Tile
)
itensor3
,
Tile
,
AdvancedIncSubtensor
)
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
from
theano.printing
import
debugprint
from
theano.printing
import
debugprint
...
@@ -6511,95 +6511,107 @@ class TestInferShape(utt.InferShapeTester):
...
@@ -6511,95 +6511,107 @@ class TestInferShape(utt.InferShapeTester):
advec
=
dvector
()
advec
=
dvector
()
adscal
=
dscalar
()
adscal
=
dscalar
()
admat_val
=
rand
(
5
,
4
)
admat_val
=
rand
(
5
,
4
)
bd
vec_val
=
[
2
,
3
]
ai
vec_val
=
[
2
,
3
]
self
.
_compile_and_check
([
admat
,
bdmat
],
self
.
_compile_and_check
([
admat
,
bdmat
],
[
set_subtensor
(
admat
[
bd
vec_val
],
bdmat
)],
[
set_subtensor
(
admat
[
ai
vec_val
],
bdmat
)],
[
admat_val
,
[[
1
,
2
,
3
,
4
]]],
AdvancedIncSubtensor1
)
[
admat_val
,
[[
1
,
2
,
3
,
4
]]],
AdvancedIncSubtensor1
)
bd
vec_val
=
[
1
,
3
,
2
]
ai
vec_val
=
[
1
,
3
,
2
]
self
.
_compile_and_check
([
admat
,
advec
],
self
.
_compile_and_check
([
admat
,
advec
],
[
set_subtensor
(
admat
[
bd
vec_val
],
advec
)],
[
set_subtensor
(
admat
[
ai
vec_val
],
advec
)],
[
admat_val
,
[
1
,
2
,
3
,
4
]],
AdvancedIncSubtensor1
)
[
admat_val
,
[
1
,
2
,
3
,
4
]],
AdvancedIncSubtensor1
)
bd
vec_val
=
[
0
,
3
,
0
]
ai
vec_val
=
[
0
,
3
,
0
]
self
.
_compile_and_check
([
admat
,
adscal
],
self
.
_compile_and_check
([
admat
,
adscal
],
[
set_subtensor
(
admat
[
bd
vec_val
],
adscal
)],
[
set_subtensor
(
admat
[
ai
vec_val
],
adscal
)],
[
admat_val
,
1
],
AdvancedIncSubtensor1
)
[
admat_val
,
1
],
AdvancedIncSubtensor1
)
bdtens4
=
dtensor4
()
bdtens4
=
dtensor4
()
adtens4_val
=
rand
(
4
,
3
,
2
,
5
)
adtens4_val
=
rand
(
4
,
3
,
2
,
5
)
bd
vec_val
=
[
2
,
3
]
ai
vec_val
=
[
2
,
3
]
self
.
_compile_and_check
([
adtens4
,
bdtens4
],
self
.
_compile_and_check
([
adtens4
,
bdtens4
],
[
set_subtensor
(
adtens4
[
bd
vec_val
],
bdtens4
)],
[
set_subtensor
(
adtens4
[
ai
vec_val
],
bdtens4
)],
[
adtens4_val
,
[[[[
1
,
2
,
3
,
4
,
5
]]]]],
[
adtens4_val
,
[[[[
1
,
2
,
3
,
4
,
5
]]]]],
AdvancedIncSubtensor1
)
AdvancedIncSubtensor1
)
bd
vec_val
=
[
1
,
3
,
2
]
ai
vec_val
=
[
1
,
3
,
2
]
self
.
_compile_and_check
([
adtens4
,
advec
],
self
.
_compile_and_check
([
adtens4
,
advec
],
[
set_subtensor
(
adtens4
[
bd
vec_val
],
advec
)],
[
set_subtensor
(
adtens4
[
ai
vec_val
],
advec
)],
[
adtens4_val
,
[
1
,
2
,
3
,
4
,
5
]],
[
adtens4_val
,
[
1
,
2
,
3
,
4
,
5
]],
AdvancedIncSubtensor1
)
AdvancedIncSubtensor1
)
bd
vec_val
=
[
0
,
3
,
0
]
ai
vec_val
=
[
0
,
3
,
0
]
self
.
_compile_and_check
([
adtens4
,
adscal
],
self
.
_compile_and_check
([
adtens4
,
adscal
],
[
set_subtensor
(
adtens4
[
bd
vec_val
],
adscal
)],
[
set_subtensor
(
adtens4
[
ai
vec_val
],
adscal
)],
[
adtens4_val
,
1
],
[
adtens4_val
,
1
],
AdvancedIncSubtensor1
)
AdvancedIncSubtensor1
)
## TODO: (!!) function inc_subtensor fails on line 5784 in perform in basic.py
## TODO: (!!) function inc_subtensor fails on line 5784 in perform in basic.py
"""
"""
bd
vec_val = [2, 3]
ai
vec_val = [2, 3]
self._compile_and_check([admat, bdmat],
self._compile_and_check([admat, bdmat],
[inc_subtensor(admat[bdvec_val], bdmat)],
[inc_subtensor(admat[aivec_val], bdmat)],
[admat_val, [[1, 2, 3, 4]]], AdvancedIncSubtensor1)
bd
vec_val = [1, 3, 2]
ai
vec_val = [1, 3, 2]
self._compile_and_check([admat, advec],
self._compile_and_check([admat, advec],
[inc_subtensor(admat[
bd
vec_val], advec)],
[inc_subtensor(admat[
ai
vec_val], advec)],
[admat_val, [1, 2, 3, 4]], AdvancedIncSubtensor1)
[admat_val, [1, 2, 3, 4]], AdvancedIncSubtensor1)
bd
vec_val = [0, 3, 0]
ai
vec_val = [0, 3, 0]
self._compile_and_check([admat, adscal],
self._compile_and_check([admat, adscal],
[inc_subtensor(admat[
bd
vec_val], adscal)],
[inc_subtensor(admat[
ai
vec_val], adscal)],
[admat_val, 1], AdvancedIncSubtensor1)
[admat_val, 1], AdvancedIncSubtensor1)
bdtens4 = dtensor4()
bdtens4 = dtensor4()
adtens4_val = rand(4, 3, 2, 5)
adtens4_val = rand(4, 3, 2, 5)
bd
vec_val = [2, 3]
ai
vec_val = [2, 3]
self._compile_and_check([adtens4, bdtens4],
self._compile_and_check([adtens4, bdtens4],
[inc_subtensor(adtens4[
bd
vec_val], bdtens4)],
[inc_subtensor(adtens4[
ai
vec_val], bdtens4)],
[adtens4_val, [[[[1, 2, 3, 4, 5]]]]],
[adtens4_val, [[[[1, 2, 3, 4, 5]]]]],
AdvancedIncSubtensor1)
AdvancedIncSubtensor1)
bd
vec_val = [1, 3, 2]
ai
vec_val = [1, 3, 2]
self._compile_and_check([adtens4, advec],
self._compile_and_check([adtens4, advec],
[inc_subtensor(adtens4[
bd
vec_val], advec)],
[inc_subtensor(adtens4[
ai
vec_val], advec)],
[adtens4_val, [[1, 2, 3, 4, 5]]],
[adtens4_val, [[1, 2, 3, 4, 5]]],
AdvancedIncSubtensor1)
AdvancedIncSubtensor1)
bd
vec_val = [0, 3, 0]
ai
vec_val = [0, 3, 0]
self._compile_and_check([adtens4, adscal],
self._compile_and_check([adtens4, adscal],
[inc_subtensor(adtens4[
bd
vec_val], adscal)],
[inc_subtensor(adtens4[
ai
vec_val], adscal)],
[adtens4_val, [[1, 2, 3, 4, 5]]],
[adtens4_val, [[1, 2, 3, 4, 5]]],
AdvancedIncSubtensor1)
AdvancedIncSubtensor1)
"""
"""
# AdvancedIncSubtensor
# AdvancedIncSubtensor
# TODO:
AdvancedIncSubtensor cannot be reached through the wrappers
# TODO:
The shape is apparently generated correctly but the final
#
set_subtensor and advanced_subtensor (see comment in Git, issue 476)
#
result is abnormal:
"""
"""
# as an example only:
topo_shape:
bdvec_val = [1, 3, 2]
[AdvancedIncSubtensor{Finplace=ainplace=linplace=sinplace=e, T set_instead_of_incr set_instead_of_incu set_instead_of_ince}(<TensorType(float64, matrix)>, <TensorType(float64, vector)>, TensorConstant{[1 3 2]}, TensorConstant{[0 3 3]}), Shape_i{1}(AdvancedIncSubtensor{Finplace=ainplace=linplace=sinplace=e, T set_instead_of_incr set_instead_of_incu set_instead_of_ince}.0), Shape_i{0}(AdvancedIncSubtensor{Finplace=ainplace=linplace=sinplace=e, T set_instead_of_incr set_instead_of_incu set_instead_of_ince}.0), MakeVector(Shape_i{0}.0, Shape_i{1}.0)]
cdvec_val = [2]
shapes_function:
self._compile_and_check([admat, advec],
MakeVector [@A] '' 3
[set_subtensor(admat[bdvec_val, cdvec_val], adscal)],
|Shape_i{0} [@B] '' 2
[admat_val, 1], AdvancedIncSubtensor)
| |AdvancedIncSubtensor{Finplace=ainplace=linplace=sinplace=e, T set_instead_of_incr set_instead_of_incu set_instead_of_ince} [@C] '' 0
| |<TensorType(float64, matrix)> [@D]
| |<TensorType(float64, vector)> [@E]
| |TensorConstant{[1 3 2]} [@F]
| |TensorConstant{[0 3 3]} [@G]
|Shape_i{1} [@H] '' 1
|AdvancedIncSubtensor{Finplace=ainplace=linplace=sinplace=e, T set_instead_of_incr set_instead_of_incu set_instead_of_ince} [@C] '' 0
remaining op as a class: AdvancedIncSubtensor{Finplace=ainplace=linplace=sinplace=e, T set_instead_of_incr set_instead_of_incu set_instead_of_ince}
(5, 4) [5 4]
"""
"""
# Reshape: basic 5094
aivec_val
=
[
1
,
3
,
2
]
bivec_val
=
[
0
,
3
,
3
]
advec_val
=
[
23
,
24
,
25
]
self
.
_compile_and_check
([
admat
,
advec
],
[
set_subtensor
(
admat
[
aivec_val
,
bivec_val
],
advec
)],
[
admat_val
,
advec_val
],
AdvancedIncSubtensor
)
# Reshape
# TODO: The shape is apparently generated correctly but the final result is abnormal:
# TODO: The shape is apparently generated correctly but the final result is abnormal:
"""
"""
topo_shape:
topo_shape:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论