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
ed3de958
Commit
ed3de958
authored
Jul 17, 2020
by
rusty1s
Browse files
Merge branch 'master' of github.com:rusty1s/pytorch_sparse
parents
3679da2b
266dffd3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
0 deletions
+24
-0
CMakeLists.txt
CMakeLists.txt
+1
-0
test/test_tensor.py
test/test_tensor.py
+21
-0
torch_sparse/tensor.py
torch_sparse/tensor.py
+2
-0
No files found.
CMakeLists.txt
View file @
ed3de958
...
@@ -9,6 +9,7 @@ if(WITH_CUDA)
...
@@ -9,6 +9,7 @@ if(WITH_CUDA)
enable_language
(
CUDA
)
enable_language
(
CUDA
)
add_definitions
(
-D__CUDA_NO_HALF_OPERATORS__
)
add_definitions
(
-D__CUDA_NO_HALF_OPERATORS__
)
add_definitions
(
-DWITH_CUDA
)
add_definitions
(
-DWITH_CUDA
)
set
(
CMAKE_CUDA_FLAGS
"
${
CMAKE_CUDA_FLAGS
}
-arch=sm_35 --expt-relaxed-constexpr"
)
endif
()
endif
()
find_package
(
Python3 COMPONENTS Development
)
find_package
(
Python3 COMPONENTS Development
)
...
...
test/test_tensor.py
0 → 100644
View file @
ed3de958
from
itertools
import
product
import
pytest
import
torch
from
torch_sparse
import
SparseTensor
from
.utils
import
grad_dtypes
,
devices
@
pytest
.
mark
.
parametrize
(
'dtype,device'
,
product
(
grad_dtypes
,
devices
))
def
test_getitem
(
dtype
,
device
):
mat
=
torch
.
randn
(
50
,
40
,
dtype
=
dtype
,
device
=
device
)
mat
=
SparseTensor
.
from_dense
(
mat
)
idx1
=
torch
.
randint
(
0
,
50
,
(
10
,
),
dtype
=
torch
.
long
,
device
=
device
)
idx2
=
torch
.
randint
(
0
,
40
,
(
10
,
),
dtype
=
torch
.
long
,
device
=
device
)
assert
mat
[:
10
,
:
10
].
sizes
()
==
[
10
,
10
]
assert
mat
[...,
:
10
].
sizes
()
==
[
50
,
10
]
assert
mat
[
idx1
,
idx2
].
sizes
()
==
[
10
,
10
]
assert
mat
[
idx1
.
tolist
()].
sizes
()
==
[
10
,
40
]
torch_sparse/tensor.py
View file @
ed3de958
...
@@ -442,6 +442,8 @@ def __getitem__(self: SparseTensor, index: Any) -> SparseTensor:
...
@@ -442,6 +442,8 @@ def __getitem__(self: SparseTensor, index: Any) -> SparseTensor:
out
=
self
out
=
self
while
len
(
index
)
>
0
:
while
len
(
index
)
>
0
:
item
=
index
.
pop
(
0
)
item
=
index
.
pop
(
0
)
if
isinstance
(
item
,
(
list
,
tuple
)):
item
=
torch
.
tensor
(
item
,
dtype
=
torch
.
long
,
device
=
self
.
device
())
if
isinstance
(
item
,
int
):
if
isinstance
(
item
,
int
):
out
=
out
.
select
(
dim
,
item
)
out
=
out
.
select
(
dim
,
item
)
dim
+=
1
dim
+=
1
...
...
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