STIR  6.3.0
norm.h
Go to the documentation of this file.
1 //
2 //
3 /*
4  Copyright (C) 2003- 2005, Hammersmith Imanet Ltd
5  This file is part of STIR.
6 
7  SPDX-License-Identifier: Apache-2.0
8 
9  See STIR/LICENSE.txt for details
10 */
11 
12 #ifndef __stir_numerics_norm_H__
13 #define __stir_numerics_norm_H__
14 
24 #include "stir/ArrayFwd.h"
25 #include <complex>
26 #include <cmath>
27 #ifdef BOOST_NO_STDC_NAMESPACE
28 namespace std
29 {
30 using ::fabs;
31 }
32 #endif
33 
34 START_NAMESPACE_STIR
35 
41 
43 
49 // specialisations for complex numbers are in .inl file for clarity of this file.
50 template <typename T>
52 {
53  double operator()(T x) const { return static_cast<double>(x) * x; }
54 };
55 
57 
58 template <typename elemT>
59 inline double
60 norm_squared(const elemT t)
61 {
62  return NormSquared<elemT>()(t);
63 }
64 
66 
67 template <typename elemT>
68 inline double
69 norm(const elemT t)
70 {
71  return sqrt(norm_squared(t));
72 }
73 
74 // 2 overloads to avoid doing sqrt(t*t)
75 inline double
76 norm(const double t)
77 {
78  return std::fabs(t);
79 }
80 
81 inline double
82 norm(const float t)
83 {
84  return std::fabs(t);
85 }
86 
88 
91 template <class Iter>
92 inline double norm_squared(Iter begin, Iter end);
93 
95 
100 template <class Iter>
101 inline double norm(Iter begin, Iter end);
102 
104 
108 template <class elemT>
109 inline double norm(const Array<1, elemT>& v1);
110 
112 
116 template <class elemT>
117 inline double norm_squared(const Array<1, elemT>& v1);
118 
120 
121 END_NAMESPACE_STIR
122 
123 #include "stir/numerics/norm.inl"
124 
125 #endif
double norm_squared(const Array< 1, elemT > &v1)
square of the l2 norm of a 1D array
Definition: norm.inl:65
forward declaration of stir::Array class for multi-dimensional (numeric) arrays
STL namespace.
double norm(const Array< 1, elemT > &v1)
l2 norm of a 1D array
Definition: norm.inl:58
Implementation of the stir::norm(), stir::norm_squared() functions and stir::NormSquared unary functi...
The 1-dimensional (partial) specialisation of Array.
Definition: Array.h:442
A helper class that computes the square of the norm of numeric data.
Definition: norm.h:51