Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d4b8841d
提交
d4b8841d
authored
1月 12, 2015
作者:
ChienliMa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Delete extra value;Modift test case to avoid uduplicate code;Expexted error not raised.
上级
3626d6d5
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
78 行增加
和
107 行删除
+78
-107
test_basic.py
theano/sparse/tests/test_basic.py
+78
-107
没有找到文件。
theano/sparse/tests/test_basic.py
浏览文件 @
d4b8841d
...
@@ -2104,9 +2104,11 @@ class Test_getitem(unittest.TestCase):
...
@@ -2104,9 +2104,11 @@ class Test_getitem(unittest.TestCase):
verify_grad_sparse
(
op_with_fixed_index
,
x_val
)
verify_grad_sparse
(
op_with_fixed_index
,
x_val
)
def
test_GetItem2D
(
self
):
def
test_GetItem2D
(
self
):
sparse_formats
=
(
'csc'
,
'csr'
)
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
assert
scipy_ver
>=
[
0
,
11
]
is_supported_version
=
bool
(
scipy_ver
>=
[
0
,
14
])
is_supported_version
=
bool
(
scipy_ver
>=
[
0
,
14
])
sparse_formats
=
(
'csc'
,
'csr'
)
for
format
in
sparse_formats
:
for
format
in
sparse_formats
:
x
=
theano
.
sparse
.
matrix
(
format
,
name
=
'x'
)
x
=
theano
.
sparse
.
matrix
(
format
,
name
=
'x'
)
a
=
theano
.
tensor
.
iscalar
(
'a'
)
a
=
theano
.
tensor
.
iscalar
(
'a'
)
...
@@ -2121,115 +2123,84 @@ class Test_getitem(unittest.TestCase):
...
@@ -2121,115 +2123,84 @@ class Test_getitem(unittest.TestCase):
n
=
5
n
=
5
p
=
10
p
=
10
q
=
15
q
=
15
j
=
2
if
is_supported_version
:
k
=
3
j
=
2
k
=
3
else
:
j
=
None
k
=
None
vx
=
as_sparse_format
(
self
.
rng
.
binomial
(
1
,
0.5
,
(
100
,
97
)),
vx
=
as_sparse_format
(
self
.
rng
.
binomial
(
1
,
0.5
,
(
100
,
97
)),
format
)
.
astype
(
theano
.
config
.
floatX
)
format
)
.
astype
(
theano
.
config
.
floatX
)
if
is_supported_version
:
#mode_no_debug = theano.compile.mode.get_default_mode()
#mode_no_debug = theano.compile.mode.get_default_mode()
#if isinstance(mode_no_debug, theano.compile.DebugMode):
#if isinstance(mode_no_debug, theano.compile.DebugMode):
# mode_no_debug = 'FAST_RUN'
# mode_no_debug = 'FAST_RUN'
f1
=
theano
.
function
([
x
,
a
,
b
,
c
,
d
,
e
,
f
],
x
[
a
:
b
:
e
,
c
:
d
:
f
])
f1
=
theano
.
function
([
x
,
a
,
b
,
c
,
d
,
e
,
f
],
x
[
a
:
b
:
e
,
c
:
d
:
f
])
r1
=
f1
(
vx
,
m
,
n
,
p
,
q
,
j
,
k
)
r1
=
f1
(
vx
,
m
,
n
,
p
,
q
,
j
,
k
)
t1
=
vx
[
m
:
n
:
j
,
p
:
q
:
k
]
t1
=
vx
[
m
:
n
:
j
,
p
:
q
:
k
]
assert
r1
.
shape
==
t1
.
shape
assert
r1
.
shape
==
t1
.
shape
assert
numpy
.
all
(
t1
.
toarray
()
==
r1
.
toarray
())
assert
numpy
.
all
(
t1
.
toarray
()
==
r1
.
toarray
())
"""
"""
Important: based on a discussion with both Fred and James
Important: based on a discussion with both Fred and James
The following indexing methods is not supported because the rval
The following indexing methods is not supported because the rval
would be a sparse matrix rather than a sparse vector, which is a
would be a sparse matrix rather than a sparse vector, which is a
deviation from numpy indexing rule. This decision is made largely
deviation from numpy indexing rule. This decision is made largely
for keeping the consistency between numpy and theano.
for keeping the consistency between numpy and theano.
f2 = theano.function([x, a, b, c], x[a:b, c])
f2 = theano.function([x, a, b, c], x[a:b, c])
r2 = f2(vx, m, n, p)
r2 = f2(vx, m, n, p)
t2 = vx[m:n, p]
t2 = vx[m:n, p]
assert r2.shape == t2.shape
assert r2.shape == t2.shape
assert numpy.all(t2.toarray() == r2.toarray())
assert numpy.all(t2.toarray() == r2.toarray())
f3 = theano.function([x, a, b, c], x[a, b:c])
f3 = theano.function([x, a, b, c], x[a, b:c])
r3 = f3(vx, m, n, p)
r3 = f3(vx, m, n, p)
t3 = vx[m, n:p]
t3 = vx[m, n:p]
assert r3.shape == t3.shape
assert r3.shape == t3.shape
assert numpy.all(t3.toarray() == r3.toarray())
assert numpy.all(t3.toarray() == r3.toarray())
f5 = theano.function([x], x[1:2,3])
f5 = theano.function([x], x[1:2,3])
r5 = f5(vx)
r5 = f5(vx)
t5 = vx[1:2, 3]
t5 = vx[1:2, 3]
assert r5.shape == t5.shape
assert r5.shape == t5.shape
assert numpy.all(r5.toarray() == t5.toarray())
assert numpy.all(r5.toarray() == t5.toarray())
f7 = theano.function([x], x[50])
f7 = theano.function([x], x[50])
r7 = f7(vx)
r7 = f7(vx)
t7 = vx[50]
t7 = vx[50]
assert r7.shape == t7.shape
assert r7.shape == t7.shape
assert numpy.all(r7.toarray() == t7.toarray())
assert numpy.all(r7.toarray() == t7.toarray())
"""
"""
f4
=
theano
.
function
([
x
,
a
,
b
,
e
],
x
[
a
:
b
:
e
])
f4
=
theano
.
function
([
x
,
a
,
b
,
e
],
x
[
a
:
b
:
e
])
r4
=
f4
(
vx
,
m
,
n
,
j
)
r4
=
f4
(
vx
,
m
,
n
,
j
)
t4
=
vx
[
m
:
n
:
j
]
t4
=
vx
[
m
:
n
:
j
]
assert
r4
.
shape
==
t4
.
shape
assert
r4
.
shape
==
t4
.
shape
assert
numpy
.
all
(
t4
.
toarray
()
==
r4
.
toarray
())
assert
numpy
.
all
(
t4
.
toarray
()
==
r4
.
toarray
())
#-----------------------------------------------------------
#-----------------------------------------------------------
# test cases using int indexing instead of theano variable
# test cases using int indexing instead of theano variable
f6
=
theano
.
function
([
x
],
x
[
1
:
10
:
j
,
10
:
20
:
k
])
f6
=
theano
.
function
([
x
],
x
[
1
:
10
:
1
,
10
:
20
:
2
])
r6
=
f6
(
vx
)
r6
=
f6
(
vx
)
t6
=
vx
[
1
:
10
:
j
,
10
:
20
:
k
]
t6
=
vx
[
1
:
10
:
1
,
10
:
20
:
2
]
assert
r6
.
shape
==
t6
.
shape
assert
r6
.
shape
==
t6
.
shape
assert
numpy
.
all
(
r6
.
toarray
()
==
t6
.
toarray
())
assert
numpy
.
all
(
r6
.
toarray
()
==
t6
.
toarray
())
#----------------------------------------------------------
#----------------------------------------------------------
# test cases with indexing both with theano variable and int
# test cases with indexing both with theano variable and int
f8
=
theano
.
function
([
x
,
a
,
b
,
e
],
x
[
a
:
b
:
e
,
10
:
20
:
1
])
f8
=
theano
.
function
([
x
,
a
,
b
,
e
],
x
[
a
:
b
:
e
,
10
:
20
:
1
])
r8
=
f8
(
vx
,
m
,
n
,
j
)
r8
=
f8
(
vx
,
m
,
n
,
j
)
t8
=
vx
[
m
:
n
:
j
,
10
:
20
:
1
]
t8
=
vx
[
m
:
n
:
j
,
10
:
20
:
1
]
assert
r8
.
shape
==
t8
.
shape
assert
r8
.
shape
==
t8
.
shape
assert
numpy
.
all
(
r8
.
toarray
()
==
t8
.
toarray
())
assert
numpy
.
all
(
r8
.
toarray
()
==
t8
.
toarray
())
f9
=
theano
.
function
([
x
,
a
,
b
],
x
[
1
:
a
:
j
,
1
:
b
:
k
])
f9
=
theano
.
function
([
x
,
a
,
b
],
x
[
1
:
a
:
2
,
1
:
b
:
2
])
r9
=
f9
(
vx
,
p
,
q
)
r9
=
f9
(
vx
,
p
,
q
)
t9
=
vx
[
1
:
p
:
j
,
1
:
q
:
k
]
t9
=
vx
[
1
:
p
:
2
,
1
:
q
:
2
]
assert
r9
.
shape
==
t9
.
shape
assert
r9
.
shape
==
t9
.
shape
assert
numpy
.
all
(
r9
.
toarray
()
==
t9
.
toarray
())
assert
numpy
.
all
(
r9
.
toarray
()
==
t9
.
toarray
())
else
:
f1
=
theano
.
function
([
x
,
a
,
b
,
c
,
d
],
x
[
a
:
b
,
c
:
d
])
r1
=
f1
(
vx
,
m
,
n
,
p
,
q
)
t1
=
vx
[
m
:
n
,
p
:
q
]
assert
r1
.
shape
==
t1
.
shape
assert
numpy
.
all
(
t1
.
toarray
()
==
r1
.
toarray
())
f4
=
theano
.
function
([
x
,
a
,
b
],
x
[
a
:
b
])
r4
=
f4
(
vx
,
m
,
n
)
t4
=
vx
[
m
:
n
]
assert
r4
.
shape
==
t4
.
shape
assert
numpy
.
all
(
t4
.
toarray
()
==
r4
.
toarray
())
#-----------------------------------------------------------
# test cases using int indexing instead of theano variable
f6
=
theano
.
function
([
x
],
x
[
1
:
10
,
10
:
20
])
r6
=
f6
(
vx
)
t6
=
vx
[
1
:
10
,
10
:
20
]
assert
r6
.
shape
==
t6
.
shape
assert
numpy
.
all
(
r6
.
toarray
()
==
t6
.
toarray
())
#----------------------------------------------------------
# test cases with indexing both with theano variable and int
f8
=
theano
.
function
([
x
,
a
,
b
,
e
],
x
[
a
:
b
,
10
:
20
])
r8
=
f8
(
vx
,
m
,
n
)
t8
=
vx
[
m
:
n
,
10
:
20
]
assert
r8
.
shape
==
t8
.
shape
assert
numpy
.
all
(
r8
.
toarray
()
==
t8
.
toarray
())
f9
=
theano
.
function
([
x
,
a
,
b
],
x
[
a
:,
b
:])
r9
=
f9
(
vx
,
p
,
q
)
t9
=
vx
[
p
:,
q
:]
assert
r9
.
shape
==
t9
.
shape
assert
numpy
.
all
(
r9
.
toarray
()
==
t9
.
toarray
())
#-----------------------------------------------------------
#-----------------------------------------------------------
# Test mixing None and variables
# Test mixing None and variables
...
@@ -2269,7 +2240,7 @@ class Test_getitem(unittest.TestCase):
...
@@ -2269,7 +2240,7 @@ class Test_getitem(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
self
.
assertRaises
(
ValueError
,
x
.
__getitem__
,
(
slice
(
a
,
b
),
slice
(
c
,
d
,
2
)))
x
.
__getitem__
,
(
slice
(
a
,
b
),
slice
(
c
,
d
,
2
)))
else
:
else
:
raise
SkipTest
(
"Slicing with step
needs newer release of scipy
"
)
raise
SkipTest
(
"Slicing with step
is supported.
"
)
# Advanced indexing is not supported
# Advanced indexing is not supported
self
.
assertRaises
(
ValueError
,
self
.
assertRaises
(
ValueError
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论