Skip to content

Commit be81a8c

Browse files
jasonkayeWentzell
andauthored
Remove unnecessary statistic parameter from convolution-related functions (#17)
* remove unnecessary statistic parameter from convolution-related functions and deprecate previous signatures * Minor syntax simplifications in #17 --------- Co-authored-by: Nils Wentzell <[email protected]>
1 parent 4cdf1dd commit be81a8c

File tree

3 files changed

+69
-29
lines changed

3 files changed

+69
-29
lines changed

c++/cppdlr/dlr_dyson.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ namespace cppdlr {
6262
auto g0c = itops_ptr->vals2coefs(g0); // DLR coefficients of free Green's function
6363

6464
// Get matrix of convolution by free Green's function
65-
g0mat = itops_ptr->convmat(beta, Fermion, g0c, time_order);
65+
g0mat = itops_ptr->convmat(beta, g0c, time_order);
6666

6767
// Get right hand side of Dyson equation
6868
if constexpr (std::floating_point<Ht>) { // If h is real scalar, rhs is a vector
@@ -86,7 +86,7 @@ namespace cppdlr {
8686
* \note Hamiltonian must either be a symmetric matrix, a Hermitian matrix,
8787
* or a real scalar.
8888
*/
89-
dyson_it(double beta, imtime_ops itops, Ht const &h, bool time_order) : dyson_it(beta, itops, h, 0, time_order) {};
89+
dyson_it(double beta, imtime_ops itops, Ht const &h, bool time_order) : dyson_it(beta, itops, h, 0, time_order){};
9090

9191
/**
9292
* @brief Solve Dyson equation for given self-energy
@@ -111,7 +111,7 @@ namespace cppdlr {
111111
// Obtain Dyson equation system matrix I - G0 * Sig, where G0 and Sig are the
112112
// matrices of convolution by the free Green's function and self-energy,
113113
// respectively.
114-
auto sysmat = make_regular(nda::eye<double>(r * norb) - g0mat * itops_ptr->convmat(beta, Fermion, sigc, time_order));
114+
auto sysmat = make_regular(nda::eye<double>(r * norb) - g0mat * itops_ptr->convmat(beta, sigc, time_order));
115115

116116
// Factorize system matrix
117117
auto ipiv = nda::vector<int>(r * norb);

c++/cppdlr/dlr_imtime.hpp

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,10 @@ namespace cppdlr {
304304
* @return Values of h = f * g on DLR imaginary time grid
305305
* */
306306
template <nda::MemoryArray T, nda::Scalar S = nda::get_value_t<T>>
307-
typename T::regular_type convolve(double beta, statistic_t statistic, T const &fc, T const &gc, bool time_order = false) const {
307+
typename T::regular_type convolve(double beta, T const &fc, T const &gc, bool time_order = false) const {
308308

309309
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.");
310310

311-
// TODO: implement bosonic case and remove
312-
if (statistic == 0) throw std::runtime_error("imtime_ops::convolve not yet implemented for bosonic Green's functions.");
313-
314311
// Initialize convolution, if it hasn't been done already
315312
if (!time_order & hilb.empty()) { convolve_init(); }
316313
if (time_order & thilb.empty()) { tconvolve_init(); }
@@ -353,6 +350,21 @@ namespace cppdlr {
353350
}
354351
}
355352

353+
/**
354+
* @brief Deprecated overload of convolve method
355+
*
356+
* This version includes an unused extra parameter for backward
357+
* compatibility.
358+
*
359+
* @deprecated Use convolve(beta, fc, gc, time_order) instead; this works for
360+
* both fermionic and bosonic functions.
361+
*/
362+
template <nda::MemoryArray T>
363+
[[deprecated("Use convolve(beta, fc, gc, time_order) instead.")]]
364+
auto convolve(double beta, [[maybe_unused]] statistic_t statistic, T const &fc, T const &gc, bool time_order = false) const {
365+
return convolve(beta, fc, gc, time_order);
366+
}
367+
356368
/**
357369
* @brief Compute convolution of two imaginary time Green's functions,
358370
* given matrix of convolution by one of them
@@ -449,7 +461,7 @@ namespace cppdlr {
449461
* r*norb2 x r*norb3 matrix, or a block r x 1 matrix of norb2 x norb3 blocks.
450462
* */
451463
template <nda::MemoryArray T, nda::Scalar S = nda::get_value_t<T>>
452-
nda::matrix<S> convmat(double beta, statistic_t statistic, T const &fc, bool time_order = false) const {
464+
nda::matrix<S> convmat(double beta, T const &fc, bool time_order = false) const {
453465

454466
int n, m;
455467

@@ -464,11 +476,26 @@ namespace cppdlr {
464476
}
465477

466478
auto fconv = nda::matrix<S, nda::C_layout>(n, m); // Matrix of convolution by f
467-
convmat_inplace(nda::matrix_view<S, nda::C_layout>(fconv), beta, statistic, fc, time_order);
479+
convmat_inplace(nda::matrix_view<S, nda::C_layout>(fconv), beta, fc, time_order);
468480

469481
return fconv;
470482
}
471483

484+
/**
485+
* @brief Deprecated overload of convmat method
486+
*
487+
* This version includes an unused extra parameter for backward
488+
* compatibility.
489+
*
490+
* @deprecated Use convmat(beta, fc, time_order) instead; this works for both
491+
* fermionic and bosonic functions.
492+
*/
493+
template <nda::MemoryArray T>
494+
[[deprecated("Use convmat(beta, fc, time_order) instead.")]] auto convmat(double beta, [[maybe_unused]] statistic_t statistic, T const &fc,
495+
bool time_order = false) const {
496+
return convmat(beta, fc, time_order);
497+
}
498+
472499
/**
473500
* @brief Compute matrix of convolution by an imaginary time Green's function
474501
* in place
@@ -519,13 +546,10 @@ namespace cppdlr {
519546
* r*norb2 x r*norb3 matrix, or a block r x 1 matrix of norb2 x norb3 blocks.
520547
* */
521548
template <nda::MemoryArray T, nda::Scalar S = nda::get_value_t<T>>
522-
void convmat_inplace(nda::matrix_view<S, nda::C_layout> fconv, double beta, statistic_t statistic, T const &fc, bool time_order = false) const {
549+
void convmat_inplace(nda::matrix_view<S, nda::C_layout> fconv, double beta, T const &fc, bool time_order = false) const {
523550

524551
if (r != fc.shape(0)) throw std::runtime_error("First dim of input array must be equal to DLR rank r.");
525552

526-
// TODO: implement bosonic case and remove
527-
if (statistic == 0) throw std::runtime_error("imtime_ops::convmat not yet implemented for bosonic Green's functions.");
528-
529553
// Initialize convolution, if it hasn't been done already
530554
if (!time_order & hilb.empty()) { convolve_init(); }
531555
if (time_order & thilb.empty()) { tconvolve_init(); }
@@ -622,6 +646,22 @@ namespace cppdlr {
622646
}
623647
}
624648

649+
/**
650+
* @brief Deprecated overload of convmat_inplace method
651+
*
652+
* This version includes an unused extra parameter for backward
653+
* compatibility.
654+
*
655+
* @deprecated Use convmat_inplace(fconv, beta, fc, time_order) instead; this
656+
* works for both fermionic and bosonic functions.
657+
*/
658+
template <nda::MemoryArray T, nda::Scalar S = nda::get_value_t<T>>
659+
[[deprecated("Use convmat_inplace(fconv, beta, fc, time_order) instead.")]] void
660+
convmat_inplace(nda::matrix_view<S, nda::C_layout> fconv, double beta, statistic_t statistic, T const &fc, bool time_order = false) const {
661+
(void)statistic; // Unused parameter, kept for backward compatibility
662+
return convmat_inplace(fconv, beta, fc, time_order);
663+
}
664+
625665
/**
626666
* @brief Compute inner product of two imaginary time Green's functions
627667
*

test/c++/imtime_ops.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -492,13 +492,13 @@ TEST(imtime_ops, convolve_scalar_real) {
492492
auto gc = itops.vals2coefs(g);
493493

494494
// Get convolution and time-ordered convolution of f and g directly
495-
auto h = itops.convolve(beta, Fermion, fc, gc);
496-
auto ht = itops.convolve(beta, Fermion, fc, gc, TIME_ORDERED);
495+
auto h = itops.convolve(beta, fc, gc);
496+
auto ht = itops.convolve(beta, fc, gc, TIME_ORDERED);
497497

498498
// Get convolution and time-ordered convolution of f and g by first forming
499499
// matrix of convolution by f and then applying it to g
500-
auto h2 = itops.convolve(itops.convmat(beta, Fermion, fc), g);
501-
auto ht2 = itops.convolve(itops.convmat(beta, Fermion, fc, TIME_ORDERED), g);
500+
auto h2 = itops.convolve(itops.convmat(beta, fc), g);
501+
auto ht2 = itops.convolve(itops.convmat(beta, fc, TIME_ORDERED), g);
502502

503503
// Check that the two methods give the same result
504504
EXPECT_LT(max_element(abs(h - h2)), 1e-14);
@@ -577,13 +577,13 @@ TEST(imtime_ops, convolve_scalar_cmplx) {
577577
auto gc = itops.vals2coefs(g);
578578

579579
// Get convolution and time-ordered convolution of f and g directly
580-
auto h = itops.convolve(beta, Fermion, fc, gc);
581-
auto ht = itops.convolve(beta, Fermion, fc, gc, TIME_ORDERED);
580+
auto h = itops.convolve(beta, fc, gc);
581+
auto ht = itops.convolve(beta, fc, gc, TIME_ORDERED);
582582

583583
// Get convolution and time-ordered convolution of f and g by first forming
584584
// matrix of convolution by f and then applying it to g
585-
auto h2 = itops.convolve(itops.convmat(beta, Fermion, fc), g);
586-
auto ht2 = itops.convolve(itops.convmat(beta, Fermion, fc, TIME_ORDERED), g);
585+
auto h2 = itops.convolve(itops.convmat(beta, fc), g);
586+
auto ht2 = itops.convolve(itops.convmat(beta, fc, TIME_ORDERED), g);
587587

588588
// Check that the two methods give the same result
589589
EXPECT_LT(max_element(abs(h - h2)), 1e-14);
@@ -667,11 +667,11 @@ TEST(imtime_ops, convolve_matrix_real) {
667667
auto gc = itops.vals2coefs(g);
668668

669669
// Get convolution and time-ordered convolution of f and g directly
670-
auto h = itops.convolve(beta, Fermion, fc, gc);
671-
auto ht = itops.convolve(beta, Fermion, fc, gc, TIME_ORDERED);
670+
auto h = itops.convolve(beta, fc, gc);
671+
auto ht = itops.convolve(beta, fc, gc, TIME_ORDERED);
672672

673-
auto h2 = itops.convolve(itops.convmat(beta, Fermion, fc), g);
674-
auto ht2 = itops.convolve(itops.convmat(beta, Fermion, fc, TIME_ORDERED), g);
673+
auto h2 = itops.convolve(itops.convmat(beta, fc), g);
674+
auto ht2 = itops.convolve(itops.convmat(beta, fc, TIME_ORDERED), g);
675675

676676
// Check that the two methods give the same result
677677
EXPECT_LT(max_element(abs(h - h2)), 1e-14);
@@ -758,13 +758,13 @@ TEST(imtime_ops, convolve_matrix_cmplx) {
758758
auto gc = itops.vals2coefs(g);
759759

760760
// Get convolution and time-ordered convolution of f and g directly
761-
auto h = itops.convolve(beta, Fermion, fc, gc);
762-
auto ht = itops.convolve(beta, Fermion, fc, gc, TIME_ORDERED);
761+
auto h = itops.convolve(beta, fc, gc);
762+
auto ht = itops.convolve(beta, fc, gc, TIME_ORDERED);
763763

764764
// Get convolution and time-ordered convolution of f and g by first forming
765765
// matrix of convolution by f and then applying it to g
766-
auto h2 = itops.convolve(itops.convmat(beta, Fermion, fc), g);
767-
auto ht2 = itops.convolve(itops.convmat(beta, Fermion, fc, TIME_ORDERED), g);
766+
auto h2 = itops.convolve(itops.convmat(beta, fc), g);
767+
auto ht2 = itops.convolve(itops.convmat(beta, fc, TIME_ORDERED), g);
768768

769769
// Check that the two methods give the same result
770770
EXPECT_LT(max_element(abs(h - h2)), 1e-14);

0 commit comments

Comments
 (0)