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
ba1f449f
Commit
ba1f449f
authored
Mar 03, 2018
by
rusty1s
Browse files
linear and one-dimensional pseudos
parent
f7377ac4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
12 deletions
+23
-12
test/basis.json
test/basis.json
+1
-1
torch_spline_conv/functions/utils.py
torch_spline_conv/functions/utils.py
+2
-2
torch_spline_conv/src/generic/cpu.c
torch_spline_conv/src/generic/cpu.c
+20
-9
No files found.
test/basis.json
View file @
ba1f449f
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
"degree"
:
1
,
"degree"
:
1
,
"pseudo"
:
[
0
,
0.25
,
0.5
,
0.75
,
1
],
"pseudo"
:
[
0
,
0.25
,
0.5
,
0.75
,
1
],
"kernel_size"
:
[
5
],
"kernel_size"
:
[
5
],
"is_open_spline"
:
[
0
],
"is_open_spline"
:
[
1
],
"expected_basis"
:
[[
0
,
1
],
[
0
,
1
],
[
0
,
1
],
[
0
,
1
],
[
0
,
1
]],
"expected_basis"
:
[[
0
,
1
],
[
0
,
1
],
[
0
,
1
],
[
0
,
1
],
[
0
,
1
]],
"expected_index"
:
[[
1
,
0
],
[
2
,
1
],
[
3
,
2
],
[
4
,
3
],
[
0
,
4
]]
"expected_index"
:
[[
1
,
0
],
[
2
,
1
],
[
3
,
2
],
[
4
,
3
],
[
0
,
4
]]
}
}
...
...
torch_spline_conv/functions/utils.py
View file @
ba1f449f
...
@@ -3,7 +3,7 @@ from torch.autograd import Function
...
@@ -3,7 +3,7 @@ from torch.autograd import Function
from
.._ext
import
ffi
from
.._ext
import
ffi
degrees
=
{
1
:
'linear'
,
2
:
'quadric'
,
3
:
'cubic'
}
implemented_
degrees
=
{
1
:
'linear'
,
2
:
'quadric'
,
3
:
'cubic'
}
def
get_func
(
name
,
tensor
):
def
get_func
(
name
,
tensor
):
...
@@ -19,7 +19,7 @@ def spline_basis(degree, pseudo, kernel_size, is_open_spline, K):
...
@@ -19,7 +19,7 @@ def spline_basis(degree, pseudo, kernel_size, is_open_spline, K):
basis
=
pseudo
.
new
(
pseudo
.
size
(
0
),
s
)
basis
=
pseudo
.
new
(
pseudo
.
size
(
0
),
s
)
weight_index
=
kernel_size
.
new
(
pseudo
.
size
(
0
),
s
)
weight_index
=
kernel_size
.
new
(
pseudo
.
size
(
0
),
s
)
degree
=
degrees
.
get
(
degree
)
degree
=
implemented_
degrees
.
get
(
degree
)
if
degree
is
None
:
if
degree
is
None
:
raise
NotImplementedError
(
'Basis computation not implemented for '
raise
NotImplementedError
(
'Basis computation not implemented for '
'specified B-spline degree'
)
'specified B-spline degree'
)
...
...
torch_spline_conv/src/generic/cpu.c
View file @
ba1f449f
...
@@ -3,30 +3,41 @@
...
@@ -3,30 +3,41 @@
#else
#else
void
spline_
(
basis_linear
)(
THTensor
*
basis
,
THLongTensor
*
weight_index
,
THTensor
*
pseudo
,
THTensor
*
kernel_size
,
THByteTensor
*
is_open_spline
,
int
K
)
{
void
spline_
(
basis_linear
)(
THTensor
*
basis
,
THLongTensor
*
weight_index
,
THTensor
*
pseudo
,
THTensor
*
kernel_size
,
THByteTensor
*
is_open_spline
,
int
K
)
{
int64_t
*
kernel_size_data
=
kernel_size
->
storage
->
data
+
kernel_size
->
storageOffset
;
uint8_t
*
is_open_spline_data
=
is_open_spline
->
storage
->
data
+
is_open_spline
->
storageOffset
;
int64_t
k
,
s
,
S
,
d
,
D
;
int64_t
k
,
s
,
S
,
d
,
D
;
real
value
;
real
value
;
D
=
THTensor_
(
size
)(
pseudo
,
1
);
D
=
THTensor_
(
size
)(
pseudo
,
1
);
S
=
THLongTensor_size
(
weight_index
,
1
);
S
=
THLongTensor_size
(
weight_index
,
1
);
/*
TH_TENSOR_DIM_APPLY3(real, basis, int64_t, weight_index, real, pseudo, 1, TH_TENSOR_DIM_APPLY3_SIZE_E
X
_EXCEPT_DIM,
*/
TH_TENSOR_DIM_APPLY3
(
real
,
basis
,
int64_t
,
weight_index
,
real
,
pseudo
,
1
,
TH_TENSOR_DIM_APPLY3_SIZE_E
Q
_EXCEPT_DIM
,
/*
for (s = 0; s < S; s++) {
*/
for
(
s
=
0
;
s
<
S
;
s
++
)
{
/* /1* k = K; *1/ */
/* /1* k = K; *1/ */
/*
/1*
b = 1; i
= 0; *1/ */
real
b
=
1
;
i
nt64_t
i
=
0
;
/*
for (d = 0; d < D; d++) {
*/
for
(
d
=
0
;
d
<
D
;
d
++
)
{
/* /1* k /= kernel_size[d]; *1/ */
/* /1* k /= kernel_size[d]; *1/ */
/* /1* value = *(pseudo_data + d * pseudo_stride) * (kernel_size[d] - is_open_spline[d]); *1/ */
value
=
*
(
pseudo_data
+
d
*
pseudo_stride
)
*
(
kernel_size_data
[
d
]
-
is_open_spline_data
[
d
]);
int64_t
bot
=
((
int64_t
)
value
)
%
kernel_size_data
[
d
];
int64_t
top
=
((
int64_t
)
(
value
+
1
))
%
kernel_size_data
[
d
];
value
-=
floor
(
value
);
int
mod
=
s
%
2
;
b
*=
(
1
-
mod
)
*
value
+
mod
*
(
1
-
value
);
i
+=
(
1
-
mod
)
*
top
+
mod
*
bot
;
/* /1* int bot = int64_t(value); *1/ */
/* /1* int bot = int64_t(value); *1/ */
/* /1* int top = (bot + 1) % kernel_size[d]; *1/ */
/* /1* int top = (bot + 1) % kernel_size[d]; *1/ */
/* /1* bot %= kernel_size[d]; *1/ */
/* /1* bot %= kernel_size[d]; *1/ */
/*
}
*/
}
/*
basis_data[s * basis_stride] =
1; */
basis_data
[
s
*
basis_stride
]
=
b
;
/*
weight_index_data[s * weight_index_stride] =
2; */
weight_index_data
[
s
*
weight_index_stride
]
=
i
;
/* }) */
})
}
}
...
...
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