From d1208c736d6021f5418578cfe7ca205c82d11790 Mon Sep 17 00:00:00 2001 From: Jason Kaye Date: Tue, 10 Jun 2025 17:32:10 -0400 Subject: [PATCH 1/2] remove unnecessary statistic parameter from convolution-related functions and deprecate previous signatures --- c++/cppdlr/dlr_dyson.hpp | 6 ++-- c++/cppdlr/dlr_imtime.hpp | 62 ++++++++++++++++++++++++++++++++------- test/c++/imtime_ops.cpp | 32 ++++++++++---------- 3 files changed, 71 insertions(+), 29 deletions(-) diff --git a/c++/cppdlr/dlr_dyson.hpp b/c++/cppdlr/dlr_dyson.hpp index d47b766..02cdaf5 100644 --- a/c++/cppdlr/dlr_dyson.hpp +++ b/c++/cppdlr/dlr_dyson.hpp @@ -62,7 +62,7 @@ namespace cppdlr { auto g0c = itops_ptr->vals2coefs(g0); // DLR coefficients of free Green's function // Get matrix of convolution by free Green's function - g0mat = itops_ptr->convmat(beta, Fermion, g0c, time_order); + g0mat = itops_ptr->convmat(beta, g0c, time_order); // Get right hand side of Dyson equation if constexpr (std::floating_point) { // If h is real scalar, rhs is a vector @@ -86,7 +86,7 @@ namespace cppdlr { * \note Hamiltonian must either be a symmetric matrix, a Hermitian matrix, * or a real scalar. */ - dyson_it(double beta, imtime_ops itops, Ht const &h, bool time_order) : dyson_it(beta, itops, h, 0, time_order) {}; + dyson_it(double beta, imtime_ops itops, Ht const &h, bool time_order) : dyson_it(beta, itops, h, 0, time_order){}; /** * @brief Solve Dyson equation for given self-energy @@ -111,7 +111,7 @@ namespace cppdlr { // Obtain Dyson equation system matrix I - G0 * Sig, where G0 and Sig are the // matrices of convolution by the free Green's function and self-energy, // respectively. - auto sysmat = make_regular(nda::eye(r * norb) - g0mat * itops_ptr->convmat(beta, Fermion, sigc, time_order)); + auto sysmat = make_regular(nda::eye(r * norb) - g0mat * itops_ptr->convmat(beta, sigc, time_order)); // Factorize system matrix auto ipiv = nda::vector(r * norb); diff --git a/c++/cppdlr/dlr_imtime.hpp b/c++/cppdlr/dlr_imtime.hpp index a743507..358a217 100644 --- a/c++/cppdlr/dlr_imtime.hpp +++ b/c++/cppdlr/dlr_imtime.hpp @@ -304,13 +304,10 @@ namespace cppdlr { * @return Values of h = f * g on DLR imaginary time grid * */ template > - typename T::regular_type convolve(double beta, statistic_t statistic, T const &fc, T const &gc, bool time_order = false) const { + typename T::regular_type convolve(double beta, T const &fc, T const &gc, bool time_order = false) const { if (r != fc.shape(0) || r != gc.shape(0)) throw std::runtime_error("First dim of input arrays must be equal to DLR rank r."); - // TODO: implement bosonic case and remove - if (statistic == 0) throw std::runtime_error("imtime_ops::convolve not yet implemented for bosonic Green's functions."); - // Initialize convolution, if it hasn't been done already if (!time_order & hilb.empty()) { convolve_init(); } if (time_order & thilb.empty()) { tconvolve_init(); } @@ -353,6 +350,22 @@ namespace cppdlr { } } + /** + * @brief Deprecated overload of convolve method + * + * This version includes an unused extra parameter for backward + * compatibility. + * + * @deprecated Use convolve(beta, fc, gc, time_order) instead; this works for + * both fermionic and bosonic functions. + */ + template > + [[deprecated("Use convolve(beta, fc, gc, time_order) instead.")]] typename T::regular_type + convolve(double beta, statistic_t statistic, T const &fc, T const &gc, bool time_order = false) const { + (void)statistic; // Unused parameter, kept for backward compatibility + return convolve(beta, fc, gc, time_order); + } + /** * @brief Compute convolution of two imaginary time Green's functions, * given matrix of convolution by one of them @@ -449,7 +462,7 @@ namespace cppdlr { * r*norb2 x r*norb3 matrix, or a block r x 1 matrix of norb2 x norb3 blocks. * */ template > - nda::matrix convmat(double beta, statistic_t statistic, T const &fc, bool time_order = false) const { + nda::matrix convmat(double beta, T const &fc, bool time_order = false) const { int n, m; @@ -464,11 +477,27 @@ namespace cppdlr { } auto fconv = nda::matrix(n, m); // Matrix of convolution by f - convmat_inplace(nda::matrix_view(fconv), beta, statistic, fc, time_order); + convmat_inplace(nda::matrix_view(fconv), beta, fc, time_order); return fconv; } + /** + * @brief Deprecated overload of convmat method + * + * This version includes an unused extra parameter for backward + * compatibility. + * + * @deprecated Use convmat(beta, fc, time_order) instead; this works for both + * fermionic and bosonic functions. + */ + template > + [[deprecated("Use convmat(beta, fc, time_order) instead.")]] nda::matrix convmat(double beta, statistic_t statistic, T const &fc, + bool time_order = false) const { + (void)statistic; // Unused parameter, kept for backward compatibility + return convmat(beta, fc, time_order); + } + /** * @brief Compute matrix of convolution by an imaginary time Green's function * in place @@ -519,13 +548,10 @@ namespace cppdlr { * r*norb2 x r*norb3 matrix, or a block r x 1 matrix of norb2 x norb3 blocks. * */ template > - void convmat_inplace(nda::matrix_view fconv, double beta, statistic_t statistic, T const &fc, bool time_order = false) const { + void convmat_inplace(nda::matrix_view fconv, double beta, T const &fc, bool time_order = false) const { if (r != fc.shape(0)) throw std::runtime_error("First dim of input array must be equal to DLR rank r."); - // TODO: implement bosonic case and remove - if (statistic == 0) throw std::runtime_error("imtime_ops::convmat not yet implemented for bosonic Green's functions."); - // Initialize convolution, if it hasn't been done already if (!time_order & hilb.empty()) { convolve_init(); } if (time_order & thilb.empty()) { tconvolve_init(); } @@ -622,6 +648,22 @@ namespace cppdlr { } } + /** + * @brief Deprecated overload of convmat_inplace method + * + * This version includes an unused extra parameter for backward + * compatibility. + * + * @deprecated Use convmat_inplace(fconv, beta, fc, time_order) instead; this + * works for both fermionic and bosonic functions. + */ + template > + [[deprecated("Use convmat_inplace(fconv, beta, fc, time_order) instead.")]] void + convmat_inplace(nda::matrix_view fconv, double beta, statistic_t statistic, T const &fc, bool time_order = false) const { + (void)statistic; // Unused parameter, kept for backward compatibility + return convmat_inplace(fconv, beta, fc, time_order); + } + /** * @brief Compute inner product of two imaginary time Green's functions * diff --git a/test/c++/imtime_ops.cpp b/test/c++/imtime_ops.cpp index 92ea6ca..ed3e796 100644 --- a/test/c++/imtime_ops.cpp +++ b/test/c++/imtime_ops.cpp @@ -492,13 +492,13 @@ TEST(imtime_ops, convolve_scalar_real) { auto gc = itops.vals2coefs(g); // Get convolution and time-ordered convolution of f and g directly - auto h = itops.convolve(beta, Fermion, fc, gc); - auto ht = itops.convolve(beta, Fermion, fc, gc, TIME_ORDERED); + auto h = itops.convolve(beta, fc, gc); + auto ht = itops.convolve(beta, fc, gc, TIME_ORDERED); // Get convolution and time-ordered convolution of f and g by first forming // matrix of convolution by f and then applying it to g - auto h2 = itops.convolve(itops.convmat(beta, Fermion, fc), g); - auto ht2 = itops.convolve(itops.convmat(beta, Fermion, fc, TIME_ORDERED), g); + auto h2 = itops.convolve(itops.convmat(beta, fc), g); + auto ht2 = itops.convolve(itops.convmat(beta, fc, TIME_ORDERED), g); // Check that the two methods give the same result EXPECT_LT(max_element(abs(h - h2)), 1e-14); @@ -577,13 +577,13 @@ TEST(imtime_ops, convolve_scalar_cmplx) { auto gc = itops.vals2coefs(g); // Get convolution and time-ordered convolution of f and g directly - auto h = itops.convolve(beta, Fermion, fc, gc); - auto ht = itops.convolve(beta, Fermion, fc, gc, TIME_ORDERED); + auto h = itops.convolve(beta, fc, gc); + auto ht = itops.convolve(beta, fc, gc, TIME_ORDERED); // Get convolution and time-ordered convolution of f and g by first forming // matrix of convolution by f and then applying it to g - auto h2 = itops.convolve(itops.convmat(beta, Fermion, fc), g); - auto ht2 = itops.convolve(itops.convmat(beta, Fermion, fc, TIME_ORDERED), g); + auto h2 = itops.convolve(itops.convmat(beta, fc), g); + auto ht2 = itops.convolve(itops.convmat(beta, fc, TIME_ORDERED), g); // Check that the two methods give the same result EXPECT_LT(max_element(abs(h - h2)), 1e-14); @@ -667,11 +667,11 @@ TEST(imtime_ops, convolve_matrix_real) { auto gc = itops.vals2coefs(g); // Get convolution and time-ordered convolution of f and g directly - auto h = itops.convolve(beta, Fermion, fc, gc); - auto ht = itops.convolve(beta, Fermion, fc, gc, TIME_ORDERED); + auto h = itops.convolve(beta, fc, gc); + auto ht = itops.convolve(beta, fc, gc, TIME_ORDERED); - auto h2 = itops.convolve(itops.convmat(beta, Fermion, fc), g); - auto ht2 = itops.convolve(itops.convmat(beta, Fermion, fc, TIME_ORDERED), g); + auto h2 = itops.convolve(itops.convmat(beta, fc), g); + auto ht2 = itops.convolve(itops.convmat(beta, fc, TIME_ORDERED), g); // Check that the two methods give the same result EXPECT_LT(max_element(abs(h - h2)), 1e-14); @@ -758,13 +758,13 @@ TEST(imtime_ops, convolve_matrix_cmplx) { auto gc = itops.vals2coefs(g); // Get convolution and time-ordered convolution of f and g directly - auto h = itops.convolve(beta, Fermion, fc, gc); - auto ht = itops.convolve(beta, Fermion, fc, gc, TIME_ORDERED); + auto h = itops.convolve(beta, fc, gc); + auto ht = itops.convolve(beta, fc, gc, TIME_ORDERED); // Get convolution and time-ordered convolution of f and g by first forming // matrix of convolution by f and then applying it to g - auto h2 = itops.convolve(itops.convmat(beta, Fermion, fc), g); - auto ht2 = itops.convolve(itops.convmat(beta, Fermion, fc, TIME_ORDERED), g); + auto h2 = itops.convolve(itops.convmat(beta, fc), g); + auto ht2 = itops.convolve(itops.convmat(beta, fc, TIME_ORDERED), g); // Check that the two methods give the same result EXPECT_LT(max_element(abs(h - h2)), 1e-14); From 541eab29d2705a23a676ce2149b874e3af3ed43f Mon Sep 17 00:00:00 2001 From: Nils Wentzell Date: Mon, 13 Oct 2025 14:12:53 -0400 Subject: [PATCH 2/2] Minor syntax simplifications in #17 --- c++/cppdlr/dlr_imtime.hpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/c++/cppdlr/dlr_imtime.hpp b/c++/cppdlr/dlr_imtime.hpp index 358a217..f8f67eb 100644 --- a/c++/cppdlr/dlr_imtime.hpp +++ b/c++/cppdlr/dlr_imtime.hpp @@ -359,10 +359,9 @@ namespace cppdlr { * @deprecated Use convolve(beta, fc, gc, time_order) instead; this works for * both fermionic and bosonic functions. */ - template > - [[deprecated("Use convolve(beta, fc, gc, time_order) instead.")]] typename T::regular_type - convolve(double beta, statistic_t statistic, T const &fc, T const &gc, bool time_order = false) const { - (void)statistic; // Unused parameter, kept for backward compatibility + template + [[deprecated("Use convolve(beta, fc, gc, time_order) instead.")]] + auto convolve(double beta, [[maybe_unused]] statistic_t statistic, T const &fc, T const &gc, bool time_order = false) const { return convolve(beta, fc, gc, time_order); } @@ -491,10 +490,9 @@ namespace cppdlr { * @deprecated Use convmat(beta, fc, time_order) instead; this works for both * fermionic and bosonic functions. */ - template > - [[deprecated("Use convmat(beta, fc, time_order) instead.")]] nda::matrix convmat(double beta, statistic_t statistic, T const &fc, - bool time_order = false) const { - (void)statistic; // Unused parameter, kept for backward compatibility + template + [[deprecated("Use convmat(beta, fc, time_order) instead.")]] auto convmat(double beta, [[maybe_unused]] statistic_t statistic, T const &fc, + bool time_order = false) const { return convmat(beta, fc, time_order); }