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
39e8533e
Commit
39e8533e
authored
Jul 02, 2021
by
rusty1s
Browse files
Clean up
parent
949c4f69
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
16 deletions
+16
-16
benchmark/ptr2ind.py
benchmark/ptr2ind.py
+16
-16
No files found.
benchmark/ptr2ind.py
View file @
39e8533e
...
...
@@ -54,6 +54,18 @@ def time_func(matrix, op, duration=5.0, warmup=1.0):
def
op1
(
matrix
):
# https://github.com/pytorch/pytorch/blob/3a777b67926c5f02bc287b25e572c521d6d11fb0/torch/_tensor.py#L928-L940
row_indices
=
matrix
.
indices
()[
0
]
ro
=
[
0
]
i
=
0
for
irow
in
range
(
matrix
.
shape
[
0
]):
while
i
<
row_indices
.
shape
[
0
]
and
row_indices
[
i
]
==
irow
:
i
+=
1
ro
.
append
(
i
)
torch
.
tensor
(
ro
,
dtype
=
torch
.
long
)
def
op2
(
matrix
):
# https://github.com/pearu/gcs/blob/b54ba0cba9c853b797274ef26b6c42386f2cafa3/gcs/storage.py#L24-L45
row_indices
=
matrix
.
indices
()[
0
]
nnz
=
row_indices
.
shape
[
0
]
...
...
@@ -74,18 +86,6 @@ def op1(matrix):
torch
.
tensor
(
compressed
,
dtype
=
torch
.
long
)
def
op2
(
matrix
):
# https://github.com/pytorch/pytorch/blob/3a777b67926c5f02bc287b25e572c521d6d11fb0/torch/_tensor.py#L928-L940
row_indices
=
matrix
.
indices
()[
0
]
ro
=
[
0
]
i
=
0
for
irow
in
range
(
matrix
.
shape
[
0
]):
while
i
<
row_indices
.
shape
[
0
]
and
row_indices
[
i
]
==
irow
:
i
+=
1
ro
.
append
(
i
)
torch
.
tensor
(
ro
,
dtype
=
torch
.
long
)
def
op3
(
matrix
):
row_indices
=
matrix
.
indices
()[
0
]
...
...
@@ -106,10 +106,10 @@ for group, name in matrices:
matrix
=
get_torch_sparse_coo_tensor
(
args
.
root
,
group
,
name
)
duration
=
time_func
(
matrix
,
op1
,
duration
=
5.0
,
warmup
=
1.0
)
print
(
'current
implementation
'
,
duration
)
print
(
'current
:
'
,
duration
)
duration
=
time_func
(
matrix
,
op2
,
duration
=
5.0
,
warmup
=
1.0
)
print
(
'compressed indices
implementation
'
,
duration
)
print
(
'compressed indices
:
'
,
duration
)
duration
=
time_func
(
matrix
,
op3
,
duration
=
5.0
,
warmup
=
1.0
)
print
(
'vectorized
implementation
:'
,
duration
)
print
(
'vectorized:'
,
duration
)
duration
=
time_func
(
matrix
,
op4
,
duration
=
5.0
,
warmup
=
1.0
)
print
(
'torch-sparse
implementation
:'
,
duration
)
print
(
'torch-sparse:'
,
duration
)
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