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-spline-conv
Commits
9ea57e71
Commit
9ea57e71
authored
Apr 12, 2018
by
rusty1s
Browse files
added no cover pragmas
parent
70465ff9
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
23 additions
and
16 deletions
+23
-16
test/test_basis.py
test/test_basis.py
+1
-1
test/test_conv.py
test/test_conv.py
+2
-2
test/test_weighting.py
test/test_weighting.py
+2
-2
torch_spline_conv/basis.py
torch_spline_conv/basis.py
+3
-2
torch_spline_conv/utils/degree.py
torch_spline_conv/utils/degree.py
+1
-1
torch_spline_conv/utils/ffi.py
torch_spline_conv/utils/ffi.py
+7
-4
torch_spline_conv/weighting.py
torch_spline_conv/weighting.py
+7
-4
No files found.
test/test_basis.py
View file @
9ea57e71
...
@@ -69,7 +69,7 @@ def test_spline_basis_backward_cpu(degree):
...
@@ -69,7 +69,7 @@ def test_spline_basis_backward_cpu(degree):
@
pytest
.
mark
.
skipif
(
not
torch
.
cuda
.
is_available
(),
reason
=
'no CUDA'
)
@
pytest
.
mark
.
skipif
(
not
torch
.
cuda
.
is_available
(),
reason
=
'no CUDA'
)
@
pytest
.
mark
.
parametrize
(
'degree'
,
implemented_degrees
.
keys
())
@
pytest
.
mark
.
parametrize
(
'degree'
,
implemented_degrees
.
keys
())
def
test_spline_basis_backward_gpu
(
degree
):
def
test_spline_basis_backward_gpu
(
degree
):
# pragma: no cover
kernel_size
=
torch
.
cuda
.
LongTensor
([
5
,
5
,
5
])
kernel_size
=
torch
.
cuda
.
LongTensor
([
5
,
5
,
5
])
is_open_spline
=
torch
.
cuda
.
ByteTensor
([
1
,
0
,
1
])
is_open_spline
=
torch
.
cuda
.
ByteTensor
([
1
,
0
,
1
])
pseudo
=
torch
.
cuda
.
DoubleTensor
(
4
,
3
).
uniform_
(
0
,
1
)
pseudo
=
torch
.
cuda
.
DoubleTensor
(
4
,
3
).
uniform_
(
0
,
1
)
...
...
test/test_conv.py
View file @
9ea57e71
...
@@ -60,7 +60,7 @@ def test_spline_conv_forward_cpu(tensor, i):
...
@@ -60,7 +60,7 @@ def test_spline_conv_forward_cpu(tensor, i):
@
pytest
.
mark
.
skipif
(
not
torch
.
cuda
.
is_available
(),
reason
=
'no CUDA'
)
@
pytest
.
mark
.
skipif
(
not
torch
.
cuda
.
is_available
(),
reason
=
'no CUDA'
)
@
pytest
.
mark
.
parametrize
(
'tensor,i'
,
product
(
tensors
,
range
(
len
(
tests
))))
@
pytest
.
mark
.
parametrize
(
'tensor,i'
,
product
(
tensors
,
range
(
len
(
tests
))))
def
test_spline_conv_forward_gpu
(
tensor
,
i
):
def
test_spline_conv_forward_gpu
(
tensor
,
i
):
# pragma: no cover
data
=
tests
[
i
]
data
=
tests
[
i
]
src
=
getattr
(
torch
.
cuda
,
tensor
)(
data
[
'src'
])
src
=
getattr
(
torch
.
cuda
,
tensor
)(
data
[
'src'
])
...
@@ -104,7 +104,7 @@ def test_spline_basis_backward_cpu(degree):
...
@@ -104,7 +104,7 @@ def test_spline_basis_backward_cpu(degree):
@
pytest
.
mark
.
skipif
(
not
torch
.
cuda
.
is_available
(),
reason
=
'no CUDA'
)
@
pytest
.
mark
.
skipif
(
not
torch
.
cuda
.
is_available
(),
reason
=
'no CUDA'
)
@
pytest
.
mark
.
parametrize
(
'degree'
,
[
2
])
@
pytest
.
mark
.
parametrize
(
'degree'
,
[
2
])
def
test_spline_basis_backward_gpu
(
degree
):
def
test_spline_basis_backward_gpu
(
degree
):
# pragma: no cover
src
=
torch
.
cuda
.
DoubleTensor
(
3
,
2
).
uniform_
(
-
1
,
1
)
src
=
torch
.
cuda
.
DoubleTensor
(
3
,
2
).
uniform_
(
-
1
,
1
)
edge_index
=
torch
.
cuda
.
LongTensor
([[
0
,
1
,
1
,
2
],
[
1
,
0
,
2
,
1
]])
edge_index
=
torch
.
cuda
.
LongTensor
([[
0
,
1
,
1
,
2
],
[
1
,
0
,
2
,
1
]])
pseudo
=
torch
.
cuda
.
DoubleTensor
(
4
,
3
).
uniform_
(
0
,
1
)
pseudo
=
torch
.
cuda
.
DoubleTensor
(
4
,
3
).
uniform_
(
0
,
1
)
...
...
test/test_weighting.py
View file @
9ea57e71
...
@@ -35,7 +35,7 @@ def test_spline_weighting_forward_cpu(tensor, i):
...
@@ -35,7 +35,7 @@ def test_spline_weighting_forward_cpu(tensor, i):
@
pytest
.
mark
.
skipif
(
not
torch
.
cuda
.
is_available
(),
reason
=
'no CUDA'
)
@
pytest
.
mark
.
skipif
(
not
torch
.
cuda
.
is_available
(),
reason
=
'no CUDA'
)
@
pytest
.
mark
.
parametrize
(
'tensor,i'
,
product
(
tensors
,
range
(
len
(
tests
))))
@
pytest
.
mark
.
parametrize
(
'tensor,i'
,
product
(
tensors
,
range
(
len
(
tests
))))
def
test_spline_weighting_forward_gpu
(
tensor
,
i
):
def
test_spline_weighting_forward_gpu
(
tensor
,
i
):
# pragma: no cover
data
=
tests
[
i
]
data
=
tests
[
i
]
src
=
getattr
(
torch
.
cuda
,
tensor
)(
data
[
'src'
])
src
=
getattr
(
torch
.
cuda
,
tensor
)(
data
[
'src'
])
...
@@ -65,7 +65,7 @@ def test_spline_basis_backward_cpu():
...
@@ -65,7 +65,7 @@ def test_spline_basis_backward_cpu():
@
pytest
.
mark
.
skipif
(
not
torch
.
cuda
.
is_available
(),
reason
=
'no CUDA'
)
@
pytest
.
mark
.
skipif
(
not
torch
.
cuda
.
is_available
(),
reason
=
'no CUDA'
)
def
test_spline_basis_backward_gpu
():
def
test_spline_basis_backward_gpu
():
# pragma: no cover
src
=
torch
.
cuda
.
DoubleTensor
(
4
,
2
).
uniform_
(
0
,
1
)
src
=
torch
.
cuda
.
DoubleTensor
(
4
,
2
).
uniform_
(
0
,
1
)
weight
=
torch
.
cuda
.
DoubleTensor
(
25
,
2
,
4
).
uniform_
(
0
,
1
)
weight
=
torch
.
cuda
.
DoubleTensor
(
25
,
2
,
4
).
uniform_
(
0
,
1
)
kernel_size
=
torch
.
cuda
.
LongTensor
([
5
,
5
])
kernel_size
=
torch
.
cuda
.
LongTensor
([
5
,
5
])
...
...
torch_spline_conv/basis.py
View file @
9ea57e71
...
@@ -13,7 +13,8 @@ def basis_forward(degree, pseudo, kernel_size, is_open_spline):
...
@@ -13,7 +13,8 @@ def basis_forward(degree, pseudo, kernel_size, is_open_spline):
return
basis
,
weight_index
return
basis
,
weight_index
def
basis_backward
(
degree
,
grad_basis
,
pseudo
,
kernel_size
,
is_open_spline
):
def
basis_backward
(
degree
,
grad_basis
,
pseudo
,
kernel_size
,
is_open_spline
):
# pragma: no cover
grad_pseudo
=
pseudo
.
new
(
pseudo
.
size
())
grad_pseudo
=
pseudo
.
new
(
pseudo
.
size
())
basis_bw
(
degree
,
grad_pseudo
,
grad_basis
,
pseudo
,
kernel_size
,
basis_bw
(
degree
,
grad_pseudo
,
grad_basis
,
pseudo
,
kernel_size
,
is_open_spline
)
is_open_spline
)
...
@@ -32,7 +33,7 @@ class SplineBasis(Function):
...
@@ -32,7 +33,7 @@ class SplineBasis(Function):
return
basis_forward
(
self
.
degree
,
pseudo
,
self
.
kernel_size
,
return
basis_forward
(
self
.
degree
,
pseudo
,
self
.
kernel_size
,
self
.
is_open_spline
)
self
.
is_open_spline
)
def
backward
(
self
,
grad_basis
,
grad_weight_index
):
def
backward
(
self
,
grad_basis
,
grad_weight_index
):
# pragma: no cover
grad_pseudo
=
None
grad_pseudo
=
None
pseudo
,
=
self
.
saved_tensors
pseudo
,
=
self
.
saved_tensors
...
...
torch_spline_conv/utils/degree.py
View file @
9ea57e71
...
@@ -4,7 +4,7 @@ from .new import new
...
@@ -4,7 +4,7 @@ from .new import new
def
node_degree
(
index
,
n
,
out
=
None
):
def
node_degree
(
index
,
n
,
out
=
None
):
if
out
is
None
:
if
out
is
None
:
# pragma: no cover
zero
=
torch
.
zeros
(
n
)
zero
=
torch
.
zeros
(
n
)
else
:
else
:
out
.
resize_
(
n
)
if
torch
.
is_tensor
(
out
)
else
out
.
data
.
resize_
(
n
)
out
.
resize_
(
n
)
if
torch
.
is_tensor
(
out
)
else
out
.
data
.
resize_
(
n
)
...
...
torch_spline_conv/utils/ffi.py
View file @
9ea57e71
...
@@ -24,7 +24,7 @@ def basis_forward(degree, basis, weight_index, pseudo, kernel_size,
...
@@ -24,7 +24,7 @@ def basis_forward(degree, basis, weight_index, pseudo, kernel_size,
def
basis_backward
(
degree
,
self
,
grad_basis
,
pseudo
,
kernel_size
,
def
basis_backward
(
degree
,
self
,
grad_basis
,
pseudo
,
kernel_size
,
is_open_spline
):
is_open_spline
):
# pragma: no cover
name
=
'{}BasisBackward'
.
format
(
get_degree_str
(
degree
))
name
=
'{}BasisBackward'
.
format
(
get_degree_str
(
degree
))
func
=
get_func
(
name
,
self
.
is_cuda
,
self
)
func
=
get_func
(
name
,
self
.
is_cuda
,
self
)
func
(
self
,
grad_basis
,
pseudo
,
kernel_size
,
is_open_spline
)
func
(
self
,
grad_basis
,
pseudo
,
kernel_size
,
is_open_spline
)
...
@@ -35,16 +35,19 @@ def weighting_forward(self, src, weight, basis, weight_index):
...
@@ -35,16 +35,19 @@ def weighting_forward(self, src, weight, basis, weight_index):
func
(
self
,
src
,
weight
,
basis
,
weight_index
)
func
(
self
,
src
,
weight
,
basis
,
weight_index
)
def
weighting_backward_src
(
self
,
grad_output
,
weight
,
basis
,
weight_index
):
def
weighting_backward_src
(
self
,
grad_output
,
weight
,
basis
,
weight_index
):
# pragma: no cover
func
=
get_func
(
'weightingBackwardSrc'
,
self
.
is_cuda
,
self
)
func
=
get_func
(
'weightingBackwardSrc'
,
self
.
is_cuda
,
self
)
func
(
self
,
grad_output
,
weight
,
basis
,
weight_index
)
func
(
self
,
grad_output
,
weight
,
basis
,
weight_index
)
def
weighting_backward_weight
(
self
,
grad_output
,
src
,
basis
,
weight_index
):
def
weighting_backward_weight
(
self
,
grad_output
,
src
,
basis
,
weight_index
):
# pragma: no cover
func
=
get_func
(
'weightingBackwardWeight'
,
self
.
is_cuda
,
self
)
func
=
get_func
(
'weightingBackwardWeight'
,
self
.
is_cuda
,
self
)
func
(
self
,
grad_output
,
src
,
basis
,
weight_index
)
func
(
self
,
grad_output
,
src
,
basis
,
weight_index
)
def
weighting_backward_basis
(
self
,
grad_output
,
src
,
weight
,
weight_index
):
def
weighting_backward_basis
(
self
,
grad_output
,
src
,
weight
,
weight_index
):
# pragma: no cover
func
=
get_func
(
'weightingBackwardBasis'
,
self
.
is_cuda
,
self
)
func
=
get_func
(
'weightingBackwardBasis'
,
self
.
is_cuda
,
self
)
func
(
self
,
grad_output
,
src
,
weight
,
weight_index
)
func
(
self
,
grad_output
,
src
,
weight
,
weight_index
)
torch_spline_conv/weighting.py
View file @
9ea57e71
...
@@ -13,19 +13,22 @@ def weighting_forward(src, weight, basis, weight_index):
...
@@ -13,19 +13,22 @@ def weighting_forward(src, weight, basis, weight_index):
return
output
return
output
def
weighting_backward_src
(
grad_output
,
weight
,
basis
,
weight_index
):
def
weighting_backward_src
(
grad_output
,
weight
,
basis
,
weight_index
):
# pragma: no cover
grad_src
=
grad_output
.
new
(
grad_output
.
size
(
0
),
weight
.
size
(
1
))
grad_src
=
grad_output
.
new
(
grad_output
.
size
(
0
),
weight
.
size
(
1
))
weighting_bw_src
(
grad_src
,
grad_output
,
weight
,
basis
,
weight_index
)
weighting_bw_src
(
grad_src
,
grad_output
,
weight
,
basis
,
weight_index
)
return
grad_src
return
grad_src
def
weighting_backward_weight
(
grad_output
,
src
,
basis
,
weight_index
,
K
):
def
weighting_backward_weight
(
grad_output
,
src
,
basis
,
weight_index
,
K
):
# pragma: no cover
grad_weight
=
src
.
new
(
K
,
src
.
size
(
1
),
grad_output
.
size
(
1
))
grad_weight
=
src
.
new
(
K
,
src
.
size
(
1
),
grad_output
.
size
(
1
))
weighting_bw_weight
(
grad_weight
,
grad_output
,
src
,
basis
,
weight_index
)
weighting_bw_weight
(
grad_weight
,
grad_output
,
src
,
basis
,
weight_index
)
return
grad_weight
return
grad_weight
def
weighting_backward_basis
(
grad_output
,
src
,
weight
,
weight_index
):
def
weighting_backward_basis
(
grad_output
,
src
,
weight
,
weight_index
):
# pragma: no cover
grad_basis
=
src
.
new
(
weight_index
.
size
())
grad_basis
=
src
.
new
(
weight_index
.
size
())
weighting_bw_basis
(
grad_basis
,
grad_output
,
src
,
weight
,
weight_index
)
weighting_bw_basis
(
grad_basis
,
grad_output
,
src
,
weight
,
weight_index
)
return
grad_basis
return
grad_basis
...
@@ -36,7 +39,7 @@ class SplineWeighting(Function):
...
@@ -36,7 +39,7 @@ class SplineWeighting(Function):
self
.
save_for_backward
(
src
,
weight
,
basis
,
weight_index
)
self
.
save_for_backward
(
src
,
weight
,
basis
,
weight_index
)
return
weighting_forward
(
src
,
weight
,
basis
,
weight_index
)
return
weighting_forward
(
src
,
weight
,
basis
,
weight_index
)
def
backward
(
self
,
grad_output
):
def
backward
(
self
,
grad_output
):
# pragma: no cover
grad_src
=
grad_weight
=
grad_basis
=
None
grad_src
=
grad_weight
=
grad_basis
=
None
src
,
weight
,
basis
,
weight_index
=
self
.
saved_tensors
src
,
weight
,
basis
,
weight_index
=
self
.
saved_tensors
...
...
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