Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Martin Reinecke
ducc
Commits
f53a2e67
Commit
f53a2e67
authored
Jul 01, 2020
by
Martin Reinecke
Browse files
temporary addition of C++ test code
parent
9abe011e
Pipeline
#77601
passed with stages
in 16 minutes and 11 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
horner_test.cc
0 → 100644
View file @
f53a2e67
// compile with "g++ -O3 -ffast-math -std=c++17 -march=native -Isrc horner_test.cc"
#include
"ducc0/math/horner_kernel.h"
#include
"ducc0/infra/timers.h"
#include
<iostream>
using
namespace
ducc0
;
using
namespace
std
;
// you can use any kernel defined on [-1; 1] here
double
es_kernel
(
size_t
w
,
double
x
)
{
auto
beta
=
2.3
*
w
;
return
exp
(
beta
*
(
sqrt
(
1
-
x
*
x
)
-
1
));
}
int
main
()
{
constexpr
size_t
W
=
12
;
// kernel support in pixels
constexpr
size_t
D
=
12
;
// degree of approximating polynomials
using
FLT
=
double
;
size_t
Neval
=
1000000000
;
// we will do a billion function evaluations altogether
size_t
Ncall
=
Neval
/
W
;
FLT
delta
=
2.
/
W
/
double
(
Ncall
);
// small offsets between individual calls to prevent the compiler from optimizing too much
HornerKernel
<
W
,
D
,
FLT
>
hk
([](
double
x
){
return
es_kernel
(
W
,
x
);});
double
sum
=
0
;
SimpleTimer
timer
;
for
(
size_t
i
=
0
;
i
<
Ncall
;
++
i
)
{
FLT
p0
=
-
FLT
(
1
)
+
i
*
delta
;
// position of first sample
auto
res
=
hk
.
eval
(
p0
);
for
(
size_t
i
=
0
;
i
<
W
;
++
i
)
sum
+=
res
[
i
];
// needed to avoid over-optimization
}
cout
<<
"HornerKernel: "
<<
Neval
/
timer
()
<<
" function approximations per second"
<<
endl
;
cout
<<
sum
<<
endl
;
HornerKernelFlexible
<
FLT
>
hk2
(
W
,
D
,[](
double
x
){
return
es_kernel
(
W
,
x
);});
sum
=
0
;
timer
.
reset
();
for
(
size_t
i
=
0
;
i
<
Ncall
;
++
i
)
{
FLT
p0
=
-
FLT
(
1
)
+
i
*
delta
;
// position of first sample
auto
res
=
hk2
.
eval
(
p0
);
for
(
size_t
i
=
0
;
i
<
W
;
++
i
)
sum
+=
res
[
i
];
// needed to avoid over-optimization
}
cout
<<
"HornerKernelFlexible: "
<<
Neval
/
timer
()
<<
" function approximations per second"
<<
endl
;
cout
<<
sum
<<
endl
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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