Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b4b82e6b
提交
b4b82e6b
authored
1月 11, 2015
作者:
ChienliMa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Sparse matrix slicing now support step. #2379
上级
5ec4c302
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
44 行增加
和
32 行删除
+44
-32
basic.py
theano/sparse/basic.py
+20
-13
test_basic.py
theano/sparse/tests/test_basic.py
+24
-19
没有找到文件。
theano/sparse/basic.py
浏览文件 @
b4b82e6b
...
...
@@ -1219,15 +1219,22 @@ class GetItem2d(gof.op.Op):
# in case of slice is written in theano variable
start
=
ind
.
start
stop
=
ind
.
stop
if
ind
.
step
is
not
None
:
raise
ValueError
((
"Using a slice with non-default step when "
"indexing into a sparse matrix is not supported. "
),
ind
,
ind
.
step
)
# If start or stop are None, make them a Generic constant
# Else, they should be converted to Tensor Variables of
# dimension 1 and int/uint dtype.
step
=
ind
.
step
# If start or stop or step are None, make them a Generic
# constant. Else, they should be converted to Tensor Variables
# of dimension 1 and int/uint dtype.
if
ind
.
step
is
None
:
step
=
generic_None
else
:
if
not
isinstance
(
step
,
gof
.
Variable
):
step
=
tensor
.
as_tensor_variable
(
step
)
if
not
(
step
.
ndim
==
0
and
step
.
dtype
in
tensor
.
discrete_dtypes
):
raise
ValueError
((
"Impossible to index into a sparse matrix with "
"slice where start=
%
s"
%
step
),
step
.
ndim
,
step
.
dtype
)
if
start
is
None
:
start
=
generic_None
else
:
...
...
@@ -1262,15 +1269,15 @@ class GetItem2d(gof.op.Op):
raise
ValueError
((
'Advanced indexing is not implemented for sparse '
'matrices. Argument not supported:
%
s'
%
ind
))
input_op
+=
[
start
,
stop
]
input_op
+=
[
start
,
stop
,
step
]
if
len
(
index
)
==
1
:
input_op
+=
[
generic_None
,
generic_None
]
input_op
+=
[
generic_None
,
generic_None
,
generic_None
]
return
gof
.
Apply
(
self
,
input_op
,
[
x
.
type
()])
def
perform
(
self
,
node
,
(
x
,
start1
,
stop1
,
st
art2
,
sto
p2
),
(
out
,
)):
def
perform
(
self
,
node
,
(
x
,
start1
,
stop1
,
st
ep1
,
start2
,
stop2
,
ste
p2
),
(
out
,
)):
assert
_is_sparse
(
x
)
out
[
0
]
=
x
[
start1
:
stop1
,
start2
:
sto
p2
]
out
[
0
]
=
x
[
start1
:
stop1
:
step1
,
start2
:
stop2
:
ste
p2
]
def
__str__
(
self
):
return
self
.
__class__
.
__name__
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
b4b82e6b
...
...
@@ -2103,6 +2103,7 @@ class Test_getitem(unittest.TestCase):
verify_grad_sparse
(
op_with_fixed_index
,
x_val
)
def
test_GetItem2D
(
self
):
sparse_formats
=
(
'csc'
,
'csr'
)
for
format
in
sparse_formats
:
...
...
@@ -2111,21 +2112,25 @@ class Test_getitem(unittest.TestCase):
b
=
theano
.
tensor
.
iscalar
(
'b'
)
c
=
theano
.
tensor
.
iscalar
(
'c'
)
d
=
theano
.
tensor
.
iscalar
(
'd'
)
e
=
theano
.
tensor
.
iscalar
(
'e'
)
f
=
theano
.
tensor
.
iscalar
(
'f'
)
# index
m
=
1
n
=
5
p
=
10
q
=
15
j
=
2
k
=
3
vx
=
as_sparse_format
(
self
.
rng
.
binomial
(
1
,
0.5
,
(
100
,
97
)),
format
)
.
astype
(
theano
.
config
.
floatX
)
#mode_no_debug = theano.compile.mode.get_default_mode()
#if isinstance(mode_no_debug, theano.compile.DebugMode):
# mode_no_debug = 'FAST_RUN'
f1
=
theano
.
function
([
x
,
a
,
b
,
c
,
d
],
x
[
a
:
b
,
c
:
d
])
r1
=
f1
(
vx
,
m
,
n
,
p
,
q
)
t1
=
vx
[
m
:
n
,
p
:
q
]
f1
=
theano
.
function
([
x
,
a
,
b
,
c
,
d
,
e
,
f
],
x
[
a
:
b
:
e
,
c
:
d
:
f
])
r1
=
f1
(
vx
,
m
,
n
,
p
,
q
,
j
,
k
)
t1
=
vx
[
m
:
n
:
j
,
p
:
q
:
k
]
assert
r1
.
shape
==
t1
.
shape
assert
numpy
.
all
(
t1
.
toarray
()
==
r1
.
toarray
())
...
...
@@ -2161,31 +2166,31 @@ class Test_getitem(unittest.TestCase):
assert numpy.all(r7.toarray() == t7.toarray())
"""
f4
=
theano
.
function
([
x
,
a
,
b
],
x
[
a
:
b
])
r4
=
f4
(
vx
,
m
,
n
)
t4
=
vx
[
m
:
n
]
f4
=
theano
.
function
([
x
,
a
,
b
,
e
],
x
[
a
:
b
:
e
])
r4
=
f4
(
vx
,
m
,
n
,
j
)
t4
=
vx
[
m
:
n
:
j
]
assert
r4
.
shape
==
t4
.
shape
assert
numpy
.
all
(
t4
.
toarray
()
==
r4
.
toarray
())
#-----------------------------------------------------------
# test cases using int indexing instead of theano variable
f6
=
theano
.
function
([
x
],
x
[
1
:
10
,
10
:
20
])
f6
=
theano
.
function
([
x
],
x
[
1
:
10
:
1
,
10
:
20
:
2
])
r6
=
f6
(
vx
)
t6
=
vx
[
1
:
10
,
10
:
20
]
t6
=
vx
[
1
:
10
:
1
,
10
:
20
:
2
]
assert
r6
.
shape
==
t6
.
shape
assert
numpy
.
all
(
r6
.
toarray
()
==
t6
.
toarray
())
#----------------------------------------------------------
# test cases with indexing both with theano variable and int
f8
=
theano
.
function
([
x
,
a
,
b
],
x
[
a
:
b
,
10
:
20
])
r8
=
f8
(
vx
,
m
,
n
)
t8
=
vx
[
m
:
n
,
10
:
20
]
f8
=
theano
.
function
([
x
,
a
,
b
,
e
],
x
[
a
:
b
:
e
,
10
:
20
:
1
])
r8
=
f8
(
vx
,
m
,
n
,
j
)
t8
=
vx
[
m
:
n
:
j
,
10
:
20
:
1
]
assert
r8
.
shape
==
t8
.
shape
assert
numpy
.
all
(
r8
.
toarray
()
==
t8
.
toarray
())
f9
=
theano
.
function
([
x
,
a
,
b
],
x
[
1
:
a
,
1
:
b
])
f9
=
theano
.
function
([
x
,
a
,
b
],
x
[
1
:
a
:
2
,
1
:
b
:
2
])
r9
=
f9
(
vx
,
p
,
q
)
t9
=
vx
[
1
:
p
,
1
:
q
]
t9
=
vx
[
1
:
p
:
2
,
1
:
q
:
2
]
assert
r9
.
shape
==
t9
.
shape
assert
numpy
.
all
(
r9
.
toarray
()
==
t9
.
toarray
())
...
...
@@ -2219,12 +2224,12 @@ class Test_getitem(unittest.TestCase):
self
.
assertRaises
(
NotImplementedError
,
x
.
__getitem__
,
(
slice
(
a
,
b
),
c
))
# x[a:b:step, c:d] is not accepted because scipy silently drops
# the step (!)
self
.
assertRaises
(
ValueError
,
x
.
__getitem__
,
(
slice
(
a
,
b
,
-
1
),
slice
(
c
,
d
)))
self
.
assertRaises
(
ValueError
,
x
.
__getitem__
,
(
slice
(
a
,
b
),
slice
(
c
,
d
,
2
)))
#
#
x[a:b:step, c:d] is not accepted because scipy silently drops
#
#
the step (!)
#
self.assertRaises(ValueError,
#
x.__getitem__, (slice(a, b, -1), slice(c, d)))
#
self.assertRaises(ValueError,
#
x.__getitem__, (slice(a, b), slice(c, d, 2)))
# Advanced indexing is not supported
self
.
assertRaises
(
ValueError
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论