Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e836df32
提交
e836df32
authored
11月 23, 2011
作者:
Li Yao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ensure sorted indices tested
上级
9109e410
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
23 行增加
和
28 行删除
+23
-28
sp.py
theano/sparse/sandbox/sp.py
+3
-1
test_sp.py
theano/sparse/sandbox/test_sp.py
+20
-27
没有找到文件。
theano/sparse/sandbox/sp.py
浏览文件 @
e836df32
...
@@ -273,7 +273,9 @@ class EnsureSortedIndices(Op):
...
@@ -273,7 +273,9 @@ class EnsureSortedIndices(Op):
def
grad
(
self
,
(
x
,),
(
gz
,)):
def
grad
(
self
,
(
x
,),
(
gz
,)):
return
[
gz
]
return
[
gz
]
def
infer_shape
(
self
,
node
,
i0_shapes
):
return
i0_shapes
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
inplace
:
if
self
.
inplace
:
return
self
.
__class__
.
__name__
+
"{inplace}"
return
self
.
__class__
.
__name__
+
"{inplace}"
...
...
theano/sparse/sandbox/test_sp.py
浏览文件 @
e836df32
...
@@ -16,7 +16,7 @@ from theano import function, tensor
...
@@ -16,7 +16,7 @@ from theano import function, tensor
import
theano
import
theano
from
theano.sparse.sandbox
import
sp
from
theano.sparse.sandbox
import
sp
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
from
theano.sparse.tests.test_basic
import
random_lil
class
TestSP
(
unittest
.
TestCase
):
class
TestSP
(
unittest
.
TestCase
):
def
test_convolution
(
self
):
def
test_convolution
(
self
):
...
@@ -414,32 +414,25 @@ def test_diagonal():
...
@@ -414,32 +414,25 @@ def test_diagonal():
assert
numpy
.
all
(
n
==
f
(
range
(
K
))
.
toarray
())
assert
numpy
.
all
(
n
==
f
(
range
(
K
))
.
toarray
())
def
test_EnsureSortedIndices
():
def
test_EnsureSortedIndices
():
x
=
2000
input_tensor
=
theano
.
sparse
.
csc_dmatrix
()
y
=
2000
sort_op
=
sp
.
ensure_sorted_indices
(
input_tensor
)
sparsity
=
1000
f
=
theano
.
function
([
input_tensor
],
sort_op
)
for
i
in
range
(
2
):
# testing both csc and csr
# test_sample = scipy.sparse.rand(1000, 1000, density=0.01)
if
i
is
0
:
# the function above is not working since scipy has lower version
# csc
# specify the number of rows and columns in the test case
input_tensor
=
theano
.
sparse
.
csc_dmatrix
()
r
=
2000
sample
=
scipy
.
sparse
.
csc_matrix
(
random_lil
((
x
,
y
),
'float64'
,
sparsity
))
c
=
2000
else
:
# construct a test sample
# csr
test_sample
=
numpy
.
random
.
rand
(
r
,
c
)
input_tensor
=
theano
.
sparse
.
csr_dmatrix
()
indices_zero_x
=
numpy
.
random
.
permutation
(
range
(
r
))
sample
=
scipy
.
sparse
.
csr_matrix
(
random_lil
((
x
,
y
),
'float64'
,
sparsity
))
indices_zero_y
=
numpy
.
random
.
permutation
(
range
(
c
))
# take 70% of the test_sample and make them 0
sort_op
=
sp
.
ensure_sorted_indices
(
input_tensor
)
sparse_ratio_x
=
int
(
r
*
0.9
)
f
=
theano
.
function
([
input_tensor
],
sort_op
)
sparse_ratio_y
=
int
(
c
*
0.9
)
sorted_scipy
=
sample
.
sorted_indices
()
for
i
in
indices_zero_x
[:
sparse_ratio_x
]:
sorted_theano
=
f
(
sample
)
for
j
in
indices_zero_y
[:
sparse_ratio_y
]:
assert
numpy
.
all
(
sorted_theano
.
todense
()
==
sorted_scipy
.
todense
())
test_sample
[
i
,
j
]
=
0
# sort test sample by scipy
test_sample
=
scipy
.
sparse
.
csc_matrix
(
test_sample
)
sorted_for_real
=
test_sample
.
sorted_indices
()
sorted_theano
=
f
(
test_sample
)
assert
numpy
.
all
(
sorted_theano
.
todense
()
==
sorted_for_real
.
todense
())
def
test_diagonal_grad
():
def
test_diagonal_grad
():
def
d
(
x
):
def
d
(
x
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论