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
c78c4cd8
Commit
c78c4cd8
authored
Mar 23, 2018
by
rusty1s
Browse files
removed unused functions
parent
4ce1c05f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
37 deletions
+24
-37
test/test_spline_conv.py
test/test_spline_conv.py
+7
-9
torch_spline_conv/functions/spline_conv.py
torch_spline_conv/functions/spline_conv.py
+17
-28
No files found.
test/test_spline_conv.py
View file @
c78c4cd8
...
...
@@ -31,15 +31,14 @@ def test_spline_conv_cpu(tensor):
]
expected_output
=
[
(
1
+
12.5
*
9
+
13
*
10
+
sum
(
edgewise_output
)
)
/
5
,
1
+
12.5
*
1
+
13
*
2
,
1
+
12.5
*
3
+
13
*
4
,
1
+
12.5
*
5
+
13
*
6
,
1
+
12.5
*
7
+
13
*
8
,
[
1
+
12.5
*
9
+
13
*
10
+
sum
(
edgewise_output
)
/
4
]
,
[
1
+
12.5
*
1
+
13
*
2
]
,
[
1
+
12.5
*
3
+
13
*
4
]
,
[
1
+
12.5
*
5
+
13
*
6
]
,
[
1
+
12.5
*
7
+
13
*
8
]
,
]
output
=
[
pytest
.
approx
(
o
,
0.01
)
for
o
in
output
.
view
(
-
1
).
tolist
()]
assert
output
==
expected_output
assert
output
.
tolist
()
==
expected_output
x
,
weight
,
pseudo
=
Variable
(
x
),
Variable
(
weight
),
Variable
(
pseudo
)
root_weight
,
bias
=
Variable
(
root_weight
),
Variable
(
bias
)
...
...
@@ -47,8 +46,7 @@ def test_spline_conv_cpu(tensor):
output
=
spline_conv
(
x
,
edge_index
,
pseudo
,
weight
,
kernel_size
,
is_open_spline
,
1
,
root_weight
,
bias
)
output
=
[
pytest
.
approx
(
o
,
0.01
)
for
o
in
output
.
data
.
view
(
-
1
).
tolist
()]
assert
output
==
expected_output
assert
output
.
data
.
tolist
()
==
expected_output
def
test_spline_weighting_backward_cpu
():
...
...
torch_spline_conv/functions/spline_conv.py
View file @
c78c4cd8
...
...
@@ -15,39 +15,12 @@ def spline_conv(x,
root_weight
=
None
,
bias
=
None
):
# Convolve over each node.
output
=
basic_spline_conv
(
x
,
edge_index
,
pseudo
,
weight
,
kernel_size
,
is_open_spline
,
degree
)
# Compute degree.
degree
=
x
.
new
()
if
torch
.
is_tensor
(
x
)
else
x
.
data
.
new
()
degree
=
node_degree
(
edge_index
,
x
.
size
(
0
),
out
=
degree
)
# Weight root node separately (if wished).
if
root_weight
is
not
None
:
output
+=
torch
.
mm
(
x
,
root_weight
)
degree
+=
1
# Normalize output by node degree.
degree
=
degree
.
unsqueeze
(
-
1
).
clamp_
(
min
=
1
)
output
/=
degree
if
torch
.
is_tensor
(
x
)
else
Var
(
degree
)
# Add bias (if wished).
if
bias
is
not
None
:
output
+=
bias
return
output
def
basic_spline_conv
(
x
,
edge_index
,
pseudo
,
weight
,
kernel_size
,
is_open_spline
,
degree
):
n
,
e
,
m_out
=
x
.
size
(
0
),
edge_index
.
size
(
1
),
weight
.
size
(
2
)
x
=
x
.
unsqueeze
(
-
1
)
if
x
.
dim
()
==
1
else
x
pseudo
=
pseudo
.
unsqueeze
(
-
1
)
if
pseudo
.
dim
()
==
1
else
pseudo
#
Weight gathered features based on B-spline bases and trainable weights
.
#
Convolve over each node
.
output
=
spline_weighting
(
x
[
edge_index
[
1
]],
pseudo
,
weight
,
kernel_size
,
is_open_spline
,
degree
)
...
...
@@ -57,4 +30,20 @@ def basic_spline_conv(x, edge_index, pseudo, weight, kernel_size,
zero
=
x
.
new
(
n
,
m_out
)
if
torch
.
is_tensor
(
x
)
else
Var
(
x
.
data
.
new
(
n
,
m_out
))
output
=
zero
.
fill_
(
0
).
scatter_add_
(
0
,
row
,
output
)
# Compute degree.
degree
=
x
.
new
()
if
torch
.
is_tensor
(
x
)
else
x
.
data
.
new
()
degree
=
node_degree
(
edge_index
,
n
,
out
=
degree
)
# Normalize output by node degree.
degree
=
degree
.
unsqueeze
(
-
1
).
clamp_
(
min
=
1
)
output
/=
degree
if
torch
.
is_tensor
(
x
)
else
Var
(
degree
)
# Weight root node separately (if wished).
if
root_weight
is
not
None
:
output
+=
torch
.
mm
(
x
,
root_weight
)
# Add bias (if wished).
if
bias
is
not
None
:
output
+=
bias
return
output
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