Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dbf6d673
提交
dbf6d673
authored
5月 14, 2014
作者:
Hengjean
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added le, lt, ge, gt and associated test cases
上级
bd65bb19
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
466 行增加
和
168 行删除
+466
-168
basic.py
theano/sparse/basic.py
+255
-90
test_basic.py
theano/sparse/tests/test_basic.py
+211
-78
没有找到文件。
theano/sparse/basic.py
浏览文件 @
dbf6d673
...
@@ -287,16 +287,16 @@ class _sparse_py_operators:
...
@@ -287,16 +287,16 @@ class _sparse_py_operators:
# comparison operators
# comparison operators
def
__lt__
(
self
,
other
):
def
__lt__
(
self
,
other
):
pass
return
lt
(
self
,
other
)
def
__le__
(
self
,
other
):
def
__le__
(
self
,
other
):
pass
return
le
(
self
,
other
)
def
__gt__
(
self
,
other
):
def
__gt__
(
self
,
other
):
pass
return
gt
(
self
,
other
)
def
__ge__
(
self
,
other
):
def
__ge__
(
self
,
other
):
pass
return
ge
(
self
,
other
)
# extra pseudo-operator symbols
# extra pseudo-operator symbols
...
@@ -351,7 +351,7 @@ class _sparse_py_operators:
...
@@ -351,7 +351,7 @@ class _sparse_py_operators:
return
ret
return
ret
class
SparseVariable
(
gof
.
Variable
,
_sparse_py_operators
):
class
SparseVariable
(
_sparse_py_operators
,
gof
.
Variable
):
dtype
=
property
(
lambda
self
:
self
.
type
.
dtype
)
dtype
=
property
(
lambda
self
:
self
.
type
.
dtype
)
format
=
property
(
lambda
self
:
self
.
type
.
format
)
format
=
property
(
lambda
self
:
self
.
type
.
format
)
...
@@ -2163,15 +2163,22 @@ def mul(x, y):
...
@@ -2163,15 +2163,22 @@ def mul(x, y):
raise
NotImplementedError
()
raise
NotImplementedError
()
class
Equal
SS
(
gof
.
op
.
Op
):
class
__ComparisonOp
SS
(
gof
.
op
.
Op
):
"""
"""
Used as a superclass for all comparisons between
two sparses matrices
:param x:first compared sparse matrix
:param x:first compared sparse matrix
:param y:second compared sparse matrix
:param y:second compared sparse matrix
:return:
x==y
:return:
Comparison(x,y)
"""
"""
#Function to override
def
comparison
(
self
,
x
,
y
):
return
x
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
))
return
(
type
(
self
)
==
type
(
other
))
...
@@ -2192,7 +2199,7 @@ class EqualSS(gof.op.Op):
...
@@ -2192,7 +2199,7 @@ class EqualSS(gof.op.Op):
def
perform
(
self
,
node
,
(
x
,
y
),
(
out
,
)):
def
perform
(
self
,
node
,
(
x
,
y
),
(
out
,
)):
assert
_is_sparse
(
x
)
and
_is_sparse
(
y
)
assert
_is_sparse
(
x
)
and
_is_sparse
(
y
)
assert
x
.
shape
==
y
.
shape
assert
x
.
shape
==
y
.
shape
out
[
0
]
=
(
x
==
y
)
.
astype
(
'uint8'
)
out
[
0
]
=
self
.
comparison
(
x
,
y
)
.
astype
(
'uint8'
)
def
infer_shape
(
self
,
node
,
ins_shapes
):
def
infer_shape
(
self
,
node
,
ins_shapes
):
return
[
ins_shapes
[
0
]]
return
[
ins_shapes
[
0
]]
...
@@ -2200,18 +2207,23 @@ class EqualSS(gof.op.Op):
...
@@ -2200,18 +2207,23 @@ class EqualSS(gof.op.Op):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
__class__
.
__name__
return
self
.
__class__
.
__name__
equal_s_s
=
EqualSS
()
class
Equal
SD
(
gof
.
op
.
Op
):
class
__ComparisonOp
SD
(
gof
.
op
.
Op
):
"""
"""
Used as a superclass for all comparisons between
sparse and dense matrix
:param x:sparse matrix
:param x:sparse matrix
:param y:dense matrix
:param y:dense matrix
:return:
x==y
:return:
Comparison(x,y)
"""
"""
#Function to override
def
comparison
(
self
,
x
,
y
):
return
x
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
))
return
(
type
(
self
)
==
type
(
other
))
...
@@ -2231,7 +2243,7 @@ class EqualSD(gof.op.Op):
...
@@ -2231,7 +2243,7 @@ class EqualSD(gof.op.Op):
assert
_is_sparse
(
x
)
assert
_is_sparse
(
x
)
assert
x
.
shape
==
y
.
shape
assert
x
.
shape
==
y
.
shape
assert
_is_dense
(
y
)
assert
_is_dense
(
y
)
out
[
0
]
=
(
x
==
y
)
.
astype
(
'uint8'
)
out
[
0
]
=
self
.
comparison
(
x
,
y
)
.
astype
(
'uint8'
)
def
infer_shape
(
self
,
node
,
ins_shapes
):
def
infer_shape
(
self
,
node
,
ins_shapes
):
return
[
ins_shapes
[
0
]]
return
[
ins_shapes
[
0
]]
...
@@ -2239,19 +2251,20 @@ class EqualSD(gof.op.Op):
...
@@ -2239,19 +2251,20 @@ class EqualSD(gof.op.Op):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
__class__
.
__name__
return
self
.
__class__
.
__name__
equal_s_d
=
EqualSD
()
def
__ComparisonSwitch
(
SS
,
SD
,
DS
):
def
eq
(
x
,
y
):
"""
"""
:param x: A matrix variable.
:param SS: function to apply between two sparses matrices.
:param y: A matrix variable.
:param SD: function to apply between a sparse and a dense matrix.
:param DS: function to apply between a dense and a sparse matrix.
:return:
`x` == `y`
:return:
switch function taking two matrices as input
:note: At least one of `x` and `y` must be a sparse matrix.
:note: At least one of `x` and `y` must be a sparse matrix.
"""
"""
def
helper
(
x
,
y
):
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
assert
scipy_ver
>=
[
0
,
14
]
assert
scipy_ver
>=
[
0
,
14
]
...
@@ -2270,16 +2283,18 @@ def eq(x, y):
...
@@ -2270,16 +2283,18 @@ def eq(x, y):
assert
x_is_sparse_variable
or
y_is_sparse_variable
assert
x_is_sparse_variable
or
y_is_sparse_variable
if
x_is_sparse_variable
and
y_is_sparse_variable
:
if
x_is_sparse_variable
and
y_is_sparse_variable
:
return
equal_s_s
(
x
,
y
)
return
SS
(
x
,
y
)
elif
x_is_sparse_variable
and
not
y_is_sparse_variable
:
elif
x_is_sparse_variable
and
not
y_is_sparse_variable
:
return
equal_s_d
(
x
,
y
)
return
SD
(
x
,
y
)
elif
y_is_sparse_variable
and
not
x_is_sparse_variable
:
elif
y_is_sparse_variable
and
not
x_is_sparse_variable
:
return
equal_s_d
(
y
,
x
)
return
DS
(
y
,
x
)
else
:
else
:
raise
NotImplementedError
()
raise
NotImplementedError
()
return
helper
class
NotEqualSS
(
gof
.
op
.
Op
):
class
EqualSS
(
__ComparisonOpSS
):
"""
"""
:param x:first compared sparse matrix
:param x:first compared sparse matrix
...
@@ -2288,72 +2303,68 @@ class NotEqualSS(gof.op.Op):
...
@@ -2288,72 +2303,68 @@ class NotEqualSS(gof.op.Op):
:return: x==y
:return: x==y
"""
"""
def
__eq__
(
self
,
other
):
def
comparison
(
self
,
x
,
y
):
return
(
type
(
self
)
==
type
(
other
))
return
x
==
y
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
make_node
(
self
,
x
,
y
):
equal_s_s
=
EqualSS
()
x
=
as_sparse_variable
(
x
)
y
=
as_sparse_variable
(
y
)
if
x
.
type
.
format
!=
y
.
type
.
format
:
raise
NotImplementedError
()
return
gof
.
Apply
(
self
,
[
x
,
y
],
[
SparseType
(
dtype
=
'uint8'
,
format
=
x
.
type
.
format
)
.
make_variable
()])
def
perform
(
self
,
node
,
(
x
,
y
),
(
out
,
)):
class
EqualSD
(
__ComparisonOpSD
):
assert
_is_sparse
(
x
)
and
_is_sparse
(
y
)
assert
x
.
shape
==
y
.
shape
out
[
0
]
=
(
x
!=
y
)
.
astype
(
'uint8'
)
def
infer_shape
(
self
,
node
,
ins_shapes
):
"""
return
[
ins_shapes
[
0
]]
:param x:sparse matrix
:param y:dense matrix
def
__str__
(
self
):
:return: x==y
return
self
.
__class__
.
__name__
"""
not_equal_s_s
=
NotEqualSS
()
def
comparison
(
self
,
x
,
y
):
return
x
==
y
equal_s_d
=
EqualSD
()
class
NotEqualSD
(
gof
.
op
.
Op
):
def
eq
(
x
,
y
):
"""
"""
:param x:
sparse matrix
:param x:
A matrix variable.
:param y:
dense matrix
:param y:
A matrix variable.
:return: x==y
:return: `x` == `y`
:note: At least one of `x` and `y` must be a sparse matrix.
"""
"""
def
__eq__
(
self
,
other
):
fE
=
__ComparisonSwitch
(
equal_s_s
,
equal_s_d
,
equal_s_d
)
return
(
type
(
self
)
==
type
(
other
)
)
return
fE
(
x
,
y
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
make_node
(
self
,
x
,
y
):
class
NotEqualSS
(
__ComparisonOpSS
):
x
,
y
=
as_sparse_variable
(
x
),
tensor
.
as_tensor_variable
(
y
)
assert
y
.
type
.
ndim
==
2
"""
return
gof
.
Apply
(
self
,
:param x:first compared sparse matrix
[
x
,
y
],
:param y:second compared sparse matrix
[
SparseType
(
dtype
=
'uint8'
,
format
=
x
.
type
.
format
)
.
make_variable
()])
def
perform
(
self
,
node
,
(
x
,
y
),
(
out
,
)):
:return: x!=y
assert
_is_sparse
(
x
)
"""
assert
x
.
shape
==
y
.
shape
assert
_is_dense
(
y
)
out
[
0
]
=
(
x
!=
y
)
.
astype
(
'uint8'
)
def
infer_shape
(
self
,
node
,
ins_shapes
):
def
comparison
(
self
,
x
,
y
):
return
[
ins_shapes
[
0
]]
return
x
!=
y
def
__str__
(
self
):
not_equal_s_s
=
NotEqualSS
()
return
self
.
__class__
.
__name__
class
NotEqualSD
(
__ComparisonOpSD
):
"""
:param x:sparse matrix
:param y:dense matrix
:return: x!=y
"""
def
comparison
(
self
,
x
,
y
):
return
x
!=
y
not_equal_s_d
=
NotEqualSD
()
not_equal_s_d
=
NotEqualSD
()
...
@@ -2368,31 +2379,185 @@ def neq(x, y):
...
@@ -2368,31 +2379,185 @@ def neq(x, y):
:note: At least one of `x` and `y` must be a sparse matrix.
:note: At least one of `x` and `y` must be a sparse matrix.
"""
"""
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
fNE
=
__ComparisonSwitch
(
not_equal_s_s
,
not_equal_s_d
,
not_equal_s_d
)
return
fNE
(
x
,
y
)
assert
scipy_ver
>=
[
0
,
14
]
if
hasattr
(
x
,
'getnnz'
):
class
LessThanSS
(
__ComparisonOpSS
):
x
=
as_sparse_variable
(
x
)
if
hasattr
(
y
,
'getnnz'
):
y
=
as_sparse_variable
(
y
)
if
not
isinstance
(
x
,
theano
.
Variable
):
x
=
theano
.
tensor
.
as_tensor_variable
(
x
)
if
not
isinstance
(
y
,
theano
.
Variable
):
y
=
theano
.
tensor
.
as_tensor_variable
(
y
)
x_is_sparse_variable
=
_is_sparse_variable
(
x
)
"""
y_is_sparse_variable
=
_is_sparse_variable
(
y
)
:param x:first compared sparse matrix
:param y:second compared sparse matrix
assert
x_is_sparse_variable
or
y_is_sparse_variable
:return: x<y
if
x_is_sparse_variable
and
y_is_sparse_variable
:
"""
return
not_equal_s_s
(
x
,
y
)
elif
x_is_sparse_variable
and
not
y_is_sparse_variable
:
def
comparison
(
self
,
x
,
y
):
return
not_equal_s_d
(
x
,
y
)
return
x
<
y
elif
y_is_sparse_variable
and
not
x_is_sparse_variable
:
return
not_equal_s_d
(
y
,
x
)
less_than_s_s
=
LessThanSS
()
else
:
raise
NotImplementedError
()
class
LessThanSD
(
__ComparisonOpSD
):
"""
:param x:sparse matrix
:param y:dense matrix
:return: x<y
"""
def
comparison
(
self
,
x
,
y
):
return
x
<
y
less_than_s_d
=
LessThanSD
()
def
lt
(
x
,
y
):
"""
:param x: A matrix variable.
:param y: A matrix variable.
:return: `x` < `y`
:note: At least one of `x` and `y` must be a sparse matrix.
"""
fL
=
__ComparisonSwitch
(
less_than_s_s
,
less_than_s_d
,
greater_than_s_d
)
return
fL
(
x
,
y
)
class
GreaterThanSS
(
__ComparisonOpSS
):
"""
:param x:first compared sparse matrix
:param y:second compared sparse matrix
:return: x>y
"""
def
comparison
(
self
,
x
,
y
):
return
x
>
y
greater_than_s_s
=
GreaterThanSS
()
class
GreaterThanSD
(
__ComparisonOpSD
):
"""
:param x:sparse matrix
:param y:dense matrix
:return: x>y
"""
def
comparison
(
self
,
x
,
y
):
return
x
>
y
greater_than_s_d
=
GreaterThanSD
()
def
gt
(
x
,
y
):
"""
:param x: A matrix variable.
:param y: A matrix variable.
:return: `x` > `y`
:note: At least one of `x` and `y` must be a sparse matrix.
"""
fG
=
__ComparisonSwitch
(
greater_than_s_s
,
greater_than_s_d
,
less_than_s_d
)
return
fG
(
x
,
y
)
class
LessEqualSS
(
__ComparisonOpSS
):
"""
:param x:first compared sparse matrix
:param y:second compared sparse matrix
:return: x>y
"""
def
comparison
(
self
,
x
,
y
):
return
x
<=
y
less_equal_s_s
=
LessEqualSS
()
class
LessEqualSD
(
__ComparisonOpSD
):
"""
:param x:sparse matrix
:param y:dense matrix
:return: x>y
"""
def
comparison
(
self
,
x
,
y
):
return
x
<=
y
less_equal_s_d
=
LessEqualSD
()
def
le
(
x
,
y
):
"""
:param x: A matrix variable.
:param y: A matrix variable.
:return: `x` >= `y`
:note: At least one of `x` and `y` must be a sparse matrix.
"""
fLE
=
__ComparisonSwitch
(
less_equal_s_s
,
less_equal_s_d
,
greater_equal_s_d
)
return
fLE
(
x
,
y
)
class
GreaterEqualSS
(
__ComparisonOpSS
):
"""
:param x:first compared sparse matrix
:param y:second compared sparse matrix
:return: x>y
"""
def
comparison
(
self
,
x
,
y
):
return
x
>=
y
greater_equal_s_s
=
GreaterEqualSS
()
class
GreaterEqualSD
(
__ComparisonOpSD
):
"""
:param x:sparse matrix
:param y:dense matrix
:return: x>y
"""
def
comparison
(
self
,
x
,
y
):
return
x
>=
y
greater_equal_s_d
=
GreaterEqualSD
()
def
ge
(
x
,
y
):
"""
:param x: A matrix variable.
:param y: A matrix variable.
:return: `x` >= `y`
:note: At least one of `x` and `y` must be a sparse matrix.
"""
fGE
=
__ComparisonSwitch
(
greater_equal_s_s
,
greater_equal_s_d
,
less_equal_s_d
)
return
fGE
(
x
,
y
)
class
HStack
(
gof
.
op
.
Op
):
class
HStack
(
gof
.
op
.
Op
):
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
dbf6d673
...
@@ -40,7 +40,7 @@ from theano.sparse import (
...
@@ -40,7 +40,7 @@ from theano.sparse import (
Diag
,
diag
,
SquareDiagonal
,
square_diagonal
,
Diag
,
diag
,
SquareDiagonal
,
square_diagonal
,
EnsureSortedIndices
,
ensure_sorted_indices
,
clean
,
EnsureSortedIndices
,
ensure_sorted_indices
,
clean
,
ConstructSparseFromList
,
construct_sparse_from_list
,
ConstructSparseFromList
,
construct_sparse_from_list
,
TrueDot
,
true_dot
,
eq
,
neq
)
TrueDot
,
true_dot
,
eq
,
neq
,
le
,
ge
,
gt
,
lt
)
# Probability distributions are currently tested in test_sp2.py
# Probability distributions are currently tested in test_sp2.py
#from theano.sparse import (
#from theano.sparse import (
...
@@ -656,157 +656,290 @@ class test_comparison(unittest.TestCase):
...
@@ -656,157 +656,290 @@ class test_comparison(unittest.TestCase):
return
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
)
*
(
max
-
min
)
+
min
,
return
numpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
)
*
(
max
-
min
)
+
min
,
dtype
=
config
.
floatX
)
dtype
=
config
.
floatX
)
def
test_equalss_csr
(
self
):
def
__generalized_ss_test
(
self
,
theanop
,
symbolicType
,
testOp
,
scipyType
):
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
if
(
bool
(
scipy_ver
<
[
0
,
14
])):
if
(
bool
(
scipy_ver
<
[
0
,
14
])):
raise
SkipTest
(
"comparison operators need newer release of scipy"
)
raise
SkipTest
(
"comparison operators need newer release of scipy"
)
x
=
s
parse
.
csr_matrix
()
x
=
s
ymbolicType
()
y
=
s
parse
.
csr_matrix
()
y
=
s
ymbolicType
()
equality
=
eq
(
x
,
y
)
op
=
theanop
(
x
,
y
)
f
=
theano
.
function
([
x
,
y
],
equality
)
f
=
theano
.
function
([
x
,
y
],
op
)
m1
=
s
p
.
csr_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
m1
=
s
cipyType
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
m2
=
s
p
.
csr_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
m2
=
s
cipyType
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
self
.
assertTrue
(
numpy
.
array_equal
(
f
(
m1
,
m2
)
.
data
,
(
m1
==
m2
)
.
data
))
self
.
assertTrue
(
numpy
.
array_equal
(
f
(
m1
,
m2
)
.
data
,
testOp
(
m1
,
m2
)
.
data
))
def
test_equalss_csc
(
self
):
def
__generalized_sd_test
(
self
,
theanop
,
symbolicType
,
testOp
,
scipyType
):
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
if
(
bool
(
scipy_ver
<
[
0
,
14
])):
if
(
bool
(
scipy_ver
<
[
0
,
14
])):
raise
SkipTest
(
"comparison operators need newer release of scipy"
)
raise
SkipTest
(
"comparison operators need newer release of scipy"
)
x
=
s
parse
.
csc_matrix
()
x
=
s
ymbolicType
()
y
=
sparse
.
csc_
matrix
()
y
=
theano
.
tensor
.
matrix
()
equality
=
eq
(
x
,
y
)
op
=
theanop
(
x
,
y
)
f
=
theano
.
function
([
x
,
y
],
equality
)
f
=
theano
.
function
([
x
,
y
],
op
)
m1
=
s
p
.
csc_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
m1
=
s
cipyType
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
m2
=
s
p
.
csc_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
)
)
m2
=
s
elf
.
_rand_ranged
(
1000
,
-
1000
,
[
10
,
40
]
)
self
.
assertTrue
(
numpy
.
array_equal
(
f
(
m1
,
m2
)
.
data
,
(
m1
==
m2
)
.
data
))
self
.
assertTrue
(
numpy
.
array_equal
(
f
(
m1
,
m2
)
.
data
,
testOp
(
m1
,
m2
)
.
data
))
def
test_not_equalss_csr
(
self
):
def
__generalized_ds_test
(
self
,
theanop
,
symbolicType
,
testOp
,
scipyType
):
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
if
(
bool
(
scipy_ver
<
[
0
,
14
])):
if
(
bool
(
scipy_ver
<
[
0
,
14
])):
raise
SkipTest
(
"comparison operators need newer release of scipy"
)
raise
SkipTest
(
"comparison operators need newer release of scipy"
)
x
=
sparse
.
csr_matrix
()
x
=
symbolicType
()
y
=
sparse
.
csr_matrix
()
y
=
theano
.
tensor
.
matrix
()
op
=
theanop
(
y
,
x
)
f
=
theano
.
function
([
y
,
x
],
op
)
m1
=
scipyType
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
m2
=
self
.
_rand_ranged
(
1000
,
-
1000
,
[
10
,
40
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
(
m2
,
m1
)
.
data
,
testOp
(
m2
,
m1
)
.
data
))
def
test_equalss_csr
(
self
):
self
.
__generalized_ss_test
(
eq
,
sparse
.
csr_matrix
,
lambda
x
,
y
:
x
==
y
,
sp
.
csr_matrix
)
unequality
=
neq
(
x
,
y
)
def
test_equalss_csc
(
self
):
f
=
theano
.
function
([
x
,
y
],
unequality
)
self
.
__generalized_ss_test
(
eq
,
sparse
.
csc_matrix
,
lambda
x
,
y
:
x
==
y
,
sp
.
csc_matrix
)
m1
=
sp
.
csr_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
def
test_not_equalss_csr
(
self
):
m2
=
sp
.
csr_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
self
.
assertTrue
(
numpy
.
array_equal
(
f
(
m1
,
m2
)
.
data
,
(
m1
!=
m2
)
.
data
))
self
.
__generalized_ss_test
(
neq
,
sparse
.
csr_matrix
,
lambda
x
,
y
:
x
!=
y
,
sp
.
csr_matrix
)
def
test_not_equalss_csc
(
self
):
def
test_not_equalss_csc
(
self
):
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
self
.
__generalized_ss_test
(
neq
,
sparse
.
csc_matrix
,
lambda
x
,
y
:
x
!=
y
,
sp
.
csc_matrix
)
if
(
bool
(
scipy_ver
<
[
0
,
14
])):
def
test_less_equalss_csr
(
self
):
raise
SkipTest
(
"comparison operators need newer release of scipy"
)
x
=
sparse
.
csc_matrix
()
opT
=
lambda
x
,
y
:
x
<=
y
y
=
sparse
.
csc_matrix
()
unequality
=
neq
(
x
,
y
)
self
.
__generalized_ss_test
(
le
,
sparse
.
csr_matrix
,
opT
,
sp
.
csr_matrix
)
f
=
theano
.
function
([
x
,
y
],
unequality
)
def
test_less_equalss_csc
(
self
):
m1
=
sp
.
csc_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
opT
=
lambda
x
,
y
:
x
<=
y
m2
=
sp
.
csc_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
self
.
assertTrue
(
numpy
.
array_equal
(
f
(
m1
,
m2
)
.
data
,
(
m1
!=
m2
)
.
data
))
self
.
__generalized_ss_test
(
le
,
sparse
.
csc_matrix
,
opT
,
sp
.
csc_matrix
)
def
test_
equalsd
_csr
(
self
):
def
test_
less_thanss
_csr
(
self
):
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
opT
=
lambda
x
,
y
:
x
<
y
if
(
bool
(
scipy_ver
<
[
0
,
14
])):
self
.
__generalized_ss_test
(
opT
,
sparse
.
csr_matrix
,
raise
SkipTest
(
"comparison operators need newer release of scipy"
)
opT
,
sp
.
csr_matrix
)
x
=
sparse
.
csr_matrix
()
def
test_less_thanss_csc
(
self
):
y
=
theano
.
tensor
.
matrix
()
equality
=
eq
(
x
,
y
)
opT
=
lambda
x
,
y
:
x
<
y
f
=
theano
.
function
([
x
,
y
],
equality
)
self
.
__generalized_ss_test
(
opT
,
sparse
.
csc_matrix
,
opT
,
sp
.
csc_matrix
)
m1
=
sp
.
csr_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
def
test_greater_equalss_csr
(
self
):
m2
=
self
.
_rand_ranged
(
1000
,
-
1000
,
[
10
,
40
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
(
m1
,
m2
)
.
data
,
(
m1
==
m2
)
.
data
))
opT
=
lambda
x
,
y
:
x
>=
y
def
test_equalsd_csc
(
self
):
self
.
__generalized_ss_test
(
opT
,
sparse
.
csr_matrix
,
opT
,
sp
.
csr_matrix
)
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
def
test_greater_equalss_csc
(
self
):
if
(
bool
(
scipy_ver
<
[
0
,
14
])):
opT
=
lambda
x
,
y
:
x
>=
y
raise
SkipTest
(
"comparison operators need newer release of scipy"
)
x
=
sparse
.
csc_matrix
()
self
.
__generalized_ss_test
(
opT
,
sparse
.
csc_matrix
,
y
=
theano
.
tensor
.
matrix
(
)
opT
,
sp
.
csc_matrix
)
equality
=
eq
(
x
,
y
)
def
test_greater_thanss_csr
(
self
):
f
=
theano
.
function
([
x
,
y
],
equality
)
opT
=
lambda
x
,
y
:
x
>
y
m1
=
sp
.
csc_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
self
.
__generalized_ss_test
(
opT
,
sparse
.
csr_matrix
,
m2
=
self
.
_rand_ranged
(
1000
,
-
1000
,
[
10
,
40
]
)
opT
,
sp
.
csr_matrix
)
self
.
assertTrue
(
numpy
.
array_equal
(
f
(
m1
,
m2
)
.
data
,
(
m1
==
m2
)
.
data
))
def
test_greater_thanss_csc
(
self
):
def
test_not_equalsd_csr
(
self
):
opT
=
lambda
x
,
y
:
x
>
y
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
self
.
__generalized_ss_test
(
opT
,
sparse
.
csc_matrix
,
opT
,
sp
.
csc_matrix
)
if
(
bool
(
scipy_ver
<
[
0
,
14
])):
def
test_equalsd_csr
(
self
):
raise
SkipTest
(
"comparison operators need newer release of scipy"
)
x
=
sparse
.
csr_matrix
()
self
.
__generalized_sd_test
(
eq
,
sparse
.
csr_matrix
,
y
=
theano
.
tensor
.
matrix
(
)
lambda
x
,
y
:
x
==
y
,
sp
.
csr_matrix
)
unequality
=
neq
(
x
,
y
)
def
test_equalsd_csc
(
self
):
f
=
theano
.
function
([
x
,
y
],
unequality
)
self
.
__generalized_sd_test
(
eq
,
sparse
.
csc_matrix
,
lambda
x
,
y
:
x
==
y
,
sp
.
csc_matrix
)
m1
=
sp
.
csr_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
def
test_not_equalsd_csr
(
self
):
m2
=
self
.
_rand_ranged
(
1000
,
-
1000
,
[
10
,
40
])
self
.
assertTrue
(
numpy
.
array_equal
(
f
(
m1
,
m2
)
.
data
,
(
m1
!=
m2
)
.
data
))
self
.
__generalized_sd_test
(
neq
,
sparse
.
csr_matrix
,
lambda
x
,
y
:
x
!=
y
,
sp
.
csr_matrix
)
def
test_not_equalsd_csc
(
self
):
def
test_not_equalsd_csc
(
self
):
scipy_ver
=
[
int
(
n
)
for
n
in
scipy
.
__version__
.
split
(
'.'
)[:
2
]]
self
.
__generalized_sd_test
(
neq
,
sparse
.
csc_matrix
,
lambda
x
,
y
:
x
!=
y
,
sp
.
csc_matrix
)
if
(
bool
(
scipy_ver
<
[
0
,
14
])):
def
test_less_equalsd_csr
(
self
):
raise
SkipTest
(
"comparison operators need newer release of scipy"
)
x
=
sparse
.
csc_matrix
()
opT
=
lambda
x
,
y
:
x
<=
y
y
=
theano
.
tensor
.
matrix
()
unequality
=
neq
(
x
,
y
)
self
.
__generalized_sd_test
(
le
,
sparse
.
csr_matrix
,
opT
,
sp
.
csr_matrix
)
f
=
theano
.
function
([
x
,
y
],
unequality
)
def
test_less_equalsd_csc
(
self
):
m1
=
sp
.
csc_matrix
(
random_lil
((
10
,
40
),
config
.
floatX
,
3
))
opT
=
lambda
x
,
y
:
x
<=
y
m2
=
self
.
_rand_ranged
(
1000
,
-
1000
,
[
10
,
40
])
self
.
__generalized_sd_test
(
le
,
sparse
.
csc_matrix
,
opT
,
sp
.
csc_matrix
)
def
test_less_thansd_csr
(
self
):
opT
=
lambda
x
,
y
:
x
<
y
self
.
__generalized_sd_test
(
opT
,
sparse
.
csr_matrix
,
opT
,
sp
.
csr_matrix
)
def
test_less_thansd_csc
(
self
):
opT
=
lambda
x
,
y
:
x
<
y
self
.
__generalized_sd_test
(
opT
,
sparse
.
csc_matrix
,
opT
,
sp
.
csc_matrix
)
def
test_greater_equalsd_csr
(
self
):
opT
=
lambda
x
,
y
:
x
>=
y
self
.
__generalized_sd_test
(
opT
,
sparse
.
csr_matrix
,
opT
,
sp
.
csr_matrix
)
def
test_greater_equalsd_csc
(
self
):
opT
=
lambda
x
,
y
:
x
>=
y
self
.
__generalized_sd_test
(
opT
,
sparse
.
csc_matrix
,
opT
,
sp
.
csc_matrix
)
def
test_greater_thansd_csr
(
self
):
opT
=
lambda
x
,
y
:
x
>
y
self
.
__generalized_sd_test
(
opT
,
sparse
.
csr_matrix
,
opT
,
sp
.
csr_matrix
)
def
test_greater_thansd_csc
(
self
):
opT
=
lambda
x
,
y
:
x
>
y
self
.
__generalized_sd_test
(
opT
,
sparse
.
csc_matrix
,
opT
,
sp
.
csc_matrix
)
def
test_equalds_csr
(
self
):
self
.
__generalized_ds_test
(
eq
,
sparse
.
csr_matrix
,
lambda
x
,
y
:
x
==
y
,
sp
.
csr_matrix
)
def
test_equalds_csc
(
self
):
self
.
__generalized_ds_test
(
eq
,
sparse
.
csc_matrix
,
lambda
x
,
y
:
x
==
y
,
sp
.
csc_matrix
)
def
test_not_equalds_csr
(
self
):
self
.
__generalized_ds_test
(
neq
,
sparse
.
csr_matrix
,
lambda
x
,
y
:
x
!=
y
,
sp
.
csr_matrix
)
def
test_not_equalds_csc
(
self
):
self
.
__generalized_ds_test
(
neq
,
sparse
.
csc_matrix
,
lambda
x
,
y
:
x
!=
y
,
sp
.
csc_matrix
)
def
test_less_equalds_csr
(
self
):
opT
=
lambda
x
,
y
:
x
<=
y
self
.
__generalized_ds_test
(
le
,
sparse
.
csr_matrix
,
opT
,
sp
.
csr_matrix
)
def
test_less_equalds_csc
(
self
):
opT
=
lambda
x
,
y
:
x
<=
y
self
.
__generalized_ds_test
(
le
,
sparse
.
csc_matrix
,
opT
,
sp
.
csc_matrix
)
def
test_less_thands_csr
(
self
):
opT
=
lambda
x
,
y
:
x
<
y
self
.
__generalized_ds_test
(
lt
,
sparse
.
csr_matrix
,
opT
,
sp
.
csr_matrix
)
def
test_less_thands_csc
(
self
):
opT
=
lambda
x
,
y
:
x
<
y
self
.
__generalized_ds_test
(
lt
,
sparse
.
csc_matrix
,
opT
,
sp
.
csc_matrix
)
def
test_greater_equalds_csr
(
self
):
opT
=
lambda
x
,
y
:
x
>=
y
self
.
__generalized_ds_test
(
ge
,
sparse
.
csr_matrix
,
opT
,
sp
.
csr_matrix
)
def
test_greater_equalds_csc
(
self
):
opT
=
lambda
x
,
y
:
x
>=
y
self
.
__generalized_ds_test
(
ge
,
sparse
.
csc_matrix
,
opT
,
sp
.
csc_matrix
)
def
test_greater_thands_csr
(
self
):
opT
=
lambda
x
,
y
:
x
>
y
self
.
__generalized_ds_test
(
gt
,
sparse
.
csr_matrix
,
opT
,
sp
.
csr_matrix
)
def
test_greater_thands_csc
(
self
):
opT
=
lambda
x
,
y
:
x
>
y
self
.
assertTrue
(
numpy
.
array_equal
(
f
(
m1
,
m2
)
.
data
,
(
m1
!=
m2
)
.
data
))
self
.
__generalized_ds_test
(
gt
,
sparse
.
csc_matrix
,
opT
,
sp
.
csc_matrix
)
class
T_conversion
(
unittest
.
TestCase
):
class
T_conversion
(
unittest
.
TestCase
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论