PURIFY
Next-generation radio interferometric imaging
Enumerations | Functions
purify::integration Namespace Reference

Enumerations

enum class  norm_type {
  individual , paired , l1 , l2 ,
  linf
}
 
enum class  method { h , p }
 

Functions

t_real integrate (const Vector< t_real > &xmin, const Vector< t_real > &xmax, const std::function< t_real(Vector< t_real >)> &func, const norm_type norm, const t_real required_abs_error, const t_real required_rel_error, const t_uint max_evaluations, const method methodtype)
 adaptive integration with cubature for real scalar to vector More...
 
t_complex integrate (const Vector< t_real > &xmin, const Vector< t_real > &xmax, const std::function< t_complex(Vector< t_real >)> &func, const norm_type norm, const t_real required_abs_error, const t_real required_rel_error, const t_uint max_evaluations, const method methodtype)
 adaptive integration with cubature for complex scalar to vector More...
 
Vector< t_real > integrate (const t_uint fdim, const Vector< t_real > &xmin, const Vector< t_real > &xmax, const std::function< Vector< t_real >(Vector< t_real >)> &func, const norm_type norm, const t_real required_abs_error, const t_real required_rel_error, const t_uint max_evaluations, const method methodtype)
 adaptive integration with cubature for vector to vector More...
 
Vector< t_complex > integrate_v (const t_uint fdim, const t_uint npts, const Vector< t_real > &xmin, const Vector< t_real > &xmax, const std::vector< std::function< t_complex(Vector< t_real >)>> &func, const norm_type norm, const t_real required_abs_error, const t_real required_rel_error, const t_uint max_evaluations, const method methodtype)
 
error_norm norm_error (norm_type norm)
 return norm used for error More...
 
t_complex convolution (const Vector< t_real > &x0, const Vector< t_real > &xmin, const Vector< t_real > &xmax, const std::function< t_complex(Vector< t_real >)> &func1, const std::function< t_complex(Vector< t_real >)> &func2, const norm_type norm, const t_real required_abs_error, const t_real required_rel_error, const t_uint max_evaluations, const method methodtype)
 use adaptive integration to calculate convolution at x0 of func1(x0 - x) * func2(x) More...
 
Vector< t_complex > integrate_v (const t_uint fdim, const Vector< t_real > &xmin, const Vector< t_real > &xmax, const std::vector< std::function< t_complex(Vector< t_real >)>> &func, const norm_type norm, const t_real required_abs_error, const t_real required_rel_error, const t_uint max_evaluations, const method methodtype)
 adaptive integration with cubature for vector to vector using SIMD More...
 
t_complex convolution (const Vector< t_real > &x0, const std::function< t_complex(Vector< t_real >)> &func1, const std::function< t_complex(Vector< t_real >)> &func2, const norm_type norm, const t_real required_abs_error, const t_real required_rel_error, const t_uint max_evaluations, const method methodtype)
 

Enumeration Type Documentation

◆ method

Enumerator

Definition at line 12 of file integration.h.

◆ norm_type

Function Documentation

◆ convolution() [1/2]

t_complex purify::integration::convolution ( const Vector< t_real > &  x0,
const std::function< t_complex(Vector< t_real >)> &  func1,
const std::function< t_complex(Vector< t_real >)> &  func2,
const norm_type  norm,
const t_real  required_abs_error,
const t_real  required_rel_error,
const t_uint  max_evaluations,
const method  methodtype 
)

use adaptive integration to calculate convolution at x0 of func1(x0 - x) * func2(x) from -∞ to +∞

◆ convolution() [2/2]

t_complex purify::integration::convolution ( const Vector< t_real > &  x0,
const Vector< t_real > &  xmin,
const Vector< t_real > &  xmax,
const std::function< t_complex(Vector< t_real >)> &  func1,
const std::function< t_complex(Vector< t_real >)> &  func2,
const norm_type  norm,
const t_real  required_abs_error,
const t_real  required_rel_error,
const t_uint  max_evaluations,
const method  methodtype 
)

use adaptive integration to calculate convolution at x0 of func1(x0 - x) * func2(x)

Definition at line 183 of file integration.cc.

188  {
189  return integrate(
190  xmin, xmax, [=](const Vector<t_real> &x) -> t_complex { return func1(x0 - x) * func2(x); },
191  norm, required_abs_error, required_rel_error, max_evaluations, methodtype);
192 }
Vector< t_real > integrate(const t_uint fdim, const Vector< t_real > &xmin, const Vector< t_real > &xmax, const std::function< Vector< t_real >(Vector< t_real >)> &func, const norm_type norm, const t_real required_abs_error, const t_real required_rel_error, const t_uint max_evaluations, const method methodtype)
adaptive integration with cubature for vector to vector
Definition: integration.cc:78

References integrate().

◆ integrate() [1/3]

Vector< t_real > purify::integration::integrate ( const t_uint  fdim,
const Vector< t_real > &  xmin,
const Vector< t_real > &  xmax,
const std::function< Vector< t_real >(Vector< t_real >)> &  func,
const norm_type  norm,
const t_real  required_abs_error,
const t_real  required_rel_error,
const t_uint  max_evaluations,
const method  methodtype 
)

