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
d8bec425
"git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "80ff4ba63eb95400e01626c1767c4e3b9b1cc4aa"
Commit
d8bec425
authored
May 18, 2020
by
rusty1s
Browse files
sample method
parent
6af9980d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
torch_sparse/sample.py
torch_sparse/sample.py
+23
-0
No files found.
torch_sparse/sample.py
0 → 100644
View file @
d8bec425
from
typing
import
Optional
import
torch
from
torch_sparse.tensor
import
SparseTensor
def
sample
(
src
:
SparseTensor
,
num_neighbors
:
int
,
subset
:
Optional
[
torch
.
Tensor
]
=
None
)
->
torch
.
Tensor
:
rowptr
,
col
,
_
=
src
.
csr
()
rowcount
=
src
.
storage
.
rowcount
()
if
subset
is
not
None
:
rowcount
=
rowcount
[
subset
]
rowptr
=
rowptr
[
subset
]
rand
=
torch
.
rand
((
rowcount
.
size
(
0
),
num_neighbors
),
device
=
col
.
device
)
rand
=
rand
.
mul_
(
rowcount
.
to
(
rand
.
dtype
)).
to
(
torch
.
long
).
add_
(
rowptr
)
return
col
[
rand
]
SparseTensor
.
sample
=
sample
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