60 lines
1.2 KiB
C++
60 lines
1.2 KiB
C++
//
|
|
// Created by dominik on 8/14/24.
|
|
//
|
|
|
|
|
|
#include <vector>
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
#include "ranges.h"
|
|
|
|
|
|
std::vector<double> arange(const int size, const double spacing=1.) {
|
|
std::vector<double> out(size);
|
|
std::generate(out.begin(), out.end(), [n = 0, spacing]() mutable { return n++ * spacing; });
|
|
|
|
return out;
|
|
}
|
|
|
|
std::vector<double> linspace(const double start, const double stop, const int steps) {
|
|
std::vector<double> range;
|
|
|
|
if (steps == 0) {
|
|
return range;
|
|
}
|
|
|
|
if (steps == 1) {
|
|
range.push_back(start);
|
|
return range;
|
|
}
|
|
|
|
const double stepsize = (stop-start) / (steps-1);
|
|
for (int i=0; i<steps; i++) {
|
|
range.push_back(start + stepsize * i);
|
|
}
|
|
return range;
|
|
}
|
|
|
|
|
|
std::vector<double> logspace(const double start, const double stop, const int steps) {
|
|
std::vector<double> range;
|
|
|
|
if (steps == 0) {
|
|
return range;
|
|
}
|
|
|
|
if (steps == 1) {
|
|
range.push_back(start);
|
|
return range;
|
|
}
|
|
|
|
const double logstart = log10(start);
|
|
const double logstop = log10(stop);
|
|
|
|
const double stepsize = (logstop-logstart) / (steps-1);
|
|
for (int i=0; i<steps; i++) {
|
|
range.push_back(pow(10, logstart + stepsize * i));
|
|
}
|
|
return range;
|
|
} |