STIR  6.2.0
Array_complex_numbers.h
Go to the documentation of this file.
1 
2 
3 #ifndef __Array_complex_numbers_H__
4 #define __Array_complex_numbers_H__
5 
14 /*
15  Copyright (C) 2004- 2011, Hammersmith Imanet Ltd
16  This file is part of STIR.
17 
18  SPDX-License-Identifier: Apache-2.0
19 
20  See STIR/LICENSE.txt for details
21 */
22 #include "stir/Array.h"
23 #include <complex>
24 
25 START_NAMESPACE_STIR
26 
31 
32 template <int num_dimensions, typename elemT>
33 Array<num_dimensions, std::complex<elemT>>&
34 operator*=(Array<num_dimensions, std::complex<elemT>>& lhs, const elemT& rhs)
35 {
36  typename Array<num_dimensions, std::complex<elemT>>::iterator iter1 = lhs.begin();
37  while (iter1 != lhs.end())
38  *iter1++ *= rhs;
39  return lhs;
40 }
41 
42 template <int num_dimensions, typename elemT>
43 Array<num_dimensions, std::complex<elemT>>&
44 operator/=(Array<num_dimensions, std::complex<elemT>>& lhs, const elemT& rhs)
45 {
46  typename Array<num_dimensions, std::complex<elemT>>::iterator iter1 = lhs.begin();
47  while (iter1 != lhs.end())
48  *iter1++ /= rhs;
49  return lhs;
50 }
51 
52 template <int num_dimensions, typename elemT>
53 Array<num_dimensions, std::complex<elemT>>&
54 operator+=(Array<num_dimensions, std::complex<elemT>>& lhs, const elemT& rhs)
55 {
56  typename Array<num_dimensions, std::complex<elemT>>::iterator iter1 = lhs.begin();
57  while (iter1 != lhs.end())
58  *iter1++ += rhs;
59  return lhs;
60 }
61 
62 template <int num_dimensions, typename elemT>
63 Array<num_dimensions, std::complex<elemT>>&
64 operator-=(Array<num_dimensions, std::complex<elemT>>& lhs, const elemT& rhs)
65 {
66  typename Array<num_dimensions, std::complex<elemT>>::iterator iter1 = lhs.begin();
67  while (iter1 != lhs.end())
68  *iter1++ -= rhs;
69  return lhs;
70 }
71 
72 // a few common cases given explictly here such that we don't get conversion warnings all the time.
73 inline void
74 assign(std::complex<double>& x, const int y)
75 {
76  x = static_cast<std::complex<double>>(y);
77 }
78 
79 inline void
80 assign(std::complex<float>& x, const int y)
81 {
82  x = static_cast<float>(y);
83 }
85 END_NAMESPACE_STIR
86 
87 #endif
defines the Array class for multi-dimensional (numeric) arrays
iterator begin()
use to initialise an iterator to the first element of the vector
Definition: VectorWithOffset.inl:182