STIR 6.4.0
norm.inl
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
21
22#include <functional>
23#include <cmath>
24#ifdef BOOST_NO_STDC_NAMESPACE
25namespace std
26{
27using ::fabs;
28}
29#endif
30
31START_NAMESPACE_STIR
32
33template <typename T>
34struct NormSquared<std::complex<T>>
35{
36 double operator()(const std::complex<T>& x) const { return square(x.real()) + square(x.imag()); }
37};
38
39template <class Iter>
40double
41norm_squared(Iter begin, Iter end)
42{
43 double res = 0;
44 for (Iter iter = begin; iter != end; ++iter)
45 res += norm_squared(*iter);
46 return res;
47}
48
49template <class Iter>
50double
51norm(Iter begin, Iter end)
52{
53 return sqrt(norm_squared(begin, end));
54}
55
56template <class elemT>
57inline double
59{
60 return norm(v1.begin(), v1.end());
61}
62
63template <class elemT>
64inline double
66{
67 return norm_squared(v1.begin(), v1.end());
68}
69
70END_NAMESPACE_STIR
This class defines multi-dimensional (numeric) arrays.
Definition Array.h:78
iterator begin()
use to initialise an iterator to the first element of the vector
Definition VectorWithOffset.inl:190
iterator end()
iterator 'past' the last element of the vector
Definition VectorWithOffset.inl:206
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
NUMBER square(const NUMBER &x)
returns the square of a number, templated.
Definition common.h:154