Sync public subset from Flux (private)
This commit is contained in:
37
include/utils/generators/linspace.h
Normal file
37
include/utils/generators/linspace.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "utils/vector.h"
|
||||
|
||||
|
||||
namespace utils{
|
||||
|
||||
template <typename T>
|
||||
void inplace_linspace(utils::Vector<T>& a, T start, T stop, bool endpoint=true){
|
||||
|
||||
uint64_t N = a.size();
|
||||
T step;
|
||||
|
||||
if (endpoint){
|
||||
step = (stop - start) / static_cast<T>(N - 1);
|
||||
}else{
|
||||
step = (stop - start) / static_cast<T>(N);
|
||||
}
|
||||
|
||||
for (uint64_t i = 0; i < N; ++i){
|
||||
a[i] = start + (step*static_cast<T>(i));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
utils::Vector<T> linspace(T start, T stop, uint64_t N, bool endpoint=true){
|
||||
|
||||
utils::Vector<T> a(N);
|
||||
|
||||
inplace_linspace(a, start, stop, endpoint);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // end namespace utils
|
||||
Reference in New Issue
Block a user