Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f4b3c8ad
提交
f4b3c8ad
authored
4月 20, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #605 from ynd/csm_fix
bugfix gradient of csm_properties
上级
bc0c3b4e
f1643043
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
46 行增加
和
6 行删除
+46
-6
basic.py
theano/sparse/basic.py
+1
-5
test_basic.py
theano/sparse/tests/test_basic.py
+45
-1
没有找到文件。
theano/sparse/basic.py
浏览文件 @
f4b3c8ad
...
@@ -558,14 +558,10 @@ class CSMProperties(gof.Op):
...
@@ -558,14 +558,10 @@ class CSMProperties(gof.Op):
out
[
2
][
0
]
=
theano
.
_asarray
(
csm
.
indptr
,
dtype
=
'int32'
)
out
[
2
][
0
]
=
theano
.
_asarray
(
csm
.
indptr
,
dtype
=
'int32'
)
out
[
3
][
0
]
=
theano
.
_asarray
(
csm
.
shape
,
dtype
=
'int32'
)
out
[
3
][
0
]
=
theano
.
_asarray
(
csm
.
shape
,
dtype
=
'int32'
)
# TODO FIX THIS
def
grad
(
self
,
(
csm
,),
g
):
def
grad
(
self
,
(
csm
,),
g
):
assert
[
gg
is
None
for
gg
in
g
[
1
:]]
assert
[
gg
is
None
for
gg
in
g
[
1
:]]
data
,
indices
,
indptr
,
shape
=
csm_properties
(
csm
)
data
,
indices
,
indptr
,
shape
=
csm_properties
(
csm
)
if
csm
.
format
==
'csc'
:
return
[
CSM
(
csm
.
format
)(
g
[
0
],
indices
,
indptr
,
shape
)]
return
[
CSM
(
'csc'
)(
g_data
,
indices
,
indptr
,
shape
)]
else
:
return
[
CSR
(
'csm'
)(
g_data
,
indices
,
indptr
,
shape
)]
# don't make this a function or it breaks some optimizations below
# don't make this a function or it breaks some optimizations below
csm_properties
=
CSMProperties
()
csm_properties
=
CSMProperties
()
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
f4b3c8ad
...
@@ -20,7 +20,8 @@ if enable_sparse == False:
...
@@ -20,7 +20,8 @@ if enable_sparse == False:
from
theano.sparse.basic
import
_is_dense
,
_is_sparse
,
_mtypes
from
theano.sparse.basic
import
_is_dense
,
_is_sparse
,
_mtypes
from
theano.sparse.basic
import
_is_dense_variable
,
_is_sparse_variable
from
theano.sparse.basic
import
_is_dense_variable
,
_is_sparse_variable
from
theano.sparse.basic
import
verify_grad_sparse
from
theano.sparse.basic
import
verify_grad_sparse
from
theano.sparse
import
as_sparse_variable
,
CSC
,
CSR
,
CSM
,
CSMProperties
from
theano.sparse
import
(
as_sparse_variable
,
CSC
,
CSR
,
CSM
,
CSMProperties
,
csm_properties
)
from
theano.sparse
import
SparseType
,
CSMGrad
from
theano.sparse
import
SparseType
,
CSMGrad
from
theano.sparse
import
StructuredDot
,
StructuredDotCSC
from
theano.sparse
import
StructuredDot
,
StructuredDotCSC
from
theano.sparse
import
StructuredDotGradCSC
,
StructuredDotGradCSR
from
theano.sparse
import
StructuredDotGradCSC
,
StructuredDotGradCSR
...
@@ -560,6 +561,49 @@ class T_conversion(unittest.TestCase):
...
@@ -560,6 +561,49 @@ class T_conversion(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
self
.
check_format_ndim
,
format
,
4
)
self
.
assertRaises
(
TypeError
,
self
.
check_format_ndim
,
format
,
4
)
class
test_csm_properties
(
unittest
.
TestCase
):
def
setUp
(
self
):
utt
.
seed_rng
()
def
test_csm_properties_grad
(
self
):
sp_types
=
{
'csc'
:
sp
.
csc_matrix
,
'csr'
:
sp
.
csr_matrix
}
for
format
in
[
'csc'
,
'csr'
]:
for
dtype
in
[
'float32'
,
'float64'
]:
spmat
=
sp_types
[
format
](
random_lil
((
4
,
3
),
dtype
,
3
))
verify_grad_sparse
(
lambda
*
x
:
CSMProperties
()(
*
x
)[
0
],
[
spmat
],
structured
=
True
)
verify_grad_sparse
(
lambda
*
x
:
CSMProperties
()(
*
x
)[
1
],
[
spmat
],
structured
=
True
)
verify_grad_sparse
(
lambda
*
x
:
CSMProperties
()(
*
x
)[
2
],
[
spmat
],
structured
=
True
)
verify_grad_sparse
(
lambda
*
x
:
CSMProperties
()(
*
x
)[
2
],
[
spmat
],
structured
=
True
)
def
test_csm_properties
(
self
):
sp_types
=
{
'csc'
:
sp
.
csc_matrix
,
'csr'
:
sp
.
csr_matrix
}
for
format
in
[
'csc'
,
'csr'
]:
for
dtype
in
[
'float32'
,
'float64'
]:
x
=
SparseType
(
format
,
dtype
=
dtype
)()
f
=
theano
.
function
([
x
],
csm_properties
(
x
))
spmat
=
sp_types
[
format
](
random_lil
((
4
,
3
),
dtype
,
3
))
data
,
indices
,
indptr
,
shape
=
f
(
spmat
)
assert
numpy
.
all
(
data
==
spmat
.
data
)
assert
numpy
.
all
(
indices
==
spmat
.
indices
)
assert
numpy
.
all
(
indptr
==
spmat
.
indptr
)
assert
numpy
.
all
(
shape
==
spmat
.
shape
)
class
test_structureddot
(
unittest
.
TestCase
):
class
test_structureddot
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
utt
.
seed_rng
()
utt
.
seed_rng
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论