iterative-solver 0.0
wrap_util.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_WRAP_UTIL_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_WRAP_UTIL_H
3#include <molpro/linalg/itsolv/wrap.h>
4
5#include <algorithm>
6#include <memory>
7
16template <typename R, typename ForwardIt>
17std::vector<size_t> find_ref(const VecRef<R>& wparams, ForwardIt begin, ForwardIt end) {
18 auto indices = std::vector<size_t>{};
19 for (auto it = begin; it != end; ++it) {
20 auto it_found = std::find_if(std::begin(wparams), std::end(wparams),
21 [&it](const auto& w) { return std::addressof(w.get()) == std::addressof(*it); });
22 if (it_found != std::end(wparams))
23 indices.emplace_back(std::distance(begin, it));
24 }
25 return indices;
26}
27
33template <typename R>
34std::vector<size_t> find_ref(const CVecRef<R>& wparams, const CVecRef<R>& wparams_ref) {
35 auto indices = std::vector<size_t>{};
36 for (auto it = wparams_ref.cbegin(); it != wparams_ref.cend(); ++it) {
37 auto it_found = std::find_if(std::begin(wparams), std::end(wparams),
38 [&it](const auto& w) { return std::addressof(w.get()) == std::addressof(it->get()); });
39 if (it_found != std::end(wparams))
40 indices.emplace_back(std::distance(wparams_ref.cbegin(), it));
41 }
42 return indices;
43}
44
53template <typename T, typename U>
54auto remove_elements(std::vector<T> params, const std::vector<U>& indices) {
55 const auto n = params.size();
56 for (size_t i = 0, j = 0; i < n; ++i) {
57 if (std::find(begin(indices), end(indices), i) != end(indices)) {
58 params.erase(begin(params) + j);
59 } else {
60 ++j;
61 }
62 }
63 return params;
64}
65
66} // namespace molpro::linalg::itsolv
67#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_WRAP_UTIL_H
4-parameter interpolation of a 1-dimensional function given two points for which function values and ...
Definition: helper.h:10
auto remove_elements(std::vector< T > params, const std::vector< U > &indices)
Removes indices from a vector.
Definition: wrap_util.h:54
std::vector< std::reference_wrapper< const A > > CVecRef
Definition: wrap.h:14
std::vector< std::reference_wrapper< A > > VecRef
Definition: wrap.h:11
std::vector< size_t > find_ref(const VecRef< R > &wparams, ForwardIt begin, ForwardIt end)
Given wrapped references in wparams and a range of original parameters [begin, end),...
Definition: wrap_util.h:17