STIR  6.2.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/common.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 
36 template <int num_dimensions, class elemT>
37 class Array;
38 
44 
46 
52 // specialisations for complex numbers are in .inl file for clarity of this file.
53 template <typename T>
55 {
56  double operator()(T x) const { return static_cast<double>(x) * x; }
57 };
58 
60 
61 template <typename elemT>
62 inline double
63 norm_squared(const elemT t)
64 {
65  return NormSquared<elemT>()(t);
66 }
67 
69 
70 template <typename elemT>
71 inline double
72 norm(const elemT t)
73 {
74  return sqrt(norm_squared(t));
75 }
76 
77 // 2 overloads to avoid doing sqrt(t*t)
78 inline double
79 norm(const double t)
80 {
81  return std::fabs(t);
82 }
83 
84 inline double
85 norm(const float t)
86 {
87  return std::fabs(t);
88 }
89 
91 
94 template <class Iter>
95 inline double norm_squared(Iter begin, Iter end);
96 
98 
103 template <class Iter>
104 inline double norm(Iter begin, Iter end);
105 
107 
111 template <class elemT>
112 inline double norm(const Array<1, elemT>& v1);
113 
115 
119 template <class elemT>
120 inline double norm_squared(const Array<1, elemT>& v1);
121 
123 
124 END_NAMESPACE_STIR
125 
126 #include "stir/numerics/norm.inl"
127 
128 #endif
double norm_squared(const Array< 1, elemT > &v1)
square of the l2 norm of a 1D array
Definition: norm.inl:65
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:339
A helper class that computes the square of the norm of numeric data.
Definition: norm.h:54
basic configuration include file