Triumvirate C++ API 0.5.0
Three-point clustering measurements in large-scale structure analyses.
Loading...
Searching...
No Matches
arrayops.hpp
Go to the documentation of this file.
1// Copyright (C) [GPLv3 Licence]
2//
3// This file is part of the Triumvirate program. See the COPYRIGHT
4// and LICENCE files at the top-level directory of this distribution
5// for details of copyright and licensing.
6//
7// This program is free software: you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15// See the GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <https://www.gnu.org/licenses/>.
19
31#ifndef TRIUMVIRATE_INCLUDE_ARRAYOPS_HPP_INCLUDED_
32#define TRIUMVIRATE_INCLUDE_ARRAYOPS_HPP_INCLUDED_
33
34#include <algorithm>
35#include <cfenv>
36#include <cmath>
37#include <cstdarg>
38#include <stdexcept>
39#include <vector>
40
41#include "monitor.hpp"
42
43namespace trv {
44
45// ***********************************************************************
46// Extrapolation
47// ***********************************************************************
48
49namespace sys {
50
55class ExtrapError: public std::runtime_error {
56 public:
57 std::string err_mesg;
58
65 ExtrapError(const char* fmt_string, ...);
66
72 virtual const char* what() const noexcept;
73};
74
75} // namespace trv::sys
76
77namespace array {
78
84 NONE = 0,
85 ZERO = 1,
86 PAD = 2,
87 LIN = 3,
88 LOGLIN = 4,
89};
90
102template <typename T>
104 const std::vector<T>& arr, const T val,
105 T atol = 1.e-8, T rtol = 1.e-5
106) {
107 for (T elem : arr) {
108 if (std::abs(elem - val) > atol + rtol * std::abs(val)) {return false;}
109 }
110 return true;
111}
112
124int check_1d_array(
125 std::vector<double>& a, bool check_lin, bool check_loglin, bool check_sign
126);
127
135void extrap_lin(std::vector<double>& a, int N_ext, std::vector<double>& a_ext);
136
144void extrap_loglin(
145 std::vector<double>& a, int N_ext, std::vector<double>& a_ext
146);
147
157void extrap_pad(
158 std::vector<double>& a,
159 int N_ext, double c_lower, double c_upper,
160 std::vector<double>& a_ext
161);
162
173void extrap2d_lin(
174 std::vector< std::vector<double> >& a,
175 int N_row_ext, int N_col_ext,
176 std::vector< std::vector<double> >& a_ext
177);
178
189void extrap2d_loglin(
190 std::vector< std::vector<double> >& a,
191 int N_row_ext, int N_col_ext,
192 std::vector< std::vector<double> >& a_ext
193);
194
209void extrap2d_pad(
210 std::vector< std::vector<double> >& a,
211 int N_row_ext, int N_col_ext,
212 double c_row_lower, double c_row_upper,
213 double c_col_lower, double c_col_upper,
214 std::vector< std::vector<double> >& a_ext
215);
216
217
218// ***********************************************************************
219// Sorting
220// ***********************************************************************
221
228std::vector<int> get_sorted_indices(std::vector<int> sorting_vector);
229
230} // namespace trv::array
231
232} // namespace trv
233
234#endif // !TRIUMVIRATE_INCLUDE_ARRAYOPS_HPP_INCLUDED_
Exception raised when an extrapolation error occurs.
Definition arrayops.hpp:55
ExtrapError(const char *fmt_string,...)
Construct an trv::sys::ExtrapError exception.
Definition arrayops.cpp:39
std::string err_mesg
error message
Definition arrayops.hpp:57
virtual const char * what() const noexcept
Exception string representation.
Definition arrayops.cpp:52
Provide tracking of program resources and exceptions.
ExtrapOption
Extrapolation scheme.
Definition arrayops.hpp:83
@ NONE
0: none
Definition arrayops.hpp:84
@ LOGLIN
4: log-linear
Definition arrayops.hpp:88
@ PAD
2: pad
Definition arrayops.hpp:86
@ ZERO
1: zero
Definition arrayops.hpp:85
@ LIN
3: linear
Definition arrayops.hpp:87
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.
Definition arrayops.hpp:103