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
572227be
Commit
572227be
authored
Jul 28, 2018
by
rusty1s
Browse files
typo
parent
d92fb90b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
10 deletions
+10
-10
torch_sparse/__init__.py
torch_sparse/__init__.py
+2
-2
torch_sparse/matmul.py
torch_sparse/matmul.py
+8
-8
No files found.
torch_sparse/__init__.py
View file @
572227be
from
.matmul
import
sp
arse_sparse_matmul
from
.matmul
import
sp
spmm
__all__
=
[
'sp
arse_sparse_matmul
'
,
'sp
spmm
'
,
]
torch_sparse/matmul.py
View file @
572227be
...
...
@@ -3,11 +3,11 @@ from torch import from_numpy
from
scipy.sparse
import
coo_matrix
class
Sp
arseSparseMatmul
(
torch
.
autograd
.
Function
):
class
Sp
SpMM
(
torch
.
autograd
.
Function
):
@
staticmethod
def
forward
(
ctx
,
matrix1
,
matrix2
):
ctx
.
save_for_backawrd
(
matrix1
,
matrix2
)
return
m
atmul
(
matrix1
,
matrix2
)
return
m
m
(
matrix1
,
matrix2
)
@
staticmethod
def
backward
(
ctx
,
grad_out
):
...
...
@@ -15,25 +15,25 @@ class SparseSparseMatmul(torch.autograd.Function):
grad_matrix1
=
grad_matrix2
=
None
if
ctx
.
needs_input_grad
[
0
]:
grad_matrix1
=
m
atmul
(
grad_out
,
matrix2
.
t
())
grad_matrix1
=
m
m
(
grad_out
,
matrix2
.
t
())
if
ctx
.
needs_input_grad
[
0
]:
grad_matrix2
=
m
atmul
(
matrix1
.
t
(),
grad_out
)
grad_matrix2
=
m
m
(
matrix1
.
t
(),
grad_out
)
return
grad_matrix1
,
grad_matrix2
sp
arse_sparse_matmul
=
SparseSparseMatmul
.
apply
sp
spmm
=
SpSpMM
.
apply
def
m
atmul
(
A
,
B
):
def
m
m
(
A
,
B
):
if
A
[
0
].
is_cuda
:
pass
else
:
return
m
atmul
_cpu
(
A
,
B
)
return
m
m
_cpu
(
A
,
B
)
def
m
atmul
_cpu
(
A
,
B
):
def
m
m
_cpu
(
A
,
B
):
A
,
B
,
=
to_csr
(
A
),
to_csr
(
B
)
C
=
A
.
dot
(
B
).
tocoo
()
row
,
col
,
value
=
from_numpy
(
C
.
row
),
from_numpy
(
C
.
col
),
from_numpy
(
C
.
data
)
...
...
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