adaptive integration with cubature for vector to vector

Definition at line 78 of file integration.cc.

82  {
83  assert(xmin.size() == xmax.size());
84  Vector<t_real> val = Vector<t_real>::Zero(fdim);
85  Vector<t_real> err = Vector<t_real>::Zero(fdim);
86  auto wrap_integrand = [](unsigned ndim, const t_real *x, void *fdata, unsigned fdim,
87  double *fval) -> int {
88  Vector<t_real>::Map(fval, fdim) =
89  (*(static_cast<std::function<Vector<t_real>(Vector<t_real>)> *>(fdata)))(
90  Vector<t_real>::Map(x, ndim));
91  return 0;
92  };
93  switch (methodtype) {
94  case method::p:
95  if (pcubature(val.size(), wrap_integrand,
96  const_cast<std::function<Vector<t_real>(Vector<t_real>)> *>(&func), xmin.size(),
97  xmin.data(), xmax.data(), max_evaluations, required_abs_error, required_rel_error,
98  norm_error(norm), val.data(), err.data()) != 0)
99  throw std::runtime_error("Error in calculating p adaptive integral with cubature.");
100  break;
101  case method::h:
102  if (hcubature(val.size(), wrap_integrand,
103  const_cast<std::function<Vector<t_real>(Vector<t_real>)> *>(&func), xmin.size(),
104  xmin.data(), xmax.data(), max_evaluations, required_abs_error, required_rel_error,
105  norm_error(norm), val.data(), err.data()) != 0)
106  throw std::runtime_error("Error in calculating h adaptive integral with cubature.");
107  break;
108  default:
109  throw std::runtime_error("Method not possible with cubature.");
110  break;
111  }
112 
113  return val;
114 }
error_norm norm_error(norm_type norm)
return norm used for error
Definition: integration.cc:161

References h, norm_error(), and p.

◆ integrate() [2/3]

t_complex purify::integration::integrate ( const Vector< t_real > &  xmin,
const Vector< t_real > &  xmax,
const std::function< t_complex(Vector< t_real >)> &  func,
const norm_type  norm,
const t_real  required_abs_error,
const t_real  required_rel_error,
const t_uint  max_evaluations,
const method  methodtype 
)

adaptive integration with cubature for complex scalar to vector

Definition at line 40 of file integration.cc.

43  {
44  assert(xmin.size() == xmax.size());
45  std::array<t_real, 2> val{0., 0.};
46  std::array<t_real, 2> err{0., 0.};
47  auto wrap_integrand = [](unsigned ndim, const t_real *x, void *fdata, unsigned fdim,
48  double *fval) -> int {
49  assert(fdim == 2);
50  const t_complex output = (*(static_cast<std::function<t_complex(Vector<t_real>)> *>(fdata)))(
51  Vector<t_real>::Map(x, ndim));
52  fval[0] = output.real();
53  fval[1] = output.imag();
54  return 0;
55  };
56  switch (methodtype) {
57  case method::p:
58  if (pcubature(val.size(), wrap_integrand,
59  const_cast<std::function<t_complex(Vector<t_real>)> *>(&func), xmin.size(),
60  xmin.data(), xmax.data(), max_evaluations, required_abs_error, required_rel_error,
61  norm_error(norm), val.data(), err.data()) != 0)
62  throw std::runtime_error("Error in calculating p adaptive integral with cubature.");
63  break;
64  case method::h:
65  if (hcubature(val.size(), wrap_integrand,
66  const_cast<std::function<t_complex(Vector<t_real>)> *>(&func), xmin.size(),
67  xmin.data(), xmax.data(), max_evaluations, required_abs_error, required_rel_error,
68  norm_error(norm), val.data(), err.data()) != 0)
69  throw std::runtime_error("Error in calculating h adaptive integral with cubature.");
70  break;
71  default:
72  throw std::runtime_error("Integration method not known with cubature.");
73  break;
74  }
75 
76  return t_complex(val.at(0), val.at(1));
77 }

References h, norm_error(), and p.

◆ integrate() [3/3]

t_real purify::integration::integrate ( const Vector< t_real > &  xmin,
const Vector< t_real > &  xmax,
const std::function< t_real(Vector< t_real >)> &  func,
const norm_type  norm,
const t_real  required_abs_error,
const t_real  required_rel_error,
const t_uint  max_evaluations,
const method  methodtype 
)

adaptive integration with cubature for real scalar to vector

Definition at line 7 of file integration.cc.

