Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torch-sparse
Commits
4a569c27
Commit
4a569c27
authored
Dec 19, 2019
by
rusty1s
Browse files
maintain colptr
parent
a28accb6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
2 deletions
+7
-2
torch_sparse/narrow.py
torch_sparse/narrow.py
+7
-2
No files found.
torch_sparse/narrow.py
View file @
4a569c27
...
...
@@ -19,20 +19,25 @@ def narrow(src, dim, start, length):
sparse_size
=
torch
.
Size
([
length
,
src
.
sparse_size
(
1
)])
storage
=
src
.
_storage
.
__class__
(
index
,
value
,
sparse_size
,
rowptr
,
is_sorted
=
True
)
index
,
value
,
sparse_size
,
rowptr
=
rowptr
,
is_sorted
=
True
)
elif
dim
==
1
:
# This is faster than accessing `csc()` in analogy to the `dim=0` case.
(
row
,
col
),
value
=
src
.
coo
()
mask
=
(
col
>=
start
)
&
(
col
<
start
+
length
)
colptr
=
src
.
_storage
.
_colptr
if
colptr
is
not
None
:
colptr
=
colptr
.
narrow
(
0
,
start
=
start
,
length
=
length
+
1
)
colptr
=
colptr
-
colptr
[
0
]
index
=
torch
.
stack
([
row
,
col
-
start
],
dim
=
0
)[:,
mask
]
if
src
.
has_value
():
value
=
value
[
mask
]
sparse_size
=
torch
.
Size
([
src
.
sparse_size
(
0
),
length
])
storage
=
src
.
_storage
.
__class__
(
index
,
value
,
sparse_size
,
is_sorted
=
True
)
index
,
value
,
sparse_size
,
colptr
=
colptr
,
is_sorted
=
True
)
else
:
storage
=
src
.
_storage
.
apply_value
(
lambda
x
:
x
.
narrow
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment