Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8d083c1a
提交
8d083c1a
authored
8月 13, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add paramter unsorted_indices and explicit_zero to sparse_random_inputs()
This help test those cases.
上级
fd8d4d32
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
26 行增加
和
12 行删除
+26
-12
test_basic.py
theano/sparse/tests/test_basic.py
+26
-12
没有找到文件。
theano/sparse/tests/test_basic.py
浏览文件 @
8d083c1a
...
...
@@ -80,7 +80,8 @@ def random_lil(shape, dtype, nnz):
return
rval
def
sparse_random_inputs
(
format
,
shape
,
n
=
1
,
out_dtype
=
None
,
p
=
0.5
,
gap
=
None
):
def
sparse_random_inputs
(
format
,
shape
,
n
=
1
,
out_dtype
=
None
,
p
=
0.5
,
gap
=
None
,
explicit_zero
=
False
,
unsorted_indices
=
False
):
"""Return a tuple containing everything needed to
perform a test.
...
...
@@ -97,9 +98,15 @@ def sparse_random_inputs(format, shape, n=1, out_dtype=None, p=0.5, gap=None):
max, when `gap` = (`a`, `b`) it provide a sample
from [a, b[. If `None` is used, it provide [0, 1]
for float dtypes and [0, 50[ for integer dtypes.
:param explicit_zero: When True, we add explicit zero in the
returned sparse matrix
:param unsorted_indices: when True, we make sure there is
unsorted indices in the returned
sparse matrix.
:return: (variable, data) where both `variable`
and `data` are list.
:note: explicit_zero and unsorted_indices was added in Theano 0.6rc4
"""
if
out_dtype
is
None
:
...
...
@@ -136,6 +143,19 @@ def sparse_random_inputs(format, shape, n=1, out_dtype=None, p=0.5, gap=None):
for
k
in
range
(
n
)]
data
=
[
getattr
(
scipy
.
sparse
,
format
+
'_matrix'
)(
_rand
(),
dtype
=
out_dtype
)
for
k
in
range
(
n
)]
if
unsorted_indices
:
for
idx
in
range
(
n
):
d
=
data
[
idx
]
d
=
d
[
range
(
d
.
shape
[
0
])]
assert
not
d
.
has_sorted_indices
data
[
idx
]
=
d
if
explicit_zero
:
for
idx
in
range
(
n
):
assert
data
[
idx
]
.
nnz
>
1
,
(
"can't make a sparse matrix with explicit 0"
)
d_idx
=
numpy
.
random
.
randint
(
data
[
idx
]
.
nnz
)
data
[
idx
]
.
data
[
d_idx
]
=
0
#numpy 1.5.0 with scipy 0.9.0 have scipy.sparse.XXX_matrix return
#typenum 10(ulonglong) instead of 8(uint64) event if they are the same!
#Theano don't like ulonglong type_num
...
...
@@ -1845,17 +1865,11 @@ class Remove0Tester(utt.InferShapeTester):
(
'csr'
,
scipy
.
sparse
.
csr_matrix
),
]
for
format
,
matrix_class
in
configs
:
# real
origin
=
(
numpy
.
arange
(
9
)
+
1
)
.
reshape
((
3
,
3
))
origin
.
astype
(
config
.
floatX
)
mat
=
matrix_class
(
origin
)
.
astype
(
theano
.
config
.
floatX
)
mat
[
0
,
1
]
=
mat
[
1
,
0
]
=
mat
[
2
,
2
]
=
0
assert
mat
.
size
==
9
(
x
,),
(
mat
,)
=
sparse_random_inputs
(
format
,
(
3
,
4
),
out_dtype
=
config
.
floatX
,
explicit_zero
=
True
)
assert
0
in
mat
.
data
# symbolic
x
=
theano
.
sparse
.
SparseType
(
format
=
format
,
dtype
=
config
.
floatX
)()
# the In thingy has to be there because theano has as rule not
# to optimize inputs
f
=
theano
.
function
([
theano
.
In
(
x
,
borrow
=
True
,
mutable
=
True
)],
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论