Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel to cpp #29

Merged
merged 15 commits into from
Nov 28, 2024
20 changes: 17 additions & 3 deletions include/sparseir/gauss.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,14 @@ class Rule {
return Rule<T>(x, new_w, x_forward, x_backward, a, b);
}

Rule<T> piecewise(const std::vector<T>& edges) const {
if (!is_sorted(edges.begin(), edges.end())) {
template <typename U>
Rule<T> piecewise(const std::vector<U>& edges) const {
if (!std::is_sorted(edges.begin(), edges.end())) {
throw std::invalid_argument("segments ends must be ordered ascendingly");
}
std::vector<Rule<T>> rules;
for (size_t i = 0; i < edges.size() - 1; ++i) {
rules.push_back(reseat(edges[i], edges[i + 1]));
rules.push_back(reseat(T(edges[i]), T(edges[i + 1])));
}
return join(rules);
}
Expand Down Expand Up @@ -192,4 +193,17 @@ Matrix<T, Dynamic, Dynamic> legendre_collocation(const Rule<T>& rule, int n = -1
return res;
}

template <typename TargetType, typename SourceType>
Rule<TargetType> convert(const Rule<SourceType> &rule)
{
std::vector<TargetType> x(rule.x.begin(), rule.x.end());
std::vector<TargetType> w(rule.w.begin(), rule.w.end());
TargetType a = static_cast<TargetType>(rule.a);
TargetType b = static_cast<TargetType>(rule.b);
std::vector<TargetType> x_forward(rule.x_forward.begin(), rule.x_forward.end());
std::vector<TargetType> x_backward(rule.x_backward.begin(), rule.x_backward.end());

return Rule<TargetType>(x, w, x_forward, x_backward, a, b);
}

} // namespace sparseir
Loading