42 "Extrapolation error."
46 char err_mesg_buf[4096];
47 va_start(args, fmt_string);
48 std::vsnprintf(err_mesg_buf,
sizeof(err_mesg_buf), fmt_string, args);
51 this->
err_mesg = std::string(err_mesg_buf);
61 std::vector<double>& a,
bool check_lin,
bool check_loglin,
bool check_sign
63 std::size_t N = a.size();
66 std::vector<double> diff_a(N - 1);
67 for (std::size_t i = 0; i < N - 1; i++) {
68 diff_a[i] = a[i + 1] - a[i];
74 std::vector<double> diff_loga(N - 1);
75 std::feclearexcept(FE_ALL_EXCEPT);
76 for (std::size_t i = 0; i < N - 1; i++) {
77 diff_loga[i] = std::log(a[i + 1] / a[i]);
78 if (std::fetestexcept(FE_DIVBYZERO) || std::fetestexcept(FE_INVALID)) {
86 for (std::size_t i = 0; i < N - 1; i++) {
87 if (a[i] * a[i + 1] <= 0.0) {
return 3;}
95 std::vector<double>& a,
int N_ext, std::vector<double>& a_ext
99 int N_notch_left = N_ext;
100 int N_notch_right = N_ext + N;
101 int N_extrap = N_ext + N + N_ext;
103 a_ext.resize(N_extrap);
106 double da_left = a[1] - a[0];
107 for (
int i = 0; i < N_notch_left; i++) {
108 a_ext[i] = a.front() + (i - N_notch_left) * da_left;
112 for (
int i = N_notch_left; i < N_notch_right; i++) {
113 a_ext[i] = a[i - N_notch_left];
117 double da_right = a[N - 1] - a[N - 2];
118 for (
int i = N_notch_right; i < N_extrap; i++) {
119 a_ext[i] = a.back() + (i - (N_notch_right - 1)) * da_right;
124 std::vector<double>& a,
int N_ext, std::vector<double>& a_ext
126 std::feclearexcept(FE_ALL_EXCEPT);
130 int N_notch_left = N_ext;
131 int N_notch_right = N_ext + N;
132 int N_extrap = N_ext + N + N_ext;
135 throw std::invalid_argument(
136 "Sign change or zeros detected in the input array."
140 a_ext.resize(N_extrap);
143 double dlna_left = std::log(a[1] / a[0]);
144 if (std::isnan(dlna_left)) {
145 throw std::invalid_argument(
146 "NaN detected at lower-end log-linear spacing."
150 for (
int i = 0; i < N_notch_left; i++) {
151 a_ext[i] = a.front() * std::exp((i - N_notch_left) * dlna_left);
152 if (std::fetestexcept(FE_DIVBYZERO) || std::fetestexcept(FE_INVALID)) {
153 throw std::invalid_argument(
154 "NaN detected at lower-end log-linear extrapolation."
160 for (
int i = N_notch_left; i < N_notch_right; i++) {
161 a_ext[i] = a[i - N_ext];
165 double dlna_right = std::log(a[N - 1] / a[N - 2]);
166 if (std::isnan(dlna_right)) {
167 throw std::invalid_argument(
168 "NaN detected at upper-end log-linear spacing."
172 for (
int i = N_notch_right; i < N_extrap; i++) {
173 a_ext[i] = a.back() * std::exp((i - (N_notch_right - 1)) * dlna_right);
174 if (std::fetestexcept(FE_DIVBYZERO) || std::fetestexcept(FE_INVALID)) {
175 throw std::invalid_argument(
176 "NaN detected at upper-end log-linear extrapolation."
183 std::vector<double>& a,
184 int N_ext,
double c_lower,
double c_upper,
185 std::vector<double>& a_ext
188 int N_notch_left = N_ext;
189 int N_notch_right = N_ext + N;
190 int N_extrap = N_ext + N + N_ext;
192 a_ext.resize(N_extrap);
194 for (
int i = 0; i < N_notch_left; i++) {
197 for (
int i = N_notch_left; i < N_notch_right; i++) {
198 a_ext[i] = a[i - N_notch_left];
200 for (
int i = N_notch_right; i < N_extrap; i++) {
206 std::vector< std::vector<double> >& a,
207 int N_row_ext,
int N_col_ext,
208 std::vector< std::vector<double> >& a_ext
212 "Function `extrap2d_lin` is not yet implemented in the C++ backend."
217 std::vector< std::vector<double> >& a,
218 int N_row_ext,
int N_col_ext,
219 std::vector< std::vector<double> >& a_ext
223 "Function `extrap2d_loglin` is not yet implemented in the C++ backend."
228 std::vector< std::vector<double> >& a,
229 int N_row_ext,
int N_col_ext,
230 double c_row_lower,
double c_row_upper,
231 double c_col_lower,
double c_col_upper,
232 std::vector< std::vector<double> >& a_ext
236 "Function `extrap2d_pad` is not yet implemented in the C++ backend."
247 std::vector<int> indices(sorting_vector.size());
250#if defined(__GNUC__) && !defined(__clang__)
251#pragma omp parallel for simd
253#pragma omp parallel for
256 for (std::size_t i = 0; i < sorting_vector.size(); i++) {
261 std::sort(indices.begin(), indices.end(), [&](std::size_t a, std::size_t b) {
262 return sorting_vector[a] < sorting_vector[b];;
273#if defined(TRV_USE_HIP)
274void copy_complex_array_dtoh(
275 fft_double_complex* d_arr, fftw_complex* arr, std::size_t length
280 sizeof(fft_double_complex) * length,
281 hipMemcpyDeviceToHost
285void copy_complex_array_htod(
286 fftw_complex* arr, fft_double_complex* d_arr, std::size_t length
291 sizeof(fftw_complex) * length,
292 hipMemcpyHostToDevice
296#elif defined(TRV_USE_CUDA)
297void copy_complex_array_dtoh(
298 fft_double_complex* d_arr, fftw_complex* arr, std::size_t length
300 CUDA_EXEC(cudaMemcpy(
301 reinterpret_cast<void*
>(arr),
302 reinterpret_cast<void*
>(d_arr),
303 sizeof(fft_double_complex) * length,
304 cudaMemcpyDeviceToHost
308void copy_complex_array_htod(
309 fftw_complex* arr, fft_double_complex* d_arr, std::size_t length
311 CUDA_EXEC(cudaMemcpy(
312 reinterpret_cast<void*
>(d_arr),
313 reinterpret_cast<void*
>(arr),
314 sizeof(fftw_complex) * length,
315 cudaMemcpyHostToDevice
320#if defined(TRV_USE_HIP)
321#elif defined(TRV_USE_CUDA)
322void copy_complex_array_dtoh_mgpu(
323 fftHandle plan, libXtDesc* libxt_desc, fftw_complex* arr
325 CUFFT_EXEC(cufftXtMemcpy(
327 reinterpret_cast<void*
>(arr),
328 reinterpret_cast<void*
>(libxt_desc),
329 CUFFT_COPY_DEVICE_TO_HOST
333void copy_complex_array_htod_mgpu(
334 fftHandle plan, libXtDesc* libxt_desc, fftw_complex* arr
336 CUFFT_EXEC(cufftXtMemcpy(
338 reinterpret_cast<void*
>(libxt_desc),
339 reinterpret_cast<void*
>(arr),
340 CUFFT_COPY_HOST_TO_DEVICE
Exception raised when a function or method is unimplemented.
int check_1d_array(std::vector< double > &a, bool check_lin, bool check_loglin, bool check_sign)
Check the linearity or log-linearity of a 1-d array.
std::vector< int > get_sorted_indices(std::vector< int > sorting_vector)
Get the sorted indices.
bool check_isclose(const std::vector< T > &arr, const T val, T atol=1.e-8, T rtol=1.e-5)
Check if all elements of a 1-d array are close to a given value.
void extrap2d_loglin(std::vector< std::vector< double > > &a, int N_row_ext, int N_col_ext, std::vector< std::vector< double > > &a_ext)
Extrapolate a 2-d array bi-exponentially (i.e. log-bilinearly).
void extrap_loglin(std::vector< double > &a, int N_ext, std::vector< double > &a_ext)
Extrapolate a 1-d array exponentially (i.e. log-linearly).
void extrap2d_pad(std::vector< std::vector< double > > &a, int N_row_ext, int N_col_ext, double c_row_lower, double c_row_upper, double c_col_lower, double c_col_upper, std::vector< std::vector< double > > &a_ext)
Extrapolate a 2-d array by constant padding.
void extrap2d_lin(std::vector< std::vector< double > > &a, int N_row_ext, int N_col_ext, std::vector< std::vector< double > > &a_ext)
Extrapolate a 2-d array bi-linearly.
void extrap_lin(std::vector< double > &a, int N_ext, std::vector< double > &a_ext)
Extrapolate a 1-d array linearly.
void extrap_pad(std::vector< double > &a, int N_ext, double c_lower, double c_upper, std::vector< double > &a_ext)
Extrapolate a 1-d array by constant padding.