Loading [MathJax]/extensions/tex2jax.js
LSST Applications 28.0.0,g1653933729+a8ce1bb630,g1a997c3884+a8ce1bb630,g28da252d5a+5bd70b7e6d,g2bbee38e9b+638fca75ac,g2bc492864f+638fca75ac,g3156d2b45e+07302053f8,g347aa1857d+638fca75ac,g35bb328faa+a8ce1bb630,g3a166c0a6a+638fca75ac,g3e281a1b8c+7bbb0b2507,g4005a62e65+17cd334064,g414038480c+5b5cd4fff3,g41af890bb2+4ffae9de63,g4e1a3235cc+0f1912dca3,g6249c6f860+3c3976f90c,g80478fca09+46aba80bd6,g82479be7b0+77990446f6,g858d7b2824+78ba4d1ce1,g89c8672015+f667a5183b,g9125e01d80+a8ce1bb630,ga5288a1d22+2a6264e9ca,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc22bb204ba+78ba4d1ce1,gc28159a63d+638fca75ac,gcf0d15dbbd+32ddb6096f,gd6b7c0dfd1+3e339405e9,gda3e153d99+78ba4d1ce1,gda6a2b7d83+32ddb6096f,gdaeeff99f8+1711a396fd,gdd5a9049c5+b18c39e5e3,ge2409df99d+a5e4577cdc,ge33fd446bb+78ba4d1ce1,ge79ae78c31+638fca75ac,gf0baf85859+64e8883e75,gf5289d68f6+e1b046a8d7,gfa443fc69c+91d9ed1ecf,gfda6b12a05+8419469a56
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
util.h
Go to the documentation of this file.
1#ifndef LSST_GAUSS2D_FIT_UTIL_H
2#define LSST_GAUSS2D_FIT_UTIL_H
3
4#include <algorithm>
5#include <memory>
6#include <set>
7#include <sstream>
8#include <stdexcept>
9#include <string>
10#include <vector>
11
12namespace lsst::gauss2d::fit {
13
19template <typename T>
21 const bool isclose;
22 const double diff_abs;
23 const T margin;
24
25 std::string str() const {
27 ss.precision(5);
28 ss << "isclose=" << isclose << " from diff=" << diff_abs << " <= margin=" << margin;
29 return ss.str();
30 }
31};
32
47template <typename T>
48IsCloseResult<T> isclose(T a, T b, T rtol = 1e-5, T atol = 1e-8) {
49 const T diff_abs = std::abs(a - b);
50 const T margin = atol + rtol * std::abs(b);
51 return IsCloseResult<T>{diff_abs <= margin, diff_abs, margin};
52}
53
54// The rest of these functions are mainly intended to make printing container members easier
55template <template <typename...> class Map, class Key, class Value>
56std::set<Key> map_keys(const Map<Key, Value>& map) {
58 for (const auto& it : map) {
59 result.insert(it.first);
60 }
61 return result;
62}
63
64template <template <typename...> class Map, class Key, class Value>
71
72template <template <typename...> class Map, class Key, class Value>
79
80template <template <typename...> class Map, class Key, class Value>
87
88// Builds a new vector with only unique elements, preserving order
89// Note: std::unique only removes consecutive identical elements
90// Also, this returns a new vector, potentially copying elements
91template <typename T>
93 std::set<T> set{};
94 std::vector<T> rval{};
95 rval.reserve(vec.size());
96 for (const auto& elem : vec) {
97 auto result = set.insert(elem);
98 if (result.second) rval.push_back(elem);
99 }
100 return rval;
101}
102
103/*
104template <typename T>
105std::string str_ptr(const T* obj) {
106 return (obj == nullptr) ? "None" : obj->str();
107}
108
109template <typename T>
110std::string str_iter_ptr(const T& container) {
111 std::string str = "[";
112 for (const auto& obj : container) str += str_ptr(obj) + ",";
113 return str.substr(0, str.size() - 1) + "]";
114}
115
116*/
117template <template <typename...> class Container, class Value>
118Container<Value> head_iter(const Container<Value>& container, size_t n) {
119 return Container<Value>(container.begin(), container.begin() + n);
120}
121
122template <template <typename...> class Container, class Value>
123Container<Value> tail_iter(const Container<Value>& container, size_t n) {
124 return Container<Value>(container.end() - n, container.end());
125}
126
127} // namespace lsst::gauss2d::fit
128
129#endif
py::object result
Definition _schema.cc:429
table::Key< int > b
T insert(T... args)
std::set< std::reference_wrapper< const Key > > map_keys_ref_const(const Map< std::reference_wrapper< const Key >, Value, std::less< const Key > > &map)
Definition util.h:65
std::set< std::shared_ptr< const Value > > map_values_shared_ptr_const(const Map< Key, std::shared_ptr< const Value > > &map)
Definition util.h:73
IsCloseResult< T > isclose(T a, T b, T rtol=1e-5, T atol=1e-8)
Check if two values are close, within some tolerances.
Definition util.h:48
Container< Value > head_iter(const Container< Value > &container, size_t n)
Definition util.h:118
std::set< Key > map_keys(const Map< Key, Value > &map)
Definition util.h:56
Container< Value > tail_iter(const Container< Value > &container, size_t n)
Definition util.h:123
std::vector< T > nonconsecutive_unique(const std::vector< T > &vec)
Definition util.h:92
std::set< std::reference_wrapper< const Value > > map_values_ref_const(const Map< Key, std::reference_wrapper< const Value > > &map)
Definition util.h:81
T precision(T... args)
T reserve(T... args)
T size(T... args)
T str(T... args)
The result of an isclose() check.
Definition util.h:20
std::string str() const
Definition util.h:25