15 #include <type_traits>
18 template <
typename tuple_t>
19 constexpr
auto get_array_from_tuple( tuple_t&& tuple ) {
20 constexpr
auto get_array = [](
auto&&... x ) {
return std::array{ std::forward<decltype( x )>( x )... }; };
21 return std::apply( get_array, std::forward<tuple_t>( tuple ) );
29 constexpr
unsigned int NSUMS(
unsigned int ND ) {
return 1 + ND + ND * ( ND + 1 ) / 2; }
31 template <
typename Arithmetic, atomicity Atomicity,
unsigned int ND>
33 using InputType = std::conditional_t<ND == 1, Arithmetic, std::array<Arithmetic, ND>>;
39 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) { ( *this )[i] = other[i]; }
43 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) { ( *this )[i] = other[i]; }
49 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) {
out[i] = ( *this )[i].load( std::memory_order_relaxed ); }
53 using InternalType = std::conditional_t<Atomicity == atomicity::full, OutputTypeTS, OutputType>;
61 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) { old[i] =
v[i].exchange( newv[i] ); }
64 return std::exchange(
v, newv );
70 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) {
fetch_add( a[i], b[i] ); }
72 for (
unsigned int i = 0; i < ND * ( ND + 3 ); i++ ) a[i] += b[i];
79 if constexpr ( ND == 1 ) {
84 for (
unsigned int i = 0; i < ND; i++ ) diff[i + 1] += b[i];
85 unsigned int n = 1 + ND;
86 for (
unsigned int i = 0; i < ND; i++ ) {
87 for (
unsigned int j = i;
j < ND;
j++ ) {
88 diff[
n] = b[i] * b[
j];
95 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) {
fetch_add( a[i], diff[i] ); }
97 for (
unsigned int i = 0; i <
NSUMS( ND ); i++ ) a[i] += diff[i];
102 template <
typename Arithmetic, atomicity Atomicity,
unsigned int ND>
104 :
GenericAccumulator<std::array<Arithmetic, ND>, std::array<Arithmetic, NSUMS( ND )>, Atomicity, Identity,
105 Identity, SigmasValueHandler<Arithmetic, Atomicity, ND>> {
110 template <
typename Arithmetic, atomicity Atomicity>
112 :
GenericAccumulator<Arithmetic, std::array<Arithmetic, 3>, Atomicity, Identity, Identity,
113 SigmasValueHandler<Arithmetic, Atomicity, 1>> {
122 template <atomicity Atomicity,
typename Arithmetic,
unsigned int ND,
typename AxisTupleType>
125 unsigned long, IntegralAccumulator, AxisTupleType> {
131 template <atomicity,
typename,
unsigned int,
typename>
134 static_assert(
ND <= 3,
"Root on supports histogrmas with dimension <= 3" );
145 typename InputType::ValueType
m_v;
149 using Parent::Parent;
161 template <atomicity ato>
175 void update(
typename InputType::ValueType
v ) {
178 if (
v.inAcceptance( this->axis() ) ) {
179 if constexpr (
ND == 1 ) {
182 m_accumulator += get_array_from_tuple(
static_cast<typename InputType::InternalType
>(
v ) );
194 template <
typename Arithmetic>
195 Arithmetic stddev( Arithmetic
n, Arithmetic
s, Arithmetic
s2 ) {
198 auto v = (
n > 0 ) ? ( (
s2 -
s * (
s /
n ) ) /
n ) : Arithmetic{};
199 return ( Arithmetic{ 0 } >
v ) ? Arithmetic{} :
sqrt(
v );
206 template <atomicity Atomicity,
typename Arithmetic,
typename ND,
typename AxisTupleType>
209 template <atomicity Atomicity,
typename Arithmetic,
typename AxisTupleType>
215 Arithmetic
nEntries()
const {
return this->sums2()[0]; }
216 Arithmetic
sum()
const {
return this->sums2()[1]; }
217 Arithmetic
sum2()
const {
return this->sums2()[2]; }
218 Arithmetic
mean()
const {
return sum() / nEntries(); }
222 template <atomicity Atomicity,
typename Arithmetic,
typename AxisTupleType>
228 Arithmetic
nEntries()
const {
return this->sums2()[0]; }
229 Arithmetic
sumx()
const {
return this->sums2()[1]; }
230 Arithmetic
sumy()
const {
return this->sums2()[2]; }
231 Arithmetic
sumx2()
const {
return this->sums2()[3]; }
232 Arithmetic
sumy2()
const {
return this->sums2()[5]; }
233 Arithmetic
sumxy()
const {
return this->sums2()[4]; }
234 Arithmetic
meanx()
const {
return sumx() / nEntries(); }
235 Arithmetic
meany()
const {
return sumy() / nEntries(); }
240 template <atomicity Atomicity,
typename Arithmetic,
typename AxisTupleType>
246 Arithmetic
nEntries()
const {
return this->sums2()[0]; }
247 Arithmetic
sumx()
const {
return this->sums2()[1]; }
248 Arithmetic
sumy()
const {
return this->sums2()[2]; }
249 Arithmetic
sumz()
const {
return this->sums2()[3]; }
250 Arithmetic
sumx2()
const {
return this->sums2()[4]; }
251 Arithmetic
sumy2()
const {
return this->sums2()[7]; }
252 Arithmetic
sumz2()
const {
return this->sums2()[9]; }
253 Arithmetic
sumxy()
const {
return this->sums2()[5]; }
254 Arithmetic
sumxz()
const {
return this->sums2()[6]; }
255 Arithmetic
sumyz()
const {
return this->sums2()[8]; }
256 Arithmetic
meanx()
const {
return sumx() / nEntries(); }
257 Arithmetic
meany()
const {
return sumy() / nEntries(); }
258 Arithmetic
meanz()
const {
return sumz() / nEntries(); }
282 template <
unsigned int ND, atomicity Atomicity,
typename Arithmetic, const
char* Type,
typename AxisTupleType>
285 template <atomicity Atomicity,
typename Arithmetic, const
char* Type,
typename AxisTupleType>
290 using Parent::Parent;
295 j[
"nTotEntries"] =
h.nEntries();
297 j[
"mean"] =
h.mean();
298 j[
"sum2"] =
h.sum2();
299 j[
"standard_deviation"] =
h.standard_deviation();
303 template <atomicity Atomicity,
typename Arithmetic, const
char* Type,
typename AxisTupleType>
308 using Parent::Parent;
313 j[
"nTotEntries"] =
h.nEntries();
314 j[
"sumx"] =
h.sumx();
315 j[
"sumy"] =
h.sumy();
316 j[
"meanx"] =
h.meanx();
317 j[
"meany"] =
h.meany();
318 j[
"sumx2"] =
h.sumx2();
319 j[
"sumy2"] =
h.sumy2();
320 j[
"sumxy"] =
h.sumxy();
321 j[
"standard_deviationx"] =
h.standard_deviationx();
322 j[
"standard_deviationy"] =
h.standard_deviationy();
326 template <atomicity Atomicity,
typename Arithmetic, const
char* Type,
typename AxisTupleType>
331 using Parent::Parent;
336 j[
"nTotEntries"] =
h.nEntries();
337 j[
"sumx"] =
h.sumx();
338 j[
"sumy"] =
h.sumy();
339 j[
"sumz"] =
h.sumz();
340 j[
"meanx"] =
h.meanx();
341 j[
"meany"] =
h.meany();
342 j[
"meanz"] =
h.meanz();
343 j[
"sumx2"] =
h.sumx2();
344 j[
"sumy2"] =
h.sumy2();
345 j[
"sumz2"] =
h.sumz2();
346 j[
"sumxy"] =
h.sumxy();
347 j[
"sumxz"] =
h.sumxz();
348 j[
"sumyz"] =
h.sumyz();
349 j[
"standard_deviationx"] =
h.standard_deviationx();
350 j[
"standard_deviationy"] =
h.standard_deviationy();
351 j[
"standard_deviationz"] =
h.standard_deviationz();
357 typename AxisTupleType = make_tuple_t<Axis<Arithmetic>, ND>>