blob: bce9ee281fe2508b2974276210e6f57672359e42 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// norm.cc -- compute norms
// $Header$
//
// *** class jtutil::norm::
//
#include <math.h>
#include <assert.h>
#include "util.hh"
//*****************************************************************************
// specify data point
namespace jtutil
{
template <typename fp>
void norm<fp>::data(fp x)
{
++N_;
sum_ += x;
sum2_ += x*x;
infinity_norm_ = jtutil::max(infinity_norm_, jtutil::abs<fp>(x));
}
} // namespace jtutil::
//******************************************************************************
// get norms etc
namespace jtutil
{
template<typename fp>
fp norm<fp>::mean() const { return sum_/fp(N_); }
template<typename fp>
fp norm<fp>::two_norm() const { return sqrt(sum2_); }
template<typename fp>
fp norm<fp>::rms_norm() const
{ assert(is_nonempty()); return sqrt(sum2_/fp(N_)); }
template<typename fp>
fp norm<fp>::infinity_norm() const { return infinity_norm_; }
} // namespace jtutil::
//******************************************************************************
//
// ***** template instantiations *****
//
template class jtutil::norm<float>;
template class jtutil::norm<double>;
|