Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fd7c30ce
提交
fd7c30ce
authored
2月 15, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #445 from lamblin/fix_test_structureddot_grad
Fix perform of structureddot_grad with dense grad
上级
daf7d9c9
5820fb40
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
37 行增加
和
10 行删除
+37
-10
basic.py
theano/sparse/basic.py
+15
-10
test_basic.py
theano/sparse/tests/test_basic.py
+22
-0
没有找到文件。
theano/sparse/basic.py
浏览文件 @
fd7c30ce
...
@@ -1666,17 +1666,10 @@ def structured_dot_grad(sparse_A, dense_B, ga):
...
@@ -1666,17 +1666,10 @@ def structured_dot_grad(sparse_A, dense_B, ga):
if
sparse_A
.
type
.
format
==
'csc'
:
if
sparse_A
.
type
.
format
==
'csc'
:
sdgcsx
=
sdg_csc
sdgcsx
=
sdg_csc
else
:
sdgcsx
=
sdg_csr
#backport
#sdgcsx = sdg_csc if sparse_A.type.format == 'csc' else sdg_csr
if
sparse_A
.
type
.
format
==
'csc'
:
CSx
=
CSC
CSx
=
CSC
else
:
else
:
sdgcsx
=
sdg_csr
CSx
=
CSR
CSx
=
CSR
#backport
#CSx = CSC if sparse_A.type.format == 'csc' else CSR
g_A_data
=
sdgcsx
(
csm_indices
(
sparse_A
),
\
g_A_data
=
sdgcsx
(
csm_indices
(
sparse_A
),
\
csm_indptr
(
sparse_A
),
dense_B
,
ga
)
csm_indptr
(
sparse_A
),
dense_B
,
ga
)
...
@@ -1705,7 +1698,13 @@ class StructuredDotGradCSC(gof.Op):
...
@@ -1705,7 +1698,13 @@ class StructuredDotGradCSC(gof.Op):
ind1
=
a_indptr
[
j
+
1
]
ind1
=
a_indptr
[
j
+
1
]
for
i_idx
in
xrange
(
ind0
,
ind1
):
for
i_idx
in
xrange
(
ind0
,
ind1
):
i
=
a_indices
[
i_idx
]
i
=
a_indices
[
i_idx
]
g_a_data
[
i_idx
]
=
numpy
.
dot
(
g_ab
[
i
],
b
[
j
]
.
T
)[
0
,
0
]
# Depending on the type of g_ab and b (sparse or dense),
# the following dot product can result in a scalar or
# a (1, 1) sparse matrix.
dot_val
=
numpy
.
dot
(
g_ab
[
i
],
b
[
j
]
.
T
)
if
isinstance
(
dot_val
,
scipy
.
sparse
.
spmatrix
):
dot_val
=
dot_val
[
0
,
0
]
g_a_data
[
i_idx
]
=
dot_val
out
[
0
]
=
g_a_data
out
[
0
]
=
g_a_data
def
c_code
(
self
,
node
,
name
,
(
_indices
,
_indptr
,
_d
,
_g
),
(
_zout
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
(
_indices
,
_indptr
,
_d
,
_g
),
(
_zout
,
),
sub
):
...
@@ -1820,7 +1819,13 @@ class StructuredDotGradCSR(gof.Op):
...
@@ -1820,7 +1819,13 @@ class StructuredDotGradCSR(gof.Op):
for
j_idx
in
xrange
(
ind0
,
ind1
):
for
j_idx
in
xrange
(
ind0
,
ind1
):
j
=
a_indices
[
j_idx
]
j
=
a_indices
[
j_idx
]
# grad is dot product of i-th row of gradient with j-th row of b
# grad is dot product of i-th row of gradient with j-th row of b
g_a_data
[
j_idx
]
=
numpy
.
dot
(
g_ab
[
i
],
b
[
j
]
.
T
)[
0
,
0
]
# Depending on the type of g_ab and b (sparse or dense),
# the following dot product can result in a scalar or
# a (1, 1) sparse matrix.
dot_val
=
numpy
.
dot
(
g_ab
[
i
],
b
[
j
]
.
T
)
if
isinstance
(
dot_val
,
scipy
.
sparse
.
spmatrix
):
dot_val
=
dot_val
[
0
,
0
]
g_a_data
[
j_idx
]
=
dot_val
out
[
0
]
=
g_a_data
out
[
0
]
=
g_a_data
def
c_code
(
self
,
node
,
name
,
(
_indices
,
_indptr
,
_d
,
_g
),
(
_zout
,
),
sub
):
def
c_code
(
self
,
node
,
name
,
(
_indices
,
_indptr
,
_d
,
_g
),
(
_zout
,
),
sub
):
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
fd7c30ce
...
@@ -448,6 +448,17 @@ class test_structureddot(unittest.TestCase):
...
@@ -448,6 +448,17 @@ class test_structureddot(unittest.TestCase):
utt
.
verify_grad
(
buildgraphCSC
,
utt
.
verify_grad
(
buildgraphCSC
,
[
spmat
.
data
,
mat
])
[
spmat
.
data
,
mat
])
def
buildgraphCSC_T
(
spdata
,
sym_mat
):
csc
=
CSC
(
spdata
,
spmat
.
indices
[:
spmat
.
size
],
spmat
.
indptr
,
spmat
.
shape
)
assert
csc
.
type
.
dtype
==
'float32'
rval
=
structured_dot
(
sym_mat
.
T
,
csc
.
T
)
assert
rval
.
type
.
dtype
==
'float32'
return
rval
utt
.
verify_grad
(
buildgraphCSC_T
,
[
spmat
.
data
,
mat
])
def
test_structureddot_csr_grad
(
self
):
def
test_structureddot_csr_grad
(
self
):
#shortcut: testing csc in float32, testing csr in float64
#shortcut: testing csc in float32, testing csr in float64
...
@@ -468,6 +479,17 @@ class test_structureddot(unittest.TestCase):
...
@@ -468,6 +479,17 @@ class test_structureddot(unittest.TestCase):
utt
.
verify_grad
(
buildgraph
,
utt
.
verify_grad
(
buildgraph
,
[
spmat
.
data
,
mat
])
[
spmat
.
data
,
mat
])
def
buildgraph_T
(
spdata
,
sym_mat
):
csr
=
CSR
(
spdata
,
spmat
.
indices
[:
spmat
.
size
],
spmat
.
indptr
,
spmat
.
shape
)
assert
csr
.
type
.
dtype
==
'float64'
rval
=
structured_dot
(
sym_mat
.
T
,
csr
.
T
)
assert
rval
.
type
.
dtype
==
'float64'
return
rval
utt
.
verify_grad
(
buildgraph
,
[
spmat
.
data
,
mat
])
def
test_infer_shape_csr_csc_grad
(
self
):
def
test_infer_shape_csr_csc_grad
(
self
):
for
sparsetype
in
(
'csr'
,
'csc'
):
for
sparsetype
in
(
'csr'
,
'csc'
):
a
=
SparseType
(
sparsetype
,
dtype
=
config
.
floatX
)()
a
=
SparseType
(
sparsetype
,
dtype
=
config
.
floatX
)()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论