Mantid
Loading...
Searching...
No Matches
HalfComplex.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9namespace Mantid {
10namespace CurveFitting {
11
20 size_t m_size;
21 double *m_data;
22 bool m_even;
23public:
27 HalfComplex(double *data, const size_t &n) : m_size(n / 2 + 1), m_data(data), m_even(n / 2 * 2 == n) {}
29 size_t size() const { return m_size; }
30
34 double real(size_t i) const {
35 if (i >= m_size)
36 return 0.;
37 if (i == 0)
38 return m_data[0];
39 return m_data[2 * i - 1];
40 }
44 double imag(size_t i) const {
45 if (i >= m_size)
46 return 0.;
47 if (i == 0)
48 return 0;
49 if (m_even && i == m_size - 1)
50 return 0;
51 return m_data[2 * i];
52 }
53
58 void set(size_t i, const double &re, const double &im) {
59 if (i >= m_size)
60 return;
61 if (i == 0) // this is purely real
62 {
63 m_data[0] = re;
64 } else if (m_even && i == m_size - 1) // this is also purely real
65 {
66 m_data[2 * i - 1] = re;
67 } else {
68 m_data[2 * i - 1] = re;
69 m_data[2 * i] = im;
70 }
71 }
72};
73
74} // namespace CurveFitting
75} // namespace Mantid
Class for helping to read the transformed data.
Definition: HalfComplex.h:19
HalfComplex(double *data, const size_t &n)
Constructor.
Definition: HalfComplex.h:27
double real(size_t i) const
The real part of i-th transform coefficient.
Definition: HalfComplex.h:34
void set(size_t i, const double &re, const double &im)
Set a new value for i-th complex coefficient.
Definition: HalfComplex.h:58
double imag(size_t i) const
The imaginary part of i-th transform coefficient.
Definition: HalfComplex.h:44
double * m_data
pointer to the transformed data
Definition: HalfComplex.h:21
size_t m_size
size of the transformed data
Definition: HalfComplex.h:20
size_t size() const
Returns the size of the transform.
Definition: HalfComplex.h:29
bool m_even
true if the size of the original data is even
Definition: HalfComplex.h:22
Helper class which provides the Collimation Length for SANS instruments.