Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2ae140cc
提交
2ae140cc
authored
9月 03, 2013
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1511 from lamblin/fix_1499
Use compat.python2x.all instead of numpy.all on generator
上级
b0de5da7
3166a3d5
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
60 行增加
和
2 行删除
+60
-2
test_subtensor.py
theano/tensor/tests/test_subtensor.py
+57
-0
var.py
theano/tensor/var.py
+3
-2
没有找到文件。
theano/tensor/tests/test_subtensor.py
浏览文件 @
2ae140cc
...
@@ -1048,6 +1048,22 @@ inplace_increment_missing = SkipTest(
...
@@ -1048,6 +1048,22 @@ inplace_increment_missing = SkipTest(
class
TestAdvancedSubtensor
(
unittest
.
TestCase
):
class
TestAdvancedSubtensor
(
unittest
.
TestCase
):
# test inc_subtensor
# test inc_subtensor
# also tests set_subtensor
# also tests set_subtensor
def
__init__
(
self
,
name
,
shared
=
tensor
.
_shared
,
sub
=
tensor
.
AdvancedSubtensor
,
inc_sub
=
tensor
.
AdvancedIncSubtensor
,
mode
=
None
,
dtype
=
theano
.
config
.
floatX
,
ignore_topo
=
DeepCopyOp
):
self
.
shared
=
shared
self
.
sub
=
sub
self
.
inc_sub
=
inc_sub
if
mode
is
None
:
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
self
.
mode
=
mode
self
.
dtype
=
dtype
self
.
ignore_topo
=
ignore_topo
return
super
(
TestAdvancedSubtensor
,
self
)
.
__init__
(
name
)
def
setUp
(
self
):
def
setUp
(
self
):
self
.
s
=
iscalar
()
self
.
s
=
iscalar
()
...
@@ -1059,6 +1075,16 @@ class TestAdvancedSubtensor(unittest.TestCase):
...
@@ -1059,6 +1075,16 @@ class TestAdvancedSubtensor(unittest.TestCase):
self
.
ix12
=
lvector
()
self
.
ix12
=
lvector
()
self
.
ix2
=
lmatrix
()
self
.
ix2
=
lmatrix
()
def
eval_output_and_check
(
self
,
t
):
f
=
inplace_func
([],
t
,
mode
=
self
.
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo_
=
[
node
for
node
in
topo
if
not
isinstance
(
node
.
op
,
self
.
ignore_topo
)]
assert
len
(
topo_
)
==
1
assert
isinstance
(
topo_
[
0
]
.
op
,
self
.
sub
)
tval
=
f
()
return
tval
def
test_cant_adv_idx_into_scalar
(
self
):
def
test_cant_adv_idx_into_scalar
(
self
):
self
.
assertRaises
(
TypeError
,
lambda
:
self
.
s
[
self
.
ix1
])
self
.
assertRaises
(
TypeError
,
lambda
:
self
.
s
[
self
.
ix1
])
...
@@ -1072,6 +1098,37 @@ class TestAdvancedSubtensor(unittest.TestCase):
...
@@ -1072,6 +1098,37 @@ class TestAdvancedSubtensor(unittest.TestCase):
assert
a
.
broadcastable
==
self
.
ix2
.
broadcastable
,
(
assert
a
.
broadcastable
==
self
.
ix2
.
broadcastable
,
(
a
.
broadcastable
,
self
.
ix2
.
broadcastable
)
a
.
broadcastable
,
self
.
ix2
.
broadcastable
)
def
test_index_w_int_and_vec
(
self
):
# like test_ok_list, but with a single index on the first one
# data has to have at least 2 dimensions
for
data
,
idx
in
[(
rand
(
4
,
5
),
[
2
,
3
]),
(
rand
(
2
,
4
,
3
),
[
0
,
3
]),
(
rand
(
2
,
4
,
3
),
[
3
,
3
,
1
,
1
,
2
,
2
,
0
,
0
]),
(
rand
(
2
,
4
,
3
),
[
3
,
3
,
1
,
1
,
2
,
2
,
0
,
0
,
-
1
,
-
2
,
-
3
,
-
4
]),
# Test 4 dims as gpu code use another algo
# in that case This new algo is not as much
# optimized for that case.
(
rand
(
4
,
4
,
2
,
3
),
[
3
,
3
,
1
,
1
,
2
,
2
,
0
,
0
,
-
1
,
-
2
,
-
3
,
-
4
]),
# Test with TensorConstant index.
(
rand
(
2
,
4
,
3
),
theano
.
tensor
.
constant
([
3
,
3
,
1
,
1
,
2
,
2
,
0
,
0
])),
]:
data
=
numpy
.
asarray
(
data
,
dtype
=
self
.
dtype
)
n
=
self
.
shared
(
data
)
t
=
n
[
0
,
idx
]
self
.
assertTrue
(
isinstance
(
t
.
owner
.
op
,
tensor
.
AdvancedSubtensor
))
val
=
self
.
eval_output_and_check
(
t
)
if
isinstance
(
idx
,
list
):
good
=
data
[
0
,
idx
]
else
:
good
=
data
[
0
,
idx
.
data
]
self
.
assertTrue
(
val
.
ndim
==
data
.
ndim
-
1
)
self
.
assertTrue
(
numpy
.
allclose
(
val
,
good
),
(
val
,
good
))
def
test_inc_adv_subtensor_w_matrix
(
self
):
def
test_inc_adv_subtensor_w_matrix
(
self
):
subt
=
self
.
v
[
self
.
ix2
]
subt
=
self
.
v
[
self
.
ix2
]
a
=
inc_subtensor
(
subt
,
subt
)
a
=
inc_subtensor
(
subt
,
subt
)
...
...
theano/tensor/var.py
浏览文件 @
2ae140cc
...
@@ -2,6 +2,7 @@ import numpy
...
@@ -2,6 +2,7 @@ import numpy
import
theano
import
theano
from
theano.compat
import
PY3
from
theano.compat
import
PY3
from
theano.compat.python2x
import
all
from
theano.scalar
import
ComplexError
,
IntegerDivisionError
from
theano.scalar
import
ComplexError
,
IntegerDivisionError
from
theano.gof
import
Constant
,
Variable
from
theano.gof
import
Constant
,
Variable
from
theano.gof.utils
import
hashtype
from
theano.gof.utils
import
hashtype
...
@@ -366,8 +367,8 @@ class _tensor_py_operators:
...
@@ -366,8 +367,8 @@ class _tensor_py_operators:
if
advanced
:
if
advanced
:
if
(
axis
is
not
None
if
(
axis
is
not
None
and
numpy
.
all
(
a
==
slice
(
None
)
for
a
in
args
[:
axis
])
and
all
(
a
==
slice
(
None
)
for
a
in
args
[:
axis
])
and
numpy
.
all
(
a
==
slice
(
None
)
for
a
in
args
[
axis
+
1
:])
and
all
(
a
==
slice
(
None
)
for
a
in
args
[
axis
+
1
:])
and
isinstance
(
args
[
axis
],
(
and
isinstance
(
args
[
axis
],
(
numpy
.
ndarray
,
numpy
.
ndarray
,
list
,
list
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论