Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0260d1b6
提交
0260d1b6
authored
8月 10, 2017
作者:
AndreiCostinescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Changed comments to docstrings where necessary in theano/sparse/tests
上级
6c5071c9
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
97 行增加
和
87 行删除
+97
-87
test_basic.py
theano/sparse/tests/test_basic.py
+97
-87
没有找到文件。
theano/sparse/tests/test_basic.py
浏览文件 @
0260d1b6
...
...
@@ -98,31 +98,30 @@ def random_lil(shape, dtype, nnz):
def
sparse_random_inputs
(
format
,
shape
,
n
=
1
,
out_dtype
=
None
,
p
=
0.5
,
gap
=
None
,
explicit_zero
=
False
,
unsorted_indices
=
False
):
# Return a tuple containing everything needed to
# perform a test.
#
# If `out_dtype` is `None`, theano.config.floatX is
# used.
#
# :param format: Sparse format.
# :param shape: Shape of data.
# :param n: Number of variable.
# :param out_dtype: dtype of output.
# :param p: Sparsity proportion.
# :param gap: Tuple for the range of the random sample. When
# length is 1, it is assumed to be the exclusive
# max, when `gap` = (`a`, `b`) it provide a sample
# from [a, b[. If `None` is used, it provide [0, 1]
# for float dtypes and [0, 50[ for integer dtypes.
# :param explicit_zero: When True, we add explicit zero in the
# returned sparse matrix
# :param unsorted_indices: when True, we make sure there is
# unsorted indices in the returned
# sparse matrix.
# :return: (variable, data) where both `variable`
# and `data` are list.
#
# :note: explicit_zero and unsorted_indices was added in Theano 0.6rc4
"""
Return a tuple containing everything needed to perform a test.
If `out_dtype` is `None`, theano.config.floatX is used.
:param format: Sparse format.
:param shape: Shape of data.
:param n: Number of variable.
:param out_dtype: dtype of output.
:param p: Sparsity proportion.
:param gap: Tuple for the range of the random sample. When
length is 1, it is assumed to be the exclusive
max, when `gap` = (`a`, `b`) it provide a sample
from [a, b[. If `None` is used, it provide [0, 1]
for float dtypes and [0, 50[ for integer dtypes.
:param explicit_zero: When True, we add explicit zero in the
returned sparse matrix
:param unsorted_indices: when True, we make sure there is
unsorted indices in the returned
sparse matrix.
:return: (variable, data) where both `variable` and `data` are list.
:note: explicit_zero and unsorted_indices was added in Theano 0.6rc4
"""
if
out_dtype
is
None
:
out_dtype
=
theano
.
config
.
floatX
...
...
@@ -182,25 +181,27 @@ def sparse_random_inputs(format, shape, n=1, out_dtype=None, p=0.5, gap=None,
def
verify_grad_sparse
(
op
,
pt
,
structured
=
False
,
*
args
,
**
kwargs
):
# Wrapper for theano.test.unittest_tools.py:verify_grad wich
# converts sparse variables back and forth.
#
# Parameters
# ----------
# op
# Op to check.
# pt
# List of inputs to realize the tests.
# structured
# True to tests with a structured grad, False otherwise.
# args
# Other `verify_grad` parameters if any.
# kwargs
# Other `verify_grad` keywords if any.
#
# Returns
# -------
# None
"""
Wrapper for theano.test.unittest_tools.py:verify_grad wich
converts sparse variables back and forth.
Parameters
----------
op
Op to check.
pt
List of inputs to realize the tests.
structured
True to tests with a structured grad, False otherwise.
args
Other `verify_grad` parameters if any.
kwargs
Other `verify_grad` keywords if any.
Returns
-------
None
"""
def
conv_none
(
x
):
return
x
...
...
@@ -1427,7 +1428,9 @@ class DotTests(utt.InferShapeTester):
class
UsmmTests
(
unittest
.
TestCase
):
# Test the Usmm and UsmmCscDense class and related optimization
"""
Test the Usmm and UsmmCscDense class and related optimization
"""
def
setUp
(
self
):
x_size
=
(
10
,
100
)
y_size
=
(
100
,
200
)
...
...
@@ -2470,8 +2473,9 @@ def _format_info(nb):
class
_HVStackTester
(
utt
.
InferShapeTester
):
# Test for both HStack and VStack.
"""
Test for both HStack and VStack.
"""
nb
=
3
# Number of sparse matrix to stack
x
,
mat
=
_format_info
(
nb
)
...
...
@@ -2517,11 +2521,13 @@ class _HVStackTester(utt.InferShapeTester):
def
_hv_switch
(
op
,
expected_function
):
# Return the right test class for HStack or VStack.
#
# :Parameters:
# - `op`: HStack or VStack class.
# - `expected_function`: function from scipy for comparaison.
"""
Return the right test class for HStack or VStack.
:Parameters:
- `op`: HStack or VStack class.
- `expected_function`: function from scipy for comparaison.
"""
class
XStackTester
(
_HVStackTester
):
op_class
=
op
...
...
@@ -2585,28 +2591,30 @@ class AddSSDataTester(utt.InferShapeTester):
def
elemwise_checker
(
op
,
expected_f
,
gap
=
None
,
test_dtypes
=
None
,
grad_test
=
True
,
name
=
None
,
gap_grad
=
None
):
# Return the appropriate test class for the elemwise on sparse.
#
# :param op: Op to test.
# :expected_f: Function use to compare. This function must act
# on dense matrix. If the op is structured
# see the `structure_function` decorator to make
# this function structured.
# :param gap: Tuple for the range of the random sample. When
# length is 1, it is assumed to be the exclusive
# max, when `gap` = (`a`, `b`) it provide a sample
# from [a, b[. If `None` is used, it provide [0, 1]
# for float dtypes and [0, 50[ for integer dtypes.
# :param test_dtypes: Particular dtypes for testing the op.
# If `None`, this is set to the most common
# dtypes.
# :param grad_test: True for testing the grad. False will
# skip this test.
# :param gap_grad: If None, we reuse gap. Otherwise it is the same as gap
# but for testing the gradiant of the op.
#
# :return: The class that perform the tests, not an instance
# of the class.
"""
Return the appropriate test class for the elemwise on sparse.
:param op: Op to test.
:expected_f: Function use to compare. This function must act
on dense matrix. If the op is structured
see the `structure_function` decorator to make
this function structured.
:param gap: Tuple for the range of the random sample. When
length is 1, it is assumed to be the exclusive
max, when `gap` = (`a`, `b`) it provide a sample
from [a, b[. If `None` is used, it provide [0, 1]
for float dtypes and [0, 50[ for integer dtypes.
:param test_dtypes: Particular dtypes for testing the op.
If `None`, this is set to the most common
dtypes.
:param grad_test: True for testing the grad. False will
skip this test.
:param gap_grad: If None, we reuse gap. Otherwise it is the same as gap
but for testing the gradiant of the op.
:return: The class that perform the tests, not an instance
of the class.
"""
if
test_dtypes
is
None
:
test_dtypes
=
sparse
.
all_dtypes
...
...
@@ -2782,19 +2790,21 @@ def test_hstack_vstack():
def
structure_function
(
f
,
index
=
0
):
# Decorator to structure a function wich
# apply on dense matrix.
#
# Here, the inputs of the function must be
# dense matrix. The sparse pattern is
# determined by finding the zeros.
#
# :param index: The index of the parameter
# from wich the function must
# be structured.
#
# :return: The structured function for its
# `index` parameter.
"""
Decorator to structure a function wich
apply on dense matrix.
Here, the inputs of the function must be
dense matrix. The sparse pattern is
determined by finding the zeros.
:param index: The index of the parameter
from wich the function must
be structured.
:return: The structured function for its
`index` parameter.
"""
def
structured_function
(
*
args
):
pattern
=
args
[
index
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论