Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c3227a52
提交
c3227a52
authored
8月 14, 2012
作者:
Nicolas Bouchard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rewrite CastTester.
上级
b68c23d6
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
53 行增加
和
72 行删除
+53
-72
test_basic.py
theano/sparse/tests/test_basic.py
+53
-72
没有找到文件。
theano/sparse/tests/test_basic.py
浏览文件 @
c3227a52
...
@@ -1934,85 +1934,66 @@ class Test_getitem(unittest.TestCase):
...
@@ -1934,85 +1934,66 @@ class Test_getitem(unittest.TestCase):
assert
numpy
.
all
(
t1
==
r1
)
assert
numpy
.
all
(
t1
==
r1
)
class
TestCast
(
utt
.
InferShapeTester
):
class
CastTester
(
utt
.
InferShapeTester
):
compatible_types
=
(
tensor
.
int_dtypes
+
tensor
.
continuous_dtypes
)
x_csc
=
[
theano
.
sparse
.
csc_matrix
(
dtype
=
t
)
for
t
in
compatible_types
]
x_csr
=
[
theano
.
sparse
.
csr_matrix
(
dtype
=
t
)
for
t
in
compatible_types
]
indptr
=
numpy
.
array
([
0
,
2
,
3
,
6
])
indices
=
numpy
.
array
([
0
,
2
,
2
,
0
,
1
,
2
])
data
=
numpy
.
array
([
1
,
2
,
3
,
4
,
5
,
6
])
properties
=
(
data
,
indices
,
indptr
)
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestCast
,
self
)
.
setUp
()
super
(
CastTester
,
self
)
.
setUp
()
self
.
op_class
=
Cast
def
test_cast
(
self
):
def
test_cast
(
self
):
cast_csc
=
dict
([
for
format
in
sparse
.
sparse_formats
:
(
x
,
[
theano
.
function
([
x
],
x
.
astype
(
t
))
for
i_dtype
in
sparse
.
all_dtypes
:
for
t
in
self
.
compatible_types
])
for
o_dtype
in
sparse
.
all_dtypes
:
for
x
in
self
.
x_csc
])
(
variable
,
),
(
data
,
)
=
sparse_random_inputs
(
format
,
cast_csr
=
dict
([
shape
=
(
4
,
7
),
(
x
,
[
theano
.
function
([
x
],
Cast
(
t
)(
x
))
out_dtype
=
i_dtype
)
for
t
in
self
.
compatible_types
])
for
x
in
self
.
x_csr
])
cast_csr_func
=
dict
([
(
x
,
[
theano
.
function
([
x
],
cast
(
x
,
t
))
for
t
in
self
.
compatible_types
])
for
x
in
self
.
x_csr
])
for
x
in
self
.
x_csc
:
for
f
,
t
in
zip
(
cast_csc
[
x
],
self
.
compatible_types
):
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
x
.
dtype
)
.
copy
()
assert
f
(
a
)
.
dtype
==
t
for
x
in
self
.
x_csr
:
for
f
,
t
in
zip
(
cast_csr
[
x
],
self
.
compatible_types
):
a
=
sp
.
csr_matrix
(
self
.
properties
,
dtype
=
x
.
dtype
)
assert
f
(
a
)
.
dtype
==
t
for
x
in
self
.
x_csr
:
for
f
,
t
in
zip
(
cast_csr_func
[
x
],
self
.
compatible_types
):
a
=
sp
.
csr_matrix
(
self
.
properties
,
dtype
=
x
.
dtype
)
assert
f
(
a
)
.
dtype
==
t
def
test_infer_shape
(
self
):
func
=
theano
.
function
([
variable
],
cast
(
variable
,
o_dtype
))
for
x
in
self
.
x_csc
:
cls
=
theano
.
function
([
variable
],
Cast
(
o_dtype
)(
variable
))
for
t
in
self
.
compatible_types
:
prop
=
theano
.
function
([
variable
],
variable
.
astype
(
o_dtype
))
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
x
.
dtype
)
self
.
_compile_and_check
([
x
],
[
Cast
(
t
)(
x
)],
[
a
],
self
.
op_class
)
for
x
in
self
.
x_csr
:
t_func
,
t_cls
,
t_prop
=
func
(
data
),
cls
(
data
),
prop
(
data
)
for
t
in
self
.
compatible_types
:
a
=
sp
.
csr_matrix
(
self
.
properties
,
dtype
=
x
.
dtype
)
expected
=
data
.
toarray
()
.
astype
(
o_dtype
)
self
.
_compile_and_check
([
x
],
[
Cast
(
t
)(
x
)],
assert
t_func
.
format
==
format
[
a
],
assert
t_cls
.
format
==
format
self
.
op_class
)
assert
t_prop
.
format
==
format
t_func
=
t_func
.
toarray
()
t_cls
=
t_cls
.
toarray
()
t_prop
=
t_prop
.
toarray
()
assert
numpy
.
allclose
(
t_func
,
expected
)
assert
numpy
.
allclose
(
t_cls
,
expected
)
assert
numpy
.
allclose
(
t_prop
,
expected
)
def
test_infer_shape
(
self
):
for
format
in
sparse
.
sparse_formats
:
for
i_dtype
in
sparse
.
all_dtypes
:
for
o_dtype
in
sparse
.
all_dtypes
:
variable
,
data
=
sparse_random_inputs
(
format
,
shape
=
(
4
,
7
),
out_dtype
=
i_dtype
)
self
.
_compile_and_check
(
variable
,
[
Cast
(
o_dtype
)(
*
variable
)],
data
,
Cast
)
def
test_grad
(
self
):
def
test_grad
(
self
):
for
dtype
in
tensor
.
float_dtypes
:
for
format
in
sparse
.
sparse_formats
:
for
t
in
tensor
.
float_dtypes
:
for
i_dtype
in
sparse
.
float_dtypes
:
eps
=
None
for
o_dtype
in
tensor
.
float_dtypes
:
if
t
==
'float32'
:
_
,
data
=
sparse_random_inputs
(
eps
=
7e-4
format
,
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
dtype
)
shape
=
(
4
,
7
),
verify_grad_sparse
(
Cast
(
t
),
[
a
],
eps
=
eps
)
out_dtype
=
i_dtype
)
for
dtype
in
tensor
.
float_dtypes
:
eps
=
None
for
t
in
tensor
.
float_dtypes
:
if
o_dtype
==
'float32'
:
eps
=
None
eps
=
7e-4
if
t
==
'float32'
:
eps
=
7e-4
verify_grad_sparse
(
Cast
(
o_dtype
),
data
,
eps
=
eps
)
a
=
sp
.
csr_matrix
(
self
.
properties
,
dtype
=
dtype
)
verify_grad_sparse
(
Cast
(
t
),
[
a
],
eps
=
eps
)
class
_HVStackTester
(
utt
.
InferShapeTester
):
class
_HVStackTester
(
utt
.
InferShapeTester
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论