File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 55// /
66
77#include < algorithm>
8+ #include < cmath>
9+ #include < vector>
10+ #include < cassert>
811
912namespace rlenvscpp {
1013namespace utils {
@@ -104,6 +107,41 @@ min(const VectorType& vec) {
104107 return *std::min_element (vec.begin (), vec.end ());
105108}
106109
110+ namespace {
111+
112+ // /
113+ // / \brief Return a value in the linear sequence in the range
114+ // / [start, stop]. The index parameter is the current number
115+ // / in the sequence of the n total numbers we are about to
116+ // / generate
117+ // /
118+ template <typename T>
119+ auto lin_value (T start, T stop, uint_t index, uint_t n){
120+
121+ assert (n > 1 && index < n);
122+ const auto amount = static_cast <T>(index) / (n -1 );
123+ const auto v = str::lerp (start, stop, amount);
124+ return v;
125+ }
126+
127+ }
128+
129+ // /
130+ // / \brief Generate n evenly linearly spaced numbers between
131+ // / [start, stop]. Analogous to NumPy linspace.
132+ // /
133+ template <typename T>
134+ std::vector<T>
135+ lin_space (T start, T stop, uint_t n){
136+
137+ auto v = std::vector<T>{};
138+ v.reserve (n);
139+ for (auto i=0u ; i<n; ++i){
140+ v.push_back (lin_value (start, stop, i, n));
141+ }
142+ return v;
143+ }
144+
107145
108146}
109147}
You can’t perform that action at this time.
0 commit comments