Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ca670ce6
提交
ca670ce6
authored
6月 15, 2012
作者:
Nicolas Bouchard
提交者:
Frederic
7月 06, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Made correction and remove dupplicate of eliminate_zeros
上级
e70f9594
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
129 行增加
和
127 行删除
+129
-127
sp2.py
theano/sparse/sandbox/sp2.py
+39
-29
test_basic.py
theano/sparse/tests/test_basic.py
+70
-35
test_sp2.py
theano/sparse/tests/test_sp2.py
+20
-63
没有找到文件。
theano/sparse/sandbox/sp2.py
浏览文件 @
ca670ce6
import
theano
import
numpy
import
numpy
import
scipy.sparse
import
scipy.sparse
from
theano
import
gof
,
tensor
,
scalar
from
theano
import
gof
,
tensor
,
scalar
from
theano.tensor
import
blas
from
theano.tensor
import
blas
from
theano
import
tensor
as
T
from
theano.sparse.basic
import
(
from
theano.sparse.basic
import
(
as_sparse_variable
,
SparseType
,
add_s_s
,
neg
,
as_sparse_variable
,
SparseType
,
add_s_s
,
neg
,
...
@@ -11,10 +11,14 @@ from theano.sparse.basic import (
...
@@ -11,10 +11,14 @@ from theano.sparse.basic import (
CSMProperties
,
CSM
,
register_specialize
,
CSMProperties
,
CSM
,
register_specialize
,
_is_sparse_variable
,
_is_dense_variable
,
CSC
,
CSR
,
_is_sparse_variable
,
_is_dense_variable
,
CSC
,
CSR
,
csm_properties
,
csm_data
,
csm_indices
,
csm_indptr
,
csm_shape
,
csm_properties
,
csm_data
,
csm_indices
,
csm_indptr
,
csm_shape
,
_is_sparse
)
_is_sparse
,
Remove0
,
remove0
)
from
theano.sparse.sandbox.sp
import
sp_sum
from
theano.sparse.sandbox.sp
import
sp_sum
EliminateZeros
=
Remove0
eliminate_zeros
=
remove0
class
Cast
(
gof
.
op
.
Op
):
class
Cast
(
gof
.
op
.
Op
):
"""Cast sparse variable to the desired dtype.
"""Cast sparse variable to the desired dtype.
...
@@ -42,7 +46,7 @@ class Cast(gof.op.Op):
...
@@ -42,7 +46,7 @@ class Cast(gof.op.Op):
out
[
0
]
=
x
.
astype
(
self
.
out_type
)
out
[
0
]
=
x
.
astype
(
self
.
out_type
)
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
tensor
.
continuous_dtypes
:
gz
=
outputs_gradients
[
0
]
gz
=
outputs_gradients
[
0
]
return
[
Cast
(
inputs
[
0
]
.
dtype
)(
gz
)]
return
[
Cast
(
inputs
[
0
]
.
dtype
)(
gz
)]
else
:
else
:
...
@@ -52,7 +56,7 @@ class Cast(gof.op.Op):
...
@@ -52,7 +56,7 @@ class Cast(gof.op.Op):
return
ins_shapes
return
ins_shapes
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
__class__
.
__name__
return
"
%
s(
%
s)"
%
(
self
.
__class__
.
__name__
,
self
.
out_type
)
def
cast
(
x
,
t
):
def
cast
(
x
,
t
):
...
@@ -341,6 +345,10 @@ mul_s_d_csr = MulSDCSR()
...
@@ -341,6 +345,10 @@ mul_s_d_csr = MulSDCSR()
class
Poisson
(
gof
.
op
.
Op
):
class
Poisson
(
gof
.
op
.
Op
):
"""Return a sparse having random values from a poisson density
with mean from the input.
"""
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
))
return
(
type
(
self
)
==
type
(
other
))
...
@@ -357,10 +365,28 @@ class Poisson(gof.op.Op):
...
@@ -357,10 +365,28 @@ class Poisson(gof.op.Op):
out
[
0
]
.
data
=
numpy
.
asarray
(
numpy
.
random
.
poisson
(
out
[
0
]
.
data
),
out
[
0
]
.
data
=
numpy
.
asarray
(
numpy
.
random
.
poisson
(
out
[
0
]
.
data
),
dtype
=
x
.
dtype
)
dtype
=
x
.
dtype
)
out
[
0
]
.
eliminate_zeros
()
out
[
0
]
.
eliminate_zeros
()
def
grad
(
self
,
inputs
,
outputs_gradients
):
return
[
None
]
def
infer_shape
(
self
,
node
,
ins_shapes
):
return
ins_shapes
def
__str__
(
self
):
return
self
.
__class__
.
__name__
poisson
=
Poisson
()
poisson
=
Poisson
()
class
Multinomial
(
gof
.
op
.
Op
):
class
Multinomial
(
gof
.
op
.
Op
):
"""Return a sparse matrix having random values from a multinomial
density having number of experiment `n` and probability of succes
`p`.
:Parameters:
- `n`: Number of experiment.
- `p`: Sparse probability of each of the different outcomes.
"""
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
))
return
(
type
(
self
)
==
type
(
other
))
...
@@ -383,38 +409,16 @@ class Multinomial(gof.op.Op):
...
@@ -383,38 +409,16 @@ class Multinomial(gof.op.Op):
for
i
in
xrange
(
p
.
shape
[
0
]):
for
i
in
xrange
(
p
.
shape
[
0
]):
k
,
l
=
p
.
indptr
[
i
],
p
.
indptr
[
i
+
1
]
k
,
l
=
p
.
indptr
[
i
],
p
.
indptr
[
i
+
1
]
out
[
0
]
.
data
[
k
:
l
]
=
numpy
.
random
.
multinomial
(
n
[
i
],
p
.
data
[
k
:
l
])
out
[
0
]
.
data
[
k
:
l
]
=
numpy
.
random
.
multinomial
(
n
[
i
],
p
.
data
[
k
:
l
])
multinomial
=
Multinomial
()
class
EliminateZeros
(
gof
.
op
.
Op
):
"""Eliminate zeros from the data of the matrix.
This wrap the method eliminate_zeros from scipy.
"""
def
__eq__
(
self
,
other
):
return
(
type
(
self
)
==
type
(
other
))
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
make_node
(
self
,
x
):
x
=
as_sparse_variable
(
x
)
return
gof
.
Apply
(
self
,
[
x
],
[
x
.
type
()])
def
perform
(
self
,
node
,
(
x
,
),
(
out
,
)):
assert
_is_sparse
(
x
)
out
[
0
]
=
x
.
copy
()
out
[
0
]
.
eliminate_zeros
()
def
grad
(
self
,
inputs
,
outputs_gradients
):
def
grad
(
self
,
inputs
,
outputs_gradients
):
return
outputs_gradients
return
[
None
,
None
]
def
infer_shape
(
self
,
node
,
ins_shapes
):
def
infer_shape
(
self
,
node
,
ins_shapes
):
return
ins_shapes
return
ins_shapes
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
__class__
.
__name__
return
self
.
__class__
.
__name__
eliminate_zeros
=
EliminateZeros
()
multinomial
=
Multinomial
()
class
Binomial
(
gof
.
op
.
Op
):
class
Binomial
(
gof
.
op
.
Op
):
...
@@ -447,9 +451,15 @@ class Binomial(gof.op.Op):
...
@@ -447,9 +451,15 @@ class Binomial(gof.op.Op):
out
[
0
]
=
getattr
(
res
,
'to'
+
self
.
format
)()
out
[
0
]
=
getattr
(
res
,
'to'
+
self
.
format
)()
out
[
0
]
.
data
=
numpy
.
ones_like
(
out
[
0
]
.
data
)
out
[
0
]
.
data
=
numpy
.
ones_like
(
out
[
0
]
.
data
)
def
grad
(
self
,
(
n
,
p
,
shape
,
),
(
gz
,)):
def
grad
(
self
,
(
n
,
p
,
shape
,
),
(
gz
,)):
return
None
,
None
,
None
return
None
,
None
,
None
def
infer_shape
(
self
,
node
,
ins_shapes
):
return
ins_shapes
def
__str__
(
self
):
return
self
.
__class__
.
__name__
csr_fbinomial
=
Binomial
(
'csr'
,
'float32'
)
csr_fbinomial
=
Binomial
(
'csr'
,
'float32'
)
csc_fbinomial
=
Binomial
(
'csc'
,
'float32'
)
csc_fbinomial
=
Binomial
(
'csc'
,
'float32'
)
csr_dbinomial
=
Binomial
(
'csr'
,
'float64'
)
csr_dbinomial
=
Binomial
(
'csr'
,
'float64'
)
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
ca670ce6
...
@@ -1320,44 +1320,79 @@ def test_size():
...
@@ -1320,44 +1320,79 @@ def test_size():
check
()
check
()
def
test_remove0
():
class
Remove0Tester
(
utt
.
InferShapeTester
):
configs
=
[
def
setUp
(
self
):
# structure type, numpy matching class
super
(
Remove0Tester
,
self
)
.
setUp
()
(
'csc'
,
scipy
.
sparse
.
csc_matrix
),
self
.
op_class
=
Remove0
(
'csr'
,
scipy
.
sparse
.
csr_matrix
),
]
def
test_remove0
(
self
):
for
format
,
matrix_class
in
configs
:
configs
=
[
# real
# structure type, numpy matching class
origin
=
(
numpy
.
arange
(
9
)
+
1
)
.
reshape
((
3
,
3
))
.
astype
(
config
.
floatX
)
(
'csc'
,
scipy
.
sparse
.
csc_matrix
),
mat
=
matrix_class
(
origin
)
.
astype
(
theano
.
config
.
floatX
)
(
'csr'
,
scipy
.
sparse
.
csr_matrix
),
]
for
format
,
matrix_class
in
configs
:
# real
origin
=
(
numpy
.
arange
(
9
)
+
1
)
.
reshape
((
3
,
3
))
origin
.
astype
(
config
.
floatX
)
mat
=
matrix_class
(
origin
)
.
astype
(
theano
.
config
.
floatX
)
mat
[
0
,
1
]
=
mat
[
1
,
0
]
=
mat
[
2
,
2
]
=
0
assert
mat
.
size
==
9
# symbolic
x
=
theano
.
sparse
.
SparseType
(
format
=
format
,
dtype
=
config
.
floatX
)()
# the In thingy has to be there because theano has as rule not
# to optimize inputs
f
=
theano
.
function
([
theano
.
In
(
x
,
borrow
=
True
,
mutable
=
True
)],
Remove0
()(
x
))
# assert optimization local_inplace_remove0 is applied in
# modes with optimization
if
theano
.
config
.
mode
not
in
[
'FAST_COMPILE'
]:
# list of apply nodes in the optimized graph.
nodes
=
f
.
maker
.
env
.
toposort
()
v
=
[
True
for
node
in
nodes
]
if
isinstance
(
node
.
op
,
Remove0
)
and
node
.
op
.
inplace
:
assert
len
(
v
),
\
'Inplacing optimization should have been applied.'
# checking
# makes sense to change its name
target
=
mat
result
=
f
(
mat
)
mat
.
eliminate_zeros
()
msg
=
'Matrices sizes differ. Have zeros been removed ?'
assert
result
.
size
==
target
.
size
,
msg
def
test_infer_shape
(
self
):
mat
=
(
numpy
.
arange
(
9
)
+
1
)
.
reshape
((
3
,
3
))
mat
[
0
,
1
]
=
mat
[
1
,
0
]
=
mat
[
2
,
2
]
=
0
mat
[
0
,
1
]
=
mat
[
1
,
0
]
=
mat
[
2
,
2
]
=
0
assert
mat
.
size
==
9
x_csc
=
theano
.
sparse
.
csc_matrix
(
dtype
=
theano
.
config
.
floatX
)
mat_csc
=
sp
.
csc_matrix
(
mat
,
dtype
=
theano
.
config
.
floatX
)
# symbolic
self
.
_compile_and_check
([
x_csc
],
x
=
theano
.
sparse
.
SparseType
(
format
=
format
,
dtype
=
config
.
floatX
)()
[
Remove0
()(
x_csc
)],
# the In thingy has to be there because theano has as rule not
[
mat_csc
],
# to optimize inputs
self
.
op_class
)
f
=
theano
.
function
([
theano
.
In
(
x
,
borrow
=
True
,
mutable
=
True
)],
Remove0
()(
x
))
x_csr
=
theano
.
sparse
.
csr_matrix
(
dtype
=
theano
.
config
.
floatX
)
mat_csr
=
sp
.
csr_matrix
(
mat
,
dtype
=
theano
.
config
.
floatX
)
# assert optimization local_inplace_remove0 is applied in
self
.
_compile_and_check
([
x_csr
],
# modes with optimization
[
Remove0
()(
x_csr
)],
if
theano
.
config
.
mode
not
in
[
'FAST_COMPILE'
]:
[
mat_csr
],
# list of apply nodes in the optimized graph.
self
.
op_class
)
nodes
=
f
.
maker
.
env
.
toposort
()
v
=
[
True
for
node
in
nodes
def
test_grad
(
self
):
if
isinstance
(
node
.
op
,
Remove0
)
and
node
.
op
.
inplace
]
mat
=
(
numpy
.
arange
(
9
)
+
1
)
.
reshape
((
3
,
3
))
assert
len
(
v
),
'Inplacing optimization should have been applied.'
mat
[
0
,
1
]
=
mat
[
1
,
0
]
=
mat
[
2
,
2
]
=
0
# checking
mat_csc
=
sp
.
csc_matrix
(
mat
,
dtype
=
theano
.
config
.
floatX
)
# makes sense to change its name
verify_grad_sparse
(
Remove0
(),
[
mat_csc
])
target
=
mat
result
=
f
(
mat
)
mat_csr
=
sp
.
csr_matrix
(
mat
,
dtype
=
theano
.
config
.
floatX
)
mat
.
eliminate_zeros
()
verify_grad_sparse
(
Remove0
(),
[
mat_csr
])
msg
=
'Matrices sizes differ. Have zeros been removed ?'
assert
result
.
size
==
target
.
size
,
msg
class
Test_getitem
(
unittest
.
TestCase
):
class
Test_getitem
(
unittest
.
TestCase
):
...
...
theano/sparse/tests/test_sp2.py
浏览文件 @
ca670ce6
...
@@ -10,10 +10,10 @@ except ImportError:
...
@@ -10,10 +10,10 @@ except ImportError:
pass
# The variable enable_sparse will be used to disable the test file.
pass
# The variable enable_sparse will be used to disable the test file.
import
theano
import
theano
from
theano
import
tensor
from
theano
import
sparse
from
theano
import
tensor
as
T
if
not
theano
.
sparse
.
enable_sparse
:
from
theano
import
sparse
as
S
if
not
S
.
enable_sparse
:
raise
SkipTest
(
'Optional package sparse disabled'
)
raise
SkipTest
(
'Optional package sparse disabled'
)
from
theano.sparse.sandbox
import
sp2
as
S2
from
theano.sparse.sandbox
import
sp2
as
S2
...
@@ -52,9 +52,10 @@ def random_lil(shape, dtype, nnz):
...
@@ -52,9 +52,10 @@ def random_lil(shape, dtype, nnz):
class
TestCast
(
utt
.
InferShapeTester
):
class
TestCast
(
utt
.
InferShapeTester
):
compatible_types
=
T
.
int_dtypes
+
T
.
continuous_dtypes
compatible_types
=
(
tensor
.
int_dtypes
+
x_csc
=
[
S
.
csc_matrix
(
dtype
=
t
)
for
t
in
compatible_types
]
tensor
.
continuous_dtypes
)
x_csr
=
[
S
.
csr_matrix
(
dtype
=
t
)
for
t
in
compatible_types
]
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
=
np
.
array
([
0
,
2
,
3
,
6
])
indptr
=
np
.
array
([
0
,
2
,
3
,
6
])
indices
=
np
.
array
([
0
,
2
,
2
,
0
,
1
,
2
])
indices
=
np
.
array
([
0
,
2
,
2
,
0
,
1
,
2
])
...
@@ -78,7 +79,7 @@ class TestCast(utt.InferShapeTester):
...
@@ -78,7 +79,7 @@ class TestCast(utt.InferShapeTester):
for
x
in
self
.
x_csc
:
for
x
in
self
.
x_csc
:
for
f
,
t
in
zip
(
cast_csc
[
x
],
self
.
compatible_types
):
for
f
,
t
in
zip
(
cast_csc
[
x
],
self
.
compatible_types
):
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
x
.
dtype
)
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
x
.
dtype
)
.
copy
()
assert
f
(
a
)
.
dtype
==
t
assert
f
(
a
)
.
dtype
==
t
for
x
in
self
.
x_csr
:
for
x
in
self
.
x_csr
:
...
@@ -104,63 +105,19 @@ class TestCast(utt.InferShapeTester):
...
@@ -104,63 +105,19 @@ class TestCast(utt.InferShapeTester):
self
.
op_class
)
self
.
op_class
)
def
test_grad
(
self
):
def
test_grad
(
self
):
for
dtype
in
T
.
float_dtypes
:
# TODO Find the problem with the grad of downcast
# a = sp.csc_matrix(self.properties, dtype='float64')
# verify_grad_sparse(S2.Cast('float32'), [a], cast_to_output_type=True)
for
dtype
in
tensor
.
float_dtypes
:
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
dtype
)
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
dtype
)
verify_grad_sparse
(
S2
.
Cast
(
'float64'
),
[
a
])
verify_grad_sparse
(
S2
.
Cast
(
'float64'
),
[
a
])
for
dtype
in
T
.
float_dtypes
:
for
dtype
in
tensor
.
float_dtypes
:
a
=
sp
.
csr_matrix
(
self
.
properties
,
dtype
=
dtype
)
a
=
sp
.
csr_matrix
(
self
.
properties
,
dtype
=
dtype
)
verify_grad_sparse
(
S2
.
Cast
(
'float64'
),
[
a
])
verify_grad_sparse
(
S2
.
Cast
(
'float64'
),
[
a
])
class
EliminateZerosTester
(
utt
.
InferShapeTester
):
indptr
=
np
.
array
([
0
,
2
,
3
,
6
])
indices
=
np
.
array
([
0
,
2
,
2
,
0
,
1
,
2
])
data
=
np
.
array
([
1
,
0
,
3
,
0
,
5
,
6
],
dtype
=
'float32'
)
properties
=
(
data
,
indices
,
indptr
)
x_csc
=
S
.
csc_matrix
(
'csc'
,
dtype
=
'float32'
)
x_csr
=
S
.
csr_matrix
(
'csr'
,
dtype
=
'float32'
)
def
setUp
(
self
):
super
(
EliminateZerosTester
,
self
)
.
setUp
()
self
.
op_class
=
S2
.
EliminateZeros
def
test_eliminate_zeros
(
self
):
f_csc
=
theano
.
function
([
self
.
x_csc
],
S2
.
eliminate_zeros
(
self
.
x_csc
))
f_csr
=
theano
.
function
([
self
.
x_csr
],
S2
.
eliminate_zeros
(
self
.
x_csr
))
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
'float32'
)
b
=
a
.
copy
()
b
.
eliminate_zeros
()
assert
np
.
all
(
f_csc
(
a
)
.
todense
()
==
b
.
todense
())
a
=
sp
.
csr_matrix
(
self
.
properties
)
b
=
a
.
copy
()
b
.
eliminate_zeros
()
assert
np
.
all
(
f_csr
(
a
)
.
todense
()
==
b
.
todense
())
def
test_infer_shape
(
self
):
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
'float32'
)
self
.
_compile_and_check
([
self
.
x_csc
],
[
S2
.
eliminate_zeros
(
self
.
x_csc
)],
[
a
],
self
.
op_class
)
a
=
sp
.
csr_matrix
(
self
.
properties
,
dtype
=
'float32'
)
self
.
_compile_and_check
([
self
.
x_csr
],
[
S2
.
eliminate_zeros
(
self
.
x_csr
)],
[
a
],
self
.
op_class
)
def
test_grad
(
self
):
a
=
sp
.
csc_matrix
(
self
.
properties
,
dtype
=
'float32'
)
verify_grad_sparse
(
S2
.
eliminate_zeros
,
[
a
])
a
=
sp
.
csr_matrix
(
self
.
properties
,
dtype
=
'float32'
)
verify_grad_sparse
(
S2
.
eliminate_zeros
,
[
a
])
class
test_structured_add_s_v
(
unittest
.
TestCase
):
class
test_structured_add_s_v
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
utt
.
seed_rng
()
utt
.
seed_rng
()
...
@@ -174,7 +131,7 @@ class test_structured_add_s_v(unittest.TestCase):
...
@@ -174,7 +131,7 @@ class test_structured_add_s_v(unittest.TestCase):
spmat
=
sp_types
[
format
](
random_lil
((
4
,
3
),
dtype
,
3
))
spmat
=
sp_types
[
format
](
random_lil
((
4
,
3
),
dtype
,
3
))
mat
=
np
.
asarray
(
np
.
random
.
rand
(
3
),
dtype
=
dtype
)
mat
=
np
.
asarray
(
np
.
random
.
rand
(
3
),
dtype
=
dtype
)
S
.
verify_grad_sparse
(
S2
.
structured_add_s_v
,
theano
.
sparse
.
verify_grad_sparse
(
S2
.
structured_add_s_v
,
[
spmat
,
mat
],
structured
=
True
)
[
spmat
,
mat
],
structured
=
True
)
def
test_structured_add_s_v
(
self
):
def
test_structured_add_s_v
(
self
):
...
@@ -183,8 +140,8 @@ class test_structured_add_s_v(unittest.TestCase):
...
@@ -183,8 +140,8 @@ class test_structured_add_s_v(unittest.TestCase):
for
format
in
[
'csr'
,
'csc'
]:
for
format
in
[
'csr'
,
'csc'
]:
for
dtype
in
[
'float32'
,
'float64'
]:
for
dtype
in
[
'float32'
,
'float64'
]:
x
=
S
.
SparseType
(
format
,
dtype
=
dtype
)()
x
=
theano
.
sparse
.
SparseType
(
format
,
dtype
=
dtype
)()
y
=
T
.
vector
(
dtype
=
dtype
)
y
=
tensor
.
vector
(
dtype
=
dtype
)
f
=
theano
.
function
([
x
,
y
],
S2
.
structured_add_s_v
(
x
,
y
))
f
=
theano
.
function
([
x
,
y
],
S2
.
structured_add_s_v
(
x
,
y
))
spmat
=
sp_types
[
format
](
random_lil
((
4
,
3
),
dtype
,
3
))
spmat
=
sp_types
[
format
](
random_lil
((
4
,
3
),
dtype
,
3
))
...
@@ -210,7 +167,7 @@ class test_mul_s_v(unittest.TestCase):
...
@@ -210,7 +167,7 @@ class test_mul_s_v(unittest.TestCase):
spmat
=
sp_types
[
format
](
random_lil
((
4
,
3
),
dtype
,
3
))
spmat
=
sp_types
[
format
](
random_lil
((
4
,
3
),
dtype
,
3
))
mat
=
np
.
asarray
(
np
.
random
.
rand
(
3
),
dtype
=
dtype
)
mat
=
np
.
asarray
(
np
.
random
.
rand
(
3
),
dtype
=
dtype
)
S
.
verify_grad_sparse
(
S2
.
mul_s_v
,
theano
.
sparse
.
verify_grad_sparse
(
S2
.
mul_s_v
,
[
spmat
,
mat
],
structured
=
True
)
[
spmat
,
mat
],
structured
=
True
)
def
test_mul_s_v
(
self
):
def
test_mul_s_v
(
self
):
...
@@ -219,8 +176,8 @@ class test_mul_s_v(unittest.TestCase):
...
@@ -219,8 +176,8 @@ class test_mul_s_v(unittest.TestCase):
for
format
in
[
'csr'
,
'csc'
]:
for
format
in
[
'csr'
,
'csc'
]:
for
dtype
in
[
'float32'
,
'float64'
]:
for
dtype
in
[
'float32'
,
'float64'
]:
x
=
S
.
SparseType
(
format
,
dtype
=
dtype
)()
x
=
theano
.
sparse
.
SparseType
(
format
,
dtype
=
dtype
)()
y
=
T
.
vector
(
dtype
=
dtype
)
y
=
tensor
.
vector
(
dtype
=
dtype
)
f
=
theano
.
function
([
x
,
y
],
S2
.
mul_s_v
(
x
,
y
))
f
=
theano
.
function
([
x
,
y
],
S2
.
mul_s_v
(
x
,
y
))
spmat
=
sp_types
[
format
](
random_lil
((
4
,
3
),
dtype
,
3
))
spmat
=
sp_types
[
format
](
random_lil
((
4
,
3
),
dtype
,
3
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论