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
258dbf0f
Commit
258dbf0f
authored
Feb 04, 2020
by
rusty1s
Browse files
from_dense with optional no values
parent
6b013fbe
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
3 deletions
+9
-3
torch_sparse/tensor.py
torch_sparse/tensor.py
+9
-3
No files found.
torch_sparse/tensor.py
View file @
258dbf0f
...
@@ -30,15 +30,21 @@ class SparseTensor(object):
...
@@ -30,15 +30,21 @@ class SparseTensor(object):
return
self
return
self
@
classmethod
@
classmethod
def
from_dense
(
self
,
mat
:
torch
.
Tensor
):
def
from_dense
(
self
,
mat
:
torch
.
Tensor
,
has_value
:
bool
=
True
):
if
mat
.
dim
()
>
2
:
if
mat
.
dim
()
>
2
:
index
=
mat
.
abs
().
sum
([
i
for
i
in
range
(
2
,
mat
.
dim
())]).
nonzero
()
index
=
mat
.
abs
().
sum
([
i
for
i
in
range
(
2
,
mat
.
dim
())]).
nonzero
()
else
:
else
:
index
=
mat
.
nonzero
()
index
=
mat
.
nonzero
()
index
=
index
.
t
()
index
=
index
.
t
()
row
,
col
=
index
[
0
],
index
[
1
]
row
=
index
[
0
]
return
SparseTensor
(
row
=
row
,
rowptr
=
None
,
col
=
col
,
value
=
mat
[
row
,
col
],
col
=
index
[
1
]
value
:
Optional
[
torch
.
Tensor
]
=
None
if
has_value
:
value
=
mat
[
row
,
col
]
return
SparseTensor
(
row
=
row
,
rowptr
=
None
,
col
=
col
,
value
=
value
,
sparse_sizes
=
mat
.
size
()[:
2
],
is_sorted
=
True
)
sparse_sizes
=
mat
.
size
()[:
2
],
is_sorted
=
True
)
@
classmethod
@
classmethod
...
...
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