blob: 1878e749f250e907dc63ea80257e31a50c5af707 (
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
|
// norm.cc -- compute norms
// $Id$
//
// *** class jtutil::norm::
//
#include <float.h>
#include <math.h>
#include <assert.h>
#include "jt/util.hh"
//*****************************************************************************
// specify data point
namespace jtutil
{
template <typename fp>
void norm<fp>::data(fp x)
{
++N_;
sum2_ += x*x;
infinity_norm_ = jtutil::max(infinity_norm_, jtutil::abs(x));
}
} // namespace jtutil::
//******************************************************************************
// get norms
namespace jtutil
{
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>;
|