STIR 6.4.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__
23
24#include "stir/ArrayFwd.h"
25#include <complex>
26#include <cmath>
27#ifdef BOOST_NO_STDC_NAMESPACE
28namespace std
29{
30using ::fabs;
31}
32#endif
33
34START_NAMESPACE_STIR
35
41
43
48
49// specialisations for complex numbers are in .inl file for clarity of this file.
50template <typename T>
52{
53 double operator()(T x) const { return static_cast<double>(x) * x; }
54};
55
57
58template <typename elemT>
59inline double
60norm_squared(const elemT t)
61{
62 return NormSquared<elemT>()(t);
63}
64
66
67template <typename elemT>
68inline double
69norm(const elemT t)
70{
71 return sqrt(norm_squared(t));
72}
73
74// 2 overloads to avoid doing sqrt(t*t)
75inline double
76norm(const double t)
77{
78 return std::fabs(t);
79}
80
81inline double
82norm(const float t)
83{
84 return std::fabs(t);
85}
86
88
91template <class Iter>
92inline double norm_squared(Iter begin, Iter end);
93
95
100template <class Iter>
101inline double norm(Iter begin, Iter end);
102
104
108template <class elemT>
109inline double norm(const Array<1, elemT>& v1);
110
112
116template <class elemT>
117inline double norm_squared(const Array<1, elemT>& v1);
118
120
121END_NAMESPACE_STIR
122
123#include "stir/numerics/norm.inl"
124
125#endif
forward declaration of stir::Array class for multi-dimensional (numeric) arrays
double norm(const BasicCoordinate< num_dimensions, coordT > &p1)
compute sqrt(inner_product(p1,p1))
Definition BasicCoordinate.inl:426
double norm_squared(const BasicCoordinate< num_dimensions, coordT > &p1)
compute (inner_product(p1,p1))
Definition BasicCoordinate.inl:415
Implementation of the stir::norm(), stir::norm_squared() functions and stir::NormSquared unary functi...
A helper class that computes the square of the norm of numeric data.
Definition norm.h:52