Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F19243920
test_StatAccumulatorArr.cc
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
test_StatAccumulatorArr.cc
View Options
#include
<sstream>
#include
"UnitTest++.h"
#include
"test_utils.hh"
#include
"npstat/stat/StatAccumulator.hh"
#include
"npstat/stat/StatAccumulatorArr.hh"
using
namespace
npstat
;
using
namespace
std
;
namespace
{
TEST
(
StatAccumulatorArr
)
{
const
double
eps
=
1.0e-14
;
const
unsigned
dim
=
10
;
const
unsigned
nfills
=
25
;
std
::
vector
<
double
>
buf
(
dim
);
StatAccumulatorArr
acc1
;
std
::
vector
<
StatAccumulator
>
acc2
(
dim
);
for
(
unsigned
i
=
0
;
i
<
nfills
;
++
i
)
{
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
buf
[
j
]
=
test_rng
()
*
2.0
-
1.0
;
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
acc2
[
j
]
+=
buf
[
j
];
acc1
+=
buf
;
}
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
{
CHECK_EQUAL
(
acc2
[
j
].
count
(),
acc1
.
count
());
CHECK_EQUAL
(
acc2
[
j
].
min
(),
acc1
.
min
(
j
));
CHECK_EQUAL
(
acc2
[
j
].
max
(),
acc1
.
max
(
j
));
CHECK_CLOSE
(
acc2
[
j
].
mean
(),
acc1
.
mean
(
j
),
eps
);
CHECK_CLOSE
(
acc2
[
j
].
stdev
(),
acc1
.
stdev
(
j
),
eps
);
CHECK_CLOSE
(
acc2
[
j
].
meanUncertainty
(),
acc1
.
meanUncertainty
(
j
),
eps
);
}
acc1
.
min
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_EQUAL
(
acc2
[
j
].
min
(),
buf
[
j
]);
acc1
.
max
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_EQUAL
(
acc2
[
j
].
max
(),
buf
[
j
]);
acc1
.
mean
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_CLOSE
(
acc2
[
j
].
mean
(),
buf
[
j
],
eps
);
acc1
.
stdev
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_CLOSE
(
acc2
[
j
].
stdev
(),
buf
[
j
],
eps
);
acc1
.
meanUncertainty
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_CLOSE
(
acc2
[
j
].
meanUncertainty
(),
buf
[
j
],
eps
);
StatAccumulatorArr
acc3
(
dim
);
for
(
unsigned
i
=
0
;
i
<
2
*
nfills
;
++
i
)
{
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
buf
[
j
]
=
test_rng
()
*
2.0
-
1.0
;
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
acc2
[
j
]
+=
buf
[
j
];
acc3
.
accumulate
(
&
buf
[
0
],
dim
);
}
acc1
+=
acc3
;
CHECK_EQUAL
(
acc2
[
0
].
count
(),
acc1
.
count
());
acc1
.
min
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_EQUAL
(
acc2
[
j
].
min
(),
buf
[
j
]);
acc1
.
max
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_EQUAL
(
acc2
[
j
].
max
(),
buf
[
j
]);
acc1
.
mean
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_CLOSE
(
acc2
[
j
].
mean
(),
buf
[
j
],
eps
);
acc1
.
stdev
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_CLOSE
(
acc2
[
j
].
stdev
(),
buf
[
j
],
eps
);
acc1
.
meanUncertainty
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_CLOSE
(
acc2
[
j
].
meanUncertainty
(),
buf
[
j
],
eps
);
std
::
ostringstream
os
;
CHECK
(
acc1
.
classId
().
write
(
os
));
CHECK
(
acc1
.
write
(
os
));
StatAccumulatorArr
acc5
;
CHECK
(
acc5
.
write
(
os
));
std
::
istringstream
is
(
os
.
str
());
gs
::
ClassId
clid
(
is
,
1
);
StatAccumulatorArr
acc4
;
StatAccumulatorArr
::
restore
(
clid
,
is
,
&
acc4
);
CHECK
(
acc1
==
acc4
);
StatAccumulatorArr
acc6
;
StatAccumulatorArr
::
restore
(
clid
,
is
,
&
acc6
);
CHECK
(
acc5
==
acc6
);
CHECK
(
acc1
!=
acc6
);
double
factor
=
1.2345
;
acc1
*=
factor
;
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
acc2
[
j
]
*=
factor
;
acc1
.
min
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_EQUAL
(
acc2
[
j
].
min
(),
buf
[
j
]);
acc1
.
max
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_EQUAL
(
acc2
[
j
].
max
(),
buf
[
j
]);
acc1
.
mean
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_CLOSE
(
acc2
[
j
].
mean
(),
buf
[
j
],
eps
);
acc1
.
stdev
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_CLOSE
(
acc2
[
j
].
stdev
(),
buf
[
j
],
eps
);
acc1
.
meanUncertainty
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_CLOSE
(
acc2
[
j
].
meanUncertainty
(),
buf
[
j
],
eps
);
factor
=
-
0.6585
;
acc1
*=
factor
;
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
acc2
[
j
]
*=
factor
;
acc1
.
min
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_EQUAL
(
acc2
[
j
].
min
(),
buf
[
j
]);
acc1
.
max
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_EQUAL
(
acc2
[
j
].
max
(),
buf
[
j
]);
acc1
.
mean
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_CLOSE
(
acc2
[
j
].
mean
(),
buf
[
j
],
eps
);
acc1
.
stdev
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_CLOSE
(
acc2
[
j
].
stdev
(),
buf
[
j
],
eps
);
acc1
.
meanUncertainty
(
&
buf
[
0
],
buf
.
size
());
for
(
unsigned
j
=
0
;
j
<
dim
;
++
j
)
CHECK_CLOSE
(
acc2
[
j
].
meanUncertainty
(),
buf
[
j
],
eps
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-c
Expires
Tue, Sep 30, 4:37 AM (1 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6509051
Default Alt Text
test_StatAccumulatorArr.cc (4 KB)
Attached To
Mode
rNPSTATSVN npstatsvn
Attached
Detach File
Event Timeline
Log In to Comment