Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
32112354
提交
32112354
authored
3月 17, 2009
作者:
desjagui@atchoum.iro.umontreal.ca
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
* Verified StructuredDotGradCSR (everything looks ok). Added more loops around
unit test just to make sure. Also changed dimensions of matrix in unit test not to be square.
上级
19239b85
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
57 行增加
和
53 行删除
+57
-53
basic.py
theano/sparse/basic.py
+1
-1
test_basic.py
theano/sparse/tests/test_basic.py
+56
-52
没有找到文件。
theano/sparse/basic.py
浏览文件 @
32112354
...
...
@@ -1193,7 +1193,7 @@ class StructuredDotGradCSR(gof.Op):
const npy_int32 * __restrict__ indptr = (npy_int32 *)
%(_indptr)
s->data;
const npy_int32 * __restrict__ indices = (npy_int32 *)
%(_indices)
s->data;
// loop over
rows
// loop over
columns of sparse matrix
for (npy_int32 i = 0; i < N; ++i)
{
// for each non-null value in the sparse row
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
32112354
...
...
@@ -153,61 +153,65 @@ class T_conversion(unittest.TestCase):
import
scipy.sparse
as
sp
class
test_structureddot
(
unittest
.
TestCase
):
def
setUp
(
self
):
unittest_tools
.
seed_rng
()
def
test_structuredot
(
self
):
bsize
=
2
spmat
=
sp
.
csc_matrix
((
5
,
5
))
spmat
[
0
,
1
]
=
1
spmat
[
0
,
2
]
=
2
spmat
[
1
,
2
]
=
3
spmat
[
1
,
4
]
=
4
spmat
[
3
,
4
]
=
5
kerns
=
tensor
.
dvector
(
'kerns'
)
images
=
tensor
.
dmatrix
(
'images'
)
##
# Test compressed-sparse column matrices ###
##
# build symbolic theano graph
def
buildgraphCSC
(
kerns
,
images
):
csc
=
CSC
(
kerns
,
spmat
.
indices
[:
spmat
.
size
],
spmat
.
indptr
,
spmat
.
shape
)
return
structured_dot
(
csc
,
images
.
T
)
out
=
buildgraphCSC
(
kerns
,
images
)
f
=
theano
.
function
([
kerns
,
images
],
out
)
# compute theano outputs
kernvals
=
spmat
.
data
[:
spmat
.
size
]
imvals
=
1.0
*
numpy
.
arange
(
bsize
*
spmat
.
shape
[
1
])
.
reshape
(
bsize
,
spmat
.
shape
[
1
])
outvals
=
f
(
kernvals
,
imvals
)
# compare to scipy
c
=
spmat
.
dot
(
imvals
.
T
)
assert
_is_dense
(
c
)
assert
numpy
.
all
(
outvals
==
c
)
tensor
.
verify_grad
(
None
,
buildgraphCSC
,
[
kernvals
,
imvals
])
##
# Test compressed-sparse row matrices ###
##
spmat
=
spmat
.
tocsr
()
# build theano graph
def
buildgraphCSR
(
kerns
,
images
):
csr
=
CSR
(
kerns
,
spmat
.
indices
[:
spmat
.
size
],
spmat
.
indptr
,
spmat
.
shape
)
return
structured_dot
(
csr
,
images
.
T
)
out
=
buildgraphCSR
(
kerns
,
images
)
f
=
theano
.
function
([
kerns
,
images
],
out
)
# compute theano output
kernvals
=
spmat
.
data
[:
spmat
.
size
]
imvals
=
1.0
*
numpy
.
arange
(
bsize
*
spmat
.
shape
[
1
])
.
reshape
(
bsize
,
spmat
.
shape
[
1
])
outvals
=
f
(
kernvals
,
imvals
)
# compare to scipy
c
=
spmat
.
dot
(
imvals
.
T
)
assert
_is_dense
(
c
)
assert
numpy
.
all
(
outvals
==
c
)
tensor
.
verify_grad
(
None
,
buildgraphCSR
,
[
kernvals
,
imvals
])
# iterate 10 times just to make sure (cannot get this wrong !)
for
i
in
range
(
10
):
spmat
=
sp
.
csc_matrix
((
4
,
6
))
for
i
in
range
(
5
):
x
=
numpy
.
floor
(
numpy
.
random
.
rand
()
*
spmat
.
shape
[
0
])
y
=
numpy
.
floor
(
numpy
.
random
.
rand
()
*
spmat
.
shape
[
1
])
spmat
[
x
,
y
]
=
numpy
.
random
.
rand
()
*
10
kerns
=
tensor
.
dvector
(
'kerns'
)
images
=
tensor
.
dmatrix
(
'images'
)
##
# Test compressed-sparse column matrices ###
##
# build symbolic theano graph
def
buildgraphCSC
(
kerns
,
images
):
csc
=
CSC
(
kerns
,
spmat
.
indices
[:
spmat
.
size
],
spmat
.
indptr
,
spmat
.
shape
)
return
structured_dot
(
csc
,
images
.
T
)
out
=
buildgraphCSC
(
kerns
,
images
)
f
=
theano
.
function
([
kerns
,
images
],
out
)
# compute theano outputs
kernvals
=
spmat
.
data
[:
spmat
.
size
]
imvals
=
1.0
*
numpy
.
arange
(
bsize
*
spmat
.
shape
[
1
])
.
reshape
(
bsize
,
spmat
.
shape
[
1
])
outvals
=
f
(
kernvals
,
imvals
)
# compare to scipy
c
=
spmat
.
dot
(
imvals
.
T
)
assert
_is_dense
(
c
)
assert
numpy
.
all
(
outvals
==
c
)
tensor
.
verify_grad
(
None
,
buildgraphCSC
,
[
kernvals
,
imvals
])
##
# Test compressed-sparse row matrices ###
##
spmat
=
spmat
.
tocsr
()
# build theano graph
def
buildgraphCSR
(
kerns
,
images
):
csr
=
CSR
(
kerns
,
spmat
.
indices
[:
spmat
.
size
],
spmat
.
indptr
,
spmat
.
shape
)
return
structured_dot
(
csr
,
images
.
T
)
out
=
buildgraphCSR
(
kerns
,
images
)
f
=
theano
.
function
([
kerns
,
images
],
out
)
# compute theano output
kernvals
=
spmat
.
data
[:
spmat
.
size
]
imvals
=
1.0
*
numpy
.
arange
(
bsize
*
spmat
.
shape
[
1
])
.
reshape
(
bsize
,
spmat
.
shape
[
1
])
outvals
=
f
(
kernvals
,
imvals
)
# compare to scipy
c
=
spmat
.
dot
(
imvals
.
T
)
assert
_is_dense
(
c
)
assert
numpy
.
all
(
outvals
==
c
)
tensor
.
verify_grad
(
None
,
buildgraphCSR
,
[
kernvals
,
imvals
])
if
__name__
==
'__main__'
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论