10  {
11  assert(xmin.size() == xmax.size());
12  t_real val = 0;
13  t_real err = 0;
14  auto wrap_integrand = [](unsigned ndim, const t_real *x, void *fdata, unsigned fdim,
15  double *fval) -> int {
16  fval[0] = (*(static_cast<std::function<t_real(Vector<t_real>)> *>(fdata)))(
17  Vector<t_real>::Map(x, ndim));
18  return 0;
19  };
20  switch (methodtype) {
21  case method::p:
22  if (pcubature(1, wrap_integrand, const_cast<std::function<t_real(Vector<t_real>)> *>(&func),
23  xmin.size(), xmin.data(), xmax.data(), max_evaluations, required_abs_error,
24  required_rel_error, norm_error(norm), &val, &err) != 0)
25  throw std::runtime_error("Error in calculating p adaptive integral with cubature.");
26  break;
27  case method::h:
28  if (hcubature(1, wrap_integrand, const_cast<std::function<t_real(Vector<t_real>)> *>(&func),
29  xmin.size(), xmin.data(), xmax.data(), max_evaluations, required_abs_error,
30  required_rel_error, norm_error(norm), &val, &err) != 0)
31  throw std::runtime_error("Error in calculating h adaptive integral with cubature.");
32  break;
33  default:
34  throw std::runtime_error("Method not possibe with cubature.");
35  break;
36  }
37  return val;
38 }

References h, norm_error(), and p.

Referenced by convolution(), purify::projection_kernels::exact_w_projection_integration(), purify::projection_kernels::exact_w_projection_integration_1d(), and TEST_CASE().

◆ integrate_v() [1/2]

Vector<t_complex> purify::integration::integrate_v ( const t_uint  fdim,
const t_uint  npts,
const Vector< t_real > &  xmin,
const Vector< t_real > &  xmax,
const std::vector< std::function< t_complex(Vector< t_real >)>  ,
func,
const norm_type  norm,
const t_real  required_abs_error,
const t_real  required_rel_error,
const t_uint  max_evaluations,
const method  methodtype 
)

Definition at line 115 of file integration.cc.

120  {
121  assert(xmin.size() == xmax.size());
122  Vector<t_real> val = Vector<t_real>::Zero(2 * fdim);
123  Vector<t_real> err = Vector<t_real>::Zero(2 * fdim);
124  auto wrap_integrand = [](unsigned ndim, unsigned long npts, const t_real *x, void *fdata,
125  unsigned fdim, double *fval) -> int {
126  for (int i = 0; i < npts; i = i + 2) {
127  const t_complex val =
128  (*(static_cast<std::vector<std::function<t_complex(Vector<t_real>)>> *>(fdata)))
129  .at(i)(Vector<t_real>::Map(x, ndim));
130  fval[i] = val.real();
131  fval[i + 1] = val.imag();
132  }
133  return 0;
134  };
135  switch (methodtype) {
136  case method::p:
137  if (pcubature_v(val.size(), wrap_integrand,
138  const_cast<std::vector<std::function<t_complex(Vector<t_real>)>> *>(&func),
139  xmin.size(), xmin.data(), xmax.data(), max_evaluations, required_abs_error,
140  required_rel_error, norm_error(norm), val.data(), err.data()) != 0)
141  throw std::runtime_error("Error in calculating p adaptive integral with cubature.");
142  break;
143  case method::h:
144  if (hcubature_v(val.size(), wrap_integrand,
145  const_cast<std::vector<std::function<t_complex(Vector<t_real>)>> *>(&func),
146  xmin.size(), xmin.data(), xmax.data(), max_evaluations, required_abs_error,
147  required_rel_error, norm_error(norm), val.data(), err.data()) != 0)
148  throw std::runtime_error("Error in calculating h adaptive integral with cubature.");
149  break;
150  default:
151  throw std::runtime_error("Method not possible with cubature.");
152  break;
153  }
154  Vector<t_complex> output = Vector<t_complex>::Zero(fdim);
155  output.real() = Vector<t_real>::Map(val.data(), fdim, 1, Eigen::Stride<Eigen::Dynamic, 1>(2, 0));
156  output.imag() =
157  Vector<t_real>::Map(val.data() + 1, fdim, 1, Eigen::Stride<Eigen::Dynamic, 1>(2, 0));
158  return output;
159 }

References h, norm_error(), and p.

◆ integrate_v() [2/2]

Vector<t_complex> purify::integration::integrate_v ( const t_uint  fdim,
const Vector< t_real > &  xmin,
const Vector< t_real > &  xmax,
const std::vector< std::function< t_complex(Vector< t_real >)>  ,
func,
const norm_type  norm,
const t_real  required_abs_error,
const t_real  required_rel_error,
const t_uint  max_evaluations,
const method  methodtype 
)

adaptive integration with cubature for vector to vector using SIMD

◆ norm_error()

error_norm purify::integration::norm_error ( norm_type  norm)

return norm used for error

Definition at line 161 of file integration.cc.

161  {
162  switch (norm) {
163  case norm_type::l1:
164  return ERROR_L1;
165  break;
166  case norm_type::l2:
167  return ERROR_L2;
168  break;
169  case norm_type::linf:
170  return ERROR_LINF;
171  break;
172  case norm_type::individual:
173  return ERROR_INDIVIDUAL;
174  break;
175  case norm_type::paired:
176  return ERROR_PAIRED;
177  break;
178  default:
179  return ERROR_L2;
180  break;
181  }
182 }

References individual, l1, l2, linf, and paired.

Referenced by integrate(), and integrate_v().