diff --git a/include/sparseir/basis.hpp b/include/sparseir/basis.hpp index 1148014..908ed56 100644 --- a/include/sparseir/basis.hpp +++ b/include/sparseir/basis.hpp @@ -224,7 +224,7 @@ class FiniteTempBasis : public AbstractBasis { // Delegating constructor 1 FiniteTempBasis(double beta, double omega_max, - double epsilon, int max_size) + double epsilon, int max_size=-1) : FiniteTempBasis(beta, omega_max, epsilon, LogisticKernel(beta * omega_max), compute_sve(LogisticKernel(beta * omega_max), epsilon), @@ -305,39 +305,6 @@ class FiniteTempBasis : public AbstractBasis { // Placeholder statistics function std::shared_ptr statistics() const { return std::make_shared(); } - // Default sampling points function - Eigen::VectorXd - default_sampling_points(const PiecewiseLegendrePolyVector &u, int L) const - { - if (u.xmin() != -1.0 || u.xmax() != 1.0) - throw std::runtime_error("Expecting unscaled functions here."); - - if (L < u.size()) { - // TODO: Resolve this errors. - return u.polyvec[L].roots(); - } else { - // Approximate roots by extrema - // TODO: resolve this error - PiecewiseLegendrePoly poly = u.polyvec.back(); - Eigen::VectorXd maxima = poly.deriv().roots(); - - double left = (maxima[0] + poly.xmin) / 2.0; - double right = (maxima[maxima.size() - 1] + poly.xmax) / 2.0; - - Eigen::VectorXd x0(maxima.size() + 2); - x0[0] = left; - x0.tail(maxima.size()) = maxima; - x0[x0.size() - 1] = right; - - if (x0.size() != L) { - std::cerr << "Warning: Expected " << L - << " sampling points, got " << x0.size() << ".\n"; - } - - return x0; - } - } - // Default Matsubara sampling points function Eigen::VectorXd defaultMatsubaraSamplingPoints( const PiecewiseLegendreFTVector &u_hat_full, int L, @@ -391,6 +358,37 @@ class FiniteTempBasis : public AbstractBasis { } }; + // Default sampling points function +inline Eigen::VectorXd default_sampling_points(const PiecewiseLegendrePolyVector &u, int L) { + if (u.xmin() != -1.0 || u.xmax() != 1.0) + throw std::runtime_error("Expecting unscaled functions here."); + + if (L < u.size()) { + // TODO: Resolve this errors. + return u.polyvec[L].roots(); + } else { + // Approximate roots by extrema + // TODO: resolve this error + PiecewiseLegendrePoly poly = u.polyvec.back(); + Eigen::VectorXd maxima = poly.deriv().roots(); + + double left = (maxima[0] + poly.xmin) / 2.0; + double right = (maxima[maxima.size() - 1] + poly.xmax) / 2.0; + + Eigen::VectorXd x0(maxima.size() + 2); + x0[0] = left; + x0.tail(maxima.size()) = maxima; + x0[x0.size() - 1] = right; + + if (x0.size() != L) { + std::cerr << "Warning: Expected " << L + << " sampling points, got " << x0.size() << ".\n"; + } + + return x0; + } + } + inline std::pair, FiniteTempBasis> finite_temp_bases( diff --git a/test/basis.cxx b/test/basis.cxx index 0206b54..d472818 100644 --- a/test/basis.cxx +++ b/test/basis.cxx @@ -99,4 +99,17 @@ TEST_CASE("FiniteTempBasis consistency tests", "[basis]") { REQUIRE(rescaled_basis.sve_result->s.size() == basis.sve_result->s.size()); REQUIRE(rescaled_basis.get_wmax() == 6.0); } + + SECTION("default_sampling_points") { + auto basis = sparseir::FiniteTempBasis(3., 4., 1e-6); + auto sve = basis.sve_result; + auto s = sve->s; + //std::cout << "Singular values: " << s.transpose() << std::endl; + int L = 10; + Eigen::VectorXd pts_L = default_sampling_points(sve->u, L); + REQUIRE(pts_L.size() == L); + Eigen::VectorXd pts_100 = default_sampling_points(sve->u, 100); + REQUIRE(pts_100.size() == 24); + } + }