Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
13de103e
提交
13de103e
authored
6月 13, 2012
作者:
Nicolas Bouchard
提交者:
Frederic
7月 06, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bugs from the gradient of Cast
上级
dcc7944a
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
14 行增加
和
22 行删除
+14
-22
sp2.py
theano/sparse/sandbox/sp2.py
+3
-4
test_sp2.py
theano/sparse/tests/test_sp2.py
+11
-18
没有找到文件。
theano/sparse/sandbox/sp2.py
浏览文件 @
13de103e
...
@@ -34,8 +34,7 @@ class Cast(gof.op.Op):
...
@@ -34,8 +34,7 @@ class Cast(gof.op.Op):
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
x
=
as_sparse_variable
(
x
)
x
=
as_sparse_variable
(
x
)
return
gof
.
Apply
(
return
gof
.
Apply
(
self
,
self
,
[
x
],
[
x
],
[
SparseType
(
dtype
=
self
.
out_type
,
format
=
x
.
format
)
.
make_variable
()])
[
SparseType
(
dtype
=
self
.
out_type
,
format
=
x
.
format
)
.
make_variable
()])
def
perform
(
self
,
node
,
(
x
,
),
(
out
,
)):
def
perform
(
self
,
node
,
(
x
,
),
(
out
,
)):
...
@@ -45,7 +44,7 @@ class Cast(gof.op.Op):
...
@@ -45,7 +44,7 @@ class Cast(gof.op.Op):
def
grad
(
self
,
inputs
,
outputs_gradients
):
def
grad
(
self
,
inputs
,
outputs_gradients
):
if
inputs
[
0
]
.
dtype
in
T
.
continuous_dtypes
:
if
inputs
[
0
]
.
dtype
in
T
.
continuous_dtypes
:
gz
=
outputs_gradients
[
0
]
gz
=
outputs_gradients
[
0
]
return
[
Cast
(
self
.
out_
type
)(
gz
)]
return
[
Cast
(
inputs
[
0
]
.
d
type
)(
gz
)]
else
:
else
:
return
[
None
]
return
[
None
]
...
@@ -56,7 +55,7 @@ class Cast(gof.op.Op):
...
@@ -56,7 +55,7 @@ class Cast(gof.op.Op):
return
self
.
__class__
.
__name__
return
self
.
__class__
.
__name__
def
astype
(
x
,
t
):
def
cast
(
x
,
t
):
"""Cast sparse variable `x` to the desired dtype `t`.
"""Cast sparse variable `x` to the desired dtype `t`.
This wrap the method astype from scipy.
This wrap the method astype from scipy.
...
...
theano/sparse/tests/test_sp2.py
浏览文件 @
13de103e
...
@@ -66,12 +66,12 @@ class TestCast(utt.InferShapeTester):
...
@@ -66,12 +66,12 @@ class TestCast(utt.InferShapeTester):
def
test_cast
(
self
):
def
test_cast
(
self
):
cast_csc
=
dict
([
cast_csc
=
dict
([
(
x
,
[
theano
.
function
([
x
],
S2
.
astype
(
x
,
t
))
(
x
,
[
theano
.
function
([
x
],
S2
.
Cast
(
t
)(
x
))
for
t
in
self
.
compatible_types
])
for
t
in
self
.
compatible_types
])
for
x
in
self
.
x_csc
])
for
x
in
self
.
x_csc
])
cast_csr
=
dict
([
cast_csr
=
dict
([
(
x
,
[
theano
.
function
([
x
],
S2
.
astype
(
x
,
t
))
(
x
,
[
theano
.
function
([
x
],
S2
.
Cast
(
t
)(
x
))
for
t
in
self
.
compatible_types
])
for
t
in
self
.
compatible_types
])
for
x
in
self
.
x_csr
])
for
x
in
self
.
x_csr
])
...
@@ -90,7 +90,7 @@ class TestCast(utt.InferShapeTester):
...
@@ -90,7 +90,7 @@ class TestCast(utt.InferShapeTester):
for
t
in
self
.
compatible_types
:
for
t
in
self
.
compatible_types
:
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
x
.
dtype
)
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
x
.
dtype
)
self
.
_compile_and_check
([
x
],
self
.
_compile_and_check
([
x
],
[
S2
.
astype
(
x
,
t
)],
[
S2
.
Cast
(
t
)(
x
)],
[
a
],
[
a
],
self
.
op_class
)
self
.
op_class
)
...
@@ -98,25 +98,18 @@ class TestCast(utt.InferShapeTester):
...
@@ -98,25 +98,18 @@ class TestCast(utt.InferShapeTester):
for
t
in
self
.
compatible_types
:
for
t
in
self
.
compatible_types
:
a
=
sp
.
csr_matrix
(
self
.
properties
,
dtype
=
x
.
dtype
)
a
=
sp
.
csr_matrix
(
self
.
properties
,
dtype
=
x
.
dtype
)
self
.
_compile_and_check
([
x
],
self
.
_compile_and_check
([
x
],
[
S2
.
astype
(
x
,
t
)],
[
S2
.
Cast
(
t
)(
x
)],
[
a
],
[
a
],
self
.
op_class
)
self
.
op_class
)
def
test_grad
(
self
):
def
test_grad
(
self
):
x_csc
=
[
S
.
csc_matrix
(
dtype
=
t
)
for
t
in
T
.
float_dtypes
]
for
dtype
in
T
.
float_dtypes
:
x_csr
=
[
S
.
csr_matrix
(
dtype
=
t
)
for
t
in
T
.
float_dtypes
]
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
dtype
)
verify_grad_sparse
(
S2
.
Cast
(
'float64'
),
[
a
])
# There is a problem with the grad
# TODO Find the problem
for
dtype
in
T
.
float_dtypes
:
# for x in x_csc:
a
=
sp
.
csr_matrix
(
self
.
properties
,
dtype
=
dtype
)
# for t in T.float_dtypes:
verify_grad_sparse
(
S2
.
Cast
(
'float64'
),
[
a
])
# a = sp.csc_matrix(self.properties, dtype=x.dtype)
# verify_grad_sparse(S2.Cast(t), [a])
# for x in x_csr:
# for t in T.float_dtypes:
# a = sp.csr_matrix(self.properties, dtype=x.dtype)
# verify_grad_sparse(S2.Cast(t), [a])
class
test_structured_add_s_v
(
unittest
.
TestCase
):
class
test_structured_add_s_v
(
unittest
.
TestCase
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论