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
c5f0df95
Commit
c5f0df95
authored
Mar 03, 2018
by
rusty1s
Browse files
two-dimensional or more basis computation
parent
77728ba9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
56 deletions
+30
-56
test/basis.json
test/basis.json
+19
-3
test/test_basis.py
test/test_basis.py
+0
-3
torch_spline_conv/src/generic/cpu.c
torch_spline_conv/src/generic/cpu.c
+11
-50
No files found.
test/basis.json
View file @
c5f0df95
[
{
"degree"
:
1
,
"pseudo"
:
[
0
,
0.25
,
0.5
,
0.75
,
1
],
"pseudo"
:
[
0
,
0.125
,
0.25
,
0.5
,
0.75
,
0.875
,
1
],
"kernel_size"
:
[
5
],
"is_open_spline"
:
[
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_basis"
:
[[
0
,
1
],
[
0.5
,
0.5
],
[
0
,
1
],
[
0
,
1
],
[
0
,
1
],
[
0.5
,
0.5
],
[
0
,
1
]],
"expected_index"
:
[[
1
,
0
],
[
1
,
0
],
[
2
,
1
],
[
3
,
2
],
[
4
,
3
],
[
4
,
3
],
[
0
,
4
]]
},
{
"degree"
:
1
,
"pseudo"
:
[
0
,
0.125
,
0.25
,
0.5
,
0.75
,
0.875
,
1
],
"kernel_size"
:
[
4
],
"is_open_spline"
:
[
0
],
"expected_basis"
:
[[
0
,
1
],
[
0.5
,
0.5
],
[
0
,
1
],
[
0
,
1
],
[
0
,
1
],
[
0.5
,
0.5
],
[
0
,
1
]],
"expected_index"
:
[[
1
,
0
],
[
1
,
0
],
[
2
,
1
],
[
3
,
2
],
[
0
,
3
],
[
0
,
3
],
[
1
,
0
]]
},
{
"degree"
:
1
,
"pseudo"
:
[[
0.125
,
0.5
],
[
0.5
,
0.5
],
[
0.75
,
0.125
]],
"kernel_size"
:
[
5
,
5
],
"is_open_spline"
:
[
1
,
1
],
"expected_basis"
:
[[
0
,
0
,
0.5
,
0.5
],
[
0
,
0
,
0
,
1
],
[
0
,
0.5
,
0
,
0.5
]],
"expected_index"
:
[[
8
,
3
,
7
,
2
],
[
18
,
13
,
17
,
12
],
[
21
,
16
,
20
,
15
]]
}
]
test/test_basis.py
View file @
c5f0df95
...
...
@@ -24,8 +24,5 @@ def test_spline_basis_cpu(tensor, i):
expected_index
=
torch
.
ByteTensor
(
data
[
i
][
'expected_index'
])
basis
,
index
=
spline_basis
(
degree
,
pseudo
,
kernel_size
,
is_open_spline
,
K
)
print
(
'basis'
,
basis
)
print
(
'weight_index'
,
index
)
return
assert
basis
.
tolist
()
==
expected_basis
.
tolist
()
assert
index
.
tolist
()
==
expected_index
.
tolist
()
torch_spline_conv/src/generic/cpu.c
View file @
c5f0df95
...
...
@@ -2,73 +2,34 @@
#define TH_GENERIC_FILE "generic/cpu.c"
#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
,
TH
Long
Tensor
*
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
D
=
THTensor_
(
size
)(
pseudo
,
1
);
int64_t
S
=
THLongTensor_size
(
weight_index
,
1
);
int64_t
s
,
d
;
int64_t
k
,
s
,
S
,
d
,
D
;
real
value
;
D
=
THTensor_
(
size
)(
pseudo
,
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_EQ_EXCEPT_DIM
,
for
(
s
=
0
;
s
<
S
;
s
++
)
{
/* /1* k = K; *1/ */
real
b
=
1
;
int64_t
i
=
0
;
int64_t
k
=
s
;
int64_t
bla
=
K
;
for
(
d
=
0
;
d
<
D
;
d
++
)
{
/*
/1* k
/= kernel_size
[d]; *1/ */
bla
/=
kernel_size
_data
[
d
];
int64_t
mod
=
k
%
2
;
k
>>=
1
;
value
=
*
(
pseudo_data
+
d
*
pseudo_stride
)
*
(
kernel_size_data
[
d
]
-
is_open_spline_data
[
d
]);
real
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 top = (bot + 1) % kernel_size[d]; *1/ */
/* /1* bot %= kernel_size[d]; *1/ */
i
+=
((
1
-
mod
)
*
top
+
mod
*
bot
)
*
bla
;
}
basis_data
[
s
*
basis_stride
]
=
b
;
weight_index_data
[
s
*
weight_index_stride
]
=
i
;
})
}
/* void spline_(linear)(THFloatTensor *amount, THLongTensor *index, THFloatTensor *input, THLongTensor *kernel, THByteTensor *open) { */
/* // s = (m+1)^d */
/* // amount: E x s */
/* // index: E x s */
/* // input: E x d */
/* // kernel: d */
/* // open: d */
/* // */
/* int64_t i, d; */
/* int64_t E = THLongTensor_size(index, 0); */
/* int64_t K = THLongTensor_size(index, 1); */
/* int64_t D = THLongTensor_size(kernel, 0); */
/* for (i = 0; i < E * K; i++) { */
/* for (d = 0; d < D; d++) { */
/* } */
/* } */
/* } */
/* void spline_(quadratic)(THFloatTensor *amount, THLongTensor *index, THFloatTensor *input, THLongTensor *kernel, THByteTensor *open) { */
/* int64_t i; */
/* for (i = 0; i < THLongTensor_size(input, dim); i++) { */
/* } */
/* } */
/* void spline_(cubic)(THFloatTensor *amount, THLongTensor *index, THFloatTensor *input, THLongTensor *kernel, THByteTensor *open) { */
/* int64_t i; */
/* for (i = 0; i < THLongTensor_size(input, dim); i++) { */
/* } */
/* } */
#endif
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